@contember/binding-legacy 2.1.0-alpha.36 → 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,136 @@
1
+ import { EntitySubTreeMarker, BindingError, EntityListSubTreeMarker, assertNever, FieldMarker, HasOneRelationMarker, HasManyRelationMarker, PRIMARY_KEY_NAME, ServerId } from "@contember/binding-common";
2
+ class RequestResponseNormalizer {
3
+ static mergeInQueryResponse(original, newPersistedData, markerTree) {
4
+ const { subTreeDataStore, persistedEntityDataStore } = original;
5
+ for (const [placeholder, marker] of markerTree.subTrees) {
6
+ const data = newPersistedData[placeholder] ?? null;
7
+ if (marker instanceof EntitySubTreeMarker) {
8
+ if (data === null) {
9
+ subTreeDataStore.delete(placeholder);
10
+ } else {
11
+ if (Array.isArray(data)) {
12
+ throw new BindingError();
13
+ }
14
+ const id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers);
15
+ subTreeDataStore.set(placeholder, id);
16
+ }
17
+ } else if (marker instanceof EntityListSubTreeMarker) {
18
+ const subTreeListIds = /* @__PURE__ */ new Set();
19
+ if (!Array.isArray(data)) {
20
+ throw new BindingError();
21
+ }
22
+ for (const row of data) {
23
+ const id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers);
24
+ subTreeListIds.add(id.value);
25
+ }
26
+ subTreeDataStore.set(placeholder, subTreeListIds);
27
+ } else {
28
+ throw new BindingError();
29
+ }
30
+ }
31
+ }
32
+ static mergeInMutationResponse(original, newPersistedData, operations) {
33
+ const { subTreeDataStore, persistedEntityDataStore } = original;
34
+ for (const operation of operations) {
35
+ const { subTreePlaceholder, subTreeType, alias } = operation;
36
+ const receivedData = newPersistedData[alias];
37
+ if (!receivedData) {
38
+ continue;
39
+ }
40
+ if (Array.isArray(receivedData)) {
41
+ throw new BindingError();
42
+ }
43
+ if (operation.type === "update" || operation.type === "create") {
44
+ const id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers);
45
+ if (subTreeType === "single") {
46
+ subTreeDataStore.set(subTreePlaceholder, id);
47
+ } else if (subTreeType === "list") {
48
+ const list = subTreeDataStore.get(subTreePlaceholder);
49
+ if (list instanceof Set) {
50
+ list.add(id.value);
51
+ } else if (list === void 0) {
52
+ subTreeDataStore.set(subTreePlaceholder, /* @__PURE__ */ new Set([id.value]));
53
+ } else {
54
+ throw new BindingError();
55
+ }
56
+ } else {
57
+ return assertNever(subTreeType);
58
+ }
59
+ } else if (operation.type === "delete") {
60
+ const id = this.extractId(receivedData);
61
+ persistedEntityDataStore.delete(id.uniqueValue);
62
+ if (subTreeType === "single") {
63
+ subTreeDataStore.delete(subTreePlaceholder);
64
+ } else if (subTreeType === "list") {
65
+ const list = subTreeDataStore.get(subTreePlaceholder);
66
+ if (!(list instanceof Set)) {
67
+ throw new BindingError();
68
+ }
69
+ list.delete(id.value);
70
+ } else {
71
+ return assertNever(subTreeType);
72
+ }
73
+ } else {
74
+ return assertNever(operation);
75
+ }
76
+ }
77
+ }
78
+ static processEntityData(entityMap, entityData, fields) {
79
+ const id = this.extractId(entityData);
80
+ const presentEntityData = entityMap.get(id.uniqueValue) ?? /* @__PURE__ */ new Map();
81
+ entityMap.set(id.uniqueValue, presentEntityData);
82
+ for (const [placeholder, field] of fields) {
83
+ const value = entityData[placeholder];
84
+ const metaFlags = {
85
+ readable: entityData._meta?.[field.parameters.field]?.readable ?? void 0,
86
+ updatable: entityData._meta?.[field.parameters.field]?.updatable ?? void 0
87
+ };
88
+ if (field instanceof FieldMarker) {
89
+ presentEntityData.set(placeholder, {
90
+ value,
91
+ ...metaFlags
92
+ });
93
+ } else if (field instanceof HasOneRelationMarker) {
94
+ if (value === null) {
95
+ presentEntityData.set(placeholder, {
96
+ value: null,
97
+ ...metaFlags
98
+ });
99
+ } else {
100
+ presentEntityData.set(placeholder, {
101
+ value: this.processEntityData(entityMap, value, field.fields.markers),
102
+ ...metaFlags
103
+ });
104
+ }
105
+ } else if (field instanceof HasManyRelationMarker) {
106
+ const ids = presentEntityData.get(placeholder)?.value ?? /* @__PURE__ */ new Set();
107
+ presentEntityData.set(placeholder, {
108
+ value: ids,
109
+ ...metaFlags
110
+ });
111
+ if (!(ids instanceof Set)) {
112
+ throw new BindingError();
113
+ }
114
+ ids.clear();
115
+ for (const row of value) {
116
+ const id2 = this.processEntityData(entityMap, row, field.fields.markers);
117
+ ids.add(id2.value);
118
+ }
119
+ } else {
120
+ throw new Error();
121
+ }
122
+ }
123
+ return id;
124
+ }
125
+ static extractId(entityData) {
126
+ const primaryKey = entityData[PRIMARY_KEY_NAME];
127
+ if (primaryKey === void 0) {
128
+ throw new BindingError(`The server has responded with an entity that lacks a primary key.`);
129
+ }
130
+ return new ServerId(primaryKey, entityData.__typename);
131
+ }
132
+ }
133
+ export {
134
+ RequestResponseNormalizer
135
+ };
136
+ //# sourceMappingURL=RequestResponseNormalizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../../../packages/binding-legacy/src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import { ReceivedDataTree, ReceivedEntityData, ServerId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME } from '@contember/binding-common'\nimport { EntityId } from '@contember/binding-common'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '@contember/binding-common'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { assertNever } from '@contember/binding-common'\nimport { NormalizedPersistedData, PersistedEntityDataStore, SingleEntityPersistedData } from '../accessorTree'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\tmarkerTree: MarkerTreeRoot,\n\t): void {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const [placeholder, marker] of markerTree.subTrees) {\n\t\t\tconst data = newPersistedData[placeholder] ?? null\n\t\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\t\tif (data === null) {\n\t\t\t\t\tsubTreeDataStore.delete(placeholder)\n\t\t\t\t} else {\n\t\t\t\t\tif (Array.isArray(data)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers)\n\t\t\t\t\tsubTreeDataStore.set(placeholder, id)\n\t\t\t\t}\n\t\t\t} else if (marker instanceof EntityListSubTreeMarker) {\n\t\t\t\tconst subTreeListIds = new Set<EntityId>()\n\t\t\t\tif (!Array.isArray(data)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tfor (const row of data) {\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers)\n\t\t\t\t\tsubTreeListIds.add(id.value)\n\t\t\t\t}\n\t\t\t\tsubTreeDataStore.set(placeholder, subTreeListIds)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\toperations: SubMutationOperation[],\n\t): void {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const operation of operations) {\n\t\t\tconst { subTreePlaceholder, subTreeType, alias } = operation\n\n\t\t\tconst receivedData = newPersistedData[alias]\n\n\t\t\t// probably multiple operations removing same entity, resulting in no data for some of them\n\t\t\tif (!receivedData) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (Array.isArray(receivedData)) {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\n\t\t\tif (operation.type === 'update' || operation.type === 'create') {\n\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, id)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t// \t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\tlist.add(id.value)\n\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([id.value]))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else if (operation.type === 'delete') {\n\t\t\t\tconst id = this.extractId(receivedData)\n\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t// \t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\tpersistedEntityDataStore.delete(id.uniqueValue)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tlist.delete(id.value)\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn assertNever(operation)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static processEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData, fields: EntityFieldMarkers): ServerId {\n\t\tconst id = this.extractId(entityData)\n\t\tconst presentEntityData: SingleEntityPersistedData = entityMap.get(id.uniqueValue) ?? new Map()\n\t\tentityMap.set(id.uniqueValue, presentEntityData)\n\n\t\tfor (const [placeholder, field] of fields) {\n\t\t\tconst value = entityData[placeholder]\n\t\t\tconst metaFlags = {\n\t\t\t\treadable: entityData._meta?.[field.parameters.field]?.readable ?? undefined,\n\t\t\t\tupdatable: entityData._meta?.[field.parameters.field]?.updatable ?? undefined,\n\t\t\t}\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: null,\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers),\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder)?.value ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue: ids,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\n\t\t\t\tif (!(ids instanceof Set)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tids.clear()\n\t\t\t\tfor (const row of value as ReceivedEntityData[]) {\n\t\t\t\t\tconst id = this.processEntityData(entityMap, row, field.fields.markers)\n\t\t\t\t\tids.add(id.value)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t}\n\n\t\treturn id\n\t}\n\n\tprivate static extractId(entityData: ReceivedEntityData): ServerId {\n\t\tconst primaryKey: EntityId | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\treturn new ServerId(primaryKey, entityData.__typename)\n\t}\n}\n"],"names":["id"],"mappings":";AAiBO,MAAM,0BAA0B;AAAA,EACtC,OAAc,qBACb,UACA,kBACA,YACO;AACP,UAAM,EAAE,kBAAkB,yBAAA,IAA6B;AAEvD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AAa;AACjC,0BAAkB,IAAI,aAAa;AAAA,UAClC;AAAA,UACA,GAAG;AAAA,QAAA,CACH;AAAA,MACF,WAAW,iBAAiB,sBAAsB;AACjD,YAAI,UAAU,MAAM;AACnB,4BAAkB,IAAI,aAAa;AAAA,YAClC,OAAO;AAAA,YACP,GAAG;AAAA,UAAA,CACH;AAAA,QACF,OAAO;AACN,4BAAkB,IAAI,aAAa;AAAA,YAClC,OAAO,KAAK,kBAAkB,WAAW,OAA6B,MAAM,OAAO,OAAO;AAAA,YAC1F,GAAG;AAAA,UAAA,CACH;AAAA,QACF;AAAA,MACD,WAAW,iBAAiB,uBAAuB;AAClD,cAAM,MAAM,kBAAkB,IAAI,WAAW,GAAG,6BAAa,IAAA;AAC7D,0BAAkB,IAAI,aAAa;AAAA,UAClC,OAAO;AAAA,UACP,GAAG;AAAA,QAAA,CACH;AACD,YAAI,EAAE,eAAe,MAAM;AAC1B,gBAAM,IAAI,aAAA;AAAA,QACX;AACA,YAAI,MAAA;AACJ,mBAAW,OAAO,OAA+B;AAChD,gBAAMA,MAAK,KAAK,kBAAkB,WAAW,KAAK,MAAM,OAAO,OAAO;AACtE,cAAI,IAAIA,IAAG,KAAK;AAAA,QACjB;AAAA,MACD,OAAO;AACN,cAAM,IAAI,MAAA;AAAA,MACX;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,OAAe,UAAU,YAA0C;AAClE,UAAM,aAAmC,WAAW,gBAAgB;AAEpE,QAAI,eAAe,QAAW;AAC7B,YAAM,IAAI,aAAa,mEAAmE;AAAA,IAC3F;AAEA,WAAO,IAAI,SAAS,YAAY,WAAW,UAAU;AAAA,EACtD;AACD;"}
@@ -0,0 +1,379 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const bindingCommon = require("@contember/binding-common");
4
+ const utilities = require("@contember/utilities");
5
+ const RealmKeyGenerator = require("./RealmKeyGenerator.cjs");
6
+ const FieldOperations = require("./operations/FieldOperations.cjs");
7
+ const EntityOperations = require("./operations/EntityOperations.cjs");
8
+ const ListOperations = require("./operations/ListOperations.cjs");
9
+ const EntityAccessorImpl = require("../accessors/EntityAccessorImpl.cjs");
10
+ const EntityListAccessorImpl = require("../accessors/EntityListAccessorImpl.cjs");
11
+ const FieldAccessorImpl = require("../accessors/FieldAccessorImpl.cjs");
12
+ const getEntityMarker = require("./state/getEntityMarker.cjs");
13
+ var __defProp = Object.defineProperty;
14
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
16
+ class StateInitializer {
17
+ constructor(accessorErrorManager, batchUpdatesOptions, eventManager, treeStore) {
18
+ this.eventManager = eventManager;
19
+ this.treeStore = treeStore;
20
+ __publicField(this, "fieldOperations");
21
+ __publicField(this, "entityOperations");
22
+ __publicField(this, "listOperations");
23
+ this.fieldOperations = new FieldOperations.FieldOperations(accessorErrorManager, this.eventManager, this, this.treeStore);
24
+ this.entityOperations = new EntityOperations.EntityOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore);
25
+ this.listOperations = new ListOperations.ListOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore);
26
+ }
27
+ initializeSubTree(tree) {
28
+ let subTreeState;
29
+ const persistedRootData = this.treeStore.subTreePersistedData.get(tree.placeholderName);
30
+ if (tree instanceof bindingCommon.EntityListSubTreeMarker) {
31
+ const persistedEntityIds = persistedRootData instanceof Set ? persistedRootData : /* @__PURE__ */ new Set();
32
+ subTreeState = this.initializeEntityListState(
33
+ { type: "subTree", marker: tree, parent: void 0 },
34
+ tree.entityName,
35
+ persistedEntityIds
36
+ );
37
+ } else {
38
+ subTreeState = this.materializeEntityRealm(
39
+ this.initializeEntityRealm(
40
+ persistedRootData instanceof bindingCommon.ServerId ? persistedRootData : new bindingCommon.UnpersistedEntityDummyId(),
41
+ tree.entityName,
42
+ {
43
+ type: "subTree",
44
+ marker: tree,
45
+ parent: void 0
46
+ }
47
+ )
48
+ );
49
+ }
50
+ return subTreeState;
51
+ }
52
+ initializeEntityRealm(id, entityName, blueprint, copyFrom) {
53
+ const entity = this.initializeEntityState(id, entityName);
54
+ const realmKey = RealmKeyGenerator.RealmKeyGenerator.getRealmKey(id, blueprint);
55
+ const existing = this.treeStore.entityRealmStore.get(realmKey);
56
+ if (existing !== void 0) {
57
+ return existing;
58
+ }
59
+ if (!copyFrom || copyFrom.type !== "entityRealm") {
60
+ const stub = {
61
+ type: "entityRealmStub",
62
+ blueprint,
63
+ entity,
64
+ realmKey,
65
+ getAccessor: () => this.materializeEntityRealm(stub).getAccessor()
66
+ };
67
+ this.registerEntityRealm(stub);
68
+ return stub;
69
+ }
70
+ const realm = this.createEntityRealm(blueprint, realmKey, entity, copyFrom);
71
+ this.registerEntityRealm(realm);
72
+ const marker = getEntityMarker.getEntityMarker(realm);
73
+ const pathBack = this.treeStore.getPathBackToParent(realm);
74
+ for (const [placeholderName, field] of marker.fields.markers) {
75
+ if (field instanceof bindingCommon.FieldMarker) {
76
+ const value = copyFrom.children.get(placeholderName);
77
+ if (!value || value.type !== "field") {
78
+ throw new bindingCommon.BindingError();
79
+ }
80
+ this.initializeFromFieldMarker(realm, field, void 0, value);
81
+ } else if (field instanceof bindingCommon.HasManyRelationMarker) {
82
+ const value = copyFrom.children.get(placeholderName);
83
+ if (!value || value.type !== "entityList") {
84
+ throw new bindingCommon.BindingError();
85
+ }
86
+ this.initializeFromHasManyRelationMarker(realm, field, new Set(value.children.keys()));
87
+ } else if (field instanceof bindingCommon.HasOneRelationMarker) {
88
+ let runtimeId;
89
+ let subCopyFrom;
90
+ if (pathBack?.fieldBackToParent === field.parameters.field && !field.parameters.reducedBy) {
91
+ runtimeId = pathBack.parent.entity.id;
92
+ } else {
93
+ const value = copyFrom.children.get(placeholderName);
94
+ if (!value || value.type !== "entityRealm" && value.type !== "entityRealmStub") {
95
+ throw new bindingCommon.BindingError();
96
+ }
97
+ runtimeId = !(value.entity.id instanceof bindingCommon.UnpersistedEntityDummyId) ? value.entity.id : new bindingCommon.UnpersistedEntityDummyId();
98
+ if (value.type === "entityRealm") {
99
+ subCopyFrom = value;
100
+ }
101
+ }
102
+ this.initializeFromHasOneRelationMarker(realm, field, runtimeId, subCopyFrom);
103
+ } else {
104
+ bindingCommon.assertNever(field);
105
+ }
106
+ }
107
+ this.eventManager.registerNewlyInitialized(realm);
108
+ return realm;
109
+ }
110
+ createEntityRealm(blueprint, realmKey, entity, copyFrom) {
111
+ const entityRealm = {
112
+ type: "entityRealm",
113
+ blueprint,
114
+ realmKey,
115
+ entity,
116
+ accessor: void 0,
117
+ children: /* @__PURE__ */ new Map(),
118
+ childrenWithPendingUpdates: void 0,
119
+ errors: void 0,
120
+ eventListeners: this.initializeEntityEventListenerStore(blueprint),
121
+ fieldsWithPendingConnectionUpdates: void 0,
122
+ plannedHasOneDeletions: void 0,
123
+ unpersistedChangesCount: copyFrom?.unpersistedChangesCount ?? 0,
124
+ getAccessor: () => {
125
+ if (entityRealm.accessor === void 0) {
126
+ const entity2 = entityRealm.entity;
127
+ entityRealm.accessor = new EntityAccessorImpl.EntityAccessorImpl(
128
+ entityRealm,
129
+ this.entityOperations,
130
+ entity2.id,
131
+ entityRealm.realmKey,
132
+ entity2.entityName,
133
+ // We're technically exposing more info in runtime than we'd like but that way we don't have to allocate and
134
+ // keep in sync two copies of the same data. TS hides the extra info anyway.
135
+ entityRealm.children,
136
+ this.treeStore.persistedEntityData.get(entity2.id.uniqueValue),
137
+ entityRealm.unpersistedChangesCount !== 0,
138
+ entityRealm.errors,
139
+ getEntityMarker.getEntityMarker(entityRealm).environment,
140
+ entityRealm.getAccessor
141
+ );
142
+ }
143
+ return entityRealm.accessor;
144
+ }
145
+ };
146
+ return entityRealm;
147
+ }
148
+ materializeEntityRealm(state) {
149
+ if (state.type === "entityRealm") {
150
+ return state;
151
+ }
152
+ const { realmKey, entity, blueprint } = state;
153
+ const existing = this.treeStore.entityRealmStore.get(realmKey);
154
+ if (existing !== void 0 && existing.type === "entityRealm") {
155
+ return existing;
156
+ }
157
+ const entityRealm = this.createEntityRealm(blueprint, realmKey, entity);
158
+ this.registerEntityRealm(entityRealm);
159
+ const persistedData = this.treeStore.persistedEntityData.get(entity.id.uniqueValue);
160
+ const marker = getEntityMarker.getEntityMarker(state);
161
+ const pathBack = this.treeStore.getPathBackToParent(entityRealm);
162
+ for (const [placeholderName, field] of marker.fields.markers) {
163
+ const fieldDatum = persistedData?.get(placeholderName)?.value;
164
+ if (field instanceof bindingCommon.FieldMarker) {
165
+ this.initializeFromFieldMarker(entityRealm, field, fieldDatum);
166
+ } else if (field instanceof bindingCommon.HasManyRelationMarker) {
167
+ this.initializeFromHasManyRelationMarker(entityRealm, field, fieldDatum instanceof Set ? fieldDatum : /* @__PURE__ */ new Set());
168
+ } else if (field instanceof bindingCommon.HasOneRelationMarker) {
169
+ let runtimeId;
170
+ if (pathBack?.fieldBackToParent === field.parameters.field && !field.parameters.reducedBy) {
171
+ runtimeId = pathBack.parent.entity.id;
172
+ } else {
173
+ runtimeId = fieldDatum instanceof bindingCommon.ServerId ? fieldDatum : new bindingCommon.UnpersistedEntityDummyId();
174
+ }
175
+ this.initializeFromHasOneRelationMarker(entityRealm, field, runtimeId);
176
+ } else {
177
+ bindingCommon.assertNever(field);
178
+ }
179
+ }
180
+ this.eventManager.registerNewlyInitialized(entityRealm);
181
+ return entityRealm;
182
+ }
183
+ registerEntityRealm(entityRealm) {
184
+ const { realmKey, blueprint, entity } = entityRealm;
185
+ this.treeStore.entityRealmStore.set(entityRealm.realmKey, entityRealm);
186
+ if (blueprint.type === "listEntity") {
187
+ blueprint.parent.children.set(entity.id.value, entityRealm);
188
+ } else if (blueprint.type === "hasOne") {
189
+ blueprint.parent.children.set(blueprint.marker.placeholderName, entityRealm);
190
+ }
191
+ entity.realms.set(realmKey, entityRealm);
192
+ }
193
+ initializeEntityState(id, entityName) {
194
+ const entityId = id.uniqueValue;
195
+ const existing = this.treeStore.entityStore.get(entityId);
196
+ if (existing !== void 0) {
197
+ return existing;
198
+ }
199
+ const entityState = {
200
+ entityName,
201
+ hasIdSetInStone: id instanceof bindingCommon.ServerId,
202
+ id,
203
+ isScheduledForDeletion: false,
204
+ maidenId: id instanceof bindingCommon.UnpersistedEntityDummyId ? id : void 0,
205
+ realms: /* @__PURE__ */ new Map()
206
+ };
207
+ this.treeStore.entityStore.set(entityId, entityState);
208
+ return entityState;
209
+ }
210
+ initializeEntityListState(blueprint, entityName, initialEntityIds) {
211
+ const entityListState = {
212
+ type: "entityList",
213
+ accessor: void 0,
214
+ blueprint,
215
+ children: new utilities.BijectiveIndexedMap((realm) => realm.entity.id.value),
216
+ childrenWithPendingUpdates: void 0,
217
+ entityName,
218
+ eventListeners: this.initializeEntityListEventListenerStore(blueprint),
219
+ childEventListeners: this.initializeEntityListChildEventListenerStore(blueprint),
220
+ errors: void 0,
221
+ plannedRemovals: void 0,
222
+ unpersistedChangesCount: 0,
223
+ // TODO force creation?
224
+ getAccessor: () => {
225
+ if (entityListState.accessor === void 0) {
226
+ const persistedEntityIds = this.treeStore.getEntityListPersistedIds(entityListState);
227
+ entityListState.accessor = new EntityListAccessorImpl.EntityListAccessorImpl(
228
+ entityListState,
229
+ this.listOperations,
230
+ entityListState.entityName,
231
+ entityListState.children,
232
+ persistedEntityIds,
233
+ entityListState.unpersistedChangesCount !== 0,
234
+ entityListState.errors,
235
+ entityListState.blueprint.marker.environment,
236
+ entityListState.getAccessor
237
+ );
238
+ }
239
+ return entityListState.accessor;
240
+ }
241
+ };
242
+ const initialData = initialEntityIds.size === 0 ? Array.from({ length: blueprint.marker.parameters.initialEntityCount }) : initialEntityIds;
243
+ for (const entityId of initialData) {
244
+ this.initializeEntityRealm(
245
+ entityId ? new bindingCommon.ServerId(entityId, entityName) : new bindingCommon.UnpersistedEntityDummyId(),
246
+ entityListState.entityName,
247
+ {
248
+ type: "listEntity",
249
+ parent: entityListState
250
+ }
251
+ );
252
+ }
253
+ this.eventManager.registerNewlyInitialized(entityListState);
254
+ return entityListState;
255
+ }
256
+ initializeFieldState(parent, placeholderName, fieldMarker, persistedValue, copyFromState) {
257
+ const resolvedFieldValue = copyFromState ? copyFromState.value : persistedValue ?? fieldMarker.defaultValue ?? null;
258
+ const fieldState = {
259
+ type: "field",
260
+ accessor: void 0,
261
+ fieldMarker,
262
+ placeholderName,
263
+ persistedValue,
264
+ parent,
265
+ value: resolvedFieldValue,
266
+ eventListeners: this.initializeFieldEventListenerStore(fieldMarker),
267
+ errors: void 0,
268
+ touchLog: void 0,
269
+ hasUnpersistedChanges: copyFromState?.hasUnpersistedChanges ?? false,
270
+ getAccessor: () => {
271
+ if (fieldState.accessor === void 0) {
272
+ const fieldSchema = this.treeStore.schema.getEntityColumn(parent.entity.entityName, fieldMarker.fieldName);
273
+ fieldState.accessor = new FieldAccessorImpl.FieldAccessorImpl(
274
+ fieldState,
275
+ this.fieldOperations,
276
+ fieldState.placeholderName,
277
+ fieldState.value,
278
+ fieldState.persistedValue === void 0 ? null : fieldState.persistedValue,
279
+ fieldState.fieldMarker.defaultValue,
280
+ fieldState.errors,
281
+ fieldState.hasUnpersistedChanges,
282
+ fieldState.touchLog,
283
+ fieldState.getAccessor,
284
+ fieldSchema
285
+ );
286
+ }
287
+ return fieldState.accessor;
288
+ }
289
+ };
290
+ this.eventManager.registerNewlyInitialized(fieldState);
291
+ return fieldState;
292
+ }
293
+ initializeFromFieldMarker(parent, field, persistedValue, copyFromState) {
294
+ if (persistedValue instanceof Set) {
295
+ throw new bindingCommon.BindingError(
296
+ `Received a collection of referenced entities where a single '${field.fieldName}' field was expected. Perhaps you wanted to use a <Repeater />?`
297
+ );
298
+ }
299
+ if (persistedValue instanceof bindingCommon.ServerId) {
300
+ throw new bindingCommon.BindingError(
301
+ `Received a referenced entity where a single '${field.fieldName}' field was expected. Perhaps you wanted to use <HasOne />?`
302
+ );
303
+ }
304
+ parent.children.set(
305
+ field.placeholderName,
306
+ this.initializeFieldState(parent, field.placeholderName, field, persistedValue, copyFromState)
307
+ );
308
+ }
309
+ initializeFromHasOneRelationMarker(parent, field, entityId, copyFrom) {
310
+ parent.children.set(
311
+ field.placeholderName,
312
+ this.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {
313
+ type: "hasOne",
314
+ parent,
315
+ marker: field
316
+ }, copyFrom)
317
+ );
318
+ }
319
+ initializeFromHasManyRelationMarker(parent, field, persistedEntityIds) {
320
+ parent.children.set(
321
+ field.placeholderName,
322
+ this.initializeEntityListState(
323
+ { type: "hasMany", marker: field, parent },
324
+ this.getRelationTargetEntityName(parent, field),
325
+ persistedEntityIds
326
+ )
327
+ );
328
+ }
329
+ getRelationTargetEntityName(entityRealm, field) {
330
+ const targetField = this.treeStore.schema.getEntityRelation(entityRealm.entity.entityName, field.parameters.field);
331
+ return targetField.targetEntity;
332
+ }
333
+ runImmediateUserInitialization(realm, initialize) {
334
+ if (initialize === void 0) {
335
+ return;
336
+ }
337
+ const entityRealm = this.materializeEntityRealm(realm);
338
+ realm.getAccessor().batchUpdates(initialize);
339
+ const initializeListeners = this.eventManager.getEventListeners(entityRealm, { type: "initialize" });
340
+ if (initializeListeners === void 0 || initializeListeners.size === 0) {
341
+ realm.entity.hasIdSetInStone = true;
342
+ }
343
+ }
344
+ initializeEntityEventListenerStore(blueprint) {
345
+ if (blueprint.type === "listEntity") {
346
+ const blueprintListeners2 = blueprint.parent.blueprint.marker.parameters.childEventListeners;
347
+ const childInitialize = blueprintListeners2?.get({ type: "initialize" });
348
+ const store = new bindingCommon.EventListenersStore(() => blueprint.parent.childEventListeners);
349
+ if (childInitialize !== void 0) {
350
+ store.set({ type: "initialize" }, childInitialize);
351
+ }
352
+ return store;
353
+ }
354
+ const blueprintListeners = blueprint.marker.parameters.eventListeners;
355
+ if (blueprintListeners === void 0) {
356
+ return void 0;
357
+ }
358
+ return blueprintListeners.clone();
359
+ }
360
+ initializeEntityListEventListenerStore(blueprint) {
361
+ const blueprintListeners = blueprint.marker.parameters.eventListeners;
362
+ if (blueprintListeners === void 0) {
363
+ return void 0;
364
+ }
365
+ return blueprintListeners.clone();
366
+ }
367
+ initializeEntityListChildEventListenerStore(blueprint) {
368
+ const blueprintListeners = blueprint.marker.parameters.childEventListeners;
369
+ if (blueprintListeners === void 0) {
370
+ return void 0;
371
+ }
372
+ return blueprintListeners.clone();
373
+ }
374
+ initializeFieldEventListenerStore(marker) {
375
+ return marker.parameters.eventListeners?.clone();
376
+ }
377
+ }
378
+ exports.StateInitializer = StateInitializer;
379
+ //# sourceMappingURL=StateInitializer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateInitializer.cjs","sources":["../../../../../packages/binding-legacy/src/core/StateInitializer.ts"],"sourcesContent":["import { BatchUpdatesOptions, EntityAccessor, FieldAccessor } from '@contember/binding-common'\nimport { RuntimeId, ServerId, UnpersistedEntityDummyId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { EntityListSubTreeMarker, EntitySubTreeMarker, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '@contember/binding-common'\nimport { BijectiveIndexedMap } from '@contember/utilities'\nimport type {\n\tEntityEventListenerStore,\n\tEntityId,\n\tEntityListEventListenerStore,\n\tEntityName,\n\tFieldEventListenerStore,\n\tFieldName,\n\tFieldValue,\n} from '@contember/binding-common'\nimport { EventListenersStore } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport type { AccessorErrorManager } from './AccessorErrorManager'\nimport type { EventManager } from './EventManager'\nimport { EntityOperations, FieldOperations, ListOperations } from './operations'\nimport { RealmKeyGenerator } from './RealmKeyGenerator'\nimport {\n\tEntityListBlueprint,\n\tEntityListState,\n\tEntityRealmBlueprint,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n} from './state'\nimport { TreeParameterMerger } from '@contember/binding-common'\nimport type { TreeStore } from './TreeStore'\nimport { EntityAccessorImpl, EntityListAccessorImpl, FieldAccessorImpl } from '../accessors'\nimport { EntityFieldPersistedData, EntityFieldPersistedValue } from '../accessorTree'\n\nexport class StateInitializer {\n\tprivate readonly fieldOperations: FieldOperations\n\tprivate readonly entityOperations: EntityOperations\n\tprivate readonly listOperations: ListOperations\n\n\tpublic constructor(\n\t\taccessorErrorManager: AccessorErrorManager,\n\t\tbatchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {\n\t\tthis.fieldOperations = new FieldOperations(accessorErrorManager, this.eventManager, this, this.treeStore)\n\t\tthis.entityOperations = new EntityOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore)\n\t\tthis.listOperations = new ListOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore)\n\t}\n\n\tpublic initializeSubTree(tree: EntitySubTreeMarker | EntityListSubTreeMarker): RootStateNode {\n\t\tlet subTreeState: RootStateNode\n\t\tconst persistedRootData = this.treeStore.subTreePersistedData.get(tree.placeholderName)\n\n\t\tif (tree instanceof EntityListSubTreeMarker) {\n\t\t\tconst persistedEntityIds: Set<EntityId> = persistedRootData instanceof Set ? persistedRootData : new Set()\n\t\t\tsubTreeState = this.initializeEntityListState(\n\t\t\t\t{ type: 'subTree', marker: tree, parent: undefined },\n\t\t\t\ttree.entityName,\n\t\t\t\tpersistedEntityIds,\n\t\t\t)\n\t\t} else {\n\t\t\tsubTreeState = this.materializeEntityRealm(\n\t\t\t\tthis.initializeEntityRealm(\n\t\t\t\t\tpersistedRootData instanceof ServerId ? persistedRootData : new UnpersistedEntityDummyId(),\n\t\t\t\t\ttree.entityName,\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'subTree',\n\t\t\t\t\t\tmarker: tree,\n\t\t\t\t\t\tparent: undefined,\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\treturn subTreeState\n\t}\n\n\tpublic initializeEntityRealm(\n\t\tid: RuntimeId,\n\t\tentityName: EntityName,\n\t\tblueprint: EntityRealmBlueprint,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t): EntityRealmState | EntityRealmStateStub {\n\t\t// This is counter-intuitive a bit. The method can also return an EntityRealmState, not just a stub.\n\t\t// The reason is so that each call-site can just default to trying to initialize a stub without having to keep\n\t\t// in mind that the realm might have already been initialized.\n\n\t\tconst entity = this.initializeEntityState(id, entityName)\n\t\tconst realmKey = RealmKeyGenerator.getRealmKey(id, blueprint)\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tif (!copyFrom || copyFrom.type !== 'entityRealm') {\n\t\t\tconst stub: EntityRealmStateStub = {\n\t\t\t\ttype: 'entityRealmStub',\n\n\t\t\t\tblueprint,\n\t\t\t\tentity,\n\t\t\t\trealmKey,\n\t\t\t\tgetAccessor: () => this.materializeEntityRealm(stub).getAccessor(),\n\t\t\t}\n\t\t\tthis.registerEntityRealm(stub)\n\n\t\t\treturn stub\n\t\t}\n\t\tconst realm = this.createEntityRealm(blueprint, realmKey, entity, copyFrom)\n\n\t\tthis.registerEntityRealm(realm)\n\n\t\tconst marker = getEntityMarker(realm)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(realm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\tif (!value || value.type !== 'field') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromFieldMarker(realm, field, undefined, value)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\tif (!value || value.type !== 'entityList') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasManyRelationMarker(realm, field, new Set(value.children.keys()))\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tlet subCopyFrom: EntityRealmState | undefined\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field && !field.parameters.reducedBy) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\t\tif (!value || (value.type !== 'entityRealm' && value.type !== 'entityRealmStub')) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\truntimeId = !(value.entity.id instanceof UnpersistedEntityDummyId) ? value.entity.id : new UnpersistedEntityDummyId()\n\t\t\t\t\tif (value.type === 'entityRealm') {\n\t\t\t\t\t\tsubCopyFrom = value\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(realm, field, runtimeId, subCopyFrom)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(realm)\n\t\treturn realm\n\t}\n\n\tprivate createEntityRealm(\n\t\tblueprint: EntityRealmBlueprint,\n\t\trealmKey: string,\n\t\tentity: EntityState,\n\t\tcopyFrom?: EntityRealmState,\n\t): EntityRealmState {\n\t\tconst entityRealm: EntityRealmState = {\n\t\t\ttype: 'entityRealm',\n\n\t\t\tblueprint,\n\t\t\trealmKey,\n\t\t\tentity,\n\n\t\t\taccessor: undefined,\n\t\t\tchildren: new Map(),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\terrors: undefined,\n\t\t\teventListeners: this.initializeEntityEventListenerStore(blueprint),\n\t\t\tfieldsWithPendingConnectionUpdates: undefined,\n\t\t\tplannedHasOneDeletions: undefined,\n\t\t\tunpersistedChangesCount: copyFrom?.unpersistedChangesCount ?? 0,\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityRealm.accessor === undefined) {\n\t\t\t\t\tconst entity = entityRealm.entity\n\t\t\t\t\tentityRealm.accessor = new EntityAccessorImpl(\n\t\t\t\t\t\tentityRealm,\n\t\t\t\t\t\tthis.entityOperations,\n\t\t\t\t\t\tentity.id,\n\t\t\t\t\t\tentityRealm.realmKey,\n\t\t\t\t\t\tentity.entityName,\n\t\t\t\t\t\t// We're technically exposing more info in runtime than we'd like but that way we don't have to allocate and\n\t\t\t\t\t\t// keep in sync two copies of the same data. TS hides the extra info anyway.\n\t\t\t\t\t\tentityRealm.children,\n\t\t\t\t\t\tthis.treeStore.persistedEntityData.get(entity.id.uniqueValue),\n\t\t\t\t\t\tentityRealm.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityRealm.errors,\n\t\t\t\t\t\tgetEntityMarker(entityRealm).environment,\n\t\t\t\t\t\tentityRealm.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityRealm.accessor\n\t\t\t},\n\t\t}\n\t\treturn entityRealm\n\t}\n\n\tprivate materializeEntityRealm(state: EntityRealmState | EntityRealmStateStub): EntityRealmState {\n\t\tif (state.type === 'entityRealm') {\n\t\t\treturn state\n\t\t}\n\t\tconst { realmKey, entity, blueprint } = state\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined && existing.type === 'entityRealm') {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityRealm = this.createEntityRealm(blueprint, realmKey, entity)\n\n\t\tthis.registerEntityRealm(entityRealm)\n\n\t\t// if (blueprint.creationParameters.forceCreation && !entity.id.existsOnServer) {\n\t\t// \tentityRealm.unpersistedChangesCount += 1\n\t\t// }\n\n\t\tconst persistedData = this.treeStore.persistedEntityData.get(entity.id.uniqueValue)\n\n\t\tconst marker = getEntityMarker(state)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(entityRealm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tconst fieldDatum = persistedData?.get(placeholderName)?.value\n\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tthis.initializeFromFieldMarker(entityRealm, field, fieldDatum)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\t// if (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t// \t// TODO this is probably wrong?\n\t\t\t\t// \tconst ids = pathBack.parent.children.get(field.placeholderName)\n\t\t\t\t// \tconst newData = this.treeStore.persistedEntityData.get(pathBack.parent.entity.id.value)\n\t\t\t\t// \tconsole.log('many?', pathBack, field, entityRealm, fieldDatum, ids)\n\t\t\t\t// }\n\t\t\t\tthis.initializeFromHasManyRelationMarker(entityRealm, field, fieldDatum instanceof Set ? fieldDatum : new Set())\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field && !field.parameters.reducedBy) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\truntimeId = fieldDatum instanceof ServerId ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(entityRealm, field, runtimeId)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityRealm)\n\n\t\treturn entityRealm\n\t}\n\n\tprivate registerEntityRealm(entityRealm: EntityRealmState | EntityRealmStateStub) {\n\t\tconst { realmKey, blueprint, entity } = entityRealm\n\n\t\tthis.treeStore.entityRealmStore.set(entityRealm.realmKey, entityRealm)\n\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tblueprint.parent.children.set(entity.id.value, entityRealm)\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tblueprint.parent.children.set(blueprint.marker.placeholderName, entityRealm)\n\t\t}\n\t\tentity.realms.set(realmKey, entityRealm)\n\t}\n\n\tpublic initializeEntityState(id: RuntimeId, entityName: EntityName): EntityState {\n\t\tconst entityId = id.uniqueValue\n\n\t\tconst existing = this.treeStore.entityStore.get(entityId)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityState: EntityState = {\n\t\t\tentityName,\n\t\t\thasIdSetInStone: id instanceof ServerId,\n\t\t\tid,\n\t\t\tisScheduledForDeletion: false,\n\t\t\tmaidenId: id instanceof UnpersistedEntityDummyId ? id : undefined,\n\t\t\trealms: new Map(),\n\t\t}\n\t\tthis.treeStore.entityStore.set(entityId, entityState)\n\n\t\treturn entityState\n\t}\n\n\tprivate initializeEntityListState(\n\t\tblueprint: EntityListBlueprint,\n\t\tentityName: EntityName,\n\t\tinitialEntityIds: Set<EntityId>,\n\t): EntityListState {\n\t\tconst entityListState: EntityListState = {\n\t\t\ttype: 'entityList',\n\t\t\taccessor: undefined,\n\t\t\tblueprint,\n\t\t\tchildren: new BijectiveIndexedMap(realm => realm.entity.id.value),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\tentityName,\n\t\t\teventListeners: this.initializeEntityListEventListenerStore(blueprint),\n\t\t\tchildEventListeners: this.initializeEntityListChildEventListenerStore(blueprint),\n\t\t\terrors: undefined,\n\t\t\tplannedRemovals: undefined,\n\t\t\tunpersistedChangesCount: 0, // TODO force creation?\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityListState.accessor === undefined) {\n\t\t\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(entityListState)\n\t\t\t\t\tentityListState.accessor = new EntityListAccessorImpl(\n\t\t\t\t\t\tentityListState,\n\t\t\t\t\t\tthis.listOperations,\n\t\t\t\t\t\tentityListState.entityName,\n\t\t\t\t\t\tentityListState.children,\n\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\tentityListState.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityListState.errors,\n\t\t\t\t\t\tentityListState.blueprint.marker.environment,\n\t\t\t\t\t\tentityListState.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityListState.accessor\n\t\t\t},\n\t\t}\n\n\t\tconst initialData: Iterable<EntityId | undefined> = initialEntityIds.size === 0\n\t\t\t? Array.from({ length: blueprint.marker.parameters.initialEntityCount })\n\t\t\t: initialEntityIds\n\t\tfor (const entityId of initialData) {\n\t\t\tthis.initializeEntityRealm(\n\t\t\t\tentityId ? new ServerId(entityId, entityName) : new UnpersistedEntityDummyId(),\n\t\t\t\tentityListState.entityName,\n\t\t\t\t{\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: entityListState,\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityListState)\n\n\t\treturn entityListState\n\t}\n\n\tprivate initializeFieldState(\n\t\tparent: EntityRealmState,\n\t\tplaceholderName: FieldName,\n\t\tfieldMarker: FieldMarker,\n\t\tpersistedValue: FieldValue | undefined,\n\t\tcopyFromState: FieldState | undefined,\n\t): FieldState {\n\t\tconst resolvedFieldValue = copyFromState ? copyFromState.value : (persistedValue ?? fieldMarker.defaultValue ?? null)\n\n\t\tconst fieldState: FieldState = {\n\t\t\ttype: 'field',\n\t\t\taccessor: undefined,\n\t\t\tfieldMarker,\n\t\t\tplaceholderName,\n\t\t\tpersistedValue,\n\t\t\tparent,\n\t\t\tvalue: resolvedFieldValue,\n\t\t\teventListeners: this.initializeFieldEventListenerStore(fieldMarker),\n\t\t\terrors: undefined,\n\t\t\ttouchLog: undefined,\n\t\t\thasUnpersistedChanges: copyFromState?.hasUnpersistedChanges ?? false,\n\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (fieldState.accessor === undefined) {\n\t\t\t\t\tconst fieldSchema = this.treeStore.schema.getEntityColumn(parent.entity.entityName, fieldMarker.fieldName)\n\n\t\t\t\t\tfieldState.accessor = new FieldAccessorImpl(\n\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\tthis.fieldOperations,\n\t\t\t\t\t\tfieldState.placeholderName,\n\t\t\t\t\t\tfieldState.value,\n\t\t\t\t\t\tfieldState.persistedValue === undefined ? null : fieldState.persistedValue,\n\t\t\t\t\t\tfieldState.fieldMarker.defaultValue,\n\t\t\t\t\t\tfieldState.errors,\n\t\t\t\t\t\tfieldState.hasUnpersistedChanges,\n\t\t\t\t\t\tfieldState.touchLog,\n\t\t\t\t\t\tfieldState.getAccessor,\n\t\t\t\t\t\tfieldSchema,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn fieldState.accessor\n\t\t\t},\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(fieldState)\n\t\treturn fieldState\n\t}\n\n\tprivate initializeFromFieldMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: FieldMarker,\n\t\tpersistedValue: EntityFieldPersistedValue | undefined,\n\t\tcopyFromState?: FieldState,\n\t) {\n\t\tif (persistedValue instanceof Set) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. `\n\t\t\t\t\t+ `Perhaps you wanted to use a <Repeater />?`,\n\t\t\t)\n\t\t}\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a referenced entity where a single '${field.fieldName}' field was expected. `\n\t\t\t\t\t+ `Perhaps you wanted to use <HasOne />?`,\n\t\t\t)\n\t\t}\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeFieldState(parent, field.placeholderName, field, persistedValue, copyFromState),\n\t\t)\n\t}\n\n\tprivate initializeFromHasOneRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasOneRelationMarker,\n\t\tentityId: RuntimeId,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {\n\t\t\t\ttype: 'hasOne',\n\t\t\t\tparent,\n\t\t\t\tmarker: field,\n\t\t\t}, copyFrom),\n\t\t)\n\t\t// if (fieldDatum instanceof ServerGeneratedUuid || fieldDatum === null || fieldDatum === undefined) {\n\t\t// \tconst entityId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t//\n\t\t//\n\t\t// } else if (fieldDatum instanceof Set) {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a collection of entities for field '${relation.field}' where a single entity was expected. ` +\n\t\t// \t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a single entity was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate initializeFromHasManyRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasManyRelationMarker,\n\t\tpersistedEntityIds: Set<EntityId>,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityListState(\n\t\t\t\t{ type: 'hasMany', marker: field, parent },\n\t\t\t\tthis.getRelationTargetEntityName(parent, field),\n\t\t\t\tpersistedEntityIds,\n\t\t\t),\n\t\t)\n\t\t// const relation = field.parameters\n\t\t//\n\t\t// if (fieldDatum === undefined || fieldDatum instanceof Set) {\n\t\t//\n\t\t// } else if (typeof fieldDatum === 'object') {\n\t\t// \t// Intentionally allowing `fieldDatum === null` here as well since this should only happen when a *hasOne\n\t\t// \t// relation is unlinked, e.g. a Person does not have a linked Nationality.\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a referenced entity for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you wanted to use a <HasOne />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate getRelationTargetEntityName(\n\t\tentityRealm: EntityRealmState,\n\t\tfield: HasOneRelationMarker | HasManyRelationMarker,\n\t): EntityName {\n\t\tconst targetField = this.treeStore.schema.getEntityRelation(entityRealm.entity.entityName, field.parameters.field)\n\t\treturn targetField.targetEntity\n\t}\n\n\tpublic runImmediateUserInitialization(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tinitialize: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tif (initialize === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst entityRealm = this.materializeEntityRealm(realm)\n\n\t\trealm.getAccessor().batchUpdates(initialize)\n\n\t\tconst initializeListeners = this.eventManager.getEventListeners(entityRealm, { type: 'initialize' })\n\t\tif (initializeListeners === undefined || initializeListeners.size === 0) {\n\t\t\trealm.entity.hasIdSetInStone = true\n\t\t}\n\t}\n\n\tpublic initializeEntityEventListenerStore(blueprint: EntityRealmBlueprint): EntityEventListenerStore | undefined {\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tconst blueprintListeners = blueprint.parent.blueprint.marker.parameters.childEventListeners\n\t\t\tconst childInitialize = blueprintListeners?.get({ type: 'initialize' })\n\t\t\tconst store: EntityEventListenerStore = new EventListenersStore(() => blueprint.parent.childEventListeners)\n\n\t\t\tif (childInitialize !== undefined) {\n\t\t\t\tstore.set({ type: 'initialize' }, childInitialize)\n\t\t\t}\n\t\t\treturn store\n\t\t}\n\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn blueprintListeners.clone()\n\t}\n\n\tprivate initializeEntityListEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityListEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn blueprintListeners.clone()\n\t}\n\n\tprivate initializeEntityListChildEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.childEventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn blueprintListeners.clone()\n\t}\n\n\tprivate initializeFieldEventListenerStore(marker: FieldMarker): FieldEventListenerStore | undefined {\n\t\treturn marker.parameters.eventListeners?.clone()\n\t}\n}\n"],"names":["FieldOperations","EntityOperations","ListOperations","EntityListSubTreeMarker","ServerId","UnpersistedEntityDummyId","RealmKeyGenerator","getEntityMarker","FieldMarker","BindingError","HasManyRelationMarker","HasOneRelationMarker","assertNever","entity","EntityAccessorImpl","BijectiveIndexedMap","EntityListAccessorImpl","FieldAccessorImpl","blueprintListeners","EventListenersStore"],"mappings":";;;;;;;;;;;;;;;AAoCO,MAAM,iBAAiB;AAAA,EAKtB,YACN,sBACA,qBACiB,cACA,WAChB;AAFgB,SAAA,eAAA;AACA,SAAA,YAAA;AARlB,kBAAA,MAAiB,iBAAA;AACjB,kBAAA,MAAiB,kBAAA;AACjB,kBAAA,MAAiB,gBAAA;AAQhB,SAAK,kBAAkB,IAAIA,gBAAAA,gBAAgB,sBAAsB,KAAK,cAAc,MAAM,KAAK,SAAS;AACxG,SAAK,mBAAmB,IAAIC,iBAAAA,iBAAiB,sBAAsB,qBAAqB,KAAK,cAAc,MAAM,KAAK,SAAS;AAC/H,SAAK,iBAAiB,IAAIC,eAAAA,eAAe,sBAAsB,qBAAqB,KAAK,cAAc,MAAM,KAAK,SAAS;AAAA,EAC5H;AAAA,EAEO,kBAAkB,MAAoE;AAC5F,QAAI;AACJ,UAAM,oBAAoB,KAAK,UAAU,qBAAqB,IAAI,KAAK,eAAe;AAEtF,QAAI,gBAAgBC,cAAAA,yBAAyB;AAC5C,YAAM,qBAAoC,6BAA6B,MAAM,wCAAwB,IAAA;AACrG,qBAAe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