@prestizni-software/server-dem 0.7.3 → 0.7.5

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 (525) hide show
  1. package/AutoUpdateClientManagerClass.d.ts +141 -0
  2. package/AutoUpdateClientManagerClass.js +656 -0
  3. package/AutoUpdateClientManagerClass.js.map +1 -0
  4. package/AutoUpdateManagerClass.d.ts +102 -0
  5. package/AutoUpdateManagerClass.js +117 -0
  6. package/AutoUpdateManagerClass.js.map +1 -0
  7. package/AutoUpdateServerManagerClass.d.ts +208 -0
  8. package/AutoUpdateServerManagerClass.js +913 -0
  9. package/AutoUpdateServerManagerClass.js.map +1 -0
  10. package/AutoUpdatedClientObjectClass.d.ts +215 -0
  11. package/AutoUpdatedClientObjectClass.js +911 -0
  12. package/AutoUpdatedClientObjectClass.js.map +1 -0
  13. package/AutoUpdatedServerObjectClass.d.ts +134 -0
  14. package/AutoUpdatedServerObjectClass.js +346 -0
  15. package/AutoUpdatedServerObjectClass.js.map +1 -0
  16. package/ClientTypes.d.ts +15 -0
  17. package/ClientTypes.js +52 -0
  18. package/ClientTypes.js.map +1 -0
  19. package/CommonTypes.d.ts +259 -0
  20. package/CommonTypes.js +233 -0
  21. package/CommonTypes.js.map +1 -0
  22. package/CommonTypes_server.d.ts +1 -0
  23. package/CommonTypes_server.js +2 -0
  24. package/CommonTypes_server.js.map +1 -0
  25. package/{dist/DEMErrors.d.ts → DEMErrors.d.ts} +22 -2
  26. package/{dist/DEMErrors.js → DEMErrors.js} +22 -2
  27. package/{dist/DEMErrors.js.map → DEMErrors.js.map} +1 -1
  28. package/ServerTypes.d.ts +16 -0
  29. package/ServerTypes.js +60 -0
  30. package/ServerTypes.js.map +1 -0
  31. package/client.d.ts +6 -0
  32. package/client.js +7 -0
  33. package/client.js.map +1 -0
  34. package/coverage/lcov-report/block-navigation.js +71 -0
  35. package/coverage/lcov-report/block-navigation.js.map +1 -0
  36. package/coverage/lcov-report/prettify.js +478 -0
  37. package/coverage/lcov-report/prettify.js.map +1 -0
  38. package/coverage/lcov-report/sorter.js +177 -0
  39. package/coverage/lcov-report/sorter.js.map +1 -0
  40. package/dist/AutoUpdateClientManagerClass.d.ts +20 -0
  41. package/dist/AutoUpdateClientManagerClass.js +283 -0
  42. package/dist/AutoUpdateClientManagerClass.js.map +1 -0
  43. package/dist/AutoUpdateManagerClass.d.ts +17 -31
  44. package/dist/AutoUpdateManagerClass.js +15 -36
  45. package/dist/AutoUpdateManagerClass.js.map +1 -1
  46. package/dist/AutoUpdateServerManagerClass.d.ts +18 -118
  47. package/dist/AutoUpdateServerManagerClass.js +198 -583
  48. package/dist/AutoUpdateServerManagerClass.js.map +1 -1
  49. package/dist/AutoUpdatedClientObjectClass.d.ts +63 -92
  50. package/dist/AutoUpdatedClientObjectClass.js +660 -599
  51. package/dist/AutoUpdatedClientObjectClass.js.map +1 -1
  52. package/dist/AutoUpdatedServerObjectClass.d.ts +13 -33
  53. package/dist/AutoUpdatedServerObjectClass.js +92 -234
  54. package/dist/AutoUpdatedServerObjectClass.js.map +1 -1
  55. package/dist/ClientTypes.d.ts +13 -0
  56. package/dist/ClientTypes.js +70 -0
  57. package/dist/ClientTypes.js.map +1 -0
  58. package/dist/CommonTypes.d.ts +3 -220
  59. package/dist/CommonTypes.js +4 -188
  60. package/dist/CommonTypes.js.map +1 -1
  61. package/dist/CommonTypes_server.d.ts +1 -1
  62. package/dist/CommonTypes_server.js +2 -1
  63. package/dist/CommonTypes_server.js.map +1 -1
  64. package/dist/ServerTypes.d.ts +13 -0
  65. package/dist/ServerTypes.js +78 -0
  66. package/dist/ServerTypes.js.map +1 -0
  67. package/dist/TestTypes.d.ts +1 -0
  68. package/dist/TestTypes.js +7 -0
  69. package/dist/TestTypes.js.map +1 -0
  70. package/dist/client.d.ts +1 -0
  71. package/dist/client.js +12 -0
  72. package/dist/client.js.map +1 -0
  73. package/dist/coverage/lcov-report/block-navigation.d.ts +1 -0
  74. package/dist/coverage/lcov-report/block-navigation.js +71 -0
  75. package/dist/coverage/lcov-report/block-navigation.js.map +1 -0
  76. package/dist/coverage/lcov-report/prettify.d.ts +0 -0
  77. package/dist/coverage/lcov-report/prettify.js +736 -0
  78. package/dist/coverage/lcov-report/prettify.js.map +1 -0
  79. package/dist/coverage/lcov-report/sorter.d.ts +1 -0
  80. package/dist/coverage/lcov-report/sorter.js +177 -0
  81. package/dist/coverage/lcov-report/sorter.js.map +1 -0
  82. package/dist/dist/AutoUpdateClientManagerClass.d.ts +19 -0
  83. package/dist/dist/AutoUpdateClientManagerClass.js +284 -0
  84. package/dist/dist/AutoUpdateClientManagerClass.js.map +1 -0
  85. package/dist/dist/AutoUpdateManagerClass.d.ts +23 -0
  86. package/dist/dist/AutoUpdateManagerClass.js +60 -0
  87. package/dist/dist/AutoUpdateManagerClass.js.map +1 -0
  88. package/dist/dist/AutoUpdateServerManagerClass.d.ts +50 -0
  89. package/dist/dist/AutoUpdateServerManagerClass.js +413 -0
  90. package/dist/dist/AutoUpdateServerManagerClass.js.map +1 -0
  91. package/dist/dist/AutoUpdatedClientObjectClass.d.ts +72 -0
  92. package/dist/dist/AutoUpdatedClientObjectClass.js +865 -0
  93. package/dist/dist/AutoUpdatedClientObjectClass.js.map +1 -0
  94. package/dist/dist/AutoUpdatedServerObjectClass.d.ts +15 -0
  95. package/dist/dist/AutoUpdatedServerObjectClass.js +124 -0
  96. package/dist/dist/AutoUpdatedServerObjectClass.js.map +1 -0
  97. package/dist/dist/ClientTypes.d.ts +13 -0
  98. package/dist/dist/ClientTypes.js +71 -0
  99. package/dist/dist/ClientTypes.js.map +1 -0
  100. package/dist/dist/CommonTypes.d.ts +3 -0
  101. package/dist/dist/CommonTypes.js +20 -0
  102. package/dist/dist/CommonTypes.js.map +1 -0
  103. package/dist/dist/CommonTypes_server.d.ts +1 -0
  104. package/dist/dist/CommonTypes_server.js +4 -0
  105. package/dist/dist/CommonTypes_server.js.map +1 -0
  106. package/dist/dist/ServerTypes.d.ts +13 -0
  107. package/dist/dist/ServerTypes.js +79 -0
  108. package/dist/dist/ServerTypes.js.map +1 -0
  109. package/dist/dist/TestTypes.d.ts +1 -0
  110. package/dist/dist/TestTypes.js +8 -0
  111. package/dist/dist/TestTypes.js.map +1 -0
  112. package/dist/dist/client.d.ts +1 -0
  113. package/dist/dist/client.js +13 -0
  114. package/dist/dist/client.js.map +1 -0
  115. package/dist/dist/coverage/lcov-report/block-navigation.d.ts +1 -0
  116. package/dist/dist/coverage/lcov-report/block-navigation.js +71 -0
  117. package/dist/dist/coverage/lcov-report/block-navigation.js.map +1 -0
  118. package/dist/dist/coverage/lcov-report/prettify.d.ts +0 -0
  119. package/dist/dist/coverage/lcov-report/prettify.js +736 -0
  120. package/dist/dist/coverage/lcov-report/prettify.js.map +1 -0
  121. package/dist/dist/coverage/lcov-report/sorter.d.ts +1 -0
  122. package/dist/dist/coverage/lcov-report/sorter.js +177 -0
  123. package/dist/dist/coverage/lcov-report/sorter.js.map +1 -0
  124. package/dist/dist/dist/AutoUpdateClientManagerClass.d.ts +19 -0
  125. package/dist/dist/dist/AutoUpdateClientManagerClass.js +285 -0
  126. package/dist/dist/dist/AutoUpdateClientManagerClass.js.map +1 -0
  127. package/dist/dist/dist/AutoUpdateManagerClass.d.ts +23 -0
  128. package/dist/dist/dist/AutoUpdateManagerClass.js +61 -0
  129. package/dist/dist/dist/AutoUpdateManagerClass.js.map +1 -0
  130. package/dist/dist/dist/AutoUpdateServerManagerClass.d.ts +158 -0
  131. package/dist/dist/dist/AutoUpdateServerManagerClass.js +414 -0
  132. package/dist/dist/dist/AutoUpdateServerManagerClass.js.map +1 -0
  133. package/dist/dist/dist/AutoUpdatedClientObjectClass.d.ts +72 -0
  134. package/dist/dist/dist/AutoUpdatedClientObjectClass.js +866 -0
  135. package/dist/dist/dist/AutoUpdatedClientObjectClass.js.map +1 -0
  136. package/dist/dist/dist/AutoUpdatedServerObjectClass.d.ts +15 -0
  137. package/dist/dist/dist/AutoUpdatedServerObjectClass.js +125 -0
  138. package/dist/dist/dist/AutoUpdatedServerObjectClass.js.map +1 -0
  139. package/dist/dist/dist/ClientTypes.d.ts +13 -0
  140. package/dist/dist/dist/ClientTypes.js +72 -0
  141. package/dist/dist/dist/ClientTypes.js.map +1 -0
  142. package/dist/dist/dist/CommonTypes.d.ts +3 -0
  143. package/dist/dist/dist/CommonTypes.js +21 -0
  144. package/dist/dist/dist/CommonTypes.js.map +1 -0
  145. package/dist/dist/dist/CommonTypes_server.d.ts +1 -0
  146. package/dist/dist/dist/CommonTypes_server.js +5 -0
  147. package/dist/dist/dist/CommonTypes_server.js.map +1 -0
  148. package/dist/dist/dist/ServerTypes.d.ts +13 -0
  149. package/dist/dist/dist/ServerTypes.js +80 -0
  150. package/dist/dist/dist/ServerTypes.js.map +1 -0
  151. package/dist/dist/dist/TestTypes.d.ts +1 -0
  152. package/dist/dist/dist/TestTypes.js +9 -0
  153. package/dist/dist/dist/TestTypes.js.map +1 -0
  154. package/dist/dist/dist/client.d.ts +1 -0
  155. package/dist/dist/dist/client.js +14 -0
  156. package/dist/dist/dist/client.js.map +1 -0
  157. package/dist/dist/dist/coverage/lcov-report/block-navigation.d.ts +1 -0
  158. package/dist/dist/dist/coverage/lcov-report/block-navigation.js +71 -0
  159. package/dist/dist/dist/coverage/lcov-report/block-navigation.js.map +1 -0
  160. package/dist/dist/dist/coverage/lcov-report/prettify.d.ts +0 -0
  161. package/dist/dist/dist/coverage/lcov-report/prettify.js +736 -0
  162. package/dist/dist/dist/coverage/lcov-report/prettify.js.map +1 -0
  163. package/dist/dist/dist/coverage/lcov-report/sorter.d.ts +1 -0
  164. package/dist/dist/dist/coverage/lcov-report/sorter.js +177 -0
  165. package/dist/dist/dist/coverage/lcov-report/sorter.js.map +1 -0
  166. package/dist/dist/dist/expo-test/app/(tabs)/_layout.d.ts +1 -0
  167. package/dist/dist/dist/expo-test/app/(tabs)/_layout.js +27 -0
  168. package/dist/dist/dist/expo-test/app/(tabs)/_layout.js.map +1 -0
  169. package/dist/dist/dist/expo-test/app/(tabs)/explore.d.ts +1 -0
  170. package/dist/dist/dist/expo-test/app/(tabs)/explore.js +95 -0
  171. package/dist/dist/dist/expo-test/app/(tabs)/explore.js.map +1 -0
  172. package/dist/dist/dist/expo-test/app/(tabs)/index.d.ts +1 -0
  173. package/dist/dist/dist/expo-test/app/(tabs)/index.js +81 -0
  174. package/dist/dist/dist/expo-test/app/(tabs)/index.js.map +1 -0
  175. package/dist/dist/dist/expo-test/app/_layout.d.ts +4 -0
  176. package/dist/dist/dist/expo-test/app/_layout.js +22 -0
  177. package/dist/dist/dist/expo-test/app/_layout.js.map +1 -0
  178. package/dist/dist/dist/expo-test/app/modal.d.ts +1 -0
  179. package/dist/dist/dist/expo-test/app/modal.js +28 -0
  180. package/dist/dist/dist/expo-test/app/modal.js.map +1 -0
  181. package/dist/dist/dist/expo-test/components/external-link.d.ts +4 -0
  182. package/dist/dist/dist/expo-test/components/external-link.js +18 -0
  183. package/dist/dist/dist/expo-test/components/external-link.js.map +1 -0
  184. package/dist/dist/dist/expo-test/components/haptic-tab.d.ts +1 -0
  185. package/dist/dist/dist/expo-test/components/haptic-tab.js +15 -0
  186. package/dist/dist/dist/expo-test/components/haptic-tab.js.map +1 -0
  187. package/dist/dist/dist/expo-test/components/hello-wave.d.ts +1 -0
  188. package/dist/dist/dist/expo-test/components/hello-wave.js +19 -0
  189. package/dist/dist/dist/expo-test/components/hello-wave.js.map +1 -0
  190. package/dist/dist/dist/expo-test/components/parallax-scroll-view.d.ts +5 -0
  191. package/dist/dist/dist/expo-test/components/parallax-scroll-view.js +53 -0
  192. package/dist/dist/dist/expo-test/components/parallax-scroll-view.js.map +1 -0
  193. package/dist/dist/dist/expo-test/components/themed-text.d.ts +7 -0
  194. package/dist/dist/dist/expo-test/components/themed-text.js +43 -0
  195. package/dist/dist/dist/expo-test/components/themed-text.js.map +1 -0
  196. package/dist/dist/dist/expo-test/components/themed-view.d.ts +6 -0
  197. package/dist/dist/dist/expo-test/components/themed-view.js +10 -0
  198. package/dist/dist/dist/expo-test/components/themed-view.js.map +1 -0
  199. package/dist/dist/dist/expo-test/components/ui/collapsible.d.ts +4 -0
  200. package/dist/dist/dist/expo-test/components/ui/collapsible.js +34 -0
  201. package/dist/dist/dist/expo-test/components/ui/collapsible.js.map +1 -0
  202. package/dist/dist/dist/expo-test/components/ui/icon-symbol.d.ts +11 -0
  203. package/dist/dist/dist/expo-test/components/ui/icon-symbol.ios.d.ts +7 -0
  204. package/dist/dist/dist/expo-test/components/ui/icon-symbol.ios.js +14 -0
  205. package/dist/dist/dist/expo-test/components/ui/icon-symbol.ios.js.map +1 -0
  206. package/dist/dist/dist/expo-test/components/ui/icon-symbol.js +25 -0
  207. package/dist/dist/dist/expo-test/components/ui/icon-symbol.js.map +1 -0
  208. package/dist/dist/dist/expo-test/constants/theme.d.ts +26 -0
  209. package/dist/dist/dist/expo-test/constants/theme.js +53 -0
  210. package/dist/dist/dist/expo-test/constants/theme.js.map +1 -0
  211. package/dist/dist/dist/expo-test/eslint.config.d.ts +2 -0
  212. package/dist/dist/dist/expo-test/eslint.config.js +11 -0
  213. package/dist/dist/dist/expo-test/eslint.config.js.map +1 -0
  214. package/dist/dist/dist/expo-test/hooks/use-color-scheme.d.ts +1 -0
  215. package/dist/dist/dist/expo-test/hooks/use-color-scheme.js +5 -0
  216. package/dist/dist/dist/expo-test/hooks/use-color-scheme.js.map +1 -0
  217. package/dist/dist/dist/expo-test/hooks/use-color-scheme.web.d.ts +4 -0
  218. package/dist/dist/dist/expo-test/hooks/use-color-scheme.web.js +20 -0
  219. package/dist/dist/dist/expo-test/hooks/use-color-scheme.web.js.map +1 -0
  220. package/dist/dist/dist/expo-test/hooks/use-theme-color.d.ts +1 -0
  221. package/dist/dist/dist/expo-test/hooks/use-theme-color.js +20 -0
  222. package/dist/dist/dist/expo-test/hooks/use-theme-color.js.map +1 -0
  223. package/dist/dist/dist/expo-test/scripts/reset-project.d.ts +2 -0
  224. package/dist/dist/dist/expo-test/scripts/reset-project.js +98 -0
  225. package/dist/dist/dist/expo-test/scripts/reset-project.js.map +1 -0
  226. package/dist/dist/dist/jest.config.d.ts +21 -0
  227. package/dist/dist/dist/jest.config.js +20 -0
  228. package/dist/dist/dist/jest.config.js.map +1 -0
  229. package/dist/dist/dist/server.d.ts +1 -0
  230. package/dist/dist/dist/server.js +16 -0
  231. package/dist/dist/dist/server.js.map +1 -0
  232. package/dist/dist/dist/socket_test.d.ts +1 -0
  233. package/dist/dist/dist/socket_test.js +24 -0
  234. package/dist/dist/dist/socket_test.js.map +1 -0
  235. package/dist/dist/dist/test.d.ts +1 -0
  236. package/dist/dist/dist/test.js +7 -0
  237. package/dist/dist/dist/test.js.map +1 -0
  238. package/dist/dist/dist/test_client.d.ts +1 -0
  239. package/dist/dist/dist/test_client.js +26 -0
  240. package/dist/dist/dist/test_client.js.map +1 -0
  241. package/dist/dist/dist/test_lib.d.ts +2 -0
  242. package/dist/dist/dist/test_lib.js +85 -0
  243. package/dist/dist/dist/test_lib.js.map +1 -0
  244. package/dist/dist/dist/test_server.d.ts +1 -0
  245. package/dist/dist/dist/test_server.js +54 -0
  246. package/dist/dist/dist/test_server.js.map +1 -0
  247. package/dist/dist/dist/tests/dem.test.d.ts +1 -0
  248. package/dist/dist/dist/tests/dem.test.js +341 -0
  249. package/dist/dist/dist/tests/dem.test.js.map +1 -0
  250. package/dist/dist/expo-test/app/(tabs)/_layout.d.ts +1 -0
  251. package/dist/dist/expo-test/app/(tabs)/_layout.js +26 -0
  252. package/dist/dist/expo-test/app/(tabs)/_layout.js.map +1 -0
  253. package/dist/dist/expo-test/app/(tabs)/explore.d.ts +1 -0
  254. package/dist/dist/expo-test/app/(tabs)/explore.js +94 -0
  255. package/dist/dist/expo-test/app/(tabs)/explore.js.map +1 -0
  256. package/dist/dist/expo-test/app/(tabs)/index.d.ts +1 -0
  257. package/dist/dist/expo-test/app/(tabs)/index.js +80 -0
  258. package/dist/dist/expo-test/app/(tabs)/index.js.map +1 -0
  259. package/dist/dist/expo-test/app/_layout.d.ts +4 -0
  260. package/dist/dist/expo-test/app/_layout.js +21 -0
  261. package/dist/dist/expo-test/app/_layout.js.map +1 -0
  262. package/dist/dist/expo-test/app/modal.d.ts +1 -0
  263. package/dist/dist/expo-test/app/modal.js +27 -0
  264. package/dist/dist/expo-test/app/modal.js.map +1 -0
  265. package/dist/dist/expo-test/components/external-link.d.ts +4 -0
  266. package/dist/dist/expo-test/components/external-link.js +17 -0
  267. package/dist/dist/expo-test/components/external-link.js.map +1 -0
  268. package/dist/dist/expo-test/components/haptic-tab.d.ts +1 -0
  269. package/dist/dist/expo-test/components/haptic-tab.js +14 -0
  270. package/dist/dist/expo-test/components/haptic-tab.js.map +1 -0
  271. package/dist/dist/expo-test/components/hello-wave.d.ts +1 -0
  272. package/dist/dist/expo-test/components/hello-wave.js +18 -0
  273. package/dist/dist/expo-test/components/hello-wave.js.map +1 -0
  274. package/dist/dist/expo-test/components/parallax-scroll-view.d.ts +5 -0
  275. package/dist/dist/expo-test/components/parallax-scroll-view.js +52 -0
  276. package/dist/dist/expo-test/components/parallax-scroll-view.js.map +1 -0
  277. package/dist/dist/expo-test/components/themed-text.d.ts +7 -0
  278. package/dist/dist/expo-test/components/themed-text.js +42 -0
  279. package/dist/dist/expo-test/components/themed-text.js.map +1 -0
  280. package/dist/dist/expo-test/components/themed-view.d.ts +6 -0
  281. package/dist/dist/expo-test/components/themed-view.js +9 -0
  282. package/dist/dist/expo-test/components/themed-view.js.map +1 -0
  283. package/dist/dist/expo-test/components/ui/collapsible.d.ts +4 -0
  284. package/dist/dist/expo-test/components/ui/collapsible.js +33 -0
  285. package/dist/dist/expo-test/components/ui/collapsible.js.map +1 -0
  286. package/dist/dist/expo-test/components/ui/icon-symbol.d.ts +11 -0
  287. package/dist/dist/expo-test/components/ui/icon-symbol.ios.d.ts +7 -0
  288. package/dist/dist/expo-test/components/ui/icon-symbol.ios.js +13 -0
  289. package/dist/dist/expo-test/components/ui/icon-symbol.ios.js.map +1 -0
  290. package/dist/dist/expo-test/components/ui/icon-symbol.js +24 -0
  291. package/dist/dist/expo-test/components/ui/icon-symbol.js.map +1 -0
  292. package/dist/dist/expo-test/constants/theme.d.ts +26 -0
  293. package/dist/dist/expo-test/constants/theme.js +52 -0
  294. package/dist/dist/expo-test/constants/theme.js.map +1 -0
  295. package/dist/dist/expo-test/eslint.config.d.ts +2 -0
  296. package/dist/dist/expo-test/eslint.config.js +11 -0
  297. package/dist/dist/expo-test/eslint.config.js.map +1 -0
  298. package/dist/dist/expo-test/hooks/use-color-scheme.d.ts +1 -0
  299. package/dist/dist/expo-test/hooks/use-color-scheme.js +4 -0
  300. package/dist/dist/expo-test/hooks/use-color-scheme.js.map +1 -0
  301. package/dist/dist/expo-test/hooks/use-color-scheme.web.d.ts +4 -0
  302. package/dist/dist/expo-test/hooks/use-color-scheme.web.js +19 -0
  303. package/dist/dist/expo-test/hooks/use-color-scheme.web.js.map +1 -0
  304. package/dist/dist/expo-test/hooks/use-theme-color.d.ts +1 -0
  305. package/dist/dist/expo-test/hooks/use-theme-color.js +19 -0
  306. package/dist/dist/expo-test/hooks/use-theme-color.js.map +1 -0
  307. package/dist/dist/expo-test/scripts/reset-project.d.ts +2 -0
  308. package/dist/dist/expo-test/scripts/reset-project.js +98 -0
  309. package/dist/dist/expo-test/scripts/reset-project.js.map +1 -0
  310. package/dist/dist/jest.config.d.ts +21 -0
  311. package/dist/dist/jest.config.js +19 -0
  312. package/dist/dist/jest.config.js.map +1 -0
  313. package/dist/dist/server.d.ts +1 -0
  314. package/dist/dist/server.js +15 -0
  315. package/dist/dist/server.js.map +1 -0
  316. package/dist/dist/socket_test.d.ts +1 -0
  317. package/dist/dist/socket_test.js +23 -0
  318. package/dist/dist/socket_test.js.map +1 -0
  319. package/dist/dist/test.d.ts +1 -0
  320. package/dist/dist/test.js +6 -0
  321. package/dist/dist/test.js.map +1 -0
  322. package/dist/dist/test_client.d.ts +1 -0
  323. package/dist/dist/test_client.js +25 -0
  324. package/dist/dist/test_client.js.map +1 -0
  325. package/dist/dist/test_lib.d.ts +2 -0
  326. package/dist/dist/test_lib.js +84 -0
  327. package/dist/dist/test_lib.js.map +1 -0
  328. package/dist/dist/test_server.d.ts +1 -0
  329. package/dist/dist/test_server.js +53 -0
  330. package/dist/dist/test_server.js.map +1 -0
  331. package/dist/dist/tests/dem.test.d.ts +1 -0
  332. package/dist/dist/tests/dem.test.js +340 -0
  333. package/dist/dist/tests/dem.test.js.map +1 -0
  334. package/dist/expo-test/app/(tabs)/_layout.d.ts +1 -0
  335. package/dist/expo-test/app/(tabs)/_layout.js +25 -0
  336. package/dist/expo-test/app/(tabs)/_layout.js.map +1 -0
  337. package/dist/expo-test/app/(tabs)/explore.d.ts +1 -0
  338. package/dist/expo-test/app/(tabs)/explore.js +93 -0
  339. package/dist/expo-test/app/(tabs)/explore.js.map +1 -0
  340. package/dist/expo-test/app/(tabs)/index.d.ts +1 -0
  341. package/dist/expo-test/app/(tabs)/index.js +79 -0
  342. package/dist/expo-test/app/(tabs)/index.js.map +1 -0
  343. package/dist/expo-test/app/_layout.d.ts +4 -0
  344. package/dist/expo-test/app/_layout.js +20 -0
  345. package/dist/expo-test/app/_layout.js.map +1 -0
  346. package/dist/expo-test/app/modal.d.ts +1 -0
  347. package/dist/expo-test/app/modal.js +26 -0
  348. package/dist/expo-test/app/modal.js.map +1 -0
  349. package/dist/expo-test/components/external-link.d.ts +4 -0
  350. package/dist/expo-test/components/external-link.js +16 -0
  351. package/dist/expo-test/components/external-link.js.map +1 -0
  352. package/dist/expo-test/components/haptic-tab.d.ts +1 -0
  353. package/dist/expo-test/components/haptic-tab.js +13 -0
  354. package/dist/expo-test/components/haptic-tab.js.map +1 -0
  355. package/dist/expo-test/components/hello-wave.d.ts +1 -0
  356. package/dist/expo-test/components/hello-wave.js +17 -0
  357. package/dist/expo-test/components/hello-wave.js.map +1 -0
  358. package/dist/expo-test/components/parallax-scroll-view.d.ts +5 -0
  359. package/dist/expo-test/components/parallax-scroll-view.js +51 -0
  360. package/dist/expo-test/components/parallax-scroll-view.js.map +1 -0
  361. package/dist/expo-test/components/themed-text.d.ts +7 -0
  362. package/dist/expo-test/components/themed-text.js +41 -0
  363. package/dist/expo-test/components/themed-text.js.map +1 -0
  364. package/dist/expo-test/components/themed-view.d.ts +6 -0
  365. package/dist/expo-test/components/themed-view.js +8 -0
  366. package/dist/expo-test/components/themed-view.js.map +1 -0
  367. package/dist/expo-test/components/ui/collapsible.d.ts +4 -0
  368. package/dist/expo-test/components/ui/collapsible.js +32 -0
  369. package/dist/expo-test/components/ui/collapsible.js.map +1 -0
  370. package/dist/expo-test/components/ui/icon-symbol.d.ts +11 -0
  371. package/dist/expo-test/components/ui/icon-symbol.ios.d.ts +7 -0
  372. package/dist/expo-test/components/ui/icon-symbol.ios.js +12 -0
  373. package/dist/expo-test/components/ui/icon-symbol.ios.js.map +1 -0
  374. package/dist/expo-test/components/ui/icon-symbol.js +23 -0
  375. package/dist/expo-test/components/ui/icon-symbol.js.map +1 -0
  376. package/dist/expo-test/constants/theme.d.ts +26 -0
  377. package/dist/expo-test/constants/theme.js +51 -0
  378. package/dist/expo-test/constants/theme.js.map +1 -0
  379. package/dist/expo-test/eslint.config.d.ts +2 -0
  380. package/dist/expo-test/eslint.config.js +11 -0
  381. package/dist/expo-test/eslint.config.js.map +1 -0
  382. package/dist/expo-test/hooks/use-color-scheme.d.ts +1 -0
  383. package/dist/expo-test/hooks/use-color-scheme.js +3 -0
  384. package/dist/expo-test/hooks/use-color-scheme.js.map +1 -0
  385. package/dist/expo-test/hooks/use-color-scheme.web.d.ts +4 -0
  386. package/dist/expo-test/hooks/use-color-scheme.web.js +18 -0
  387. package/dist/expo-test/hooks/use-color-scheme.web.js.map +1 -0
  388. package/dist/expo-test/hooks/use-theme-color.d.ts +1 -0
  389. package/dist/expo-test/hooks/use-theme-color.js +18 -0
  390. package/dist/expo-test/hooks/use-theme-color.js.map +1 -0
  391. package/dist/expo-test/scripts/reset-project.d.ts +2 -0
  392. package/dist/expo-test/scripts/reset-project.js +98 -0
  393. package/dist/expo-test/scripts/reset-project.js.map +1 -0
  394. package/dist/jest.config.d.ts +21 -0
  395. package/dist/jest.config.js +18 -0
  396. package/dist/jest.config.js.map +1 -0
  397. package/dist/server.d.ts +1 -8
  398. package/dist/server.js +13 -8
  399. package/dist/server.js.map +1 -1
  400. package/dist/socket_test.d.ts +1 -0
  401. package/dist/socket_test.js +22 -0
  402. package/dist/socket_test.js.map +1 -0
  403. package/dist/test.d.ts +1 -0
  404. package/dist/test.js +5 -0
  405. package/dist/test.js.map +1 -0
  406. package/dist/test_client.d.ts +1 -0
  407. package/dist/test_client.js +24 -0
  408. package/dist/test_client.js.map +1 -0
  409. package/dist/test_lib.d.ts +12 -0
  410. package/dist/test_lib.js +83 -0
  411. package/dist/test_lib.js.map +1 -0
  412. package/dist/test_server.d.ts +1 -0
  413. package/dist/test_server.js +52 -0
  414. package/dist/test_server.js.map +1 -0
  415. package/dist/tests/dem.test.d.ts +1 -0
  416. package/dist/tests/dem.test.js +339 -0
  417. package/dist/tests/dem.test.js.map +1 -0
  418. package/expo-test/app/(tabs)/_layout.d.ts +2 -0
  419. package/expo-test/app/(tabs)/_layout.js +24 -0
  420. package/expo-test/app/(tabs)/_layout.js.map +1 -0
  421. package/expo-test/app/(tabs)/explore.d.ts +1 -0
  422. package/expo-test/app/(tabs)/explore.js +92 -0
  423. package/expo-test/app/(tabs)/explore.js.map +1 -0
  424. package/expo-test/app/(tabs)/index.d.ts +1 -0
  425. package/expo-test/app/(tabs)/index.js +78 -0
  426. package/expo-test/app/(tabs)/index.js.map +1 -0
  427. package/expo-test/app/_layout.d.ts +5 -0
  428. package/expo-test/app/_layout.js +19 -0
  429. package/expo-test/app/_layout.js.map +1 -0
  430. package/expo-test/app/modal.d.ts +1 -0
  431. package/expo-test/app/modal.js +25 -0
  432. package/expo-test/app/modal.js.map +1 -0
  433. package/expo-test/components/external-link.d.ts +7 -0
  434. package/expo-test/components/external-link.js +15 -0
  435. package/expo-test/components/external-link.js.map +1 -0
  436. package/expo-test/components/haptic-tab.d.ts +2 -0
  437. package/expo-test/components/haptic-tab.js +12 -0
  438. package/expo-test/components/haptic-tab.js.map +1 -0
  439. package/expo-test/components/hello-wave.d.ts +1 -0
  440. package/expo-test/components/hello-wave.js +16 -0
  441. package/expo-test/components/hello-wave.js.map +1 -0
  442. package/expo-test/components/parallax-scroll-view.d.ts +10 -0
  443. package/expo-test/components/parallax-scroll-view.js +50 -0
  444. package/expo-test/components/parallax-scroll-view.js.map +1 -0
  445. package/expo-test/components/themed-text.d.ts +7 -0
  446. package/expo-test/components/themed-text.js +40 -0
  447. package/expo-test/components/themed-text.js.map +1 -0
  448. package/expo-test/components/themed-view.d.ts +6 -0
  449. package/expo-test/components/themed-view.js +7 -0
  450. package/expo-test/components/themed-view.js.map +1 -0
  451. package/expo-test/components/ui/collapsible.d.ts +4 -0
  452. package/expo-test/components/ui/collapsible.js +31 -0
  453. package/expo-test/components/ui/collapsible.js.map +1 -0
  454. package/expo-test/components/ui/icon-symbol.d.ts +25 -0
  455. package/expo-test/components/ui/icon-symbol.ios.d.ts +9 -0
  456. package/expo-test/components/ui/icon-symbol.ios.js +11 -0
  457. package/expo-test/components/ui/icon-symbol.ios.js.map +1 -0
  458. package/expo-test/components/ui/icon-symbol.js +22 -0
  459. package/expo-test/components/ui/icon-symbol.js.map +1 -0
  460. package/expo-test/constants/theme.d.ts +32 -0
  461. package/expo-test/constants/theme.js +50 -0
  462. package/expo-test/constants/theme.js.map +1 -0
  463. package/expo-test/eslint.config.d.ts +2 -0
  464. package/expo-test/eslint.config.js +11 -0
  465. package/expo-test/eslint.config.js.map +1 -0
  466. package/expo-test/hooks/use-color-scheme.d.ts +1 -0
  467. package/expo-test/hooks/use-color-scheme.js +2 -0
  468. package/expo-test/hooks/use-color-scheme.js.map +1 -0
  469. package/expo-test/hooks/use-color-scheme.web.d.ts +4 -0
  470. package/expo-test/hooks/use-color-scheme.web.js +17 -0
  471. package/expo-test/hooks/use-color-scheme.web.js.map +1 -0
  472. package/expo-test/hooks/use-theme-color.d.ts +9 -0
  473. package/expo-test/hooks/use-theme-color.js +17 -0
  474. package/expo-test/hooks/use-theme-color.js.map +1 -0
  475. package/expo-test/scripts/reset-project.d.ts +2 -0
  476. package/expo-test/scripts/reset-project.js +98 -0
  477. package/expo-test/scripts/reset-project.js.map +1 -0
  478. package/index.d.ts +4 -0
  479. package/index.js +5 -0
  480. package/index.js.map +1 -0
  481. package/jest.config.d.ts +3 -0
  482. package/jest.config.js +17 -0
  483. package/jest.config.js.map +1 -0
  484. package/package.json +23 -42
  485. package/server.d.ts +8 -0
  486. package/server.js +9 -0
  487. package/server.js.map +1 -0
  488. package/{dist/sync → sync}/ClientStateReconciler.d.ts +20 -0
  489. package/{dist/sync → sync}/ClientStateReconciler.js +20 -0
  490. package/sync/ClientStateReconciler.js.map +1 -0
  491. package/{dist/sync → sync}/ServerChangeTracker.d.ts +46 -0
  492. package/{dist/sync → sync}/ServerChangeTracker.js +46 -0
  493. package/sync/ServerChangeTracker.js.map +1 -0
  494. package/sync/storage/IndexedDbStorageAdapter.d.ts +53 -0
  495. package/{dist/sync → sync}/storage/IndexedDbStorageAdapter.js +31 -0
  496. package/sync/storage/IndexedDbStorageAdapter.js.map +1 -0
  497. package/sync/storage/LocalStorageAdapter.d.ts +59 -0
  498. package/{dist/sync → sync}/storage/LocalStorageAdapter.js +32 -0
  499. package/sync/storage/LocalStorageAdapter.js.map +1 -0
  500. package/sync/storage/MemoryStorageAdapter.d.ts +34 -0
  501. package/sync/storage/MemoryStorageAdapter.js +45 -0
  502. package/sync/storage/MemoryStorageAdapter.js.map +1 -0
  503. package/version.d.ts +21 -0
  504. package/version.js +22 -0
  505. package/version.js.map +1 -0
  506. package/README.md +0 -18
  507. package/dist/sync/ClientStateReconciler.js.map +0 -1
  508. package/dist/sync/ServerChangeTracker.js.map +0 -1
  509. package/dist/sync/storage/IndexedDbStorageAdapter.d.ts +0 -22
  510. package/dist/sync/storage/IndexedDbStorageAdapter.js.map +0 -1
  511. package/dist/sync/storage/LocalStorageAdapter.d.ts +0 -27
  512. package/dist/sync/storage/LocalStorageAdapter.js.map +0 -1
  513. package/dist/sync/storage/MemoryStorageAdapter.d.ts +0 -13
  514. package/dist/sync/storage/MemoryStorageAdapter.js +0 -25
  515. package/dist/sync/storage/MemoryStorageAdapter.js.map +0 -1
  516. package/dist/tsconfig.tsbuildinfo +0 -1
  517. /package/{dist/sync → sync}/index.d.ts +0 -0
  518. /package/{dist/sync → sync}/index.js +0 -0
  519. /package/{dist/sync → sync}/index.js.map +0 -0
  520. /package/{dist/sync → sync}/storage/IClientStorageAdapter.d.ts +0 -0
  521. /package/{dist/sync → sync}/storage/IClientStorageAdapter.js +0 -0
  522. /package/{dist/sync → sync}/storage/IClientStorageAdapter.js.map +0 -0
  523. /package/{dist/sync → sync}/types.d.ts +0 -0
  524. /package/{dist/sync → sync}/types.js +0 -0
  525. /package/{dist/sync → sync}/types.js.map +0 -0
@@ -1,129 +1,177 @@
1
1
  import "reflect-metadata";
2
2
  import _ from "lodash";
3
- import { EVENT_INTERNAL_PRE_LOADED, EVENT_DELETE, EVENT_GET, EVENT_NEW, EVENT_UPDATE, globalCache, DEMError, DEMErrorCode, toDEMError, } from "./CommonTypes.js";
4
3
  import { ObjectId } from "bson";
4
+ import { stringSimilarity } from "string-similarity-js";
5
+ export async function createAutoUpdatedClass(classParam, className, socket, data, loggers, parentManager, emitter, callback) {
6
+ if (typeof data !== "string" && data._id) {
7
+ processIsRefProperties(data, classParam.prototype, undefined, [], loggers);
8
+ }
9
+ const props = Reflect.getMetadata("props", classParam.prototype);
10
+ const instance = new AutoUpdatedClientObject(socket, data, loggers, props, className, classParam, parentManager, callback, emitter, false);
11
+ return instance;
12
+ }
5
13
  export class AutoUpdatedClientObject {
6
- entry;
7
14
  socket;
8
15
  data;
9
16
  isServer = false;
10
- loggers;
17
+ loggers = {
18
+ info: () => { },
19
+ debug: () => { },
20
+ error: () => { },
21
+ warn: () => { },
22
+ };
11
23
  isLoading = true;
12
- loadError;
13
- isLoadingReferences = true;
14
- checkedMissingProperties;
15
24
  emitter;
16
25
  properties;
17
- classParam;
18
26
  className;
19
27
  parentManager;
20
- static _emitterCounter = 0;
21
- EmitterID = `dem_e_${++AutoUpdatedClientObject._emitterCounter}`;
22
- toChangeOnParents;
28
+ isLoadingReferences = true;
29
+ classProp;
30
+ EmitterID = new ObjectId().toHexString();
31
+ toChangeOnParents = [];
23
32
  callbacks;
24
- loadReferencesAsync = async () => {
25
- try {
26
- if (!this.isLoaded) {
27
- await this.waitForPreloaded();
28
- }
29
- this.generateSettersAndGetters();
30
- if (this.isServer) {
33
+ referencesLoaded = false;
34
+ loadShit = async () => {
35
+ if (this.isLoaded) {
36
+ try {
31
37
  await this.loadForceReferences();
32
- if (this.toChangeOnParents) {
33
- for (const thing of this.toChangeOnParents) {
34
- await this.setValue__(thing.key, thing.value, true, false, false, true);
35
- }
38
+ for (const thing of this.toChangeOnParents) {
39
+ await this.setValue__(thing.key, thing.value);
36
40
  }
37
41
  }
42
+ catch (error) {
43
+ this.loggers.error("Error loading references");
44
+ this.loggers.error(error.message);
45
+ this.loggers.error(error.stack);
46
+ }
47
+ this.isLoadingReferences = false;
48
+ return;
38
49
  }
39
- catch (error) {
40
- // Fix 3: Enhanced diagnostics with stack trace
41
- this.loggers.error?.("Error loading references: " +
42
- (error instanceof Error ? error.message + "\n" + error.stack : String(error)));
50
+ await new Promise((resolve, reject) => {
51
+ this.emitter.once("pre-loaded" + this.EmitterID, (failed, reason) => {
52
+ if (failed) {
53
+ reject(new Error(reason));
54
+ }
55
+ else
56
+ resolve();
57
+ });
58
+ });
59
+ try {
60
+ await this.loadForceReferences();
61
+ for (const thing of this.toChangeOnParents) {
62
+ await this.setValue__(thing.key, thing.value);
63
+ }
64
+ this.isLoadingReferences = false;
43
65
  }
44
- finally {
66
+ catch (error) {
45
67
  this.isLoadingReferences = false;
68
+ this.loggers.error("Error loading references");
69
+ this.loggers.error(error.message);
70
+ this.loggers.error(error.stack);
46
71
  }
72
+ this.callbacks.new(this);
47
73
  };
48
- constructor(classParam, socket, data, loggers, className, parentManager, callback, emitter, isServer = false) {
49
- if (!classParam ||
50
- !socket ||
51
- !data ||
52
- !loggers ||
53
- !className ||
54
- !parentManager ||
55
- !emitter) {
56
- this.classParam = classParam;
57
- this.socket = socket;
58
- this.data = data;
59
- this.loggers = loggers;
60
- this.className = className;
61
- this.parentManager = parentManager;
62
- this.callbacks = callback;
63
- this.emitter = emitter;
64
- this.properties = undefined;
65
- if (!classParam &&
66
- !socket &&
67
- !data &&
68
- !loggers &&
69
- !className &&
70
- !parentManager &&
71
- !callback &&
72
- !emitter)
73
- return;
74
- else
75
- throw new DEMError(DEMErrorCode.MISSING_ARGUMENT, "Missing arguments for AutoUpdatedClientObject: " + className);
76
- }
77
- this.classParam = classParam;
78
- this.socket = socket;
74
+ constructor(socket, data, loggers, properties, className, classProperty, parentManager, callback, emitter, isServer = false) {
79
75
  this.isServer = isServer;
80
76
  this.emitter = emitter;
77
+ this.classProp = classProperty;
81
78
  this.isLoadingReferences = true;
82
79
  this.isLoading = true;
83
80
  this.parentManager = parentManager;
84
81
  this.className = className;
85
- if (classParam) {
86
- const meta = setupClassAccessors(classParam);
87
- this.properties = meta.properties;
88
- }
89
- else {
90
- this.properties = [];
91
- }
82
+ this.properties = properties;
92
83
  this.callbacks = callback;
93
- this.loggers = {
94
- debug: (s) => loggers.debug?.(`[DEM - ${this.className}: ${this.data?._id ?? this._id ?? "not loaded"}] ${s}`),
95
- info: (s) => loggers.info?.(`[DEM - ${this.className}: ${this.data?._id ?? this._id ?? "not loaded"}] ${s}`),
96
- warn: (s) => loggers.warn?.(`[DEM - ${this.className}: ${this.data?._id ?? this._id ?? "not loaded"}] ${s}`),
97
- error: (s) => loggers.error?.(`[DEM - ${this.className}: ${this.data?._id ?? this._id ?? "not loaded"}] ${s}`),
98
- };
84
+ this.loggers.debug = (s) => loggers.debug("[DEM - " +
85
+ this.className +
86
+ ": " +
87
+ (this.data?._id ?? "not loaded") +
88
+ "] " +
89
+ s);
90
+ this.loggers.info = (s) => loggers.info("[DEM - " +
91
+ this.className +
92
+ ": " +
93
+ (this.data?._id ?? "not loaded") +
94
+ "] " +
95
+ s);
96
+ this.loggers.error = (s) => loggers.error("[DEM - " +
97
+ this.className +
98
+ ": " +
99
+ (this.data?._id ?? "not loaded") +
100
+ "] " +
101
+ s);
102
+ this.loggers.warn = (s) => loggers.warn("[DEM - " +
103
+ this.className +
104
+ ": " +
105
+ (this.data?._id ?? "not loaded") +
106
+ "] " +
107
+ s);
108
+ for (const prop of properties) {
109
+ if (typeof prop !== "string")
110
+ throw new Error("Property '" + prop.toString() + "' is not a string");
111
+ if (prop.includes("."))
112
+ throw new Error("Property '" +
113
+ prop.toString() +
114
+ "' constain the illegal character '.'");
115
+ }
116
+ this.socket = socket;
99
117
  if (typeof data === "string") {
100
- this.data = { _id: data };
101
118
  if (this.isServer) {
102
119
  this.isLoading = false;
103
- this.generateSettersAndGetters();
120
+ this.data = { _id: data };
104
121
  return;
105
122
  }
106
- this.socket.emit(EVENT_GET + this.className + data, null, (res) => {
123
+ if (!data || data === "" || data === "undefined") {
124
+ this.loggers.error("Cannot create a new AutoUpdatedClientClass with an empty string for ID. Data typeof: " +
125
+ typeof data +
126
+ " Data: " +
127
+ data);
128
+ throw new Error("Cannot create a new AutoUpdatedClientClass with an empty string for ID.");
129
+ }
130
+ this.loggers.debug("Getting new object from server " + this.className + " - " + data);
131
+ this.socket.emit("get" + this.className + data, null, (res) => {
107
132
  if (!res.success) {
108
133
  this.isLoading = false;
109
- this.loadError = res.message;
110
- this.loggers.error?.("Could not load data from server: " + res.message);
111
- this.emitter.emit(EVENT_INTERNAL_PRE_LOADED + this.EmitterID, true, res.message);
134
+ this.loggers.error("Could not load data from server: " + res.message);
135
+ this.emitter.emit("pre-loaded" + this.EmitterID);
112
136
  return;
113
137
  }
114
- this.data = this.handleDataCleanup(res.data);
115
- this.generateSettersAndGetters();
138
+ this.data = res.data;
116
139
  this.isLoading = false;
117
- this.emitter.emit(EVENT_INTERNAL_PRE_LOADED + this.EmitterID);
140
+ this.emitter.emit("pre-loaded" + this.EmitterID);
118
141
  this.openSockets();
119
142
  });
143
+ this.data = { _id: data };
120
144
  }
121
145
  else {
122
146
  this.isLoading = true;
123
- this.data = this.handleDataCleanup(data);
124
- if ((!this.data._id || this.data._id === "") && !this.isServer) {
125
- this.handleNewObject(this.data);
147
+ this.data = data;
148
+ const dataKeys = Object.keys(data);
149
+ for (const key of this.properties) {
150
+ if (typeof key !== "string")
151
+ throw new Error("Only string keys allowed. Not this shit: " + String(key));
152
+ dataKeys.splice(dataKeys.indexOf(key), 1);
153
+ const isRef = getMetadataRecursive("isRef", this.classProp.prototype, key);
154
+ if (isRef) {
155
+ if (Array.isArray(this.data[key])) {
156
+ this.data[key] = this.data[key].map((obj) => obj._id?.toString() ?? obj?.toString());
157
+ }
158
+ else {
159
+ this.data[key] =
160
+ this.data[key]?._id?.toString() ??
161
+ this.data[key]?.toString();
162
+ }
163
+ }
126
164
  }
165
+ if (dataKeys.includes("__v"))
166
+ dataKeys.splice(dataKeys.indexOf("__v"), 1);
167
+ if (dataKeys.length > 0)
168
+ this.loggers.warn((dataKeys.length > 1 ? "Properties " : "Property ") +
169
+ dataKeys.join(", ") +
170
+ (dataKeys.length > 1 ? " were " : " was ") +
171
+ "unexpected. These properties are not known by the class. Please check your level of skill issue. Known properties are:\n" +
172
+ this.properties.join("\n"));
173
+ if ((!this.data._id || this.data._id === "") && !this.isServer)
174
+ this.handleNewObject(data);
127
175
  else {
128
176
  this.isLoading = false;
129
177
  if (!this.isServer)
@@ -131,666 +179,678 @@ export class AutoUpdatedClientObject {
131
179
  }
132
180
  }
133
181
  this.generateSettersAndGetters();
134
- Promise.resolve().then(() => {
135
- this.generateSettersAndGetters();
136
- });
137
- }
138
- handleDataCleanup(data) {
139
- if (!data || typeof data !== "object")
140
- return data;
141
- const meta = this.classParam ? setupClassAccessors(this.classParam) : null;
142
- const refProps = meta ? meta.refProps : null;
143
- if (!refProps || refProps.size === 0)
144
- return data;
145
- const dataAsRecord = data;
146
- for (const key of refProps) {
147
- const val = dataAsRecord[key];
148
- if (!val)
149
- continue;
150
- if (Array.isArray(val)) {
151
- let needsNormalization = false;
152
- for (let i = 0; i < val.length; i++) {
153
- const item = val[i];
154
- if (item && typeof item === "object") {
155
- needsNormalization = true;
156
- break;
157
- }
158
- }
159
- if (needsNormalization) {
160
- dataAsRecord[key] = val.map((obj) => obj?._id?.toString() ??
161
- obj?.toString());
162
- }
163
- }
164
- else if (typeof val === "object") {
165
- dataAsRecord[key] =
166
- val?._id?.toString() ??
167
- val?.toString();
168
- }
169
- }
170
- return data;
171
- }
172
- async waitForPreloaded(timeoutMs = 15000) {
173
- if (this.loadError)
174
- throw new DEMError(DEMErrorCode.OBJECT_LOAD_FAILED, this.loadError);
175
- if (this.isLoaded)
176
- return;
177
- await new Promise((resolve, reject) => {
178
- const timer = setTimeout(() => {
179
- const errorMsg = `Timeout waiting for object preloading (${this.className})`;
180
- this.loadError = errorMsg;
181
- this.isLoading = false;
182
- reject(new DEMError(DEMErrorCode.PRELOAD_TIMEOUT, errorMsg));
183
- }, timeoutMs);
184
- this.emitter.once(EVENT_INTERNAL_PRE_LOADED + this.EmitterID, (failed, reason) => {
185
- clearTimeout(timer);
186
- if (failed)
187
- reject(new DEMError(DEMErrorCode.OBJECT_LOAD_FAILED, reason));
188
- else
189
- resolve();
190
- });
191
- });
192
182
  }
193
183
  handleNewObject(data) {
194
184
  this.isLoading = true;
195
- if (!this.socket) {
196
- const errorMsg = `Cannot create ${this.className}: Socket is missing.`;
197
- this.loadError = errorMsg;
198
- this.isLoading = false;
199
- this.loggers.error?.(errorMsg);
200
- this.emitter.emit(EVENT_INTERNAL_PRE_LOADED + this.EmitterID, true, errorMsg);
201
- return;
185
+ if (!this.className)
186
+ throw new Error("Cannot create a new AutoUpdatedClientClass without a class name.");
187
+ this.loggers.debug(this.className + " - Requesting new object creation on server");
188
+ for (const key of this.properties) {
189
+ if (typeof key !== "string")
190
+ continue;
191
+ let pointer = getMetadataRecursive("refsTo", this.classProp.prototype, key);
192
+ if (pointer) {
193
+ pointer = pointer.split(":");
194
+ if (pointer.length != 2)
195
+ throw new Error("population ref incorrectly defined. Sould be 'ParentClass:PropName.Path'");
196
+ const temp = data[key];
197
+ delete data[key];
198
+ if (temp)
199
+ this.toChangeOnParents.push({ key: key, value: temp });
200
+ }
202
201
  }
203
- let payload = data;
204
202
  try {
205
- if (data && typeof data === "object") {
206
- payload = JSON.parse(JSON.stringify(data));
207
- }
203
+ data = _.cloneDeep(data);
208
204
  }
209
- catch (err) {
210
- this.loggers.warn?.(`Failed to JSON-serialize creation payload for ${this.className}, falling back to raw data: ${err instanceof Error ? err.message : String(err)}`);
205
+ catch (error) {
206
+ this.loggers.error("Most likely cycled object: " + error.message);
207
+ this.loggers.error(error.stack);
211
208
  }
212
- this.socket.emit(EVENT_NEW + this.className, payload, (res) => {
213
- if (this.loadError)
214
- return;
215
- if (!res) {
216
- const errorMsg = `No response received from server when creating ${this.className}`;
217
- this.isLoading = false;
218
- this.loadError = errorMsg;
219
- this.loggers.error?.(errorMsg);
220
- this.emitter.emit(EVENT_INTERNAL_PRE_LOADED + this.EmitterID, true, errorMsg);
221
- return;
222
- }
209
+ this.socket.emit("new" + this.className, data, (res) => {
223
210
  if (!res.success) {
224
211
  this.isLoading = false;
225
- this.loadError = res.message;
226
- this.loggers.error?.("Could not create data on server: " + res.message);
227
- this.emitter.emit(EVENT_INTERNAL_PRE_LOADED + this.EmitterID, true, res.message);
212
+ this.loggers.error("Could not create data on server: " + res.message);
213
+ this.emitter.emit("pre-loaded" + this.EmitterID, true, res.message);
228
214
  return;
229
215
  }
230
216
  this.data = res.data;
231
- this.generateSettersAndGetters();
232
217
  this.isLoading = false;
233
- this.emitter.emit(EVENT_INTERNAL_PRE_LOADED + this.EmitterID);
218
+ this.loggers.debug("Created new object: " + this.data._id);
219
+ this.emitter.emit("pre-loaded" + this.EmitterID);
234
220
  if (!this.isServer)
235
221
  this.openSockets();
236
222
  });
237
223
  }
238
224
  get extractedData() {
239
- const extracted = processIsRefProperties(this.data, this, null, [], {}, this.loggers).newData;
225
+ const extracted = processIsRefProperties(this.data, this.classProp.prototype, null, [], {}, this.loggers).newData;
240
226
  return _.cloneDeep(extracted);
241
227
  }
242
228
  get isLoaded() {
243
229
  return !this.isLoading;
244
230
  }
245
231
  async isPreLoadedAsync() {
246
- await this.loadReferencesAsync();
232
+ await this.loadShit();
247
233
  this.generateSettersAndGetters();
248
234
  return true;
249
235
  }
250
- async loadMissingReferences() {
251
- if (!this.isServer)
236
+ loadMissingReferences() {
237
+ if (this.referencesLoaded)
252
238
  return;
253
- this.checkedMissingProperties = {};
254
- await this.checkForMissingRefs();
239
+ this.referencesLoaded = true;
240
+ this.checkForMissingRefs();
255
241
  this.generateSettersAndGetters();
256
242
  }
257
243
  openSockets() {
258
- const id = this.data?._id ?? this._id;
259
- const event = EVENT_UPDATE + this.className + id.toString();
260
- this.socket.on(event, async (update, ack) => {
261
- const res = await this.handleUpdateRequest(update);
262
- if (ack && typeof ack === "function")
263
- ack(res);
264
- return res;
244
+ const event = "update" + this.className + this.data._id.toString();
245
+ this.socket.on(event, async (update) => {
246
+ await this.handleUpdateRequest(update);
265
247
  });
266
248
  }
267
249
  async handleUpdateRequest(update) {
268
250
  try {
269
251
  await this.setValue__(update.key, update.value, true);
270
- if (this.isLoaded)
271
- this.callbacks.update(this, update.key);
252
+ this.loggers.debug(`Applied patch ${update.key} set to ${update.value}`);
253
+ // Return success with the applied patch
272
254
  return { success: true, data: undefined, message: "" };
273
255
  }
274
256
  catch (error) {
275
- this.loggers.error?.(`[${this.data._id}] Error applying patch: ${error instanceof Error ? error.message : String(error)}`);
257
+ this.loggers.error(`[${this.data._id}] Error applying patch: ` +
258
+ error.message +
259
+ "\n" +
260
+ error.stack);
276
261
  return {
277
262
  success: false,
278
- message: "Error applying update: " +
279
- (error instanceof Error ? error.message : String(error)),
263
+ message: "Error applying update: " + error.message,
280
264
  };
281
265
  }
282
266
  }
283
- _gettersGenerated = false;
284
- writeQueue = Promise.resolve();
285
- get updateEventName() {
286
- const id = this.data?._id ?? this._id;
287
- return EVENT_UPDATE + this.className + (id ? id.toString() : "");
288
- }
289
- getRawId(key) {
290
- if (!this.data)
291
- return undefined;
292
- const val = this.data[key];
293
- if (!val)
294
- return undefined;
295
- if (typeof val === "string")
296
- return val;
297
- if (typeof val === "object" && val !== null && val._id) {
298
- return val._id.toString();
299
- }
300
- return String(val);
301
- }
302
267
  generateSettersAndGetters() {
303
- if (this.classParam) {
304
- setupClassAccessors(this.classParam);
305
- }
306
- if (this.properties) {
307
- for (const key of this.properties) {
308
- if (typeof key === "string" && Object.hasOwn(this, key)) {
309
- delete this[key];
310
- }
311
- }
312
- }
313
- }
314
- getValue(key_) {
315
- const key = key_;
316
- const parts = key.split(".");
317
- let value = this;
318
- for (const part of parts) {
319
- if (value === undefined || value === null)
320
- return undefined;
321
- const nextValue = value[part];
322
- if (nextValue !== undefined) {
323
- value = nextValue;
324
- }
325
- else if (value.data &&
326
- value.data[part] !== undefined) {
327
- value = value.data[part];
328
- }
329
- else {
330
- return undefined;
331
- }
268
+ for (const key of this.properties) {
269
+ if (typeof key !== "string")
270
+ return;
271
+ const k = key;
272
+ const isRef = getMetadataRecursive("isRef", this.classProp.prototype, key);
273
+ Object.defineProperty(this, key, {
274
+ get: () => {
275
+ if (isRef) {
276
+ if (Array.isArray(this.data[k])) {
277
+ const filtered = this.data[k]
278
+ .map((id) => this.findReference(id))
279
+ .filter(Boolean);
280
+ if (filtered.length !== this.data[k].length &&
281
+ this.parentManager.isLoaded)
282
+ this.data[k] = filtered.map((obj) => obj._id?.toString() ?? obj.toString());
283
+ return filtered;
284
+ }
285
+ else {
286
+ const result = this.findReference(this.data[k]);
287
+ if (!result && this.data[k] && this.parentManager.isLoaded)
288
+ this.data[k] = undefined;
289
+ return result;
290
+ }
291
+ }
292
+ else
293
+ return this.data[k];
294
+ },
295
+ set: () => {
296
+ throw new Error(`Cannot set ${key} this way, use "setValue" function.`);
297
+ },
298
+ enumerable: true,
299
+ configurable: true,
300
+ });
332
301
  }
333
- return value;
334
302
  }
335
- findReference(id, key) {
336
- if (!id)
337
- return undefined;
338
- const idStr = typeof id === "string" ? id : id.toString();
339
- const cached = globalCache.objects[idStr];
340
- if (cached?.object)
341
- return cached.object;
342
- const cacheKey = `${this.className}:${key}`;
343
- const cachedManager = this.parentManager?.cache?.references?.[cacheKey];
344
- if (cachedManager) {
345
- const res = cachedManager.getObject(idStr);
346
- if (res)
347
- return res;
348
- }
349
- if (this.parentManager?.managers) {
350
- for (const manager of Object.values(this.parentManager.managers)) {
351
- const result = manager.getObject(idStr);
352
- if (result) {
353
- if (this.parentManager.cache?.references) {
354
- this.parentManager.cache.references[cacheKey] = manager;
355
- }
356
- return result;
357
- }
358
- }
303
+ findReference(id) {
304
+ if (typeof id !== "string" && !ObjectId.isValid(id))
305
+ return id;
306
+ for (const manager of Object.values(this.parentManager.managers)) {
307
+ const result = manager.getObject(id.toString());
308
+ if (result)
309
+ return result;
359
310
  }
360
311
  return undefined;
361
312
  }
362
313
  async setValue(key, val) {
363
- return await this.setValue__(key, val);
364
- }
365
- async setValue__(key, val, silent = false, noGet = false, noUpdate = false, isParentUpdate = false) {
366
- this.writeQueue = this.writeQueue
367
- .catch(() => { })
368
- .then(() => this.setValueQueueInternal(key, val, silent, noGet, noUpdate, isParentUpdate));
369
- return this.writeQueue;
370
- }
371
- async setValueQueueInternal(key, val, silent = false, noGet = false, noUpdate = false, isParentUpdate = false) {
372
- const rootProp = key.split(".")[0];
373
- if (key === "__proto__" ||
374
- key === "constructor" ||
375
- key === "prototype" ||
376
- (this.properties && !this.properties.includes(rootProp) && rootProp !== "_id")) {
377
- return { success: false, msg: `Invalid property key: ${key}` };
378
- }
314
+ const result = await this.setValue__(key, val);
315
+ if (this.isLoaded)
316
+ this.callbacks.update(this, key);
317
+ return result;
318
+ }
319
+ async setValue__(key, val, silent = false, noGet = false, noUpdate = false) {
320
+ let message = "Setting value " + key + " of " + this.className + " to ";
321
+ const isRef = getMetadataRecursive("isRef", this.classProp.prototype, key);
322
+ if (isRef)
323
+ val = Array.isArray(val)
324
+ ? val.map((v) => {
325
+ return v._id?.toString() ?? v;
326
+ })
327
+ : (val?._id ?? val);
328
+ message += JSON.stringify(val);
329
+ this.loggers.debug(message);
379
330
  try {
380
- const isRef = getMetadataRecursive("isRef", this, key);
381
- const pointer = getMetadataRecursive("refsTo", this, key);
382
- if (pointer && !isParentUpdate && !silent && !this.isServer) {
383
- throw new DEMError(DEMErrorCode.CANNOT_SET_REF_DIRECTLY, "Cannot set value of a reference pointer directly.");
384
- }
385
- let valueToStore = val;
386
- if (isRef) {
387
- valueToStore = Array.isArray(val)
388
- ? val.map((v) => v?._id?.toString() ??
389
- v?.toString() ??
390
- v)
391
- : (val?._id?.toString() ??
392
- val?.toString() ??
393
- val);
394
- }
395
- const currentVal = this.getValue(key);
396
- const currentValId = Array.isArray(currentVal)
397
- ? currentVal.map((v) => v?._id?.toString() ??
398
- v?.toString() ??
399
- v)
400
- : (currentVal?._id?.toString() ??
401
- currentVal?.toString());
402
- if (_.isEqual(currentValId, valueToStore))
403
- return { success: true, msg: "Successfully set " + key + " to " + val };
331
+ if (val instanceof AutoUpdatedClientObject)
332
+ val = val.extractedData._id;
404
333
  const path = key.split(".");
405
- if (path.length > 1) {
406
- let obj = this.data;
407
- for (let i = 0; i < path.length - 1; i++) {
408
- const currentKey = path[i];
409
- const valAtKey = obj[currentKey];
410
- if (typeof valAtKey === "string" ||
411
- (valAtKey && ObjectId.isValid(valAtKey))) {
412
- const ref = await this.resolveReference(String(valAtKey));
413
- if (!ref)
414
- throw new DEMError(DEMErrorCode.REFERENCE_RESOLUTION_FAILED, "Could not resolve reference on path: " + key);
415
- return await ref.setValue(path.slice(i + 1).join("."), val);
334
+ let obj = this.data;
335
+ let lastClass = this;
336
+ let lastPath = path[0];
337
+ for (let i = 0; i < path.length - 1; i++) {
338
+ if (typeof obj[path[i]] === "string" ||
339
+ ObjectId.isValid(obj[path[i]])) {
340
+ let temp;
341
+ try {
342
+ temp = this.resolveReference(obj[path[i]]?.toString());
343
+ }
344
+ catch (error) {
345
+ message +=
346
+ "\n Error: likely undefined property on path: " +
347
+ path +
348
+ " on index: " +
349
+ i +
350
+ " with error: " +
351
+ error.message;
352
+ }
353
+ if (!temp) {
354
+ message +=
355
+ "\nLikely undefined property " +
356
+ path[i] +
357
+ " on path: " +
358
+ path +
359
+ " at index: " +
360
+ i;
361
+ this.loggers.warn("Failed to set value for " + this.className + "\n" + message);
362
+ return {
363
+ success: false,
364
+ msg: message,
365
+ };
366
+ }
367
+ lastClass = temp;
368
+ lastPath = path.slice(i + 1).join(".");
369
+ const res = await lastClass.setValue(lastPath, val);
370
+ if (!noUpdate)
371
+ await this.onUpdate(noUpdate);
372
+ return res;
373
+ }
374
+ else
375
+ obj = obj[path[i]];
376
+ }
377
+ if (lastClass !== this) {
378
+ message +=
379
+ "\n What the actual fuckity fuck error on path: " +
380
+ path +
381
+ " on index: " +
382
+ (path.length - 1);
383
+ this.loggers.error("Failed to set value for " + this.className + "\n" + message);
384
+ return {
385
+ success: false,
386
+ msg: message,
387
+ };
388
+ }
389
+ if (!this.properties.includes(lastPath) &&
390
+ !lastPath.includes(".")) {
391
+ let nearest = "";
392
+ for (const prop of this.properties) {
393
+ if (typeof prop !== "string")
394
+ continue;
395
+ if (stringSimilarity(lastPath, prop) > 0 &&
396
+ stringSimilarity(lastPath, prop) > stringSimilarity(nearest, prop)) {
397
+ nearest = prop;
416
398
  }
417
- obj = obj[currentKey];
418
399
  }
400
+ throw new Error(`Property ${lastPath} not found in class ${this.className}, did you mean ${nearest ?? "--No similar prop found--"}?`);
419
401
  }
420
- const res = await this.setValueInternal(key, valueToStore, silent, noUpdate);
421
- if (res.success) {
422
- const pathArr = key.split(".");
423
- let obj = this.data;
424
- for (let i = 0; i < pathArr.length - 1; i++) {
425
- obj = obj[pathArr[i]];
402
+ let success;
403
+ try {
404
+ let isPopulated = getMetadataRecursive("refsTo", this.classProp.prototype, lastPath);
405
+ if (isPopulated) {
406
+ isPopulated = isPopulated.split(":");
407
+ const parentObj = this.parentManager.managers[isPopulated[0]].getObject(val);
408
+ if (!parentObj) {
409
+ message +=
410
+ "\nFailed to set value for " +
411
+ this.className +
412
+ " parent not found";
413
+ this.loggers.error(message);
414
+ return { success: false, msg: message };
415
+ }
416
+ if (parentObj.getValue(isPopulated[1]) &&
417
+ !Array.isArray(parentObj.getValue(isPopulated[1]))) {
418
+ message +=
419
+ "\nThis is a 1:1 relationship and the parent already has a parent with the ID: " +
420
+ (parentObj.getValue(isPopulated[1])._id?.toString() ??
421
+ parentObj.getValue(isPopulated[1]).toString()) +
422
+ this.loggers.error(message);
423
+ return { success: false, msg: message };
424
+ }
425
+ let res;
426
+ if (this.isServer) {
427
+ const value = parentObj.getValue(isPopulated[1]);
428
+ if (Array.isArray(value)) {
429
+ res = await parentObj.setValue__(isPopulated[1], value.concat(this.data._id.toString()), false, false, true);
430
+ }
431
+ else
432
+ res = await parentObj.setValue__(isPopulated[1], this.data._id.toString(), false, false, true);
433
+ }
434
+ else
435
+ ({ res, val } = await this.preInnerSetValue(noGet, key, val, lastPath, silent, noUpdate));
436
+ success = res.success;
437
+ message +=
438
+ "\nReport from inner setValue function: " +
439
+ res.msg.split("\n").join("\n ");
426
440
  }
427
- obj[pathArr[pathArr.length - 1]] = valueToStore;
428
- if (this.isServer) {
429
- await this.findAndLoadReferences(key, valueToStore);
430
- if (isRef && this.parentManager.isLoaded)
431
- await this.contactChildren();
441
+ else {
442
+ const isRef = getMetadataRecursive("isRef", this.classProp.prototype, key);
443
+ if (isRef && this.isServer && ObjectId.isValid(val))
444
+ val = Array.isArray(val)
445
+ ? val.map((v) => new ObjectId(v))
446
+ : new ObjectId(val);
447
+ let res;
448
+ ({ res, val } = await this.preInnerSetValue(noGet, key, val, lastPath, silent, noUpdate));
449
+ if (res.success) {
450
+ const originalValue = obj[path.at(-1)];
451
+ if (!Array.isArray(val) && Array.isArray(originalValue)) {
452
+ if (!originalValue.includes(val))
453
+ originalValue.push(val);
454
+ val = originalValue;
455
+ }
456
+ else
457
+ obj[path.at(-1)] = val;
458
+ }
459
+ success = res.success;
460
+ message += "\nReport from inner setValue function: \n " + res.msg;
432
461
  }
433
- if (this.isLoaded) {
434
- this.callbacks.update(this, key);
435
- await this.onUpdate(noUpdate, key);
462
+ }
463
+ catch (error) {
464
+ success = false;
465
+ message += "\nError from inner setValue function: \n " + error.message;
466
+ }
467
+ if (!success) {
468
+ this.loggers.warn("Failed to set value for " + this.className + "\n" + message);
469
+ return { success: false, msg: message };
470
+ }
471
+ const pathArr = lastPath.split(".");
472
+ if (pathArr.length === 1) {
473
+ this.data[key] = val;
474
+ }
475
+ else {
476
+ const last = pathArr.splice(-1, 1);
477
+ let ref = this;
478
+ for (const p of pathArr) {
479
+ ref = ref[p];
436
480
  }
481
+ ref[last.at(-1)] = val;
482
+ }
483
+ if (!noUpdate)
484
+ await this.onUpdate(noUpdate);
485
+ this.findAndLoadReferences(lastPath, val);
486
+ const isRef = getMetadataRecursive("isRef", this.classProp.prototype, path.at(-1));
487
+ if (isRef && this.parentManager.isLoaded) {
488
+ this.contactChildren();
437
489
  }
438
490
  return {
439
- ...res,
440
- msg: res.msg ?? "Successfully set " + key + " to " + val,
491
+ success: true,
492
+ msg: "Successfully set " + key + " to " + val,
441
493
  };
442
494
  }
443
495
  catch (error) {
444
- this.loggers.error?.(`Error setting value ${key}: ${error instanceof Error ? error.message : String(error)}`);
445
- const demErr = error instanceof DEMError
446
- ? error
447
- : toDEMError(error, DEMErrorCode.DB_SAVE_FAILED);
496
+ this.loggers.error("An error occurred setting value for " +
497
+ this.className +
498
+ "\n" +
499
+ message +
500
+ "\n Random error here: " +
501
+ error.message +
502
+ "\n" +
503
+ error.stack);
504
+ this.loggers.error(error);
448
505
  return {
449
506
  success: false,
450
- code: demErr.code,
451
- msg: demErr.message,
507
+ msg: message +
508
+ "\n Random error here: " +
509
+ error.message +
510
+ "\n" +
511
+ error.stack,
452
512
  };
453
513
  }
454
514
  }
455
- async setValueInternal(key, value, silent = false, noUpdate = false) {
456
- if (silent)
457
- return { success: true, msg: "Silent" };
458
- return new Promise((resolve) => {
459
- const id = this.data?._id ?? this._id;
460
- this.socket.emit(EVENT_UPDATE + this.className + id, { _id: id.toString(), key, value }, (res) => {
461
- resolve({
462
- success: res.success,
463
- code: res.code,
464
- msg: res.message ?? (res.success ? "Success" : "Error"),
465
- });
466
- });
467
- });
468
- }
469
- makeUpdate(key, value) {
470
- const id = this.data?._id ?? this._id;
471
- if (!id) {
472
- this.loggers.error?.(`Probably missing the identifier ['_id'] again: ${key} = ${value}`);
473
- throw new DEMError(DEMErrorCode.MISSING_ID, `Cannot make update for ${this.className} because _id is missing.`);
474
- }
475
- return { _id: id.toString(), key, value };
476
- }
477
- async resolveReference(id) {
478
- for (const manager of Object.values(this.parentManager.managers)) {
479
- const obj = manager.getObject(id);
480
- if (obj)
481
- return obj;
482
- }
483
- return null;
484
- }
485
- async findAndLoadReferences(lastPath, value) {
486
- const isRef = getMetadataRecursive("isRef", this, lastPath);
515
+ async preInnerSetValue(noGet, key, val, lastPath, silent, noUpdate) {
516
+ if (!noGet &&
517
+ this.isServer &&
518
+ this.getValue(key) &&
519
+ Array.isArray(this.getValue(key)) &&
520
+ !Array.isArray(val)) {
521
+ val = this.getValue(key).concat(val);
522
+ }
523
+ const res = await this.setValueInternal(lastPath, val, silent, noUpdate);
524
+ if (!noGet &&
525
+ !this.isServer &&
526
+ this.getValue(key) &&
527
+ Array.isArray(this.getValue(key)) &&
528
+ !Array.isArray(val)) {
529
+ val = [
530
+ ...new Set(this.getValue(key)
531
+ .concat(val)
532
+ .map((v) => v.toString())),
533
+ ];
534
+ }
535
+ return { res, val };
536
+ }
537
+ findAndLoadReferences(lastPath, value) {
538
+ const isRef = getMetadataRecursive("isRef", this.classProp.prototype, lastPath);
487
539
  if (isRef) {
488
540
  for (const id of Array.isArray(value) ? value : [value]) {
489
- if (!id)
490
- continue;
491
541
  let result;
492
542
  for (const manager of Object.values(this.parentManager.managers)) {
493
543
  result = manager.getObject(id?.toString());
494
544
  if (result)
495
545
  break;
496
546
  }
497
- if (result && result.parentManager.isLoaded && typeof result.loadMissingReferences === "function") {
498
- await result.loadMissingReferences();
547
+ if (!result) {
548
+ this.loggers.warn("Failed to update childerns parent for " +
549
+ this.className +
550
+ " updating " +
551
+ id +
552
+ "'s parent to " +
553
+ this.data._id);
554
+ continue;
499
555
  }
556
+ this.referencesLoaded = false;
557
+ result.loadMissingReferences();
500
558
  }
501
559
  }
502
560
  }
503
- async wipeSelf() {
504
- if (this.data.Wiped)
505
- return;
506
- const id = this.data?._id ?? this._id;
507
- const _id = id ? id.toString() : "unknown";
508
- for (const key of Object.keys(this.data)) {
509
- delete this.data[key];
561
+ getValue(key) {
562
+ let value;
563
+ for (const part of key.split(".")) {
564
+ try {
565
+ if (value)
566
+ value = value[part];
567
+ else
568
+ value = this[part];
569
+ }
570
+ catch (error) {
571
+ this.loggers.error("Error getting value for " +
572
+ this.className +
573
+ " on key " +
574
+ key +
575
+ " on index " +
576
+ part +
577
+ ":" +
578
+ error.message);
579
+ }
510
580
  }
511
- this.data = { Wiped: true };
512
- this.loggers.info?.(`[${_id}] ${this.className} object wiped`);
581
+ return value;
513
582
  }
514
- destroyImmediate() {
515
- this.wipeSelf();
583
+ async setValueInternal(key, value, silent = false, noUpdate = false) {
584
+ const update = this.makeUpdate(key, value);
585
+ const promise = new Promise((resolve) => {
586
+ if (silent) {
587
+ if (noUpdate)
588
+ return;
589
+ return this.onUpdate(true).then(() => {
590
+ return resolve({ success: true, msg: "Success - silent" });
591
+ });
592
+ }
593
+ try {
594
+ this.socket.emit("update" + this.className + this.data._id, update, async (res) => {
595
+ if (!res.success) {
596
+ this.loggers.error("Error sending update: " + res.message);
597
+ resolve({ success: false, msg: res.message });
598
+ return;
599
+ }
600
+ if (!noUpdate)
601
+ await this.onUpdate(noUpdate);
602
+ resolve({
603
+ success: res.success,
604
+ msg: res.message ?? "Success",
605
+ });
606
+ });
607
+ }
608
+ catch (error) {
609
+ this.loggers.error("Error sending update:" + error.message);
610
+ this.loggers.error(error.stack);
611
+ resolve({ success: false, msg: error.message });
612
+ }
613
+ });
614
+ return promise;
615
+ }
616
+ makeUpdate(key, value) {
617
+ try {
618
+ const id = this.data._id.toString();
619
+ return { _id: id, key, value };
620
+ }
621
+ catch (error) {
622
+ this.loggers.error("Probably missing the fucking identifier ['_id'] again: " +
623
+ error.message);
624
+ throw error;
625
+ }
516
626
  }
517
- async loadForceReferences(obj = this.data, proto = this, alreadySeen = new Set()) {
518
- const meta = this.classParam ? setupClassAccessors(this.classParam) : null;
519
- const props = obj === this.data && this.properties
520
- ? this.properties
521
- : Reflect.getMetadata("props", proto) ||
522
- Reflect.getMetadata("props", Object.getPrototypeOf(proto)) ||
523
- [];
627
+ async onUpdate(noUpdate) {
628
+ return;
629
+ }
630
+ // return a properly typed AutoUpdatedClientClass (or null)
631
+ // inside AutoUpdatedClientClass
632
+ resolveReference(id) {
633
+ if (!this.parentManager)
634
+ throw new Error("No Manager");
635
+ for (const manager of Object.values(this.parentManager.managers)) {
636
+ const data = manager.getObject(id);
637
+ if (data)
638
+ return data;
639
+ }
640
+ return null;
641
+ }
642
+ async loadForceReferences(obj = this.data, proto = this.classProp.prototype, alreadySeen = []) {
643
+ const props = Reflect.getMetadata("props", proto) || [];
524
644
  for (const key of props) {
525
645
  if (typeof key !== "string")
526
- continue;
527
- const pointer = meta?.refsToMap.get(key) ||
528
- Reflect.getMetadata("refsTo", proto, key) ||
529
- (proto ? Reflect.getMetadata("refsTo", Object.getPrototypeOf(proto), key) : undefined);
530
- if (pointer &&
531
- obj === (this.data) &&
532
- obj[key] &&
533
- !alreadySeen.has(obj)) {
646
+ return;
647
+ const isRef = Reflect.getMetadata("isRef", proto, key);
648
+ const pointer = Reflect.getMetadata("refsTo", proto, key);
649
+ if (pointer && obj === this.data && obj[key])
534
650
  await this.createdWithParent(pointer.split(":"), obj[key]);
651
+ if (isRef) {
652
+ await this.handleLoad(obj, key, alreadySeen);
535
653
  }
536
- if (obj[key] && !alreadySeen.has(obj[key]))
537
- alreadySeen.add(obj[key]);
538
- const val = obj[key];
539
- if (val &&
540
- typeof val === "object" &&
541
- !(val instanceof Date) &&
542
- !(val instanceof ObjectId)) {
543
- const nestedProto = Object.getPrototypeOf(val);
544
- if (nestedProto && !alreadySeen.has(val)) {
545
- alreadySeen.add(val);
546
- await this.loadForceReferences(val, nestedProto, alreadySeen);
547
- }
548
- }
654
+ await this.checkRecursiveReferenceLoading(obj, key, alreadySeen);
549
655
  }
550
656
  }
551
- async createdWithParent(pointer, parent) {
552
- if (pointer.length !== 2)
553
- return;
554
- const parentId = parent._id?.toString() ?? parent.toString();
555
- const manager = this.parentManager.managers[pointer[0]];
556
- if (!manager) {
557
- this.loggers.warn?.(`createdWithParent: Manager not found for ${pointer[0]}.`);
558
- return;
559
- }
560
- const obj = manager.getObject(parentId);
561
- if (!obj) {
562
- this.loggers.warn?.(`createdWithParent: Parent object not found for ID ${parentId} in manager ${pointer[0]}`);
563
- return;
657
+ async checkRecursiveReferenceLoading(obj, key, alreadySeen) {
658
+ const val = obj ? obj[key] : null;
659
+ if (val && typeof val === "object") {
660
+ const nestedProto = Object.getPrototypeOf(val);
661
+ if (nestedProto && !alreadySeen.includes(val)) {
662
+ alreadySeen.push(val);
663
+ await this.loadForceReferences(val, nestedProto, alreadySeen);
664
+ }
564
665
  }
565
- const myId = this.data._id?.toString?.() ?? String(this.data._id);
566
- const rawData = obj.data;
567
- const rawVal = rawData ? rawData[pointer[1]] : undefined;
568
- if (Array.isArray(rawVal)) {
569
- let alreadyIncluded = false;
570
- for (let i = 0; i < rawVal.length; i++) {
571
- const item = rawVal[i];
572
- const idStr = item?._id?.toString?.() ?? item?.toString?.();
573
- if (idStr === myId) {
574
- alreadyIncluded = true;
666
+ }
667
+ async handleLoad(obj, key, alreadySeen) {
668
+ if (!this.parentManager)
669
+ throw new Error("No manager");
670
+ const refId = obj[key];
671
+ if (refId) {
672
+ for (const manager of Object.values(this.parentManager.managers)) {
673
+ const result = manager.getObject(refId);
674
+ if (result && !alreadySeen.includes(refId)) {
675
+ alreadySeen.push(refId);
676
+ await result.loadForceReferences(undefined, undefined, alreadySeen);
575
677
  break;
576
678
  }
577
679
  }
578
- if (!alreadyIncluded) {
579
- this.loggers.debug?.(`createdWithParent: Adding myId to parent array`);
580
- await obj.setValue__(pointer[1], [...rawVal, myId], false, false, false, true);
581
- }
582
680
  }
583
- else {
584
- const currentIdStr = rawVal?._id?.toString?.() ?? rawVal?.toString?.();
585
- if (currentIdStr !== myId) {
586
- this.loggers.debug?.(`createdWithParent: Setting myId to parent field`);
587
- await obj.setValue__(pointer[1], myId, false, false, false, true);
681
+ }
682
+ async createdWithParent(pointer, parent) {
683
+ if (pointer.length !== 2) {
684
+ throw new Error("Invalid pointer: " +
685
+ JSON.stringify(pointer) +
686
+ " for " +
687
+ this.className +
688
+ ", poiter must be 'className:pathToParentProperty'");
689
+ }
690
+ if (!parent)
691
+ throw new Error("Invalid pointer: " +
692
+ JSON.stringify(pointer) +
693
+ " for " +
694
+ this.className +
695
+ ", parent is null");
696
+ const obj = this.parentManager.managers[pointer[0]]?.getObject(parent._id?.toString() ?? parent.toString());
697
+ const val = obj?.getValue(pointer[1]);
698
+ if (!val)
699
+ return;
700
+ if (Array.isArray(val)) {
701
+ const originalLength = val.length;
702
+ const filtred = val.filter(Boolean);
703
+ if (filtred.length !== originalLength) {
704
+ await obj?.setValue(pointer[1], filtred);
705
+ this.loggers.warn("Array value changed from " +
706
+ originalLength +
707
+ " to " +
708
+ filtred.length +
709
+ " - some values were undefined");
588
710
  }
711
+ if (filtred
712
+ .map((id) => id?._id.toString())
713
+ .includes(this.data._id))
714
+ obj?.contactChildren();
715
+ else
716
+ await obj?.setValue(pointer[1], [
717
+ ...new Set([...filtred, this.data._id]),
718
+ ]);
589
719
  }
720
+ else if (val?.toString() === this.data?._id.toString())
721
+ obj?.contactChildren();
722
+ else
723
+ await obj?.setValue(pointer[1], this.data?._id.toString());
590
724
  }
591
725
  async destroy(once = false) {
592
- if (!once)
593
- return await this.parentManager.deleteObject(this.data._id.toString());
594
- return new Promise((resolve) => {
595
- this.socket.emit(EVENT_DELETE + this.className, this.data._id, (res) => {
726
+ if (!once) {
727
+ return await this.parentManager.deleteObject(this.data._id);
728
+ }
729
+ await this.callbacks.delete(this);
730
+ const res = await new Promise((resolve) => {
731
+ this.socket.emit("delete" + this.className, this.data._id, (res) => {
732
+ if (!res.success) {
733
+ this.loggers.error("Error deleting object from database - " +
734
+ this.className +
735
+ " - " +
736
+ this.data._id);
737
+ this.loggers.error(res.message);
738
+ resolve({
739
+ success: false,
740
+ message: res.message,
741
+ });
742
+ return;
743
+ }
744
+ this.socket.removeAllListeners("update" + this.className + this.data._id);
745
+ this.socket.removeAllListeners("delete" + this.className);
746
+ this.wipeSelf();
596
747
  resolve({
597
- success: res.success,
598
- code: res.code,
599
- message: res.message ?? "",
748
+ success: true,
749
+ message: "Deleted",
600
750
  });
601
751
  });
602
752
  });
753
+ return res;
603
754
  }
604
- async checkForMissingRefs() {
755
+ checkForMissingRefs() {
605
756
  for (const prop of this.properties) {
606
- const pointer = getMetadataRecursive("refsTo", this, prop.toString());
607
- if (pointer && !this.data?.[prop]) {
608
- const parts = pointer.split(":");
609
- if (parts.length === 2)
610
- await this.findMissingObjectReference(prop, parts);
757
+ let pointer = getMetadataRecursive("refsTo", this.classProp.prototype, prop.toString());
758
+ if (pointer) {
759
+ pointer = pointer.split(":");
760
+ if (pointer.length != 2)
761
+ throw new Error("population rf incorrectly defined. Sould be 'ParentClass:PropName'");
762
+ this.findMissingObjectReference(prop, pointer);
611
763
  }
612
764
  }
613
765
  }
614
- async findMissingObjectReference(prop, pointer) {
615
- this.checkedMissingProperties ??= {};
616
- if (this.checkedMissingProperties[prop])
617
- return;
618
- this.checkedMissingProperties[prop] = true;
766
+ findMissingObjectReference(prop, pointer) {
619
767
  const ac = this.parentManager.managers[pointer[0]];
620
768
  if (!ac)
621
- return;
622
- const targetId = this.data._id?.toString?.() ?? String(this.data._id);
623
- const allObjects = ac.objectsAsArray;
624
- for (let i = 0; i < allObjects.length; i++) {
625
- const obj = allObjects[i];
626
- const rawData = obj.data;
627
- if (!rawData)
628
- continue;
629
- const val = rawData[pointer[1]];
630
- if (!val)
631
- continue;
632
- if (Array.isArray(val)) {
633
- for (let j = 0; j < val.length; j++) {
634
- const id = val[j]?._id?.toString?.() ?? val[j]?.toString?.();
635
- if (id === targetId) {
636
- this.data[prop] = obj._id;
637
- return;
638
- }
769
+ throw new Error(`No AutoUpdateManager found for class ${pointer[0]}`);
770
+ for (const obj of ac.objectsAsArray) {
771
+ let eData = obj.extractedData;
772
+ let found;
773
+ for (const pathPart of pointer[1].split(".")) {
774
+ if (!eData[pathPart] ||
775
+ (Array.isArray(eData[pathPart]) &&
776
+ !eData[pathPart]
777
+ .map((id) => id.toString())
778
+ .includes(this._id.toString())) ||
779
+ (!Array.isArray(eData[pathPart]) &&
780
+ eData[pathPart].toString() !== this.data._id.toString())) {
781
+ found = false;
782
+ break;
639
783
  }
784
+ found = eData = eData[pathPart];
640
785
  }
641
- else {
642
- const id = val?._id?.toString?.() ?? val?.toString?.();
643
- if (id === targetId) {
644
- this.data[prop] = obj._id;
645
- return;
646
- }
786
+ if (found) {
787
+ this.data[prop] = obj._id;
788
+ return;
647
789
  }
648
790
  }
649
791
  }
650
- async contactChildren() {
651
- if (!this.isServer)
792
+ wipeSelf() {
793
+ if (this.data.Wiped)
652
794
  return;
795
+ const _id = this.data._id.toString();
796
+ for (const key of Object.keys(this.data)) {
797
+ delete this.data[key];
798
+ }
799
+ this.data = { Wiped: true };
800
+ this.loggers.info(`[${_id}] ${this.className} object wiped`);
801
+ }
802
+ contactChildren() {
653
803
  for (const prop of this.properties) {
654
- const isRef = getMetadataRecursive("isRef", this, prop.toString());
655
- const pointer = getMetadataRecursive("refsTo", this, prop.toString());
656
- if (!isRef || pointer)
657
- continue;
658
- const obj = this.getValue(prop);
659
- if (!obj)
660
- continue;
661
- const children = Array.isArray(obj) ? obj : [obj];
662
- for (const child of children) {
663
- if (child &&
664
- typeof child
665
- .loadMissingReferences === "function") {
666
- await child.loadMissingReferences();
804
+ const pointer = getMetadataRecursive("refsTo", this.classProp.prototype, prop.toString());
805
+ const isRef = getMetadataRecursive("isRef", this.classProp.prototype, prop.toString());
806
+ if (isRef && !pointer) {
807
+ if (!this.getValue(prop))
808
+ continue;
809
+ if (Array.isArray(this.getValue(prop))) {
810
+ for (const child of this.getValue(prop)) {
811
+ try {
812
+ child?.loadMissingReferences();
813
+ }
814
+ catch (error) {
815
+ this.loggers.error(error.message);
816
+ }
817
+ }
667
818
  }
819
+ else
820
+ this.getValue(prop)?.loadMissingReferences();
668
821
  }
669
822
  }
670
- this.generateSettersAndGetters();
671
- }
672
- async onUpdate(noUpdate = false, key) {
673
- // Placeholder for server-side override
674
- }
675
- async onDeletion() {
676
- // Placeholder for server-side override
677
823
  }
678
824
  }
679
- export function processIsRefProperties(instance, target, prefix, allProps, newData, loggers) {
825
+ export function processIsRefProperties(instance, target, prefix = null, allProps = [], newData = {}, loggers = console) {
680
826
  const props = Reflect.getMetadata("props", target) || [];
681
827
  for (const prop of props) {
682
828
  const path = prefix ? `${prefix}.${prop}` : prop;
683
829
  allProps.push(path);
684
- newData[prop] =
685
- instance[prop] && ObjectId.isValid(instance[prop])
686
- ? instance[prop]?.toString()
687
- : instance[prop];
830
+ newData[prop] = ObjectId.isValid(instance[prop])
831
+ ? instance[prop]?.toString()
832
+ : instance[prop];
688
833
  if (Reflect.getMetadata("isRef", target, prop)) {
689
834
  if (Array.isArray(instance[prop]))
690
835
  newData[prop] = instance[prop]
691
- .map((item) => item?._id?.toString() ??
692
- item?.toString())
836
+ .map((item) => item?._id?.toString() ?? item?.toString() ?? undefined)
693
837
  .filter(Boolean);
694
838
  else
695
839
  newData[prop] =
696
840
  instance[prop]?._id?.toString() ??
697
- instance[prop]?.toString();
841
+ instance[prop]?.toString() ??
842
+ undefined;
698
843
  }
699
844
  const type = Reflect.getMetadata("design:type", target, prop);
700
845
  if (type?.prototype) {
701
846
  const nestedProps = Reflect.getMetadata("props", type.prototype);
702
847
  if (nestedProps && instance[prop]) {
703
- newData[prop] = processIsRefProperties(instance[prop], type.prototype, path, allProps, {}, loggers).newData;
848
+ newData[prop] = processIsRefProperties(instance[prop], type.prototype, path, allProps, undefined, loggers).newData;
704
849
  }
705
850
  }
706
851
  }
707
852
  return { allProps, newData };
708
853
  }
709
- export function setupClassAccessors(classParam) {
710
- if (!classParam) {
711
- return { properties: [], refProps: new Set(), refsToMap: new Map() };
712
- }
713
- if (classParam.__metaCache) {
714
- return classParam.__metaCache;
715
- }
716
- const allProps = new Set();
717
- const refProps = new Set();
718
- const refsToMap = new Map();
719
- let proto_ = classParam.prototype;
720
- while (proto_ && proto_ !== Object.prototype) {
721
- const props = Reflect.getMetadata("props", proto_) ||
722
- Reflect.getOwnMetadata("props", proto_) ||
723
- [];
724
- for (const p of props) {
725
- if (typeof p === "string") {
726
- allProps.add(p);
727
- const isRef = Reflect.getMetadata("isRef", proto_, p) || Reflect.getOwnMetadata("isRef", proto_, p);
728
- if (isRef)
729
- refProps.add(p);
730
- const refsTo = Reflect.getMetadata("refsTo", proto_, p) || Reflect.getOwnMetadata("refsTo", proto_, p);
731
- if (refsTo)
732
- refsToMap.set(p, refsTo);
733
- }
734
- }
735
- proto_ = Object.getPrototypeOf(proto_);
736
- }
737
- const properties = Array.from(allProps);
738
- for (const key of properties) {
739
- const isRef = refProps.has(key);
740
- Object.defineProperty(classParam.prototype, key, {
741
- get() {
742
- if (!this.data)
743
- return undefined;
744
- let val = this.data[key];
745
- if (val === null)
746
- val = undefined;
747
- if (isRef && val) {
748
- if (Array.isArray(val)) {
749
- const result = [];
750
- for (let i = 0; i < val.length; i++) {
751
- const item = val[i];
752
- if (item) {
753
- const ref = this.findReference(item, key);
754
- if (ref)
755
- result.push(ref);
756
- }
757
- }
758
- return result;
759
- }
760
- else {
761
- return this.findReference(val, key);
762
- }
763
- }
764
- return val;
765
- },
766
- set(v) {
767
- if (this.data) {
768
- let valueToSet = v;
769
- if (isRef && v) {
770
- if (Array.isArray(v)) {
771
- valueToSet = v.map((item) => item && item._id
772
- ? item._id.toString()
773
- : item?.toString());
774
- }
775
- else {
776
- valueToSet = v._id
777
- ? v._id.toString()
778
- : v.toString();
779
- }
780
- }
781
- this.data[key] = valueToSet;
782
- }
783
- },
784
- enumerable: true,
785
- configurable: true,
786
- });
787
- }
788
- const meta = { properties, refProps, refsToMap };
789
- classParam.__metaCache = meta;
790
- classParam.__propsCache = properties;
791
- classParam.__refPropsCache = Array.from(refProps);
792
- return meta;
793
- }
794
854
  export function getMetadataRecursive(metaKey, proto, prop) {
795
855
  while (proto) {
796
856
  const meta = Reflect.getMetadata(metaKey, proto, prop);
@@ -800,4 +860,5 @@ export function getMetadataRecursive(metaKey, proto, prop) {
800
860
  }
801
861
  return undefined;
802
862
  }
863
+ //# sourceMappingURL=AutoUpdatedClientObjectClass.js.map
803
864
  //# sourceMappingURL=AutoUpdatedClientObjectClass.js.map