@contember/binding-legacy 2.1.0-alpha.30 → 2.1.0-alpha.36

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 (412) hide show
  1. package/package.json +10 -5
  2. package/src/accessorTree/NormalizedPersistedData.ts +1 -1
  3. package/src/accessors/EntityAccessorImpl.ts +13 -11
  4. package/src/accessors/EntityListAccessorImpl.ts +16 -7
  5. package/src/core/AccessorErrorManager.ts +2 -2
  6. package/src/core/DataBinding.ts +24 -15
  7. package/src/core/ErrorsPreprocessor.ts +4 -5
  8. package/src/core/EventManager.ts +34 -46
  9. package/src/core/MutationGenerator.ts +23 -27
  10. package/src/core/QueryGenerator.ts +4 -5
  11. package/src/core/RealmKeyGenerator.ts +5 -3
  12. package/src/core/RequestResponseNormalizer.ts +3 -8
  13. package/src/core/StateInitializer.ts +10 -18
  14. package/src/core/TreeAugmenter.ts +8 -15
  15. package/src/core/TreeStore.ts +5 -4
  16. package/src/core/operations/EntityOperations.ts +25 -25
  17. package/src/core/operations/FieldOperations.ts +15 -17
  18. package/src/core/operations/ListOperations.ts +15 -15
  19. package/src/core/operations/OperationsHelpers.ts +2 -2
  20. package/src/core/state/EntityListState.ts +3 -9
  21. package/src/fieldHelpers/helpers/TemporalFieldHelper.ts +3 -3
  22. package/src/utils/assertNever.ts +4 -4
  23. package/tests/example.test.ts +2 -2
  24. package/dist/development/index.cjs +0 -34
  25. package/dist/development/index.cjs.map +0 -1
  26. package/dist/development/index.js +0 -28
  27. package/dist/development/index.js.map +0 -1
  28. package/dist/development/src/accessorTree/NormalizedPersistedData.cjs +0 -10
  29. package/dist/development/src/accessorTree/NormalizedPersistedData.cjs.map +0 -1
  30. package/dist/development/src/accessorTree/NormalizedPersistedData.js +0 -10
  31. package/dist/development/src/accessorTree/NormalizedPersistedData.js.map +0 -1
  32. package/dist/development/src/accessors/EntityAccessorImpl.cjs +0 -179
  33. package/dist/development/src/accessors/EntityAccessorImpl.cjs.map +0 -1
  34. package/dist/development/src/accessors/EntityAccessorImpl.js +0 -179
  35. package/dist/development/src/accessors/EntityAccessorImpl.js.map +0 -1
  36. package/dist/development/src/accessors/EntityListAccessorImpl.cjs +0 -112
  37. package/dist/development/src/accessors/EntityListAccessorImpl.cjs.map +0 -1
  38. package/dist/development/src/accessors/EntityListAccessorImpl.js +0 -112
  39. package/dist/development/src/accessors/EntityListAccessorImpl.js.map +0 -1
  40. package/dist/development/src/accessors/FieldAccessorImpl.cjs +0 -54
  41. package/dist/development/src/accessors/FieldAccessorImpl.cjs.map +0 -1
  42. package/dist/development/src/accessors/FieldAccessorImpl.js +0 -54
  43. package/dist/development/src/accessors/FieldAccessorImpl.js.map +0 -1
  44. package/dist/development/src/core/AccessorErrorManager.cjs +0 -200
  45. package/dist/development/src/core/AccessorErrorManager.cjs.map +0 -1
  46. package/dist/development/src/core/AccessorErrorManager.js +0 -200
  47. package/dist/development/src/core/AccessorErrorManager.js.map +0 -1
  48. package/dist/development/src/core/Config.cjs +0 -29
  49. package/dist/development/src/core/Config.cjs.map +0 -1
  50. package/dist/development/src/core/Config.js +0 -29
  51. package/dist/development/src/core/Config.js.map +0 -1
  52. package/dist/development/src/core/DataBinding.cjs +0 -354
  53. package/dist/development/src/core/DataBinding.cjs.map +0 -1
  54. package/dist/development/src/core/DataBinding.js +0 -354
  55. package/dist/development/src/core/DataBinding.js.map +0 -1
  56. package/dist/development/src/core/DirtinessTracker.cjs +0 -26
  57. package/dist/development/src/core/DirtinessTracker.cjs.map +0 -1
  58. package/dist/development/src/core/DirtinessTracker.js +0 -26
  59. package/dist/development/src/core/DirtinessTracker.js.map +0 -1
  60. package/dist/development/src/core/ErrorsPreprocessor.cjs +0 -180
  61. package/dist/development/src/core/ErrorsPreprocessor.cjs.map +0 -1
  62. package/dist/development/src/core/ErrorsPreprocessor.js +0 -180
  63. package/dist/development/src/core/ErrorsPreprocessor.js.map +0 -1
  64. package/dist/development/src/core/EventManager.cjs +0 -439
  65. package/dist/development/src/core/EventManager.cjs.map +0 -1
  66. package/dist/development/src/core/EventManager.js +0 -439
  67. package/dist/development/src/core/EventManager.js.map +0 -1
  68. package/dist/development/src/core/MutationGenerator.cjs +0 -670
  69. package/dist/development/src/core/MutationGenerator.cjs.map +0 -1
  70. package/dist/development/src/core/MutationGenerator.js +0 -670
  71. package/dist/development/src/core/MutationGenerator.js.map +0 -1
  72. package/dist/development/src/core/QueryGenerator.cjs +0 -110
  73. package/dist/development/src/core/QueryGenerator.cjs.map +0 -1
  74. package/dist/development/src/core/QueryGenerator.js +0 -110
  75. package/dist/development/src/core/QueryGenerator.js.map +0 -1
  76. package/dist/development/src/core/RealmKeyGenerator.cjs +0 -42
  77. package/dist/development/src/core/RealmKeyGenerator.cjs.map +0 -1
  78. package/dist/development/src/core/RealmKeyGenerator.js +0 -42
  79. package/dist/development/src/core/RealmKeyGenerator.js.map +0 -1
  80. package/dist/development/src/core/RequestResponseNormalizer.cjs +0 -136
  81. package/dist/development/src/core/RequestResponseNormalizer.cjs.map +0 -1
  82. package/dist/development/src/core/RequestResponseNormalizer.js +0 -136
  83. package/dist/development/src/core/RequestResponseNormalizer.js.map +0 -1
  84. package/dist/development/src/core/StateInitializer.cjs +0 -379
  85. package/dist/development/src/core/StateInitializer.cjs.map +0 -1
  86. package/dist/development/src/core/StateInitializer.js +0 -379
  87. package/dist/development/src/core/StateInitializer.js.map +0 -1
  88. package/dist/development/src/core/TreeAugmenter.cjs +0 -354
  89. package/dist/development/src/core/TreeAugmenter.cjs.map +0 -1
  90. package/dist/development/src/core/TreeAugmenter.js +0 -354
  91. package/dist/development/src/core/TreeAugmenter.js.map +0 -1
  92. package/dist/development/src/core/TreeStore.cjs +0 -172
  93. package/dist/development/src/core/TreeStore.cjs.map +0 -1
  94. package/dist/development/src/core/TreeStore.js +0 -172
  95. package/dist/development/src/core/TreeStore.js.map +0 -1
  96. package/dist/development/src/core/exceptions/ErrorLocator.cjs +0 -59
  97. package/dist/development/src/core/exceptions/ErrorLocator.cjs.map +0 -1
  98. package/dist/development/src/core/exceptions/ErrorLocator.js +0 -59
  99. package/dist/development/src/core/exceptions/ErrorLocator.js.map +0 -1
  100. package/dist/development/src/core/exceptions/MarkerSugarer.cjs +0 -51
  101. package/dist/development/src/core/exceptions/MarkerSugarer.cjs.map +0 -1
  102. package/dist/development/src/core/exceptions/MarkerSugarer.js +0 -51
  103. package/dist/development/src/core/exceptions/MarkerSugarer.js.map +0 -1
  104. package/dist/development/src/core/exceptions/TreeParameterSugarer.cjs +0 -33
  105. package/dist/development/src/core/exceptions/TreeParameterSugarer.cjs.map +0 -1
  106. package/dist/development/src/core/exceptions/TreeParameterSugarer.js +0 -33
  107. package/dist/development/src/core/exceptions/TreeParameterSugarer.js.map +0 -1
  108. package/dist/development/src/core/factories/createBatchUpdatesOptions.cjs +0 -23
  109. package/dist/development/src/core/factories/createBatchUpdatesOptions.cjs.map +0 -1
  110. package/dist/development/src/core/factories/createBatchUpdatesOptions.js +0 -23
  111. package/dist/development/src/core/factories/createBatchUpdatesOptions.js.map +0 -1
  112. package/dist/development/src/core/operations/EntityOperations.cjs +0 -226
  113. package/dist/development/src/core/operations/EntityOperations.cjs.map +0 -1
  114. package/dist/development/src/core/operations/EntityOperations.js +0 -226
  115. package/dist/development/src/core/operations/EntityOperations.js.map +0 -1
  116. package/dist/development/src/core/operations/FieldOperations.cjs +0 -92
  117. package/dist/development/src/core/operations/FieldOperations.cjs.map +0 -1
  118. package/dist/development/src/core/operations/FieldOperations.js +0 -92
  119. package/dist/development/src/core/operations/FieldOperations.js.map +0 -1
  120. package/dist/development/src/core/operations/ListOperations.cjs +0 -158
  121. package/dist/development/src/core/operations/ListOperations.cjs.map +0 -1
  122. package/dist/development/src/core/operations/ListOperations.js +0 -158
  123. package/dist/development/src/core/operations/ListOperations.js.map +0 -1
  124. package/dist/development/src/core/operations/OperationsHelpers.cjs +0 -87
  125. package/dist/development/src/core/operations/OperationsHelpers.cjs.map +0 -1
  126. package/dist/development/src/core/operations/OperationsHelpers.js +0 -87
  127. package/dist/development/src/core/operations/OperationsHelpers.js.map +0 -1
  128. package/dist/development/src/core/requestAliases/MutationAlias.cjs +0 -14
  129. package/dist/development/src/core/requestAliases/MutationAlias.cjs.map +0 -1
  130. package/dist/development/src/core/requestAliases/MutationAlias.js +0 -14
  131. package/dist/development/src/core/requestAliases/MutationAlias.js.map +0 -1
  132. package/dist/development/src/core/state/StateIterator.cjs +0 -100
  133. package/dist/development/src/core/state/StateIterator.cjs.map +0 -1
  134. package/dist/development/src/core/state/StateIterator.js +0 -100
  135. package/dist/development/src/core/state/StateIterator.js.map +0 -1
  136. package/dist/development/src/core/state/getEntityMarker.cjs +0 -5
  137. package/dist/development/src/core/state/getEntityMarker.cjs.map +0 -1
  138. package/dist/development/src/core/state/getEntityMarker.js +0 -5
  139. package/dist/development/src/core/state/getEntityMarker.js.map +0 -1
  140. package/dist/development/src/core/utils/getCombinedSignal.cjs +0 -33
  141. package/dist/development/src/core/utils/getCombinedSignal.cjs.map +0 -1
  142. package/dist/development/src/core/utils/getCombinedSignal.js +0 -33
  143. package/dist/development/src/core/utils/getCombinedSignal.js.map +0 -1
  144. package/dist/development/src/fieldHelpers/helpers/FieldHelper.cjs +0 -13
  145. package/dist/development/src/fieldHelpers/helpers/FieldHelper.cjs.map +0 -1
  146. package/dist/development/src/fieldHelpers/helpers/FieldHelper.js +0 -13
  147. package/dist/development/src/fieldHelpers/helpers/FieldHelper.js.map +0 -1
  148. package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs +0 -18
  149. package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +0 -1
  150. package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js +0 -18
  151. package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +0 -1
  152. package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.cjs +0 -16
  153. package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +0 -1
  154. package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.js +0 -16
  155. package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.js.map +0 -1
  156. package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.cjs +0 -7
  157. package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.cjs.map +0 -1
  158. package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.js +0 -7
  159. package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.js.map +0 -1
  160. package/dist/development/src/utils/isEmptyObject.cjs +0 -12
  161. package/dist/development/src/utils/isEmptyObject.cjs.map +0 -1
  162. package/dist/development/src/utils/isEmptyObject.js +0 -12
  163. package/dist/development/src/utils/isEmptyObject.js.map +0 -1
  164. package/dist/production/index.cjs +0 -34
  165. package/dist/production/index.cjs.map +0 -1
  166. package/dist/production/index.js +0 -28
  167. package/dist/production/index.js.map +0 -1
  168. package/dist/production/src/accessorTree/NormalizedPersistedData.cjs +0 -10
  169. package/dist/production/src/accessorTree/NormalizedPersistedData.cjs.map +0 -1
  170. package/dist/production/src/accessorTree/NormalizedPersistedData.js +0 -10
  171. package/dist/production/src/accessorTree/NormalizedPersistedData.js.map +0 -1
  172. package/dist/production/src/accessors/EntityAccessorImpl.cjs +0 -179
  173. package/dist/production/src/accessors/EntityAccessorImpl.cjs.map +0 -1
  174. package/dist/production/src/accessors/EntityAccessorImpl.js +0 -179
  175. package/dist/production/src/accessors/EntityAccessorImpl.js.map +0 -1
  176. package/dist/production/src/accessors/EntityListAccessorImpl.cjs +0 -112
  177. package/dist/production/src/accessors/EntityListAccessorImpl.cjs.map +0 -1
  178. package/dist/production/src/accessors/EntityListAccessorImpl.js +0 -112
  179. package/dist/production/src/accessors/EntityListAccessorImpl.js.map +0 -1
  180. package/dist/production/src/accessors/FieldAccessorImpl.cjs +0 -54
  181. package/dist/production/src/accessors/FieldAccessorImpl.cjs.map +0 -1
  182. package/dist/production/src/accessors/FieldAccessorImpl.js +0 -54
  183. package/dist/production/src/accessors/FieldAccessorImpl.js.map +0 -1
  184. package/dist/production/src/core/AccessorErrorManager.cjs +0 -200
  185. package/dist/production/src/core/AccessorErrorManager.cjs.map +0 -1
  186. package/dist/production/src/core/AccessorErrorManager.js +0 -200
  187. package/dist/production/src/core/AccessorErrorManager.js.map +0 -1
  188. package/dist/production/src/core/Config.cjs +0 -29
  189. package/dist/production/src/core/Config.cjs.map +0 -1
  190. package/dist/production/src/core/Config.js +0 -29
  191. package/dist/production/src/core/Config.js.map +0 -1
  192. package/dist/production/src/core/DataBinding.cjs +0 -354
  193. package/dist/production/src/core/DataBinding.cjs.map +0 -1
  194. package/dist/production/src/core/DataBinding.js +0 -354
  195. package/dist/production/src/core/DataBinding.js.map +0 -1
  196. package/dist/production/src/core/DirtinessTracker.cjs +0 -26
  197. package/dist/production/src/core/DirtinessTracker.cjs.map +0 -1
  198. package/dist/production/src/core/DirtinessTracker.js +0 -26
  199. package/dist/production/src/core/DirtinessTracker.js.map +0 -1
  200. package/dist/production/src/core/ErrorsPreprocessor.cjs +0 -180
  201. package/dist/production/src/core/ErrorsPreprocessor.cjs.map +0 -1
  202. package/dist/production/src/core/ErrorsPreprocessor.js +0 -180
  203. package/dist/production/src/core/ErrorsPreprocessor.js.map +0 -1
  204. package/dist/production/src/core/EventManager.cjs +0 -413
  205. package/dist/production/src/core/EventManager.cjs.map +0 -1
  206. package/dist/production/src/core/EventManager.js +0 -413
  207. package/dist/production/src/core/EventManager.js.map +0 -1
  208. package/dist/production/src/core/MutationGenerator.cjs +0 -670
  209. package/dist/production/src/core/MutationGenerator.cjs.map +0 -1
  210. package/dist/production/src/core/MutationGenerator.js +0 -670
  211. package/dist/production/src/core/MutationGenerator.js.map +0 -1
  212. package/dist/production/src/core/QueryGenerator.cjs +0 -110
  213. package/dist/production/src/core/QueryGenerator.cjs.map +0 -1
  214. package/dist/production/src/core/QueryGenerator.js +0 -110
  215. package/dist/production/src/core/QueryGenerator.js.map +0 -1
  216. package/dist/production/src/core/RealmKeyGenerator.cjs +0 -42
  217. package/dist/production/src/core/RealmKeyGenerator.cjs.map +0 -1
  218. package/dist/production/src/core/RealmKeyGenerator.js +0 -42
  219. package/dist/production/src/core/RealmKeyGenerator.js.map +0 -1
  220. package/dist/production/src/core/RequestResponseNormalizer.cjs +0 -136
  221. package/dist/production/src/core/RequestResponseNormalizer.cjs.map +0 -1
  222. package/dist/production/src/core/RequestResponseNormalizer.js +0 -136
  223. package/dist/production/src/core/RequestResponseNormalizer.js.map +0 -1
  224. package/dist/production/src/core/StateInitializer.cjs +0 -379
  225. package/dist/production/src/core/StateInitializer.cjs.map +0 -1
  226. package/dist/production/src/core/StateInitializer.js +0 -379
  227. package/dist/production/src/core/StateInitializer.js.map +0 -1
  228. package/dist/production/src/core/TreeAugmenter.cjs +0 -354
  229. package/dist/production/src/core/TreeAugmenter.cjs.map +0 -1
  230. package/dist/production/src/core/TreeAugmenter.js +0 -354
  231. package/dist/production/src/core/TreeAugmenter.js.map +0 -1
  232. package/dist/production/src/core/TreeStore.cjs +0 -172
  233. package/dist/production/src/core/TreeStore.cjs.map +0 -1
  234. package/dist/production/src/core/TreeStore.js +0 -172
  235. package/dist/production/src/core/TreeStore.js.map +0 -1
  236. package/dist/production/src/core/exceptions/ErrorLocator.cjs +0 -59
  237. package/dist/production/src/core/exceptions/ErrorLocator.cjs.map +0 -1
  238. package/dist/production/src/core/exceptions/ErrorLocator.js +0 -59
  239. package/dist/production/src/core/exceptions/ErrorLocator.js.map +0 -1
  240. package/dist/production/src/core/exceptions/MarkerSugarer.cjs +0 -51
  241. package/dist/production/src/core/exceptions/MarkerSugarer.cjs.map +0 -1
  242. package/dist/production/src/core/exceptions/MarkerSugarer.js +0 -51
  243. package/dist/production/src/core/exceptions/MarkerSugarer.js.map +0 -1
  244. package/dist/production/src/core/exceptions/TreeParameterSugarer.cjs +0 -33
  245. package/dist/production/src/core/exceptions/TreeParameterSugarer.cjs.map +0 -1
  246. package/dist/production/src/core/exceptions/TreeParameterSugarer.js +0 -33
  247. package/dist/production/src/core/exceptions/TreeParameterSugarer.js.map +0 -1
  248. package/dist/production/src/core/factories/createBatchUpdatesOptions.cjs +0 -23
  249. package/dist/production/src/core/factories/createBatchUpdatesOptions.cjs.map +0 -1
  250. package/dist/production/src/core/factories/createBatchUpdatesOptions.js +0 -23
  251. package/dist/production/src/core/factories/createBatchUpdatesOptions.js.map +0 -1
  252. package/dist/production/src/core/operations/EntityOperations.cjs +0 -226
  253. package/dist/production/src/core/operations/EntityOperations.cjs.map +0 -1
  254. package/dist/production/src/core/operations/EntityOperations.js +0 -226
  255. package/dist/production/src/core/operations/EntityOperations.js.map +0 -1
  256. package/dist/production/src/core/operations/FieldOperations.cjs +0 -73
  257. package/dist/production/src/core/operations/FieldOperations.cjs.map +0 -1
  258. package/dist/production/src/core/operations/FieldOperations.js +0 -73
  259. package/dist/production/src/core/operations/FieldOperations.js.map +0 -1
  260. package/dist/production/src/core/operations/ListOperations.cjs +0 -158
  261. package/dist/production/src/core/operations/ListOperations.cjs.map +0 -1
  262. package/dist/production/src/core/operations/ListOperations.js +0 -158
  263. package/dist/production/src/core/operations/ListOperations.js.map +0 -1
  264. package/dist/production/src/core/operations/OperationsHelpers.cjs +0 -87
  265. package/dist/production/src/core/operations/OperationsHelpers.cjs.map +0 -1
  266. package/dist/production/src/core/operations/OperationsHelpers.js +0 -87
  267. package/dist/production/src/core/operations/OperationsHelpers.js.map +0 -1
  268. package/dist/production/src/core/requestAliases/MutationAlias.cjs +0 -14
  269. package/dist/production/src/core/requestAliases/MutationAlias.cjs.map +0 -1
  270. package/dist/production/src/core/requestAliases/MutationAlias.js +0 -14
  271. package/dist/production/src/core/requestAliases/MutationAlias.js.map +0 -1
  272. package/dist/production/src/core/state/StateIterator.cjs +0 -100
  273. package/dist/production/src/core/state/StateIterator.cjs.map +0 -1
  274. package/dist/production/src/core/state/StateIterator.js +0 -100
  275. package/dist/production/src/core/state/StateIterator.js.map +0 -1
  276. package/dist/production/src/core/state/getEntityMarker.cjs +0 -5
  277. package/dist/production/src/core/state/getEntityMarker.cjs.map +0 -1
  278. package/dist/production/src/core/state/getEntityMarker.js +0 -5
  279. package/dist/production/src/core/state/getEntityMarker.js.map +0 -1
  280. package/dist/production/src/core/utils/getCombinedSignal.cjs +0 -33
  281. package/dist/production/src/core/utils/getCombinedSignal.cjs.map +0 -1
  282. package/dist/production/src/core/utils/getCombinedSignal.js +0 -33
  283. package/dist/production/src/core/utils/getCombinedSignal.js.map +0 -1
  284. package/dist/production/src/fieldHelpers/helpers/FieldHelper.cjs +0 -13
  285. package/dist/production/src/fieldHelpers/helpers/FieldHelper.cjs.map +0 -1
  286. package/dist/production/src/fieldHelpers/helpers/FieldHelper.js +0 -13
  287. package/dist/production/src/fieldHelpers/helpers/FieldHelper.js.map +0 -1
  288. package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs +0 -18
  289. package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +0 -1
  290. package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js +0 -18
  291. package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +0 -1
  292. package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.cjs +0 -16
  293. package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +0 -1
  294. package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.js +0 -16
  295. package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.js.map +0 -1
  296. package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.cjs +0 -7
  297. package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.cjs.map +0 -1
  298. package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.js +0 -7
  299. package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.js.map +0 -1
  300. package/dist/production/src/utils/isEmptyObject.cjs +0 -12
  301. package/dist/production/src/utils/isEmptyObject.cjs.map +0 -1
  302. package/dist/production/src/utils/isEmptyObject.js +0 -12
  303. package/dist/production/src/utils/isEmptyObject.js.map +0 -1
  304. package/dist/types/accessorTree/NormalizedPersistedData.d.ts +0 -18
  305. package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +0 -1
  306. package/dist/types/accessorTree/index.d.ts +0 -2
  307. package/dist/types/accessorTree/index.d.ts.map +0 -1
  308. package/dist/types/accessors/BindingConfig.d.ts +0 -6
  309. package/dist/types/accessors/BindingConfig.d.ts.map +0 -1
  310. package/dist/types/accessors/EntityAccessorImpl.d.ts +0 -56
  311. package/dist/types/accessors/EntityAccessorImpl.d.ts.map +0 -1
  312. package/dist/types/accessors/EntityListAccessorImpl.d.ts +0 -57
  313. package/dist/types/accessors/EntityListAccessorImpl.d.ts.map +0 -1
  314. package/dist/types/accessors/FieldAccessorImpl.d.ts +0 -32
  315. package/dist/types/accessors/FieldAccessorImpl.d.ts.map +0 -1
  316. package/dist/types/accessors/index.d.ts +0 -5
  317. package/dist/types/accessors/index.d.ts.map +0 -1
  318. package/dist/types/core/AccessorErrorManager.d.ts +0 -25
  319. package/dist/types/core/AccessorErrorManager.d.ts.map +0 -1
  320. package/dist/types/core/Config.d.ts +0 -9
  321. package/dist/types/core/Config.d.ts.map +0 -1
  322. package/dist/types/core/DataBinding.d.ts +0 -54
  323. package/dist/types/core/DataBinding.d.ts.map +0 -1
  324. package/dist/types/core/DirtinessTracker.d.ts +0 -9
  325. package/dist/types/core/DirtinessTracker.d.ts.map +0 -1
  326. package/dist/types/core/ErrorsPreprocessor.d.ts +0 -34
  327. package/dist/types/core/ErrorsPreprocessor.d.ts.map +0 -1
  328. package/dist/types/core/EventManager.d.ts +0 -57
  329. package/dist/types/core/EventManager.d.ts.map +0 -1
  330. package/dist/types/core/MutationGenerator.d.ts +0 -49
  331. package/dist/types/core/MutationGenerator.d.ts.map +0 -1
  332. package/dist/types/core/QueryGenerator.d.ts +0 -13
  333. package/dist/types/core/QueryGenerator.d.ts.map +0 -1
  334. package/dist/types/core/RealmKeyGenerator.d.ts +0 -10
  335. package/dist/types/core/RealmKeyGenerator.d.ts.map +0 -1
  336. package/dist/types/core/RequestResponseNormalizer.d.ts +0 -11
  337. package/dist/types/core/RequestResponseNormalizer.d.ts.map +0 -1
  338. package/dist/types/core/StateInitializer.d.ts +0 -34
  339. package/dist/types/core/StateInitializer.d.ts.map +0 -1
  340. package/dist/types/core/TreeAugmenter.d.ts +0 -25
  341. package/dist/types/core/TreeAugmenter.d.ts.map +0 -1
  342. package/dist/types/core/TreeStore.d.ts +0 -30
  343. package/dist/types/core/TreeStore.d.ts.map +0 -1
  344. package/dist/types/core/UpdateMetadata.d.ts +0 -4
  345. package/dist/types/core/UpdateMetadata.d.ts.map +0 -1
  346. package/dist/types/core/exceptions/ErrorLocator.d.ts +0 -8
  347. package/dist/types/core/exceptions/ErrorLocator.d.ts.map +0 -1
  348. package/dist/types/core/exceptions/MarkerSugarer.d.ts +0 -10
  349. package/dist/types/core/exceptions/MarkerSugarer.d.ts.map +0 -1
  350. package/dist/types/core/exceptions/TreeParameterSugarer.d.ts +0 -11
  351. package/dist/types/core/exceptions/TreeParameterSugarer.d.ts.map +0 -1
  352. package/dist/types/core/factories/createBatchUpdatesOptions.d.ts +0 -5
  353. package/dist/types/core/factories/createBatchUpdatesOptions.d.ts.map +0 -1
  354. package/dist/types/core/factories/index.d.ts +0 -2
  355. package/dist/types/core/factories/index.d.ts.map +0 -1
  356. package/dist/types/core/index.d.ts +0 -9
  357. package/dist/types/core/index.d.ts.map +0 -1
  358. package/dist/types/core/operations/EntityOperations.d.ts +0 -26
  359. package/dist/types/core/operations/EntityOperations.d.ts.map +0 -1
  360. package/dist/types/core/operations/FieldOperations.d.ts +0 -22
  361. package/dist/types/core/operations/FieldOperations.d.ts.map +0 -1
  362. package/dist/types/core/operations/ListOperations.d.ts +0 -32
  363. package/dist/types/core/operations/ListOperations.d.ts.map +0 -1
  364. package/dist/types/core/operations/OperationsHelpers.d.ts +0 -14
  365. package/dist/types/core/operations/OperationsHelpers.d.ts.map +0 -1
  366. package/dist/types/core/operations/index.d.ts +0 -4
  367. package/dist/types/core/operations/index.d.ts.map +0 -1
  368. package/dist/types/core/requestAliases/MutationAlias.d.ts +0 -6
  369. package/dist/types/core/requestAliases/MutationAlias.d.ts.map +0 -1
  370. package/dist/types/core/requestAliases/index.d.ts +0 -2
  371. package/dist/types/core/requestAliases/index.d.ts.map +0 -1
  372. package/dist/types/core/state/EntityListState.d.ts +0 -29
  373. package/dist/types/core/state/EntityListState.d.ts.map +0 -1
  374. package/dist/types/core/state/EntityRealmState.d.ts +0 -44
  375. package/dist/types/core/state/EntityRealmState.d.ts.map +0 -1
  376. package/dist/types/core/state/EntityState.d.ts +0 -11
  377. package/dist/types/core/state/EntityState.d.ts.map +0 -1
  378. package/dist/types/core/state/FieldState.d.ts +0 -19
  379. package/dist/types/core/state/FieldState.d.ts.map +0 -1
  380. package/dist/types/core/state/StateIterator.d.ts +0 -14
  381. package/dist/types/core/state/StateIterator.d.ts.map +0 -1
  382. package/dist/types/core/state/StateNode.d.ts +0 -8
  383. package/dist/types/core/state/StateNode.d.ts.map +0 -1
  384. package/dist/types/core/state/getEntityMarker.d.ts +0 -3
  385. package/dist/types/core/state/getEntityMarker.d.ts.map +0 -1
  386. package/dist/types/core/state/index.d.ts +0 -8
  387. package/dist/types/core/state/index.d.ts.map +0 -1
  388. package/dist/types/core/utils/getCombinedSignal.d.ts +0 -2
  389. package/dist/types/core/utils/getCombinedSignal.d.ts.map +0 -1
  390. package/dist/types/core/utils/index.d.ts +0 -2
  391. package/dist/types/core/utils/index.d.ts.map +0 -1
  392. package/dist/types/fieldHelpers/helpers/FieldHelper.d.ts +0 -7
  393. package/dist/types/fieldHelpers/helpers/FieldHelper.d.ts.map +0 -1
  394. package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts +0 -10
  395. package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts.map +0 -1
  396. package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts +0 -10
  397. package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts.map +0 -1
  398. package/dist/types/fieldHelpers/helpers/index.d.ts +0 -3
  399. package/dist/types/fieldHelpers/helpers/index.d.ts.map +0 -1
  400. package/dist/types/fieldHelpers/index.d.ts +0 -2
  401. package/dist/types/fieldHelpers/index.d.ts.map +0 -1
  402. package/dist/types/index.d.ts +0 -5
  403. package/dist/types/index.d.ts.map +0 -1
  404. package/dist/types/tsconfig.tsbuildinfo +0 -1
  405. package/dist/types/utils/assertNever.d.ts +0 -2
  406. package/dist/types/utils/assertNever.d.ts.map +0 -1
  407. package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts +0 -2
  408. package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts.map +0 -1
  409. package/dist/types/utils/index.d.ts +0 -4
  410. package/dist/types/utils/index.d.ts.map +0 -1
  411. package/dist/types/utils/isEmptyObject.d.ts +0 -2
  412. package/dist/types/utils/isEmptyObject.d.ts.map +0 -1
@@ -1,226 +0,0 @@
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 || // We're updating.
95
- persistedId === void 0 && // We're creating.
96
- (!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing)) {
97
- changesDelta++;
98
- }
99
- }
100
- if (stateToConnect.type === "entityRealm") {
101
- changesDelta += stateToConnect.unpersistedChangesCount;
102
- }
103
- this.stateInitializer.initializeEntityRealm(
104
- stateToConnect.entity.id,
105
- stateToConnect.entity.entityName,
106
- previouslyConnectedState.blueprint,
107
- stateToConnect
108
- );
109
- this.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName);
110
- this.eventManager.registerJustUpdated(state, changesDelta);
111
- }
112
- }
113
- });
114
- }
115
- disconnectEntityAtField(outerState, fieldName, initializeReplacement) {
116
- this.eventManager.syncOperation(() => {
117
- const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue);
118
- for (const state of StateIterator.StateIterator.eachSiblingRealm(outerState)) {
119
- const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker.getEntityMarker(state).fields, fieldName, "disconnect", state === outerState);
120
- for (const targetHasOneMarker of targetHasOneMarkers) {
121
- const stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName);
122
- if (stateToDisconnect === void 0 || stateToDisconnect.type !== "entityRealm" && stateToDisconnect.type !== "entityRealmStub") {
123
- OperationsHelpers.OperationsHelpers.rejectInvalidAccessorTree();
124
- }
125
- this.treeStore.disposeOfRealm(stateToDisconnect);
126
- let changesDelta = 0;
127
- if (stateToDisconnect.type === "entityRealm") {
128
- changesDelta -= stateToDisconnect.unpersistedChangesCount;
129
- }
130
- const persistedId = persistedData?.get(targetHasOneMarker.placeholderName)?.value;
131
- if (persistedId instanceof bindingCommon.ServerId) {
132
- if (persistedId.value === stateToDisconnect.entity.id.value) {
133
- changesDelta++;
134
- }
135
- } else if (persistedId === void 0 || persistedId === null) {
136
- if (stateToDisconnect.entity.id.existsOnServer) {
137
- changesDelta--;
138
- }
139
- } else ;
140
- const newEntity = this.stateInitializer.initializeEntityRealm(
141
- new bindingCommon.UnpersistedEntityDummyId(),
142
- stateToDisconnect.entity.entityName,
143
- stateToDisconnect.blueprint
144
- );
145
- this.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement);
146
- this.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName);
147
- this.eventManager.registerJustUpdated(state, changesDelta);
148
- }
149
- }
150
- });
151
- }
152
- deleteEntity(realm) {
153
- this.eventManager.syncOperation(() => {
154
- const outerState = realm.entity;
155
- outerState.isScheduledForDeletion = true;
156
- const entityId = outerState.id;
157
- for (const realmToDelete of outerState.realms.values()) {
158
- let parent;
159
- let changesDelta = 0;
160
- if (realmToDelete.blueprint.type === "listEntity") {
161
- parent = realmToDelete.blueprint.parent;
162
- parent.children.delete(entityId.value);
163
- if (entityId.existsOnServer) {
164
- if (parent.plannedRemovals === void 0) {
165
- parent.plannedRemovals = /* @__PURE__ */ new Map();
166
- }
167
- changesDelta++;
168
- parent.plannedRemovals.set(entityId.value, "delete");
169
- }
170
- } else if (realmToDelete.blueprint.type === "hasOne") {
171
- parent = realmToDelete.blueprint.parent;
172
- const placeholderName = realmToDelete.blueprint.marker.placeholderName;
173
- if (entityId.existsOnServer) {
174
- if (parent.plannedHasOneDeletions === void 0) {
175
- parent.plannedHasOneDeletions = /* @__PURE__ */ new Map();
176
- }
177
- changesDelta++;
178
- parent.plannedHasOneDeletions.set(placeholderName, realmToDelete);
179
- }
180
- this.stateInitializer.initializeEntityRealm(
181
- new bindingCommon.UnpersistedEntityDummyId(),
182
- outerState.entityName,
183
- realmToDelete.blueprint
184
- );
185
- this.eventManager.registerUpdatedConnection(parent, placeholderName);
186
- } else if (realmToDelete.blueprint.type === "subTree") {
187
- parent = void 0;
188
- if (realmToDelete.type === "entityRealm") {
189
- this.eventManager.registerJustUpdated(realmToDelete, 1);
190
- }
191
- } else {
192
- return bindingCommon.assertNever(realmToDelete.blueprint);
193
- }
194
- if (parent) {
195
- if (realmToDelete.type === "entityRealm") {
196
- changesDelta -= realmToDelete.unpersistedChangesCount;
197
- }
198
- this.eventManager.registerJustUpdated(parent, changesDelta);
199
- if (realmToDelete.type === "entityRealm") {
200
- parent.childrenWithPendingUpdates?.delete(realmToDelete);
201
- }
202
- this.treeStore.disposeOfRealm(realmToDelete);
203
- }
204
- }
205
- });
206
- }
207
- *resolveHasOneRelationMarkers(container, field, type, mustExists) {
208
- const placeholders = container.placeholders.get(field);
209
- if (placeholders === void 0) {
210
- if (!mustExists) {
211
- return;
212
- }
213
- throw new bindingCommon.BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`);
214
- }
215
- const normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders];
216
- for (const placeholderName of normalizedPlaceholders) {
217
- const hasOneRelation = container.markers.get(placeholderName);
218
- if (!(hasOneRelation instanceof bindingCommon.HasOneRelationMarker)) {
219
- throw new bindingCommon.BindingError(`Cannot ${type} at field '${field}' as it doesn't refer to a has one relation.`);
220
- }
221
- yield hasOneRelation;
222
- }
223
- }
224
- }
225
- exports.EntityOperations = EntityOperations;
226
- //# sourceMappingURL=EntityOperations.cjs.map
@@ -1 +0,0 @@
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\tpreviouslyConnectedState.type === 'field' ||\n\t\t\t\t\t\tpreviouslyConnectedState.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\tpreviouslyConnectedState.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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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 || // We're updating.
93
- persistedId === void 0 && // We're creating.
94
- (!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.eachSiblingRealm(outerState)) {
117
- const targetHasOneMarkers = this.resolveHasOneRelationMarkers(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.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 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 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 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 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 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 HasOneRelationMarker)) {
217
- throw new BindingError(`Cannot ${type} at field '${field}' as it doesn't refer to a has one relation.`);
218
- }
219
- yield hasOneRelation;
220
- }
221
- }
222
- }
223
- export {
224
- EntityOperations
225
- };
226
- //# sourceMappingURL=EntityOperations.js.map
@@ -1 +0,0 @@
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\tpreviouslyConnectedState.type === 'field' ||\n\t\t\t\t\t\tpreviouslyConnectedState.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\tpreviouslyConnectedState.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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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
@@ -1 +0,0 @@
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 =\n\t\t\t\t\tfield.fieldMarker.defaultValue === undefined\n\t\t\t\t\t\t? newValue\n\t\t\t\t\t\t: newValue === null\n\t\t\t\t\t\t\t? field.fieldMarker.defaultValue\n\t\t\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 =\n\t\t\t\t\t!getEntityMarker(parent).fields.hasAtLeastOneBearingField ||\n\t\t\t\t\t!field.fieldMarker.isNonbearing ||\n\t\t\t\t\tfield.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,EAAA;AAAA,EAGX,SAAS,YAA6B,O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