@contember/binding-legacy 2.1.0-alpha.37 → 2.1.0-alpha.39

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 (390) hide show
  1. package/dist/development/index.cjs +34 -0
  2. package/dist/development/index.cjs.map +1 -0
  3. package/dist/development/index.js +28 -0
  4. package/dist/development/index.js.map +1 -0
  5. package/dist/development/src/accessorTree/NormalizedPersistedData.cjs +10 -0
  6. package/dist/development/src/accessorTree/NormalizedPersistedData.cjs.map +1 -0
  7. package/dist/development/src/accessorTree/NormalizedPersistedData.js +10 -0
  8. package/dist/development/src/accessorTree/NormalizedPersistedData.js.map +1 -0
  9. package/dist/development/src/accessors/EntityAccessorImpl.cjs +179 -0
  10. package/dist/development/src/accessors/EntityAccessorImpl.cjs.map +1 -0
  11. package/dist/development/src/accessors/EntityAccessorImpl.js +179 -0
  12. package/dist/development/src/accessors/EntityAccessorImpl.js.map +1 -0
  13. package/dist/development/src/accessors/EntityListAccessorImpl.cjs +112 -0
  14. package/dist/development/src/accessors/EntityListAccessorImpl.cjs.map +1 -0
  15. package/dist/development/src/accessors/EntityListAccessorImpl.js +112 -0
  16. package/dist/development/src/accessors/EntityListAccessorImpl.js.map +1 -0
  17. package/dist/development/src/accessors/FieldAccessorImpl.cjs +54 -0
  18. package/dist/development/src/accessors/FieldAccessorImpl.cjs.map +1 -0
  19. package/dist/development/src/accessors/FieldAccessorImpl.js +54 -0
  20. package/dist/development/src/accessors/FieldAccessorImpl.js.map +1 -0
  21. package/dist/development/src/core/AccessorErrorManager.cjs +200 -0
  22. package/dist/development/src/core/AccessorErrorManager.cjs.map +1 -0
  23. package/dist/development/src/core/AccessorErrorManager.js +200 -0
  24. package/dist/development/src/core/AccessorErrorManager.js.map +1 -0
  25. package/dist/development/src/core/Config.cjs +29 -0
  26. package/dist/development/src/core/Config.cjs.map +1 -0
  27. package/dist/development/src/core/Config.js +29 -0
  28. package/dist/development/src/core/Config.js.map +1 -0
  29. package/dist/development/src/core/DataBinding.cjs +357 -0
  30. package/dist/development/src/core/DataBinding.cjs.map +1 -0
  31. package/dist/development/src/core/DataBinding.js +357 -0
  32. package/dist/development/src/core/DataBinding.js.map +1 -0
  33. package/dist/development/src/core/DirtinessTracker.cjs +26 -0
  34. package/dist/development/src/core/DirtinessTracker.cjs.map +1 -0
  35. package/dist/development/src/core/DirtinessTracker.js +26 -0
  36. package/dist/development/src/core/DirtinessTracker.js.map +1 -0
  37. package/dist/development/src/core/ErrorsPreprocessor.cjs +180 -0
  38. package/dist/development/src/core/ErrorsPreprocessor.cjs.map +1 -0
  39. package/dist/development/src/core/ErrorsPreprocessor.js +180 -0
  40. package/dist/development/src/core/ErrorsPreprocessor.js.map +1 -0
  41. package/dist/development/src/core/EventManager.cjs +439 -0
  42. package/dist/development/src/core/EventManager.cjs.map +1 -0
  43. package/dist/development/src/core/EventManager.js +439 -0
  44. package/dist/development/src/core/EventManager.js.map +1 -0
  45. package/dist/development/src/core/MutationGenerator.cjs +670 -0
  46. package/dist/development/src/core/MutationGenerator.cjs.map +1 -0
  47. package/dist/development/src/core/MutationGenerator.js +670 -0
  48. package/dist/development/src/core/MutationGenerator.js.map +1 -0
  49. package/dist/development/src/core/QueryGenerator.cjs +110 -0
  50. package/dist/development/src/core/QueryGenerator.cjs.map +1 -0
  51. package/dist/development/src/core/QueryGenerator.js +110 -0
  52. package/dist/development/src/core/QueryGenerator.js.map +1 -0
  53. package/dist/development/src/core/RealmKeyGenerator.cjs +42 -0
  54. package/dist/development/src/core/RealmKeyGenerator.cjs.map +1 -0
  55. package/dist/development/src/core/RealmKeyGenerator.js +42 -0
  56. package/dist/development/src/core/RealmKeyGenerator.js.map +1 -0
  57. package/dist/development/src/core/RequestResponseNormalizer.cjs +136 -0
  58. package/dist/development/src/core/RequestResponseNormalizer.cjs.map +1 -0
  59. package/dist/development/src/core/RequestResponseNormalizer.js +136 -0
  60. package/dist/development/src/core/RequestResponseNormalizer.js.map +1 -0
  61. package/dist/development/src/core/StateInitializer.cjs +379 -0
  62. package/dist/development/src/core/StateInitializer.cjs.map +1 -0
  63. package/dist/development/src/core/StateInitializer.js +379 -0
  64. package/dist/development/src/core/StateInitializer.js.map +1 -0
  65. package/dist/development/src/core/TreeAugmenter.cjs +351 -0
  66. package/dist/development/src/core/TreeAugmenter.cjs.map +1 -0
  67. package/dist/development/src/core/TreeAugmenter.js +351 -0
  68. package/dist/development/src/core/TreeAugmenter.js.map +1 -0
  69. package/dist/development/src/core/TreeStore.cjs +172 -0
  70. package/dist/development/src/core/TreeStore.cjs.map +1 -0
  71. package/dist/development/src/core/TreeStore.js +172 -0
  72. package/dist/development/src/core/TreeStore.js.map +1 -0
  73. package/dist/development/src/core/exceptions/ErrorLocator.cjs +59 -0
  74. package/dist/development/src/core/exceptions/ErrorLocator.cjs.map +1 -0
  75. package/dist/development/src/core/exceptions/ErrorLocator.js +59 -0
  76. package/dist/development/src/core/exceptions/ErrorLocator.js.map +1 -0
  77. package/dist/development/src/core/exceptions/MarkerSugarer.cjs +51 -0
  78. package/dist/development/src/core/exceptions/MarkerSugarer.cjs.map +1 -0
  79. package/dist/development/src/core/exceptions/MarkerSugarer.js +51 -0
  80. package/dist/development/src/core/exceptions/MarkerSugarer.js.map +1 -0
  81. package/dist/development/src/core/exceptions/TreeParameterSugarer.cjs +33 -0
  82. package/dist/development/src/core/exceptions/TreeParameterSugarer.cjs.map +1 -0
  83. package/dist/development/src/core/exceptions/TreeParameterSugarer.js +33 -0
  84. package/dist/development/src/core/exceptions/TreeParameterSugarer.js.map +1 -0
  85. package/dist/development/src/core/factories/createBatchUpdatesOptions.cjs +23 -0
  86. package/dist/development/src/core/factories/createBatchUpdatesOptions.cjs.map +1 -0
  87. package/dist/development/src/core/factories/createBatchUpdatesOptions.js +23 -0
  88. package/dist/development/src/core/factories/createBatchUpdatesOptions.js.map +1 -0
  89. package/dist/development/src/core/operations/EntityOperations.cjs +224 -0
  90. package/dist/development/src/core/operations/EntityOperations.cjs.map +1 -0
  91. package/dist/development/src/core/operations/EntityOperations.js +224 -0
  92. package/dist/development/src/core/operations/EntityOperations.js.map +1 -0
  93. package/dist/development/src/core/operations/FieldOperations.cjs +92 -0
  94. package/dist/development/src/core/operations/FieldOperations.cjs.map +1 -0
  95. package/dist/development/src/core/operations/FieldOperations.js +92 -0
  96. package/dist/development/src/core/operations/FieldOperations.js.map +1 -0
  97. package/dist/development/src/core/operations/ListOperations.cjs +158 -0
  98. package/dist/development/src/core/operations/ListOperations.cjs.map +1 -0
  99. package/dist/development/src/core/operations/ListOperations.js +158 -0
  100. package/dist/development/src/core/operations/ListOperations.js.map +1 -0
  101. package/dist/development/src/core/operations/OperationsHelpers.cjs +87 -0
  102. package/dist/development/src/core/operations/OperationsHelpers.cjs.map +1 -0
  103. package/dist/development/src/core/operations/OperationsHelpers.js +87 -0
  104. package/dist/development/src/core/operations/OperationsHelpers.js.map +1 -0
  105. package/dist/development/src/core/requestAliases/MutationAlias.cjs +14 -0
  106. package/dist/development/src/core/requestAliases/MutationAlias.cjs.map +1 -0
  107. package/dist/development/src/core/requestAliases/MutationAlias.js +14 -0
  108. package/dist/development/src/core/requestAliases/MutationAlias.js.map +1 -0
  109. package/dist/development/src/core/state/StateIterator.cjs +100 -0
  110. package/dist/development/src/core/state/StateIterator.cjs.map +1 -0
  111. package/dist/development/src/core/state/StateIterator.js +100 -0
  112. package/dist/development/src/core/state/StateIterator.js.map +1 -0
  113. package/dist/development/src/core/state/getEntityMarker.cjs +5 -0
  114. package/dist/development/src/core/state/getEntityMarker.cjs.map +1 -0
  115. package/dist/development/src/core/state/getEntityMarker.js +5 -0
  116. package/dist/development/src/core/state/getEntityMarker.js.map +1 -0
  117. package/dist/development/src/core/utils/getCombinedSignal.cjs +33 -0
  118. package/dist/development/src/core/utils/getCombinedSignal.cjs.map +1 -0
  119. package/dist/development/src/core/utils/getCombinedSignal.js +33 -0
  120. package/dist/development/src/core/utils/getCombinedSignal.js.map +1 -0
  121. package/dist/development/src/fieldHelpers/helpers/FieldHelper.cjs +13 -0
  122. package/dist/development/src/fieldHelpers/helpers/FieldHelper.cjs.map +1 -0
  123. package/dist/development/src/fieldHelpers/helpers/FieldHelper.js +13 -0
  124. package/dist/development/src/fieldHelpers/helpers/FieldHelper.js.map +1 -0
  125. package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs +18 -0
  126. package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +1 -0
  127. package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js +18 -0
  128. package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -0
  129. package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.cjs +16 -0
  130. package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +1 -0
  131. package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.js +16 -0
  132. package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -0
  133. package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.cjs +7 -0
  134. package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.cjs.map +1 -0
  135. package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.js +7 -0
  136. package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.js.map +1 -0
  137. package/dist/development/src/utils/isEmptyObject.cjs +12 -0
  138. package/dist/development/src/utils/isEmptyObject.cjs.map +1 -0
  139. package/dist/development/src/utils/isEmptyObject.js +12 -0
  140. package/dist/development/src/utils/isEmptyObject.js.map +1 -0
  141. package/dist/production/index.cjs +34 -0
  142. package/dist/production/index.cjs.map +1 -0
  143. package/dist/production/index.js +28 -0
  144. package/dist/production/index.js.map +1 -0
  145. package/dist/production/src/accessorTree/NormalizedPersistedData.cjs +10 -0
  146. package/dist/production/src/accessorTree/NormalizedPersistedData.cjs.map +1 -0
  147. package/dist/production/src/accessorTree/NormalizedPersistedData.js +10 -0
  148. package/dist/production/src/accessorTree/NormalizedPersistedData.js.map +1 -0
  149. package/dist/production/src/accessors/EntityAccessorImpl.cjs +179 -0
  150. package/dist/production/src/accessors/EntityAccessorImpl.cjs.map +1 -0
  151. package/dist/production/src/accessors/EntityAccessorImpl.js +179 -0
  152. package/dist/production/src/accessors/EntityAccessorImpl.js.map +1 -0
  153. package/dist/production/src/accessors/EntityListAccessorImpl.cjs +112 -0
  154. package/dist/production/src/accessors/EntityListAccessorImpl.cjs.map +1 -0
  155. package/dist/production/src/accessors/EntityListAccessorImpl.js +112 -0
  156. package/dist/production/src/accessors/EntityListAccessorImpl.js.map +1 -0
  157. package/dist/production/src/accessors/FieldAccessorImpl.cjs +54 -0
  158. package/dist/production/src/accessors/FieldAccessorImpl.cjs.map +1 -0
  159. package/dist/production/src/accessors/FieldAccessorImpl.js +54 -0
  160. package/dist/production/src/accessors/FieldAccessorImpl.js.map +1 -0
  161. package/dist/production/src/core/AccessorErrorManager.cjs +200 -0
  162. package/dist/production/src/core/AccessorErrorManager.cjs.map +1 -0
  163. package/dist/production/src/core/AccessorErrorManager.js +200 -0
  164. package/dist/production/src/core/AccessorErrorManager.js.map +1 -0
  165. package/dist/production/src/core/Config.cjs +29 -0
  166. package/dist/production/src/core/Config.cjs.map +1 -0
  167. package/dist/production/src/core/Config.js +29 -0
  168. package/dist/production/src/core/Config.js.map +1 -0
  169. package/dist/production/src/core/DataBinding.cjs +357 -0
  170. package/dist/production/src/core/DataBinding.cjs.map +1 -0
  171. package/dist/production/src/core/DataBinding.js +357 -0
  172. package/dist/production/src/core/DataBinding.js.map +1 -0
  173. package/dist/production/src/core/DirtinessTracker.cjs +26 -0
  174. package/dist/production/src/core/DirtinessTracker.cjs.map +1 -0
  175. package/dist/production/src/core/DirtinessTracker.js +26 -0
  176. package/dist/production/src/core/DirtinessTracker.js.map +1 -0
  177. package/dist/production/src/core/ErrorsPreprocessor.cjs +180 -0
  178. package/dist/production/src/core/ErrorsPreprocessor.cjs.map +1 -0
  179. package/dist/production/src/core/ErrorsPreprocessor.js +180 -0
  180. package/dist/production/src/core/ErrorsPreprocessor.js.map +1 -0
  181. package/dist/production/src/core/EventManager.cjs +413 -0
  182. package/dist/production/src/core/EventManager.cjs.map +1 -0
  183. package/dist/production/src/core/EventManager.js +413 -0
  184. package/dist/production/src/core/EventManager.js.map +1 -0
  185. package/dist/production/src/core/MutationGenerator.cjs +670 -0
  186. package/dist/production/src/core/MutationGenerator.cjs.map +1 -0
  187. package/dist/production/src/core/MutationGenerator.js +670 -0
  188. package/dist/production/src/core/MutationGenerator.js.map +1 -0
  189. package/dist/production/src/core/QueryGenerator.cjs +110 -0
  190. package/dist/production/src/core/QueryGenerator.cjs.map +1 -0
  191. package/dist/production/src/core/QueryGenerator.js +110 -0
  192. package/dist/production/src/core/QueryGenerator.js.map +1 -0
  193. package/dist/production/src/core/RealmKeyGenerator.cjs +42 -0
  194. package/dist/production/src/core/RealmKeyGenerator.cjs.map +1 -0
  195. package/dist/production/src/core/RealmKeyGenerator.js +42 -0
  196. package/dist/production/src/core/RealmKeyGenerator.js.map +1 -0
  197. package/dist/production/src/core/RequestResponseNormalizer.cjs +136 -0
  198. package/dist/production/src/core/RequestResponseNormalizer.cjs.map +1 -0
  199. package/dist/production/src/core/RequestResponseNormalizer.js +136 -0
  200. package/dist/production/src/core/RequestResponseNormalizer.js.map +1 -0
  201. package/dist/production/src/core/StateInitializer.cjs +379 -0
  202. package/dist/production/src/core/StateInitializer.cjs.map +1 -0
  203. package/dist/production/src/core/StateInitializer.js +379 -0
  204. package/dist/production/src/core/StateInitializer.js.map +1 -0
  205. package/dist/production/src/core/TreeAugmenter.cjs +351 -0
  206. package/dist/production/src/core/TreeAugmenter.cjs.map +1 -0
  207. package/dist/production/src/core/TreeAugmenter.js +351 -0
  208. package/dist/production/src/core/TreeAugmenter.js.map +1 -0
  209. package/dist/production/src/core/TreeStore.cjs +172 -0
  210. package/dist/production/src/core/TreeStore.cjs.map +1 -0
  211. package/dist/production/src/core/TreeStore.js +172 -0
  212. package/dist/production/src/core/TreeStore.js.map +1 -0
  213. package/dist/production/src/core/exceptions/ErrorLocator.cjs +59 -0
  214. package/dist/production/src/core/exceptions/ErrorLocator.cjs.map +1 -0
  215. package/dist/production/src/core/exceptions/ErrorLocator.js +59 -0
  216. package/dist/production/src/core/exceptions/ErrorLocator.js.map +1 -0
  217. package/dist/production/src/core/exceptions/MarkerSugarer.cjs +51 -0
  218. package/dist/production/src/core/exceptions/MarkerSugarer.cjs.map +1 -0
  219. package/dist/production/src/core/exceptions/MarkerSugarer.js +51 -0
  220. package/dist/production/src/core/exceptions/MarkerSugarer.js.map +1 -0
  221. package/dist/production/src/core/exceptions/TreeParameterSugarer.cjs +33 -0
  222. package/dist/production/src/core/exceptions/TreeParameterSugarer.cjs.map +1 -0
  223. package/dist/production/src/core/exceptions/TreeParameterSugarer.js +33 -0
  224. package/dist/production/src/core/exceptions/TreeParameterSugarer.js.map +1 -0
  225. package/dist/production/src/core/factories/createBatchUpdatesOptions.cjs +23 -0
  226. package/dist/production/src/core/factories/createBatchUpdatesOptions.cjs.map +1 -0
  227. package/dist/production/src/core/factories/createBatchUpdatesOptions.js +23 -0
  228. package/dist/production/src/core/factories/createBatchUpdatesOptions.js.map +1 -0
  229. package/dist/production/src/core/operations/EntityOperations.cjs +224 -0
  230. package/dist/production/src/core/operations/EntityOperations.cjs.map +1 -0
  231. package/dist/production/src/core/operations/EntityOperations.js +224 -0
  232. package/dist/production/src/core/operations/EntityOperations.js.map +1 -0
  233. package/dist/production/src/core/operations/FieldOperations.cjs +73 -0
  234. package/dist/production/src/core/operations/FieldOperations.cjs.map +1 -0
  235. package/dist/production/src/core/operations/FieldOperations.js +73 -0
  236. package/dist/production/src/core/operations/FieldOperations.js.map +1 -0
  237. package/dist/production/src/core/operations/ListOperations.cjs +158 -0
  238. package/dist/production/src/core/operations/ListOperations.cjs.map +1 -0
  239. package/dist/production/src/core/operations/ListOperations.js +158 -0
  240. package/dist/production/src/core/operations/ListOperations.js.map +1 -0
  241. package/dist/production/src/core/operations/OperationsHelpers.cjs +87 -0
  242. package/dist/production/src/core/operations/OperationsHelpers.cjs.map +1 -0
  243. package/dist/production/src/core/operations/OperationsHelpers.js +87 -0
  244. package/dist/production/src/core/operations/OperationsHelpers.js.map +1 -0
  245. package/dist/production/src/core/requestAliases/MutationAlias.cjs +14 -0
  246. package/dist/production/src/core/requestAliases/MutationAlias.cjs.map +1 -0
  247. package/dist/production/src/core/requestAliases/MutationAlias.js +14 -0
  248. package/dist/production/src/core/requestAliases/MutationAlias.js.map +1 -0
  249. package/dist/production/src/core/state/StateIterator.cjs +100 -0
  250. package/dist/production/src/core/state/StateIterator.cjs.map +1 -0
  251. package/dist/production/src/core/state/StateIterator.js +100 -0
  252. package/dist/production/src/core/state/StateIterator.js.map +1 -0
  253. package/dist/production/src/core/state/getEntityMarker.cjs +5 -0
  254. package/dist/production/src/core/state/getEntityMarker.cjs.map +1 -0
  255. package/dist/production/src/core/state/getEntityMarker.js +5 -0
  256. package/dist/production/src/core/state/getEntityMarker.js.map +1 -0
  257. package/dist/production/src/core/utils/getCombinedSignal.cjs +33 -0
  258. package/dist/production/src/core/utils/getCombinedSignal.cjs.map +1 -0
  259. package/dist/production/src/core/utils/getCombinedSignal.js +33 -0
  260. package/dist/production/src/core/utils/getCombinedSignal.js.map +1 -0
  261. package/dist/production/src/fieldHelpers/helpers/FieldHelper.cjs +13 -0
  262. package/dist/production/src/fieldHelpers/helpers/FieldHelper.cjs.map +1 -0
  263. package/dist/production/src/fieldHelpers/helpers/FieldHelper.js +13 -0
  264. package/dist/production/src/fieldHelpers/helpers/FieldHelper.js.map +1 -0
  265. package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs +18 -0
  266. package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +1 -0
  267. package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js +18 -0
  268. package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -0
  269. package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.cjs +16 -0
  270. package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +1 -0
  271. package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.js +16 -0
  272. package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -0
  273. package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.cjs +7 -0
  274. package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.cjs.map +1 -0
  275. package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.js +7 -0
  276. package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.js.map +1 -0
  277. package/dist/production/src/utils/isEmptyObject.cjs +12 -0
  278. package/dist/production/src/utils/isEmptyObject.cjs.map +1 -0
  279. package/dist/production/src/utils/isEmptyObject.js +12 -0
  280. package/dist/production/src/utils/isEmptyObject.js.map +1 -0
  281. package/dist/types/accessorTree/NormalizedPersistedData.d.ts +18 -0
  282. package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -0
  283. package/dist/types/accessorTree/index.d.ts +2 -0
  284. package/dist/types/accessorTree/index.d.ts.map +1 -0
  285. package/dist/types/accessors/BindingConfig.d.ts +6 -0
  286. package/dist/types/accessors/BindingConfig.d.ts.map +1 -0
  287. package/dist/types/accessors/EntityAccessorImpl.d.ts +56 -0
  288. package/dist/types/accessors/EntityAccessorImpl.d.ts.map +1 -0
  289. package/dist/types/accessors/EntityListAccessorImpl.d.ts +57 -0
  290. package/dist/types/accessors/EntityListAccessorImpl.d.ts.map +1 -0
  291. package/dist/types/accessors/FieldAccessorImpl.d.ts +32 -0
  292. package/dist/types/accessors/FieldAccessorImpl.d.ts.map +1 -0
  293. package/dist/types/accessors/index.d.ts +5 -0
  294. package/dist/types/accessors/index.d.ts.map +1 -0
  295. package/dist/types/core/AccessorErrorManager.d.ts +25 -0
  296. package/dist/types/core/AccessorErrorManager.d.ts.map +1 -0
  297. package/dist/types/core/Config.d.ts +9 -0
  298. package/dist/types/core/Config.d.ts.map +1 -0
  299. package/dist/types/core/DataBinding.d.ts +54 -0
  300. package/dist/types/core/DataBinding.d.ts.map +1 -0
  301. package/dist/types/core/DirtinessTracker.d.ts +9 -0
  302. package/dist/types/core/DirtinessTracker.d.ts.map +1 -0
  303. package/dist/types/core/ErrorsPreprocessor.d.ts +34 -0
  304. package/dist/types/core/ErrorsPreprocessor.d.ts.map +1 -0
  305. package/dist/types/core/EventManager.d.ts +57 -0
  306. package/dist/types/core/EventManager.d.ts.map +1 -0
  307. package/dist/types/core/MutationGenerator.d.ts +49 -0
  308. package/dist/types/core/MutationGenerator.d.ts.map +1 -0
  309. package/dist/types/core/QueryGenerator.d.ts +13 -0
  310. package/dist/types/core/QueryGenerator.d.ts.map +1 -0
  311. package/dist/types/core/RealmKeyGenerator.d.ts +10 -0
  312. package/dist/types/core/RealmKeyGenerator.d.ts.map +1 -0
  313. package/dist/types/core/RequestResponseNormalizer.d.ts +11 -0
  314. package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -0
  315. package/dist/types/core/StateInitializer.d.ts +34 -0
  316. package/dist/types/core/StateInitializer.d.ts.map +1 -0
  317. package/dist/types/core/TreeAugmenter.d.ts +25 -0
  318. package/dist/types/core/TreeAugmenter.d.ts.map +1 -0
  319. package/dist/types/core/TreeStore.d.ts +30 -0
  320. package/dist/types/core/TreeStore.d.ts.map +1 -0
  321. package/dist/types/core/UpdateMetadata.d.ts +4 -0
  322. package/dist/types/core/UpdateMetadata.d.ts.map +1 -0
  323. package/dist/types/core/exceptions/ErrorLocator.d.ts +8 -0
  324. package/dist/types/core/exceptions/ErrorLocator.d.ts.map +1 -0
  325. package/dist/types/core/exceptions/MarkerSugarer.d.ts +10 -0
  326. package/dist/types/core/exceptions/MarkerSugarer.d.ts.map +1 -0
  327. package/dist/types/core/exceptions/TreeParameterSugarer.d.ts +11 -0
  328. package/dist/types/core/exceptions/TreeParameterSugarer.d.ts.map +1 -0
  329. package/dist/types/core/factories/createBatchUpdatesOptions.d.ts +5 -0
  330. package/dist/types/core/factories/createBatchUpdatesOptions.d.ts.map +1 -0
  331. package/dist/types/core/factories/index.d.ts +2 -0
  332. package/dist/types/core/factories/index.d.ts.map +1 -0
  333. package/dist/types/core/index.d.ts +9 -0
  334. package/dist/types/core/index.d.ts.map +1 -0
  335. package/dist/types/core/operations/EntityOperations.d.ts +26 -0
  336. package/dist/types/core/operations/EntityOperations.d.ts.map +1 -0
  337. package/dist/types/core/operations/FieldOperations.d.ts +22 -0
  338. package/dist/types/core/operations/FieldOperations.d.ts.map +1 -0
  339. package/dist/types/core/operations/ListOperations.d.ts +32 -0
  340. package/dist/types/core/operations/ListOperations.d.ts.map +1 -0
  341. package/dist/types/core/operations/OperationsHelpers.d.ts +14 -0
  342. package/dist/types/core/operations/OperationsHelpers.d.ts.map +1 -0
  343. package/dist/types/core/operations/index.d.ts +4 -0
  344. package/dist/types/core/operations/index.d.ts.map +1 -0
  345. package/dist/types/core/requestAliases/MutationAlias.d.ts +6 -0
  346. package/dist/types/core/requestAliases/MutationAlias.d.ts.map +1 -0
  347. package/dist/types/core/requestAliases/index.d.ts +2 -0
  348. package/dist/types/core/requestAliases/index.d.ts.map +1 -0
  349. package/dist/types/core/state/EntityListState.d.ts +29 -0
  350. package/dist/types/core/state/EntityListState.d.ts.map +1 -0
  351. package/dist/types/core/state/EntityRealmState.d.ts +44 -0
  352. package/dist/types/core/state/EntityRealmState.d.ts.map +1 -0
  353. package/dist/types/core/state/EntityState.d.ts +11 -0
  354. package/dist/types/core/state/EntityState.d.ts.map +1 -0
  355. package/dist/types/core/state/FieldState.d.ts +19 -0
  356. package/dist/types/core/state/FieldState.d.ts.map +1 -0
  357. package/dist/types/core/state/StateIterator.d.ts +14 -0
  358. package/dist/types/core/state/StateIterator.d.ts.map +1 -0
  359. package/dist/types/core/state/StateNode.d.ts +8 -0
  360. package/dist/types/core/state/StateNode.d.ts.map +1 -0
  361. package/dist/types/core/state/getEntityMarker.d.ts +3 -0
  362. package/dist/types/core/state/getEntityMarker.d.ts.map +1 -0
  363. package/dist/types/core/state/index.d.ts +8 -0
  364. package/dist/types/core/state/index.d.ts.map +1 -0
  365. package/dist/types/core/utils/getCombinedSignal.d.ts +2 -0
  366. package/dist/types/core/utils/getCombinedSignal.d.ts.map +1 -0
  367. package/dist/types/core/utils/index.d.ts +2 -0
  368. package/dist/types/core/utils/index.d.ts.map +1 -0
  369. package/dist/types/fieldHelpers/helpers/FieldHelper.d.ts +7 -0
  370. package/dist/types/fieldHelpers/helpers/FieldHelper.d.ts.map +1 -0
  371. package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts +10 -0
  372. package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts.map +1 -0
  373. package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts +10 -0
  374. package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts.map +1 -0
  375. package/dist/types/fieldHelpers/helpers/index.d.ts +3 -0
  376. package/dist/types/fieldHelpers/helpers/index.d.ts.map +1 -0
  377. package/dist/types/fieldHelpers/index.d.ts +2 -0
  378. package/dist/types/fieldHelpers/index.d.ts.map +1 -0
  379. package/dist/types/index.d.ts +5 -0
  380. package/dist/types/index.d.ts.map +1 -0
  381. package/dist/types/tsconfig.tsbuildinfo +1 -0
  382. package/dist/types/utils/assertNever.d.ts +2 -0
  383. package/dist/types/utils/assertNever.d.ts.map +1 -0
  384. package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts +2 -0
  385. package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts.map +1 -0
  386. package/dist/types/utils/index.d.ts +4 -0
  387. package/dist/types/utils/index.d.ts.map +1 -0
  388. package/dist/types/utils/isEmptyObject.d.ts +2 -0
  389. package/dist/types/utils/isEmptyObject.d.ts.map +1 -0
  390. package/package.json +5 -5
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const bindingCommon = require("@contember/binding-common");
4
+ const OperationsHelpers = require("./OperationsHelpers.cjs");
5
+ const ErrorLocator = require("../exceptions/ErrorLocator.cjs");
6
+ const getEntityMarker = require("../state/getEntityMarker.cjs");
7
+ const StateIterator = require("../state/StateIterator.cjs");
8
+ class EntityOperations {
9
+ constructor(accessorErrorManager, batchUpdatesOptions, eventManager, stateInitializer, treeStore) {
10
+ this.accessorErrorManager = accessorErrorManager;
11
+ this.batchUpdatesOptions = batchUpdatesOptions;
12
+ this.eventManager = eventManager;
13
+ this.stateInitializer = stateInitializer;
14
+ this.treeStore = treeStore;
15
+ }
16
+ addError(entityRealm, error) {
17
+ return this.accessorErrorManager.addError(entityRealm, error);
18
+ }
19
+ addEventListener(state, event, listener) {
20
+ if (state.eventListeners === void 0) {
21
+ state.eventListeners = new bindingCommon.EventListenersStore();
22
+ }
23
+ return state.eventListeners.add(event, listener);
24
+ }
25
+ batchUpdates(state, performUpdates) {
26
+ this.eventManager.syncOperation(() => {
27
+ performUpdates(state.getAccessor, this.batchUpdatesOptions);
28
+ });
29
+ }
30
+ connectEntityAtField(outerState, fieldName, entityToConnect) {
31
+ this.eventManager.syncOperation(() => {
32
+ const stateToConnect = OperationsHelpers.OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect);
33
+ const fieldsToConnect = getEntityMarker.getEntityMarker(stateToConnect).fields;
34
+ const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue);
35
+ const entityName = outerState.entity.entityName;
36
+ const fieldSchema = this.treeStore.schema.getEntityFieldOrUndefined(entityName, fieldName);
37
+ if (fieldSchema === void 0) {
38
+ throw new bindingCommon.BindingError(
39
+ `EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.
40
+
41
+ Entity located at: ${ErrorLocator.ErrorLocator.locateInternalState(outerState)}.`
42
+ );
43
+ } else if (fieldSchema.__typename === "_Column") {
44
+ throw new bindingCommon.BindingError(
45
+ `EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because it's not a has-one relation.
46
+
47
+ Entity located at: ${ErrorLocator.ErrorLocator.locateInternalState(outerState)}.`
48
+ );
49
+ }
50
+ for (const state of StateIterator.StateIterator.eachSiblingRealm(outerState)) {
51
+ const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker.getEntityMarker(state).fields, fieldName, "connect", state === outerState);
52
+ for (const targetHasOneMarker of targetHasOneMarkers) {
53
+ const previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName);
54
+ if (previouslyConnectedState === void 0 || previouslyConnectedState.type === "field" || previouslyConnectedState.type === "entityList") {
55
+ OperationsHelpers.OperationsHelpers.rejectInvalidAccessorTree();
56
+ }
57
+ if (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {
58
+ throw new bindingCommon.BindingError(
59
+ `EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} an entity of type '${stateToConnect.entity.entityName}' but '${previouslyConnectedState.entity.entityName}' is expected.
60
+
61
+ Entity located at: ${ErrorLocator.ErrorLocator.locateInternalState(outerState)}.`
62
+ );
63
+ }
64
+ try {
65
+ bindingCommon.MarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect);
66
+ } catch (error) {
67
+ if (error instanceof bindingCommon.LocalizedBindingError) {
68
+ throw new bindingCommon.BindingError(
69
+ `EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields areincompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.
70
+
71
+ ${error.message}
72
+
73
+ ` + (error.markerPath.length > 1 ? `Incompatibility found at: ${ErrorLocator.ErrorLocator.locateMarkerPath(error.markerPath)}.
74
+
75
+ ` : "") + `Entity located at: ${ErrorLocator.ErrorLocator.locateInternalState(state)}.`
76
+ );
77
+ }
78
+ throw error;
79
+ }
80
+ if (previouslyConnectedState === stateToConnect || previouslyConnectedState.entity.id.value === stateToConnect.entity.id.value) {
81
+ continue;
82
+ }
83
+ this.treeStore.disposeOfRealm(previouslyConnectedState);
84
+ let changesDelta = 0;
85
+ if (previouslyConnectedState.type === "entityRealm") {
86
+ changesDelta -= previouslyConnectedState.unpersistedChangesCount;
87
+ }
88
+ const persistedId = persistedData?.get(targetHasOneMarker.placeholderName)?.value;
89
+ if (persistedId instanceof bindingCommon.ServerId && persistedId.value === stateToConnect.entity.id.value) {
90
+ changesDelta--;
91
+ } else if (persistedId instanceof bindingCommon.ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {
92
+ changesDelta++;
93
+ } else if (!previouslyConnectedState.entity.id.existsOnServer) {
94
+ if (persistedId === null || persistedId === void 0 && (!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing)) {
95
+ changesDelta++;
96
+ }
97
+ }
98
+ if (stateToConnect.type === "entityRealm") {
99
+ changesDelta += stateToConnect.unpersistedChangesCount;
100
+ }
101
+ this.stateInitializer.initializeEntityRealm(
102
+ stateToConnect.entity.id,
103
+ stateToConnect.entity.entityName,
104
+ previouslyConnectedState.blueprint,
105
+ stateToConnect
106
+ );
107
+ this.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName);
108
+ this.eventManager.registerJustUpdated(state, changesDelta);
109
+ }
110
+ }
111
+ });
112
+ }
113
+ disconnectEntityAtField(outerState, fieldName, initializeReplacement) {
114
+ this.eventManager.syncOperation(() => {
115
+ const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue);
116
+ for (const state of StateIterator.StateIterator.eachSiblingRealm(outerState)) {
117
+ const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker.getEntityMarker(state).fields, fieldName, "disconnect", state === outerState);
118
+ for (const targetHasOneMarker of targetHasOneMarkers) {
119
+ const stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName);
120
+ if (stateToDisconnect === void 0 || stateToDisconnect.type !== "entityRealm" && stateToDisconnect.type !== "entityRealmStub") {
121
+ OperationsHelpers.OperationsHelpers.rejectInvalidAccessorTree();
122
+ }
123
+ this.treeStore.disposeOfRealm(stateToDisconnect);
124
+ let changesDelta = 0;
125
+ if (stateToDisconnect.type === "entityRealm") {
126
+ changesDelta -= stateToDisconnect.unpersistedChangesCount;
127
+ }
128
+ const persistedId = persistedData?.get(targetHasOneMarker.placeholderName)?.value;
129
+ if (persistedId instanceof bindingCommon.ServerId) {
130
+ if (persistedId.value === stateToDisconnect.entity.id.value) {
131
+ changesDelta++;
132
+ }
133
+ } else if (persistedId === void 0 || persistedId === null) {
134
+ if (stateToDisconnect.entity.id.existsOnServer) {
135
+ changesDelta--;
136
+ }
137
+ } else ;
138
+ const newEntity = this.stateInitializer.initializeEntityRealm(
139
+ new bindingCommon.UnpersistedEntityDummyId(),
140
+ stateToDisconnect.entity.entityName,
141
+ stateToDisconnect.blueprint
142
+ );
143
+ this.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement);
144
+ this.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName);
145
+ this.eventManager.registerJustUpdated(state, changesDelta);
146
+ }
147
+ }
148
+ });
149
+ }
150
+ deleteEntity(realm) {
151
+ this.eventManager.syncOperation(() => {
152
+ const outerState = realm.entity;
153
+ outerState.isScheduledForDeletion = true;
154
+ const entityId = outerState.id;
155
+ for (const realmToDelete of outerState.realms.values()) {
156
+ let parent;
157
+ let changesDelta = 0;
158
+ if (realmToDelete.blueprint.type === "listEntity") {
159
+ parent = realmToDelete.blueprint.parent;
160
+ parent.children.delete(entityId.value);
161
+ if (entityId.existsOnServer) {
162
+ if (parent.plannedRemovals === void 0) {
163
+ parent.plannedRemovals = /* @__PURE__ */ new Map();
164
+ }
165
+ changesDelta++;
166
+ parent.plannedRemovals.set(entityId.value, "delete");
167
+ }
168
+ } else if (realmToDelete.blueprint.type === "hasOne") {
169
+ parent = realmToDelete.blueprint.parent;
170
+ const placeholderName = realmToDelete.blueprint.marker.placeholderName;
171
+ if (entityId.existsOnServer) {
172
+ if (parent.plannedHasOneDeletions === void 0) {
173
+ parent.plannedHasOneDeletions = /* @__PURE__ */ new Map();
174
+ }
175
+ changesDelta++;
176
+ parent.plannedHasOneDeletions.set(placeholderName, realmToDelete);
177
+ }
178
+ this.stateInitializer.initializeEntityRealm(
179
+ new bindingCommon.UnpersistedEntityDummyId(),
180
+ outerState.entityName,
181
+ realmToDelete.blueprint
182
+ );
183
+ this.eventManager.registerUpdatedConnection(parent, placeholderName);
184
+ } else if (realmToDelete.blueprint.type === "subTree") {
185
+ parent = void 0;
186
+ if (realmToDelete.type === "entityRealm") {
187
+ this.eventManager.registerJustUpdated(realmToDelete, 1);
188
+ }
189
+ } else {
190
+ return bindingCommon.assertNever(realmToDelete.blueprint);
191
+ }
192
+ if (parent) {
193
+ if (realmToDelete.type === "entityRealm") {
194
+ changesDelta -= realmToDelete.unpersistedChangesCount;
195
+ }
196
+ this.eventManager.registerJustUpdated(parent, changesDelta);
197
+ if (realmToDelete.type === "entityRealm") {
198
+ parent.childrenWithPendingUpdates?.delete(realmToDelete);
199
+ }
200
+ this.treeStore.disposeOfRealm(realmToDelete);
201
+ }
202
+ }
203
+ });
204
+ }
205
+ *resolveHasOneRelationMarkers(container, field, type, mustExists) {
206
+ const placeholders = container.placeholders.get(field);
207
+ if (placeholders === void 0) {
208
+ if (!mustExists) {
209
+ return;
210
+ }
211
+ throw new bindingCommon.BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`);
212
+ }
213
+ const normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders];
214
+ for (const placeholderName of normalizedPlaceholders) {
215
+ const hasOneRelation = container.markers.get(placeholderName);
216
+ if (!(hasOneRelation instanceof bindingCommon.HasOneRelationMarker)) {
217
+ throw new bindingCommon.BindingError(`Cannot ${type} at field '${field}' as it doesn't refer to a has one relation.`);
218
+ }
219
+ yield hasOneRelation;
220
+ }
221
+ }
222
+ }
223
+ exports.EntityOperations = EntityOperations;
224
+ //# sourceMappingURL=EntityOperations.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityOperations.cjs","sources":["../../../../../../packages/binding-legacy/src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '@contember/binding-common'\nimport { ServerId, UnpersistedEntityDummyId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { EntityFieldMarkersContainer, HasOneRelationMarker } from '@contember/binding-common'\nimport type { FieldName } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport type { EventManager } from '../EventManager'\nimport { LocalizedBindingError } from '@contember/binding-common'\nimport { MarkerComparator } from '@contember/binding-common'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '@contember/binding-common'\nimport { ErrorLocator } from '../exceptions/ErrorLocator'\n\nexport class EntityOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(entityRealm: EntityRealmState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(entityRealm, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tstate: EntityRealmState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityRealmState, performUpdates: EntityAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntityAtField(outerState: EntityRealmState, fieldName: FieldName, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst fieldsToConnect = getEntityMarker(stateToConnect).fields\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityFieldOrUndefined(entityName, fieldName)\n\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.\\n\\n`\n\t\t\t\t\t\t+ `Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t} else if (fieldSchema.__typename === '_Column') {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because `\n\t\t\t\t\t\t+ `it's not a has-one relation.\\n\\n`\n\t\t\t\t\t\t+ `Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'connect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === undefined\n\t\t\t\t\t\t|| previouslyConnectedState.type === 'field'\n\t\t\t\t\t\t|| previouslyConnectedState.type === 'entityList'\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} `\n\t\t\t\t\t\t\t\t+ `an entity of type '${stateToConnect.entity.entityName}' but `\n\t\t\t\t\t\t\t\t+ `'${previouslyConnectedState.entity.entityName}' is expected.\\n\\n`\n\t\t\t\t\t\t\t\t+ `Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t\t`EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields are`\n\t\t\t\t\t\t\t\t\t+ `incompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.\\n\\n`\n\t\t\t\t\t\t\t\t\t+ `${error.message}\\n\\n`\n\t\t\t\t\t\t\t\t\t+ (error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t\t: '')\n\t\t\t\t\t\t\t\t\t+ `Entity located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === stateToConnect\n\t\t\t\t\t\t|| previouslyConnectedState.entity.id.value === stateToConnect.entity.id.value\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue // Do nothing.\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO remove from planned deletions if appropriate\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(previouslyConnectedState)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (previouslyConnectedState.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= previouslyConnectedState.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)?.value\n\t\t\t\t\tif (persistedId instanceof ServerId && persistedId.value === stateToConnect.entity.id.value) {\n\t\t\t\t\t\tchangesDelta-- // It was removed from the list but now we're adding it back.\n\t\t\t\t\t} else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tpersistedId === null // We're updating.\n\t\t\t\t\t\t\t|| (persistedId === undefined // We're creating.\n\t\t\t\t\t\t\t\t&& (!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO do something about the existing state…\n\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tstateToConnect.entity.id,\n\t\t\t\t\t\tstateToConnect.entity.entityName,\n\t\t\t\t\t\tpreviouslyConnectedState.blueprint,\n\t\t\t\t\t\tstateToConnect,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntityAtField(\n\t\touterState: EntityRealmState,\n\t\tfieldName: FieldName,\n\t\tinitializeReplacement: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'disconnect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstateToDisconnect === undefined\n\t\t\t\t\t\t|| (stateToDisconnect.type !== 'entityRealm' && stateToDisconnect.type !== 'entityRealmStub')\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(stateToDisconnect)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (stateToDisconnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= stateToDisconnect.unpersistedChangesCount\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)?.value\n\n\t\t\t\t\tif (persistedId instanceof ServerId) {\n\t\t\t\t\t\tif (persistedId.value === stateToDisconnect.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // Disconnecting the persisted entity.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Do nothing. The entity that is being disconnected is already different from the one that is persisted,\n\t\t\t\t\t\t\t// and so we must have already accounted for this change.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (persistedId === undefined || persistedId === null) {\n\t\t\t\t\t\tif (stateToDisconnect.entity.id.existsOnServer) {\n\t\t\t\t\t\t\t// We had connected a persisted entity, which increased the changes count,\n\t\t\t\t\t\t\t// but now are disconnecting it again.\n\t\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Do nothing. Disconnecting unpersisted entities doesn't change the count.\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\tstateToDisconnect.entity.entityName,\n\t\t\t\t\t\tstateToDisconnect.blueprint,\n\t\t\t\t\t)\n\t\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic deleteEntity(realm: EntityRealmState) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst outerState = realm.entity\n\t\t\touterState.isScheduledForDeletion = true\n\n\t\t\tconst entityId = outerState.id\n\n\t\t\tfor (const realmToDelete of outerState.realms.values()) {\n\t\t\t\tlet parent: EntityRealmState | EntityRealmStateStub | EntityListState | undefined\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (realmToDelete.blueprint.type === 'listEntity') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tparent.children.delete(entityId.value)\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedRemovals === undefined) {\n\t\t\t\t\t\t\tparent.plannedRemovals = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedRemovals.set(entityId.value, 'delete')\n\t\t\t\t\t}\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'hasOne') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tconst placeholderName = realmToDelete.blueprint.marker.placeholderName\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedHasOneDeletions === undefined) {\n\t\t\t\t\t\t\tparent.plannedHasOneDeletions = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedHasOneDeletions.set(placeholderName, realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\touterState.entityName,\n\t\t\t\t\t\trealmToDelete.blueprint,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(parent, placeholderName)\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'subTree') {\n\t\t\t\t\tparent = undefined\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(realmToDelete, 1)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(realmToDelete.blueprint)\n\t\t\t\t}\n\n\t\t\t\tif (parent) {\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\t// Undoing whatever this had caused\n\t\t\t\t\t\tchangesDelta -= realmToDelete.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(parent, changesDelta)\n\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates?.delete(realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.treeStore.disposeOfRealm(realmToDelete)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate *resolveHasOneRelationMarkers(\n\t\tcontainer: EntityFieldMarkersContainer,\n\t\tfield: FieldName,\n\t\ttype: 'connect' | 'disconnect',\n\t\tmustExists: boolean,\n\t): IterableIterator<HasOneRelationMarker> {\n\t\tconst placeholders = container.placeholders.get(field)\n\n\t\tif (placeholders === undefined) {\n\t\t\tif (!mustExists) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`)\n\t\t}\n\t\tconst normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]\n\n\t\tfor (const placeholderName of normalizedPlaceholders) {\n\t\t\tconst hasOneRelation = container.markers.get(placeholderName)\n\n\t\t\tif (!(hasOneRelation instanceof HasOneRelationMarker)) {\n\t\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it doesn't refer to a has one relation.`)\n\t\t\t}\n\t\t\tyield hasOneRelation\n\t\t}\n\t}\n}\n"],"names":["EventListenersStore","OperationsHelpers","getEntityMarker","BindingError","ErrorLocator","StateIterator","MarkerComparator","LocalizedBindingError","ServerId","UnpersistedEntityDummyId","assertNever","HasOneRelationMarker"],"mappings":";;;;;;;AAiBO,MAAM,iBAAiB;AAAA,EACtB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;AALgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEI,SAAS,aAA+B,OAAwC;AACtF,WAAO,KAAK,qBAAqB,SAAS,aAAa,KAAK;AAAA,EAC7D;AAAA,EAEO,iBACN,OACA,OACA,UACC;AACD,QAAI,MAAM,mBAAmB,QAAW;AACvC,YAAM,iBAAiB,IAAIA,kCAAA;AAAA,IAC5B;AACA,WAAO,MAAM,eAAe,IAAI,OAAO,QAAQ;AAAA,EAChD;AAAA,EAEO,aAAa,OAAyB,gBAAoD;AAChG,SAAK,aAAa,cAAc,MAAM;AACrC,qBAAe,MAAM,aAAa,KAAK,mBAAmB;AAAA,IAC3D,CAAC;AAAA,EACF;AAAA,EAEO,qBAAqB,YAA8B,WAAsB,iBAAiC;AACh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Q,YAAY;AAE1D,cAAI,cAAc,SAAS,eAAe;AACzC,mBAAO,4BAA4B,OAAO,aAAa;AAAA,UACxD;AACA,eAAK,UAAU,eAAe,aAAa;AAAA,QAC5C;AAAA,MACD;AAAA,IACD,CAAC;AAAA,EACF;AAAA,EAEA,CAAS,6BACR,WACA,OACA,MACA,YACyC;AACzC,UAAM,eAAe,UAAU,aAAa,IAAI,KAAK;AAErD,QAAI,iBAAiB,QAAW;AAC/B,UAAI,CAAC,YAAY;AAChB;AAAA,MACD;AACA,YAAM,IAAIP,cAAAA,aAAa,UAAU,IAAI,cAAc,KAAK,iDAAiD;AAAA,IAC1G;AACA,UAAM,yBAAyB,wBAAwB,MAAM,eAAe,CAAC,YAAY;AAEzF,eAAW,mBAAmB,wBAAwB;AACrD,YAAM,iBAAiB,UAAU,QAAQ,IAAI,eAAe;AAE5D,UAAI,EAAE,0BAA0BQ,cAAAA,uBAAuB;AACtD,cAAM,IAAIR,cAAAA,aAAa,UAAU,IAAI,cAAc,KAAK,8CAA8C;AAAA,MACvG;AACA,YAAM;AAAA,IACP;AAAA,EACD;AACD;;"}
@@ -0,0 +1,224 @@
1
+ import { EventListenersStore, BindingError, MarkerComparator, LocalizedBindingError, ServerId, UnpersistedEntityDummyId, assertNever, HasOneRelationMarker } from "@contember/binding-common";
2
+ import { OperationsHelpers } from "./OperationsHelpers.js";
3
+ import { ErrorLocator } from "../exceptions/ErrorLocator.js";
4
+ import { getEntityMarker } from "../state/getEntityMarker.js";
5
+ import { StateIterator } from "../state/StateIterator.js";
6
+ class EntityOperations {
7
+ constructor(accessorErrorManager, batchUpdatesOptions, eventManager, stateInitializer, treeStore) {
8
+ this.accessorErrorManager = accessorErrorManager;
9
+ this.batchUpdatesOptions = batchUpdatesOptions;
10
+ this.eventManager = eventManager;
11
+ this.stateInitializer = stateInitializer;
12
+ this.treeStore = treeStore;
13
+ }
14
+ addError(entityRealm, error) {
15
+ return this.accessorErrorManager.addError(entityRealm, error);
16
+ }
17
+ addEventListener(state, event, listener) {
18
+ if (state.eventListeners === void 0) {
19
+ state.eventListeners = new EventListenersStore();
20
+ }
21
+ return state.eventListeners.add(event, listener);
22
+ }
23
+ batchUpdates(state, performUpdates) {
24
+ this.eventManager.syncOperation(() => {
25
+ performUpdates(state.getAccessor, this.batchUpdatesOptions);
26
+ });
27
+ }
28
+ connectEntityAtField(outerState, fieldName, entityToConnect) {
29
+ this.eventManager.syncOperation(() => {
30
+ const stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect);
31
+ const fieldsToConnect = getEntityMarker(stateToConnect).fields;
32
+ const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue);
33
+ const entityName = outerState.entity.entityName;
34
+ const fieldSchema = this.treeStore.schema.getEntityFieldOrUndefined(entityName, fieldName);
35
+ if (fieldSchema === void 0) {
36
+ throw new BindingError(
37
+ `EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.
38
+
39
+ Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`
40
+ );
41
+ } else if (fieldSchema.__typename === "_Column") {
42
+ throw new BindingError(
43
+ `EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because it's not a has-one relation.
44
+
45
+ Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`
46
+ );
47
+ }
48
+ for (const state of StateIterator.eachSiblingRealm(outerState)) {
49
+ const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, "connect", state === outerState);
50
+ for (const targetHasOneMarker of targetHasOneMarkers) {
51
+ const previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName);
52
+ if (previouslyConnectedState === void 0 || previouslyConnectedState.type === "field" || previouslyConnectedState.type === "entityList") {
53
+ OperationsHelpers.rejectInvalidAccessorTree();
54
+ }
55
+ if (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {
56
+ throw new BindingError(
57
+ `EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} an entity of type '${stateToConnect.entity.entityName}' but '${previouslyConnectedState.entity.entityName}' is expected.
58
+
59
+ Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`
60
+ );
61
+ }
62
+ try {
63
+ MarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect);
64
+ } catch (error) {
65
+ if (error instanceof LocalizedBindingError) {
66
+ throw new BindingError(
67
+ `EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields areincompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.
68
+
69
+ ${error.message}
70
+
71
+ ` + (error.markerPath.length > 1 ? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.
72
+
73
+ ` : "") + `Entity located at: ${ErrorLocator.locateInternalState(state)}.`
74
+ );
75
+ }
76
+ throw error;
77
+ }
78
+ if (previouslyConnectedState === stateToConnect || previouslyConnectedState.entity.id.value === stateToConnect.entity.id.value) {
79
+ continue;
80
+ }
81
+ this.treeStore.disposeOfRealm(previouslyConnectedState);
82
+ let changesDelta = 0;
83
+ if (previouslyConnectedState.type === "entityRealm") {
84
+ changesDelta -= previouslyConnectedState.unpersistedChangesCount;
85
+ }
86
+ const persistedId = persistedData?.get(targetHasOneMarker.placeholderName)?.value;
87
+ if (persistedId instanceof ServerId && persistedId.value === stateToConnect.entity.id.value) {
88
+ changesDelta--;
89
+ } else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {
90
+ changesDelta++;
91
+ } else if (!previouslyConnectedState.entity.id.existsOnServer) {
92
+ if (persistedId === null || persistedId === void 0 && (!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing)) {
93
+ changesDelta++;
94
+ }
95
+ }
96
+ if (stateToConnect.type === "entityRealm") {
97
+ changesDelta += stateToConnect.unpersistedChangesCount;
98
+ }
99
+ this.stateInitializer.initializeEntityRealm(
100
+ stateToConnect.entity.id,
101
+ stateToConnect.entity.entityName,
102
+ previouslyConnectedState.blueprint,
103
+ stateToConnect
104
+ );
105
+ this.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName);
106
+ this.eventManager.registerJustUpdated(state, changesDelta);
107
+ }
108
+ }
109
+ });
110
+ }
111
+ disconnectEntityAtField(outerState, fieldName, initializeReplacement) {
112
+ this.eventManager.syncOperation(() => {
113
+ const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue);
114
+ for (const state of StateIterator.eachSiblingRealm(outerState)) {
115
+ const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, "disconnect", state === outerState);
116
+ for (const targetHasOneMarker of targetHasOneMarkers) {
117
+ const stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName);
118
+ if (stateToDisconnect === void 0 || stateToDisconnect.type !== "entityRealm" && stateToDisconnect.type !== "entityRealmStub") {
119
+ OperationsHelpers.rejectInvalidAccessorTree();
120
+ }
121
+ this.treeStore.disposeOfRealm(stateToDisconnect);
122
+ let changesDelta = 0;
123
+ if (stateToDisconnect.type === "entityRealm") {
124
+ changesDelta -= stateToDisconnect.unpersistedChangesCount;
125
+ }
126
+ const persistedId = persistedData?.get(targetHasOneMarker.placeholderName)?.value;
127
+ if (persistedId instanceof ServerId) {
128
+ if (persistedId.value === stateToDisconnect.entity.id.value) {
129
+ changesDelta++;
130
+ }
131
+ } else if (persistedId === void 0 || persistedId === null) {
132
+ if (stateToDisconnect.entity.id.existsOnServer) {
133
+ changesDelta--;
134
+ }
135
+ } else ;
136
+ const newEntity = this.stateInitializer.initializeEntityRealm(
137
+ new UnpersistedEntityDummyId(),
138
+ stateToDisconnect.entity.entityName,
139
+ stateToDisconnect.blueprint
140
+ );
141
+ this.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement);
142
+ this.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName);
143
+ this.eventManager.registerJustUpdated(state, changesDelta);
144
+ }
145
+ }
146
+ });
147
+ }
148
+ deleteEntity(realm) {
149
+ this.eventManager.syncOperation(() => {
150
+ const outerState = realm.entity;
151
+ outerState.isScheduledForDeletion = true;
152
+ const entityId = outerState.id;
153
+ for (const realmToDelete of outerState.realms.values()) {
154
+ let parent;
155
+ let changesDelta = 0;
156
+ if (realmToDelete.blueprint.type === "listEntity") {
157
+ parent = realmToDelete.blueprint.parent;
158
+ parent.children.delete(entityId.value);
159
+ if (entityId.existsOnServer) {
160
+ if (parent.plannedRemovals === void 0) {
161
+ parent.plannedRemovals = /* @__PURE__ */ new Map();
162
+ }
163
+ changesDelta++;
164
+ parent.plannedRemovals.set(entityId.value, "delete");
165
+ }
166
+ } else if (realmToDelete.blueprint.type === "hasOne") {
167
+ parent = realmToDelete.blueprint.parent;
168
+ const placeholderName = realmToDelete.blueprint.marker.placeholderName;
169
+ if (entityId.existsOnServer) {
170
+ if (parent.plannedHasOneDeletions === void 0) {
171
+ parent.plannedHasOneDeletions = /* @__PURE__ */ new Map();
172
+ }
173
+ changesDelta++;
174
+ parent.plannedHasOneDeletions.set(placeholderName, realmToDelete);
175
+ }
176
+ this.stateInitializer.initializeEntityRealm(
177
+ new UnpersistedEntityDummyId(),
178
+ outerState.entityName,
179
+ realmToDelete.blueprint
180
+ );
181
+ this.eventManager.registerUpdatedConnection(parent, placeholderName);
182
+ } else if (realmToDelete.blueprint.type === "subTree") {
183
+ parent = void 0;
184
+ if (realmToDelete.type === "entityRealm") {
185
+ this.eventManager.registerJustUpdated(realmToDelete, 1);
186
+ }
187
+ } else {
188
+ return assertNever(realmToDelete.blueprint);
189
+ }
190
+ if (parent) {
191
+ if (realmToDelete.type === "entityRealm") {
192
+ changesDelta -= realmToDelete.unpersistedChangesCount;
193
+ }
194
+ this.eventManager.registerJustUpdated(parent, changesDelta);
195
+ if (realmToDelete.type === "entityRealm") {
196
+ parent.childrenWithPendingUpdates?.delete(realmToDelete);
197
+ }
198
+ this.treeStore.disposeOfRealm(realmToDelete);
199
+ }
200
+ }
201
+ });
202
+ }
203
+ *resolveHasOneRelationMarkers(container, field, type, mustExists) {
204
+ const placeholders = container.placeholders.get(field);
205
+ if (placeholders === void 0) {
206
+ if (!mustExists) {
207
+ return;
208
+ }
209
+ throw new BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`);
210
+ }
211
+ const normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders];
212
+ for (const placeholderName of normalizedPlaceholders) {
213
+ const hasOneRelation = container.markers.get(placeholderName);
214
+ if (!(hasOneRelation instanceof HasOneRelationMarker)) {
215
+ throw new BindingError(`Cannot ${type} at field '${field}' as it doesn't refer to a has one relation.`);
216
+ }
217
+ yield hasOneRelation;
218
+ }
219
+ }
220
+ }
221
+ export {
222
+ EntityOperations
223
+ };
224
+ //# sourceMappingURL=EntityOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityOperations.js","sources":["../../../../../../packages/binding-legacy/src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '@contember/binding-common'\nimport { ServerId, UnpersistedEntityDummyId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { EntityFieldMarkersContainer, HasOneRelationMarker } from '@contember/binding-common'\nimport type { FieldName } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport type { EventManager } from '../EventManager'\nimport { LocalizedBindingError } from '@contember/binding-common'\nimport { MarkerComparator } from '@contember/binding-common'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '@contember/binding-common'\nimport { ErrorLocator } from '../exceptions/ErrorLocator'\n\nexport class EntityOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(entityRealm: EntityRealmState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(entityRealm, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tstate: EntityRealmState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityRealmState, performUpdates: EntityAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntityAtField(outerState: EntityRealmState, fieldName: FieldName, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst fieldsToConnect = getEntityMarker(stateToConnect).fields\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityFieldOrUndefined(entityName, fieldName)\n\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.\\n\\n`\n\t\t\t\t\t\t+ `Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t} else if (fieldSchema.__typename === '_Column') {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because `\n\t\t\t\t\t\t+ `it's not a has-one relation.\\n\\n`\n\t\t\t\t\t\t+ `Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'connect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === undefined\n\t\t\t\t\t\t|| previouslyConnectedState.type === 'field'\n\t\t\t\t\t\t|| previouslyConnectedState.type === 'entityList'\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} `\n\t\t\t\t\t\t\t\t+ `an entity of type '${stateToConnect.entity.entityName}' but `\n\t\t\t\t\t\t\t\t+ `'${previouslyConnectedState.entity.entityName}' is expected.\\n\\n`\n\t\t\t\t\t\t\t\t+ `Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t\t`EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields are`\n\t\t\t\t\t\t\t\t\t+ `incompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.\\n\\n`\n\t\t\t\t\t\t\t\t\t+ `${error.message}\\n\\n`\n\t\t\t\t\t\t\t\t\t+ (error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t\t: '')\n\t\t\t\t\t\t\t\t\t+ `Entity located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === stateToConnect\n\t\t\t\t\t\t|| previouslyConnectedState.entity.id.value === stateToConnect.entity.id.value\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue // Do nothing.\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO remove from planned deletions if appropriate\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(previouslyConnectedState)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (previouslyConnectedState.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= previouslyConnectedState.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)?.value\n\t\t\t\t\tif (persistedId instanceof ServerId && persistedId.value === stateToConnect.entity.id.value) {\n\t\t\t\t\t\tchangesDelta-- // It was removed from the list but now we're adding it back.\n\t\t\t\t\t} else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tpersistedId === null // We're updating.\n\t\t\t\t\t\t\t|| (persistedId === undefined // We're creating.\n\t\t\t\t\t\t\t\t&& (!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO do something about the existing state…\n\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tstateToConnect.entity.id,\n\t\t\t\t\t\tstateToConnect.entity.entityName,\n\t\t\t\t\t\tpreviouslyConnectedState.blueprint,\n\t\t\t\t\t\tstateToConnect,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntityAtField(\n\t\touterState: EntityRealmState,\n\t\tfieldName: FieldName,\n\t\tinitializeReplacement: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'disconnect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstateToDisconnect === undefined\n\t\t\t\t\t\t|| (stateToDisconnect.type !== 'entityRealm' && stateToDisconnect.type !== 'entityRealmStub')\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(stateToDisconnect)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (stateToDisconnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= stateToDisconnect.unpersistedChangesCount\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)?.value\n\n\t\t\t\t\tif (persistedId instanceof ServerId) {\n\t\t\t\t\t\tif (persistedId.value === stateToDisconnect.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // Disconnecting the persisted entity.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Do nothing. The entity that is being disconnected is already different from the one that is persisted,\n\t\t\t\t\t\t\t// and so we must have already accounted for this change.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (persistedId === undefined || persistedId === null) {\n\t\t\t\t\t\tif (stateToDisconnect.entity.id.existsOnServer) {\n\t\t\t\t\t\t\t// We had connected a persisted entity, which increased the changes count,\n\t\t\t\t\t\t\t// but now are disconnecting it again.\n\t\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Do nothing. Disconnecting unpersisted entities doesn't change the count.\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\tstateToDisconnect.entity.entityName,\n\t\t\t\t\t\tstateToDisconnect.blueprint,\n\t\t\t\t\t)\n\t\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic deleteEntity(realm: EntityRealmState) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst outerState = realm.entity\n\t\t\touterState.isScheduledForDeletion = true\n\n\t\t\tconst entityId = outerState.id\n\n\t\t\tfor (const realmToDelete of outerState.realms.values()) {\n\t\t\t\tlet parent: EntityRealmState | EntityRealmStateStub | EntityListState | undefined\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (realmToDelete.blueprint.type === 'listEntity') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tparent.children.delete(entityId.value)\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedRemovals === undefined) {\n\t\t\t\t\t\t\tparent.plannedRemovals = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedRemovals.set(entityId.value, 'delete')\n\t\t\t\t\t}\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'hasOne') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tconst placeholderName = realmToDelete.blueprint.marker.placeholderName\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedHasOneDeletions === undefined) {\n\t\t\t\t\t\t\tparent.plannedHasOneDeletions = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedHasOneDeletions.set(placeholderName, realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\touterState.entityName,\n\t\t\t\t\t\trealmToDelete.blueprint,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(parent, placeholderName)\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'subTree') {\n\t\t\t\t\tparent = undefined\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(realmToDelete, 1)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(realmToDelete.blueprint)\n\t\t\t\t}\n\n\t\t\t\tif (parent) {\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\t// Undoing whatever this had caused\n\t\t\t\t\t\tchangesDelta -= realmToDelete.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(parent, changesDelta)\n\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates?.delete(realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.treeStore.disposeOfRealm(realmToDelete)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate *resolveHasOneRelationMarkers(\n\t\tcontainer: EntityFieldMarkersContainer,\n\t\tfield: FieldName,\n\t\ttype: 'connect' | 'disconnect',\n\t\tmustExists: boolean,\n\t): IterableIterator<HasOneRelationMarker> {\n\t\tconst placeholders = container.placeholders.get(field)\n\n\t\tif (placeholders === undefined) {\n\t\t\tif (!mustExists) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`)\n\t\t}\n\t\tconst normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]\n\n\t\tfor (const placeholderName of normalizedPlaceholders) {\n\t\t\tconst hasOneRelation = container.markers.get(placeholderName)\n\n\t\t\tif (!(hasOneRelation instanceof HasOneRelationMarker)) {\n\t\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it doesn't refer to a has one relation.`)\n\t\t\t}\n\t\t\tyield hasOneRelation\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;AAiBO,MAAM,iBAAiB;AAAA,EACtB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;AALgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;A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,mBAAS;AACT,cAAI,cAAc,SAAS,eAAe;AACzC,iBAAK,aAAa,oBAAoB,eAAe,CAAC;AAAA,UACvD;AAAA,QACD,OAAO;AACN,iBAAO,YAAY,cAAc,SAAS;AAAA,QAC3C;AAEA,YAAI,QAAQ;AACX,cAAI,cAAc,SAAS,eAAe;AAEzC,4BAAgB,cAAc;AAAA,UAC/B;AAEA,eAAK,aAAa,oBAAoB,QAAQ,YAAY;AAE1D,cAAI,cAAc,SAAS,eAAe;AACzC,mBAAO,4BAA4B,OAAO,aAAa;AAAA,UACxD;AACA,eAAK,UAAU,eAAe,aAAa;AAAA,QAC5C;AAAA,MACD;AAAA,IACD,CAAC;AAAA,EACF;AAAA,EAEA,CAAS,6BACR,WACA,OACA,MACA,YACyC;AACzC,UAAM,eAAe,UAAU,aAAa,IAAI,KAAK;AAErD,QAAI,iBAAiB,QAAW;AAC/B,UAAI,CAAC,YAAY;AAChB;AAAA,MACD;AACA,YAAM,IAAI,aAAa,UAAU,IAAI,cAAc,KAAK,iDAAiD;AAAA,IAC1G;AACA,UAAM,yBAAyB,wBAAwB,MAAM,eAAe,CAAC,YAAY;AAEzF,eAAW,mBAAmB,wBAAwB;AACrD,YAAM,iBAAiB,UAAU,QAAQ,IAAI,eAAe;AAE5D,UAAI,EAAE,0BAA0B,uBAAuB;AACtD,cAAM,IAAI,aAAa,UAAU,IAAI,cAAc,KAAK,8CAA8C;AAAA,MACvG;AACA,YAAM;AAAA,IACP;AAAA,EACD;AACD;"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const uuid = require("uuid");
4
+ const bindingCommon = require("@contember/binding-common");
5
+ const EventManager = require("../EventManager.cjs");
6
+ const OperationsHelpers = require("./OperationsHelpers.cjs");
7
+ const StateIterator = require("../state/StateIterator.cjs");
8
+ const getEntityMarker = require("../state/getEntityMarker.cjs");
9
+ class FieldOperations {
10
+ constructor(accessorErrorManager, eventManager, stateInitializer, treeStore) {
11
+ this.accessorErrorManager = accessorErrorManager;
12
+ this.eventManager = eventManager;
13
+ this.stateInitializer = stateInitializer;
14
+ this.treeStore = treeStore;
15
+ }
16
+ addError(fieldState, error) {
17
+ return this.accessorErrorManager.addError(fieldState, error);
18
+ }
19
+ clearErrors(fieldState) {
20
+ return this.accessorErrorManager.clearErrorsByState(fieldState);
21
+ }
22
+ addEventListener(state, event, listener) {
23
+ if (!state.eventListeners) {
24
+ state.eventListeners = new bindingCommon.EventListenersStore();
25
+ }
26
+ return state.eventListeners.add(event, listener);
27
+ }
28
+ updateValue(fieldState, newValue, { agent = "user" } = {}) {
29
+ this.eventManager.syncOperation(() => {
30
+ const { placeholderName, parent } = fieldState;
31
+ if (placeholderName === bindingCommon.PRIMARY_KEY_NAME) {
32
+ const entity = fieldState.parent.entity;
33
+ {
34
+ if (newValue !== fieldState.value && (fieldState.touchLog !== void 0 || entity.hasIdSetInStone)) {
35
+ throw new bindingCommon.BindingError(
36
+ `Trying to set the '${bindingCommon.PRIMARY_KEY_NAME}' field for the second time. This is prohibited.
37
+ Once set, it is immutable.`
38
+ );
39
+ }
40
+ if (typeof newValue !== "string" || !uuid.validate(newValue)) {
41
+ throw new bindingCommon.BindingError(
42
+ `Invalid value supplied for the '${bindingCommon.PRIMARY_KEY_NAME}' field. Expecting a valid uuid but '${newValue}' was given.
43
+ Hint: you may use 'FieldAccessor.asUuid.setToUuid()'.`
44
+ );
45
+ }
46
+ if (this.treeStore.entityStore.has(bindingCommon.ServerId.formatUniqueValue(newValue, entity.entityName))) {
47
+ throw new bindingCommon.BindingError(
48
+ `Trying to set the '${bindingCommon.PRIMARY_KEY_NAME}' field to '${newValue}' which is a valid uuid but is not unique. It is already in use by an existing entity.`
49
+ );
50
+ }
51
+ }
52
+ if (typeof newValue !== "string") {
53
+ throw new bindingCommon.BindingError();
54
+ }
55
+ OperationsHelpers.OperationsHelpers.changeEntityId(
56
+ this.treeStore,
57
+ this.eventManager,
58
+ this.stateInitializer,
59
+ entity,
60
+ new bindingCommon.ClientGeneratedUuid(newValue)
61
+ );
62
+ }
63
+ for (const field of StateIterator.StateIterator.eachSiblingRealmChild(this.treeStore, fieldState)) {
64
+ if (newValue === field.value) {
65
+ continue;
66
+ }
67
+ if (field.touchLog === void 0) {
68
+ field.touchLog = /* @__PURE__ */ new Set();
69
+ }
70
+ field.touchLog.add(agent);
71
+ field.value = newValue;
72
+ const resolvedValue = field.fieldMarker.defaultValue === void 0 ? newValue : newValue === null ? field.fieldMarker.defaultValue : newValue;
73
+ const normalizedPersistedValue = field.persistedValue === void 0 ? null : field.persistedValue;
74
+ const hadUnpersistedChangesBefore = field.hasUnpersistedChanges;
75
+ const hasUnpersistedChangesNow = resolvedValue !== normalizedPersistedValue;
76
+ field.hasUnpersistedChanges = hasUnpersistedChangesNow;
77
+ const shouldInfluenceUpdateCount = !getEntityMarker.getEntityMarker(parent).fields.hasAtLeastOneBearingField || !field.fieldMarker.isNonbearing || field.persistedValue !== void 0;
78
+ let changesDelta = EventManager.EventManager.NO_CHANGES_DIFFERENCE;
79
+ if (shouldInfluenceUpdateCount) {
80
+ if (!hadUnpersistedChangesBefore && hasUnpersistedChangesNow) {
81
+ changesDelta++;
82
+ } else if (hadUnpersistedChangesBefore && !hasUnpersistedChangesNow) {
83
+ changesDelta--;
84
+ }
85
+ }
86
+ this.eventManager.registerJustUpdated(field, changesDelta);
87
+ }
88
+ });
89
+ }
90
+ }
91
+ exports.FieldOperations = FieldOperations;
92
+ //# sourceMappingURL=FieldOperations.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldOperations.cjs","sources":["../../../../../../packages/binding-legacy/src/core/operations/FieldOperations.ts"],"sourcesContent":["import { validate as uuidValidate } from 'uuid'\nimport type { FieldValue } from '@contember/binding-common'\nimport {\n\tBindingError,\n\tClientGeneratedUuid,\n\tErrorAccessor,\n\tEventListenersStore,\n\tFieldAccessor,\n\tPRIMARY_KEY_NAME,\n\tServerId,\n} from '@contember/binding-common'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport { EventManager } from '../EventManager'\nimport { FieldState, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\n\nexport class FieldOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(fieldState: FieldState<any>, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(fieldState, error)\n\t}\n\n\tpublic clearErrors(fieldState: FieldState<any>): void {\n\t\treturn this.accessorErrorManager.clearErrorsByState(fieldState)\n\t}\n\n\tpublic addEventListener<\n\t\tType extends keyof FieldAccessor.FieldEventListenerMap,\n\t\tValue extends FieldValue = FieldValue,\n\t>(\n\t\tstate: FieldState<Value>,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\tif (!state.eventListeners) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic updateValue<Value extends FieldValue = FieldValue>(\n\t\tfieldState: FieldState<Value>,\n\t\tnewValue: Value | null,\n\t\t{ agent = 'user' }: FieldAccessor.UpdateOptions = {},\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst { placeholderName, parent } = fieldState\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME) {\n\t\t\t\tconst entity = fieldState.parent.entity\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (newValue !== fieldState.value && (fieldState.touchLog !== undefined || entity.hasIdSetInStone)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field for the second time. This is prohibited.\\n`\n\t\t\t\t\t\t\t\t+ `Once set, it is immutable.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (typeof newValue !== 'string' || !uuidValidate(newValue)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Invalid value supplied for the '${PRIMARY_KEY_NAME}' field. `\n\t\t\t\t\t\t\t\t+ `Expecting a valid uuid but '${newValue}' was given.\\n`\n\t\t\t\t\t\t\t\t+ `Hint: you may use 'FieldAccessor.asUuid.setToUuid()'.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (this.treeStore.entityStore.has(ServerId.formatUniqueValue(newValue, entity.entityName))) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field to '${newValue}' which is a valid uuid but is not unique. `\n\t\t\t\t\t\t\t\t+ `It is already in use by an existing entity.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof newValue !== 'string') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tOperationsHelpers.changeEntityId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tentity,\n\t\t\t\t\tnew ClientGeneratedUuid(newValue),\n\t\t\t\t)\n\t\t\t}\n\t\t\tfor (const field of StateIterator.eachSiblingRealmChild(this.treeStore, fieldState)) {\n\t\t\t\tif (newValue === field.value) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (field.touchLog === undefined) {\n\t\t\t\t\tfield.touchLog = new Set()\n\t\t\t\t}\n\t\t\t\tfield.touchLog.add(agent)\n\t\t\t\tfield.value = newValue\n\n\t\t\t\tconst resolvedValue = field.fieldMarker.defaultValue === undefined\n\t\t\t\t\t? newValue\n\t\t\t\t\t: newValue === null\n\t\t\t\t\t? field.fieldMarker.defaultValue\n\t\t\t\t\t: newValue\n\t\t\t\tconst normalizedPersistedValue = field.persistedValue === undefined ? null : field.persistedValue\n\t\t\t\tconst hadUnpersistedChangesBefore = field.hasUnpersistedChanges\n\t\t\t\tconst hasUnpersistedChangesNow = resolvedValue !== normalizedPersistedValue\n\t\t\t\tfield.hasUnpersistedChanges = hasUnpersistedChangesNow\n\n\t\t\t\tconst shouldInfluenceUpdateCount = !getEntityMarker(parent).fields.hasAtLeastOneBearingField\n\t\t\t\t\t|| !field.fieldMarker.isNonbearing\n\t\t\t\t\t|| field.persistedValue !== undefined\n\n\t\t\t\tlet changesDelta = EventManager.NO_CHANGES_DIFFERENCE\n\n\t\t\t\tif (shouldInfluenceUpdateCount) {\n\t\t\t\t\tif (!hadUnpersistedChangesBefore && hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t} else if (hadUnpersistedChangesBefore && !hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(field, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n}\n"],"names":["EventListenersStore","PRIMARY_KEY_NAME","BindingError","uuidValidate","ServerId","OperationsHelpers","ClientGeneratedUuid","StateIterator","getEntityMarker","EventManager"],"mappings":";;;;;;;;AAkBO,MAAM,gBAAgB;AAAA,EACrB,YACW,sBACA,cACA,kBACA,WAChB;AAJgB,SAAA,uBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEI,SAAS,YAA6B,OAAwC;AACpF,WAAO,KAAK,qBAAqB,SAAS,YAAY,KAAK;AAAA,EAC5D;AAAA,EAEO,YAAY,YAAmC;AACrD,WAAO,KAAK,qBAAqB,mBAAmB,UAAU;AAAA,EAC/D;AAAA,EAEO,iBAIN,OACA,OACA,UACa;AACb,QAAI,CAAC,MAAM,gBAAgB;AAC1B,YAA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