@prestizni-software/server-dem 0.7.4 → 0.9.0
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.
- package/AutoUpdateClientManagerClass.d.ts +158 -0
- package/AutoUpdateClientManagerClass.js +820 -0
- package/AutoUpdateClientManagerClass.js.map +1 -0
- package/AutoUpdateManagerClass.d.ts +102 -0
- package/AutoUpdateManagerClass.js +117 -0
- package/AutoUpdateManagerClass.js.map +1 -0
- package/AutoUpdateServerManagerClass.d.ts +238 -0
- package/AutoUpdateServerManagerClass.js +1087 -0
- package/AutoUpdateServerManagerClass.js.map +1 -0
- package/AutoUpdatedClientObjectClass.d.ts +244 -0
- package/AutoUpdatedClientObjectClass.js +969 -0
- package/AutoUpdatedClientObjectClass.js.map +1 -0
- package/AutoUpdatedServerObjectClass.d.ts +134 -0
- package/AutoUpdatedServerObjectClass.js +346 -0
- package/AutoUpdatedServerObjectClass.js.map +1 -0
- package/ClientTypes.d.ts +15 -0
- package/ClientTypes.js +52 -0
- package/ClientTypes.js.map +1 -0
- package/CommonTypes.d.ts +296 -0
- package/CommonTypes.js +233 -0
- package/CommonTypes.js.map +1 -0
- package/CommonTypes_server.d.ts +1 -0
- package/CommonTypes_server.js +2 -0
- package/CommonTypes_server.js.map +1 -0
- package/{dist/DEMErrors.js.map → DEMErrors.js.map} +1 -1
- package/ServerTypes.d.ts +16 -0
- package/ServerTypes.js +60 -0
- package/ServerTypes.js.map +1 -0
- package/client.d.ts +6 -0
- package/client.js +7 -0
- package/client.js.map +1 -0
- package/coverage/lcov-report/block-navigation.js +71 -0
- package/coverage/lcov-report/block-navigation.js.map +1 -0
- package/coverage/lcov-report/prettify.js +478 -0
- package/coverage/lcov-report/prettify.js.map +1 -0
- package/coverage/lcov-report/sorter.js +177 -0
- package/coverage/lcov-report/sorter.js.map +1 -0
- package/dist/AutoUpdateClientManagerClass.d.ts +20 -0
- package/dist/AutoUpdateClientManagerClass.js +283 -0
- package/dist/AutoUpdateClientManagerClass.js.map +1 -0
- package/dist/AutoUpdateManagerClass.d.ts +17 -96
- package/dist/AutoUpdateManagerClass.js +15 -73
- package/dist/AutoUpdateManagerClass.js.map +1 -1
- package/dist/AutoUpdateServerManagerClass.d.ts +18 -207
- package/dist/AutoUpdateServerManagerClass.js +198 -680
- package/dist/AutoUpdateServerManagerClass.js.map +1 -1
- package/dist/AutoUpdatedClientObjectClass.d.ts +63 -206
- package/dist/AutoUpdatedClientObjectClass.js +660 -707
- package/dist/AutoUpdatedClientObjectClass.js.map +1 -1
- package/dist/AutoUpdatedServerObjectClass.d.ts +13 -126
- package/dist/AutoUpdatedServerObjectClass.js +92 -315
- package/dist/AutoUpdatedServerObjectClass.js.map +1 -1
- package/dist/ClientTypes.d.ts +13 -0
- package/dist/ClientTypes.js +70 -0
- package/dist/ClientTypes.js.map +1 -0
- package/dist/CommonTypes.d.ts +3 -266
- package/dist/CommonTypes.js +4 -234
- package/dist/CommonTypes.js.map +1 -1
- package/dist/CommonTypes_server.d.ts +1 -1
- package/dist/CommonTypes_server.js +2 -1
- package/dist/CommonTypes_server.js.map +1 -1
- package/dist/ServerTypes.d.ts +13 -0
- package/dist/ServerTypes.js +78 -0
- package/dist/ServerTypes.js.map +1 -0
- package/dist/TestTypes.d.ts +1 -0
- package/dist/TestTypes.js +7 -0
- package/dist/TestTypes.js.map +1 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +12 -0
- package/dist/client.js.map +1 -0
- package/dist/coverage/lcov-report/block-navigation.d.ts +1 -0
- package/dist/coverage/lcov-report/block-navigation.js +71 -0
- package/dist/coverage/lcov-report/block-navigation.js.map +1 -0
- package/dist/coverage/lcov-report/prettify.d.ts +0 -0
- package/dist/coverage/lcov-report/prettify.js +736 -0
- package/dist/coverage/lcov-report/prettify.js.map +1 -0
- package/dist/coverage/lcov-report/sorter.d.ts +1 -0
- package/dist/coverage/lcov-report/sorter.js +177 -0
- package/dist/coverage/lcov-report/sorter.js.map +1 -0
- package/dist/dist/AutoUpdateClientManagerClass.d.ts +19 -0
- package/dist/dist/AutoUpdateClientManagerClass.js +284 -0
- package/dist/dist/AutoUpdateClientManagerClass.js.map +1 -0
- package/dist/dist/AutoUpdateManagerClass.d.ts +23 -0
- package/dist/dist/AutoUpdateManagerClass.js +60 -0
- package/dist/dist/AutoUpdateManagerClass.js.map +1 -0
- package/dist/dist/AutoUpdateServerManagerClass.d.ts +50 -0
- package/dist/dist/AutoUpdateServerManagerClass.js +413 -0
- package/dist/dist/AutoUpdateServerManagerClass.js.map +1 -0
- package/dist/dist/AutoUpdatedClientObjectClass.d.ts +72 -0
- package/dist/dist/AutoUpdatedClientObjectClass.js +865 -0
- package/dist/dist/AutoUpdatedClientObjectClass.js.map +1 -0
- package/dist/dist/AutoUpdatedServerObjectClass.d.ts +15 -0
- package/dist/dist/AutoUpdatedServerObjectClass.js +124 -0
- package/dist/dist/AutoUpdatedServerObjectClass.js.map +1 -0
- package/dist/dist/ClientTypes.d.ts +13 -0
- package/dist/dist/ClientTypes.js +71 -0
- package/dist/dist/ClientTypes.js.map +1 -0
- package/dist/dist/CommonTypes.d.ts +3 -0
- package/dist/dist/CommonTypes.js +20 -0
- package/dist/dist/CommonTypes.js.map +1 -0
- package/dist/dist/CommonTypes_server.d.ts +1 -0
- package/dist/dist/CommonTypes_server.js +4 -0
- package/dist/dist/CommonTypes_server.js.map +1 -0
- package/dist/dist/ServerTypes.d.ts +13 -0
- package/dist/dist/ServerTypes.js +79 -0
- package/dist/dist/ServerTypes.js.map +1 -0
- package/dist/dist/TestTypes.d.ts +1 -0
- package/dist/dist/TestTypes.js +8 -0
- package/dist/dist/TestTypes.js.map +1 -0
- package/dist/dist/client.d.ts +1 -0
- package/dist/dist/client.js +13 -0
- package/dist/dist/client.js.map +1 -0
- package/dist/dist/coverage/lcov-report/block-navigation.d.ts +1 -0
- package/dist/dist/coverage/lcov-report/block-navigation.js +71 -0
- package/dist/dist/coverage/lcov-report/block-navigation.js.map +1 -0
- package/dist/dist/coverage/lcov-report/prettify.d.ts +0 -0
- package/dist/dist/coverage/lcov-report/prettify.js +736 -0
- package/dist/dist/coverage/lcov-report/prettify.js.map +1 -0
- package/dist/dist/coverage/lcov-report/sorter.d.ts +1 -0
- package/dist/dist/coverage/lcov-report/sorter.js +177 -0
- package/dist/dist/coverage/lcov-report/sorter.js.map +1 -0
- package/dist/dist/dist/AutoUpdateClientManagerClass.d.ts +19 -0
- package/dist/dist/dist/AutoUpdateClientManagerClass.js +285 -0
- package/dist/dist/dist/AutoUpdateClientManagerClass.js.map +1 -0
- package/dist/dist/dist/AutoUpdateManagerClass.d.ts +23 -0
- package/dist/dist/dist/AutoUpdateManagerClass.js +61 -0
- package/dist/dist/dist/AutoUpdateManagerClass.js.map +1 -0
- package/dist/dist/dist/AutoUpdateServerManagerClass.d.ts +158 -0
- package/dist/dist/dist/AutoUpdateServerManagerClass.js +414 -0
- package/dist/dist/dist/AutoUpdateServerManagerClass.js.map +1 -0
- package/dist/dist/dist/AutoUpdatedClientObjectClass.d.ts +72 -0
- package/dist/dist/dist/AutoUpdatedClientObjectClass.js +866 -0
- package/dist/dist/dist/AutoUpdatedClientObjectClass.js.map +1 -0
- package/dist/dist/dist/AutoUpdatedServerObjectClass.d.ts +15 -0
- package/dist/dist/dist/AutoUpdatedServerObjectClass.js +125 -0
- package/dist/dist/dist/AutoUpdatedServerObjectClass.js.map +1 -0
- package/dist/dist/dist/ClientTypes.d.ts +13 -0
- package/dist/dist/dist/ClientTypes.js +72 -0
- package/dist/dist/dist/ClientTypes.js.map +1 -0
- package/dist/dist/dist/CommonTypes.d.ts +3 -0
- package/dist/dist/dist/CommonTypes.js +21 -0
- package/dist/dist/dist/CommonTypes.js.map +1 -0
- package/dist/dist/dist/CommonTypes_server.d.ts +1 -0
- package/dist/dist/dist/CommonTypes_server.js +5 -0
- package/dist/dist/dist/CommonTypes_server.js.map +1 -0
- package/dist/dist/dist/ServerTypes.d.ts +13 -0
- package/dist/dist/dist/ServerTypes.js +80 -0
- package/dist/dist/dist/ServerTypes.js.map +1 -0
- package/dist/dist/dist/TestTypes.d.ts +1 -0
- package/dist/dist/dist/TestTypes.js +9 -0
- package/dist/dist/dist/TestTypes.js.map +1 -0
- package/dist/dist/dist/client.d.ts +1 -0
- package/dist/dist/dist/client.js +14 -0
- package/dist/dist/dist/client.js.map +1 -0
- package/dist/dist/dist/coverage/lcov-report/block-navigation.d.ts +1 -0
- package/dist/dist/dist/coverage/lcov-report/block-navigation.js +71 -0
- package/dist/dist/dist/coverage/lcov-report/block-navigation.js.map +1 -0
- package/dist/dist/dist/coverage/lcov-report/prettify.d.ts +0 -0
- package/dist/dist/dist/coverage/lcov-report/prettify.js +736 -0
- package/dist/dist/dist/coverage/lcov-report/prettify.js.map +1 -0
- package/dist/dist/dist/coverage/lcov-report/sorter.d.ts +1 -0
- package/dist/dist/dist/coverage/lcov-report/sorter.js +177 -0
- package/dist/dist/dist/coverage/lcov-report/sorter.js.map +1 -0
- package/dist/dist/dist/expo-test/app/(tabs)/_layout.d.ts +1 -0
- package/dist/dist/dist/expo-test/app/(tabs)/_layout.js +27 -0
- package/dist/dist/dist/expo-test/app/(tabs)/_layout.js.map +1 -0
- package/dist/dist/dist/expo-test/app/(tabs)/explore.d.ts +1 -0
- package/dist/dist/dist/expo-test/app/(tabs)/explore.js +95 -0
- package/dist/dist/dist/expo-test/app/(tabs)/explore.js.map +1 -0
- package/dist/dist/dist/expo-test/app/(tabs)/index.d.ts +1 -0
- package/dist/dist/dist/expo-test/app/(tabs)/index.js +81 -0
- package/dist/dist/dist/expo-test/app/(tabs)/index.js.map +1 -0
- package/dist/dist/dist/expo-test/app/_layout.d.ts +4 -0
- package/dist/dist/dist/expo-test/app/_layout.js +22 -0
- package/dist/dist/dist/expo-test/app/_layout.js.map +1 -0
- package/dist/dist/dist/expo-test/app/modal.d.ts +1 -0
- package/dist/dist/dist/expo-test/app/modal.js +28 -0
- package/dist/dist/dist/expo-test/app/modal.js.map +1 -0
- package/dist/dist/dist/expo-test/components/external-link.d.ts +4 -0
- package/dist/dist/dist/expo-test/components/external-link.js +18 -0
- package/dist/dist/dist/expo-test/components/external-link.js.map +1 -0
- package/dist/dist/dist/expo-test/components/haptic-tab.d.ts +1 -0
- package/dist/dist/dist/expo-test/components/haptic-tab.js +15 -0
- package/dist/dist/dist/expo-test/components/haptic-tab.js.map +1 -0
- package/dist/dist/dist/expo-test/components/hello-wave.d.ts +1 -0
- package/dist/dist/dist/expo-test/components/hello-wave.js +19 -0
- package/dist/dist/dist/expo-test/components/hello-wave.js.map +1 -0
- package/dist/dist/dist/expo-test/components/parallax-scroll-view.d.ts +5 -0
- package/dist/dist/dist/expo-test/components/parallax-scroll-view.js +53 -0
- package/dist/dist/dist/expo-test/components/parallax-scroll-view.js.map +1 -0
- package/dist/dist/dist/expo-test/components/themed-text.d.ts +7 -0
- package/dist/dist/dist/expo-test/components/themed-text.js +43 -0
- package/dist/dist/dist/expo-test/components/themed-text.js.map +1 -0
- package/dist/dist/dist/expo-test/components/themed-view.d.ts +6 -0
- package/dist/dist/dist/expo-test/components/themed-view.js +10 -0
- package/dist/dist/dist/expo-test/components/themed-view.js.map +1 -0
- package/dist/dist/dist/expo-test/components/ui/collapsible.d.ts +4 -0
- package/dist/dist/dist/expo-test/components/ui/collapsible.js +34 -0
- package/dist/dist/dist/expo-test/components/ui/collapsible.js.map +1 -0
- package/dist/dist/dist/expo-test/components/ui/icon-symbol.d.ts +11 -0
- package/dist/dist/dist/expo-test/components/ui/icon-symbol.ios.d.ts +7 -0
- package/dist/dist/dist/expo-test/components/ui/icon-symbol.ios.js +14 -0
- package/dist/dist/dist/expo-test/components/ui/icon-symbol.ios.js.map +1 -0
- package/dist/dist/dist/expo-test/components/ui/icon-symbol.js +25 -0
- package/dist/dist/dist/expo-test/components/ui/icon-symbol.js.map +1 -0
- package/dist/dist/dist/expo-test/constants/theme.d.ts +26 -0
- package/dist/dist/dist/expo-test/constants/theme.js +53 -0
- package/dist/dist/dist/expo-test/constants/theme.js.map +1 -0
- package/dist/dist/dist/expo-test/eslint.config.d.ts +2 -0
- package/dist/dist/dist/expo-test/eslint.config.js +11 -0
- package/dist/dist/dist/expo-test/eslint.config.js.map +1 -0
- package/dist/dist/dist/expo-test/hooks/use-color-scheme.d.ts +1 -0
- package/dist/dist/dist/expo-test/hooks/use-color-scheme.js +5 -0
- package/dist/dist/dist/expo-test/hooks/use-color-scheme.js.map +1 -0
- package/dist/dist/dist/expo-test/hooks/use-color-scheme.web.d.ts +4 -0
- package/dist/dist/dist/expo-test/hooks/use-color-scheme.web.js +20 -0
- package/dist/dist/dist/expo-test/hooks/use-color-scheme.web.js.map +1 -0
- package/dist/dist/dist/expo-test/hooks/use-theme-color.d.ts +1 -0
- package/dist/dist/dist/expo-test/hooks/use-theme-color.js +20 -0
- package/dist/dist/dist/expo-test/hooks/use-theme-color.js.map +1 -0
- package/dist/dist/dist/expo-test/scripts/reset-project.d.ts +2 -0
- package/dist/dist/dist/expo-test/scripts/reset-project.js +98 -0
- package/dist/dist/dist/expo-test/scripts/reset-project.js.map +1 -0
- package/dist/dist/dist/jest.config.d.ts +21 -0
- package/dist/dist/dist/jest.config.js +20 -0
- package/dist/dist/dist/jest.config.js.map +1 -0
- package/dist/dist/dist/server.d.ts +1 -0
- package/dist/dist/dist/server.js +16 -0
- package/dist/dist/dist/server.js.map +1 -0
- package/dist/dist/dist/socket_test.d.ts +1 -0
- package/dist/dist/dist/socket_test.js +24 -0
- package/dist/dist/dist/socket_test.js.map +1 -0
- package/dist/dist/dist/test.d.ts +1 -0
- package/dist/dist/dist/test.js +7 -0
- package/dist/dist/dist/test.js.map +1 -0
- package/dist/dist/dist/test_client.d.ts +1 -0
- package/dist/dist/dist/test_client.js +26 -0
- package/dist/dist/dist/test_client.js.map +1 -0
- package/dist/dist/dist/test_lib.d.ts +2 -0
- package/dist/dist/dist/test_lib.js +85 -0
- package/dist/dist/dist/test_lib.js.map +1 -0
- package/dist/dist/dist/test_server.d.ts +1 -0
- package/dist/dist/dist/test_server.js +54 -0
- package/dist/dist/dist/test_server.js.map +1 -0
- package/dist/dist/dist/tests/dem.test.d.ts +1 -0
- package/dist/dist/dist/tests/dem.test.js +341 -0
- package/dist/dist/dist/tests/dem.test.js.map +1 -0
- package/dist/dist/expo-test/app/(tabs)/_layout.d.ts +1 -0
- package/dist/dist/expo-test/app/(tabs)/_layout.js +26 -0
- package/dist/dist/expo-test/app/(tabs)/_layout.js.map +1 -0
- package/dist/dist/expo-test/app/(tabs)/explore.d.ts +1 -0
- package/dist/dist/expo-test/app/(tabs)/explore.js +94 -0
- package/dist/dist/expo-test/app/(tabs)/explore.js.map +1 -0
- package/dist/dist/expo-test/app/(tabs)/index.d.ts +1 -0
- package/dist/dist/expo-test/app/(tabs)/index.js +80 -0
- package/dist/dist/expo-test/app/(tabs)/index.js.map +1 -0
- package/dist/dist/expo-test/app/_layout.d.ts +4 -0
- package/dist/dist/expo-test/app/_layout.js +21 -0
- package/dist/dist/expo-test/app/_layout.js.map +1 -0
- package/dist/dist/expo-test/app/modal.d.ts +1 -0
- package/dist/dist/expo-test/app/modal.js +27 -0
- package/dist/dist/expo-test/app/modal.js.map +1 -0
- package/dist/dist/expo-test/components/external-link.d.ts +4 -0
- package/dist/dist/expo-test/components/external-link.js +17 -0
- package/dist/dist/expo-test/components/external-link.js.map +1 -0
- package/dist/dist/expo-test/components/haptic-tab.d.ts +1 -0
- package/dist/dist/expo-test/components/haptic-tab.js +14 -0
- package/dist/dist/expo-test/components/haptic-tab.js.map +1 -0
- package/dist/dist/expo-test/components/hello-wave.d.ts +1 -0
- package/dist/dist/expo-test/components/hello-wave.js +18 -0
- package/dist/dist/expo-test/components/hello-wave.js.map +1 -0
- package/dist/dist/expo-test/components/parallax-scroll-view.d.ts +5 -0
- package/dist/dist/expo-test/components/parallax-scroll-view.js +52 -0
- package/dist/dist/expo-test/components/parallax-scroll-view.js.map +1 -0
- package/dist/dist/expo-test/components/themed-text.d.ts +7 -0
- package/dist/dist/expo-test/components/themed-text.js +42 -0
- package/dist/dist/expo-test/components/themed-text.js.map +1 -0
- package/dist/dist/expo-test/components/themed-view.d.ts +6 -0
- package/dist/dist/expo-test/components/themed-view.js +9 -0
- package/dist/dist/expo-test/components/themed-view.js.map +1 -0
- package/dist/dist/expo-test/components/ui/collapsible.d.ts +4 -0
- package/dist/dist/expo-test/components/ui/collapsible.js +33 -0
- package/dist/dist/expo-test/components/ui/collapsible.js.map +1 -0
- package/dist/dist/expo-test/components/ui/icon-symbol.d.ts +11 -0
- package/dist/dist/expo-test/components/ui/icon-symbol.ios.d.ts +7 -0
- package/dist/dist/expo-test/components/ui/icon-symbol.ios.js +13 -0
- package/dist/dist/expo-test/components/ui/icon-symbol.ios.js.map +1 -0
- package/dist/dist/expo-test/components/ui/icon-symbol.js +24 -0
- package/dist/dist/expo-test/components/ui/icon-symbol.js.map +1 -0
- package/dist/dist/expo-test/constants/theme.d.ts +26 -0
- package/dist/dist/expo-test/constants/theme.js +52 -0
- package/dist/dist/expo-test/constants/theme.js.map +1 -0
- package/dist/dist/expo-test/eslint.config.d.ts +2 -0
- package/dist/dist/expo-test/eslint.config.js +11 -0
- package/dist/dist/expo-test/eslint.config.js.map +1 -0
- package/dist/dist/expo-test/hooks/use-color-scheme.d.ts +1 -0
- package/dist/dist/expo-test/hooks/use-color-scheme.js +4 -0
- package/dist/dist/expo-test/hooks/use-color-scheme.js.map +1 -0
- package/dist/dist/expo-test/hooks/use-color-scheme.web.d.ts +4 -0
- package/dist/dist/expo-test/hooks/use-color-scheme.web.js +19 -0
- package/dist/dist/expo-test/hooks/use-color-scheme.web.js.map +1 -0
- package/dist/dist/expo-test/hooks/use-theme-color.d.ts +1 -0
- package/dist/dist/expo-test/hooks/use-theme-color.js +19 -0
- package/dist/dist/expo-test/hooks/use-theme-color.js.map +1 -0
- package/dist/dist/expo-test/scripts/reset-project.d.ts +2 -0
- package/dist/dist/expo-test/scripts/reset-project.js +98 -0
- package/dist/dist/expo-test/scripts/reset-project.js.map +1 -0
- package/dist/dist/jest.config.d.ts +21 -0
- package/dist/dist/jest.config.js +19 -0
- package/dist/dist/jest.config.js.map +1 -0
- package/dist/dist/server.d.ts +1 -0
- package/dist/dist/server.js +15 -0
- package/dist/dist/server.js.map +1 -0
- package/dist/dist/socket_test.d.ts +1 -0
- package/dist/dist/socket_test.js +23 -0
- package/dist/dist/socket_test.js.map +1 -0
- package/dist/dist/test.d.ts +1 -0
- package/dist/dist/test.js +6 -0
- package/dist/dist/test.js.map +1 -0
- package/dist/dist/test_client.d.ts +1 -0
- package/dist/dist/test_client.js +25 -0
- package/dist/dist/test_client.js.map +1 -0
- package/dist/dist/test_lib.d.ts +2 -0
- package/dist/dist/test_lib.js +84 -0
- package/dist/dist/test_lib.js.map +1 -0
- package/dist/dist/test_server.d.ts +1 -0
- package/dist/dist/test_server.js +53 -0
- package/dist/dist/test_server.js.map +1 -0
- package/dist/dist/tests/dem.test.d.ts +1 -0
- package/dist/dist/tests/dem.test.js +340 -0
- package/dist/dist/tests/dem.test.js.map +1 -0
- package/dist/expo-test/app/(tabs)/_layout.d.ts +1 -0
- package/dist/expo-test/app/(tabs)/_layout.js +25 -0
- package/dist/expo-test/app/(tabs)/_layout.js.map +1 -0
- package/dist/expo-test/app/(tabs)/explore.d.ts +1 -0
- package/dist/expo-test/app/(tabs)/explore.js +93 -0
- package/dist/expo-test/app/(tabs)/explore.js.map +1 -0
- package/dist/expo-test/app/(tabs)/index.d.ts +1 -0
- package/dist/expo-test/app/(tabs)/index.js +79 -0
- package/dist/expo-test/app/(tabs)/index.js.map +1 -0
- package/dist/expo-test/app/_layout.d.ts +4 -0
- package/dist/expo-test/app/_layout.js +20 -0
- package/dist/expo-test/app/_layout.js.map +1 -0
- package/dist/expo-test/app/modal.d.ts +1 -0
- package/dist/expo-test/app/modal.js +26 -0
- package/dist/expo-test/app/modal.js.map +1 -0
- package/dist/expo-test/components/external-link.d.ts +4 -0
- package/dist/expo-test/components/external-link.js +16 -0
- package/dist/expo-test/components/external-link.js.map +1 -0
- package/dist/expo-test/components/haptic-tab.d.ts +1 -0
- package/dist/expo-test/components/haptic-tab.js +13 -0
- package/dist/expo-test/components/haptic-tab.js.map +1 -0
- package/dist/expo-test/components/hello-wave.d.ts +1 -0
- package/dist/expo-test/components/hello-wave.js +17 -0
- package/dist/expo-test/components/hello-wave.js.map +1 -0
- package/dist/expo-test/components/parallax-scroll-view.d.ts +5 -0
- package/dist/expo-test/components/parallax-scroll-view.js +51 -0
- package/dist/expo-test/components/parallax-scroll-view.js.map +1 -0
- package/dist/expo-test/components/themed-text.d.ts +7 -0
- package/dist/expo-test/components/themed-text.js +41 -0
- package/dist/expo-test/components/themed-text.js.map +1 -0
- package/dist/expo-test/components/themed-view.d.ts +6 -0
- package/dist/expo-test/components/themed-view.js +8 -0
- package/dist/expo-test/components/themed-view.js.map +1 -0
- package/dist/expo-test/components/ui/collapsible.d.ts +4 -0
- package/dist/expo-test/components/ui/collapsible.js +32 -0
- package/dist/expo-test/components/ui/collapsible.js.map +1 -0
- package/dist/expo-test/components/ui/icon-symbol.d.ts +11 -0
- package/dist/expo-test/components/ui/icon-symbol.ios.d.ts +7 -0
- package/dist/expo-test/components/ui/icon-symbol.ios.js +12 -0
- package/dist/expo-test/components/ui/icon-symbol.ios.js.map +1 -0
- package/dist/expo-test/components/ui/icon-symbol.js +23 -0
- package/dist/expo-test/components/ui/icon-symbol.js.map +1 -0
- package/dist/expo-test/constants/theme.d.ts +26 -0
- package/dist/expo-test/constants/theme.js +51 -0
- package/dist/expo-test/constants/theme.js.map +1 -0
- package/dist/expo-test/eslint.config.d.ts +2 -0
- package/dist/expo-test/eslint.config.js +11 -0
- package/dist/expo-test/eslint.config.js.map +1 -0
- package/dist/expo-test/hooks/use-color-scheme.d.ts +1 -0
- package/dist/expo-test/hooks/use-color-scheme.js +3 -0
- package/dist/expo-test/hooks/use-color-scheme.js.map +1 -0
- package/dist/expo-test/hooks/use-color-scheme.web.d.ts +4 -0
- package/dist/expo-test/hooks/use-color-scheme.web.js +18 -0
- package/dist/expo-test/hooks/use-color-scheme.web.js.map +1 -0
- package/dist/expo-test/hooks/use-theme-color.d.ts +1 -0
- package/dist/expo-test/hooks/use-theme-color.js +18 -0
- package/dist/expo-test/hooks/use-theme-color.js.map +1 -0
- package/dist/expo-test/scripts/reset-project.d.ts +2 -0
- package/dist/expo-test/scripts/reset-project.js +98 -0
- package/dist/expo-test/scripts/reset-project.js.map +1 -0
- package/dist/jest.config.d.ts +21 -0
- package/dist/jest.config.js +18 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/server.d.ts +1 -8
- package/dist/server.js +13 -8
- package/dist/server.js.map +1 -1
- package/dist/socket_test.d.ts +1 -0
- package/dist/socket_test.js +22 -0
- package/dist/socket_test.js.map +1 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +5 -0
- package/dist/test.js.map +1 -0
- package/dist/test_client.d.ts +1 -0
- package/dist/test_client.js +24 -0
- package/dist/test_client.js.map +1 -0
- package/dist/test_lib.d.ts +12 -0
- package/dist/test_lib.js +83 -0
- package/dist/test_lib.js.map +1 -0
- package/dist/test_server.d.ts +1 -0
- package/dist/test_server.js +52 -0
- package/dist/test_server.js.map +1 -0
- package/dist/tests/dem.test.d.ts +1 -0
- package/dist/tests/dem.test.js +339 -0
- package/dist/tests/dem.test.js.map +1 -0
- package/expo-test/app/(tabs)/_layout.d.ts +2 -0
- package/expo-test/app/(tabs)/_layout.js +24 -0
- package/expo-test/app/(tabs)/_layout.js.map +1 -0
- package/expo-test/app/(tabs)/explore.d.ts +1 -0
- package/expo-test/app/(tabs)/explore.js +92 -0
- package/expo-test/app/(tabs)/explore.js.map +1 -0
- package/expo-test/app/(tabs)/index.d.ts +1 -0
- package/expo-test/app/(tabs)/index.js +78 -0
- package/expo-test/app/(tabs)/index.js.map +1 -0
- package/expo-test/app/_layout.d.ts +5 -0
- package/expo-test/app/_layout.js +19 -0
- package/expo-test/app/_layout.js.map +1 -0
- package/expo-test/app/modal.d.ts +1 -0
- package/expo-test/app/modal.js +25 -0
- package/expo-test/app/modal.js.map +1 -0
- package/expo-test/components/external-link.d.ts +7 -0
- package/expo-test/components/external-link.js +15 -0
- package/expo-test/components/external-link.js.map +1 -0
- package/expo-test/components/haptic-tab.d.ts +2 -0
- package/expo-test/components/haptic-tab.js +12 -0
- package/expo-test/components/haptic-tab.js.map +1 -0
- package/expo-test/components/hello-wave.d.ts +1 -0
- package/expo-test/components/hello-wave.js +16 -0
- package/expo-test/components/hello-wave.js.map +1 -0
- package/expo-test/components/parallax-scroll-view.d.ts +10 -0
- package/expo-test/components/parallax-scroll-view.js +50 -0
- package/expo-test/components/parallax-scroll-view.js.map +1 -0
- package/expo-test/components/themed-text.d.ts +7 -0
- package/expo-test/components/themed-text.js +40 -0
- package/expo-test/components/themed-text.js.map +1 -0
- package/expo-test/components/themed-view.d.ts +6 -0
- package/expo-test/components/themed-view.js +7 -0
- package/expo-test/components/themed-view.js.map +1 -0
- package/expo-test/components/ui/collapsible.d.ts +4 -0
- package/expo-test/components/ui/collapsible.js +31 -0
- package/expo-test/components/ui/collapsible.js.map +1 -0
- package/expo-test/components/ui/icon-symbol.d.ts +25 -0
- package/expo-test/components/ui/icon-symbol.ios.d.ts +9 -0
- package/expo-test/components/ui/icon-symbol.ios.js +11 -0
- package/expo-test/components/ui/icon-symbol.ios.js.map +1 -0
- package/expo-test/components/ui/icon-symbol.js +22 -0
- package/expo-test/components/ui/icon-symbol.js.map +1 -0
- package/expo-test/constants/theme.d.ts +32 -0
- package/expo-test/constants/theme.js +50 -0
- package/expo-test/constants/theme.js.map +1 -0
- package/expo-test/eslint.config.d.ts +2 -0
- package/expo-test/eslint.config.js +11 -0
- package/expo-test/eslint.config.js.map +1 -0
- package/expo-test/hooks/use-color-scheme.d.ts +1 -0
- package/expo-test/hooks/use-color-scheme.js +2 -0
- package/expo-test/hooks/use-color-scheme.js.map +1 -0
- package/expo-test/hooks/use-color-scheme.web.d.ts +4 -0
- package/expo-test/hooks/use-color-scheme.web.js +17 -0
- package/expo-test/hooks/use-color-scheme.web.js.map +1 -0
- package/expo-test/hooks/use-theme-color.d.ts +9 -0
- package/expo-test/hooks/use-theme-color.js +17 -0
- package/expo-test/hooks/use-theme-color.js.map +1 -0
- package/expo-test/scripts/reset-project.d.ts +2 -0
- package/expo-test/scripts/reset-project.js +98 -0
- package/expo-test/scripts/reset-project.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/jest.config.d.ts +3 -0
- package/jest.config.js +17 -0
- package/jest.config.js.map +1 -0
- package/package.json +23 -42
- package/server.d.ts +8 -0
- package/server.js +9 -0
- package/server.js.map +1 -0
- package/sync/ServerChangeTracker.js.map +1 -0
- package/version.d.ts +21 -0
- package/version.js +22 -0
- package/version.js.map +1 -0
- package/README.md +0 -18
- package/dist/sync/ServerChangeTracker.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- /package/{dist/DEMErrors.d.ts → DEMErrors.d.ts} +0 -0
- /package/{dist/DEMErrors.js → DEMErrors.js} +0 -0
- /package/{dist/sync → sync}/ClientStateReconciler.d.ts +0 -0
- /package/{dist/sync → sync}/ClientStateReconciler.js +0 -0
- /package/{dist/sync → sync}/ClientStateReconciler.js.map +0 -0
- /package/{dist/sync → sync}/ServerChangeTracker.d.ts +0 -0
- /package/{dist/sync → sync}/ServerChangeTracker.js +0 -0
- /package/{dist/sync → sync}/index.d.ts +0 -0
- /package/{dist/sync → sync}/index.js +0 -0
- /package/{dist/sync → sync}/index.js.map +0 -0
- /package/{dist/sync → sync}/storage/IClientStorageAdapter.d.ts +0 -0
- /package/{dist/sync → sync}/storage/IClientStorageAdapter.js +0 -0
- /package/{dist/sync → sync}/storage/IClientStorageAdapter.js.map +0 -0
- /package/{dist/sync → sync}/storage/IndexedDbStorageAdapter.d.ts +0 -0
- /package/{dist/sync → sync}/storage/IndexedDbStorageAdapter.js +0 -0
- /package/{dist/sync → sync}/storage/IndexedDbStorageAdapter.js.map +0 -0
- /package/{dist/sync → sync}/storage/LocalStorageAdapter.d.ts +0 -0
- /package/{dist/sync → sync}/storage/LocalStorageAdapter.js +0 -0
- /package/{dist/sync → sync}/storage/LocalStorageAdapter.js.map +0 -0
- /package/{dist/sync → sync}/storage/MemoryStorageAdapter.d.ts +0 -0
- /package/{dist/sync → sync}/storage/MemoryStorageAdapter.js +0 -0
- /package/{dist/sync → sync}/storage/MemoryStorageAdapter.js.map +0 -0
- /package/{dist/sync → sync}/types.d.ts +0 -0
- /package/{dist/sync → sync}/types.js +0 -0
- /package/{dist/sync → sync}/types.js.map +0 -0
|
@@ -1,143 +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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
isLoadingReferences = true;
|
|
29
|
+
classProp;
|
|
30
|
+
EmitterID = new ObjectId().toHexString();
|
|
31
|
+
toChangeOnParents = [];
|
|
23
32
|
callbacks;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
49
|
-
* Initializes an AutoUpdatedClientObject instance.
|
|
50
|
-
*
|
|
51
|
-
* @param classParam - Constructor of the client object entity.
|
|
52
|
-
* @param socket - Socket.IO client socket connection.
|
|
53
|
-
* @param data - Entity identifier string or initial data object.
|
|
54
|
-
* @param loggers - Logging interfaces.
|
|
55
|
-
* @param className - Managed entity class name.
|
|
56
|
-
* @param parentManager - Host client manager.
|
|
57
|
-
* @param callback - Event callbacks interface.
|
|
58
|
-
* @param emitter - Shared event emitter.
|
|
59
|
-
* @param isServer - Flag indicating whether running on server runtime.
|
|
60
|
-
* @throws {DEMError} Throws DEMErrorCode.MISSING_ARGUMENT when required parameters are omitted.
|
|
61
|
-
*/
|
|
62
|
-
constructor(classParam, socket, data, loggers, className, parentManager, callback, emitter, isServer = false) {
|
|
63
|
-
if (!classParam ||
|
|
64
|
-
!socket ||
|
|
65
|
-
!data ||
|
|
66
|
-
!loggers ||
|
|
67
|
-
!className ||
|
|
68
|
-
!parentManager ||
|
|
69
|
-
!emitter) {
|
|
70
|
-
this.classParam = classParam;
|
|
71
|
-
this.socket = socket;
|
|
72
|
-
this.data = data;
|
|
73
|
-
this.loggers = loggers;
|
|
74
|
-
this.className = className;
|
|
75
|
-
this.parentManager = parentManager;
|
|
76
|
-
this.callbacks = callback;
|
|
77
|
-
this.emitter = emitter;
|
|
78
|
-
this.properties = undefined;
|
|
79
|
-
if (!classParam &&
|
|
80
|
-
!socket &&
|
|
81
|
-
!data &&
|
|
82
|
-
!loggers &&
|
|
83
|
-
!className &&
|
|
84
|
-
!parentManager &&
|
|
85
|
-
!callback &&
|
|
86
|
-
!emitter)
|
|
87
|
-
return;
|
|
88
|
-
else
|
|
89
|
-
throw new DEMError(DEMErrorCode.MISSING_ARGUMENT, "Missing arguments for AutoUpdatedClientObject: " + className);
|
|
90
|
-
}
|
|
91
|
-
this.classParam = classParam;
|
|
92
|
-
this.socket = socket;
|
|
74
|
+
constructor(socket, data, loggers, properties, className, classProperty, parentManager, callback, emitter, isServer = false) {
|
|
93
75
|
this.isServer = isServer;
|
|
94
76
|
this.emitter = emitter;
|
|
77
|
+
this.classProp = classProperty;
|
|
95
78
|
this.isLoadingReferences = true;
|
|
96
79
|
this.isLoading = true;
|
|
97
80
|
this.parentManager = parentManager;
|
|
98
81
|
this.className = className;
|
|
99
|
-
|
|
100
|
-
const meta = setupClassAccessors(classParam);
|
|
101
|
-
this.properties = meta.properties;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
this.properties = [];
|
|
105
|
-
}
|
|
82
|
+
this.properties = properties;
|
|
106
83
|
this.callbacks = callback;
|
|
107
|
-
this.loggers =
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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;
|
|
113
117
|
if (typeof data === "string") {
|
|
114
|
-
this.data = { _id: data };
|
|
115
118
|
if (this.isServer) {
|
|
116
119
|
this.isLoading = false;
|
|
117
|
-
this.
|
|
120
|
+
this.data = { _id: data };
|
|
118
121
|
return;
|
|
119
122
|
}
|
|
120
|
-
|
|
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) => {
|
|
121
132
|
if (!res.success) {
|
|
122
133
|
this.isLoading = false;
|
|
123
|
-
this.
|
|
124
|
-
this.
|
|
125
|
-
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);
|
|
126
136
|
return;
|
|
127
137
|
}
|
|
128
|
-
this.data =
|
|
129
|
-
this.generateSettersAndGetters();
|
|
138
|
+
this.data = res.data;
|
|
130
139
|
this.isLoading = false;
|
|
131
|
-
this.emitter.emit(
|
|
140
|
+
this.emitter.emit("pre-loaded" + this.EmitterID);
|
|
132
141
|
this.openSockets();
|
|
133
142
|
});
|
|
143
|
+
this.data = { _id: data };
|
|
134
144
|
}
|
|
135
145
|
else {
|
|
136
146
|
this.isLoading = true;
|
|
137
|
-
this.data =
|
|
138
|
-
|
|
139
|
-
|
|
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
|
+
}
|
|
140
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);
|
|
141
175
|
else {
|
|
142
176
|
this.isLoading = false;
|
|
143
177
|
if (!this.isServer)
|
|
@@ -145,760 +179,678 @@ export class AutoUpdatedClientObject {
|
|
|
145
179
|
}
|
|
146
180
|
}
|
|
147
181
|
this.generateSettersAndGetters();
|
|
148
|
-
Promise.resolve().then(() => {
|
|
149
|
-
this.generateSettersAndGetters();
|
|
150
|
-
});
|
|
151
182
|
}
|
|
152
|
-
/**
|
|
153
|
-
* Normalizes reference fields in entity data into string IDs.
|
|
154
|
-
*
|
|
155
|
-
* @param data - Entity data payload.
|
|
156
|
-
* @returns Cleaned entity data payload.
|
|
157
|
-
*/
|
|
158
|
-
handleDataCleanup(data) {
|
|
159
|
-
if (!data || typeof data !== "object")
|
|
160
|
-
return data;
|
|
161
|
-
const meta = this.classParam ? setupClassAccessors(this.classParam) : null;
|
|
162
|
-
const refProps = meta ? meta.refProps : null;
|
|
163
|
-
if (!refProps || refProps.size === 0)
|
|
164
|
-
return data;
|
|
165
|
-
const dataAsRecord = data;
|
|
166
|
-
for (const key of refProps) {
|
|
167
|
-
const val = dataAsRecord[key];
|
|
168
|
-
if (!val)
|
|
169
|
-
continue;
|
|
170
|
-
if (Array.isArray(val)) {
|
|
171
|
-
let needsNormalization = false;
|
|
172
|
-
for (let i = 0; i < val.length; i++) {
|
|
173
|
-
const item = val[i];
|
|
174
|
-
if (item && typeof item === "object") {
|
|
175
|
-
needsNormalization = true;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (needsNormalization) {
|
|
180
|
-
dataAsRecord[key] = val.map((obj) => obj?._id?.toString() ??
|
|
181
|
-
obj?.toString());
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
else if (typeof val === "object") {
|
|
185
|
-
dataAsRecord[key] =
|
|
186
|
-
val?._id?.toString() ??
|
|
187
|
-
val?.toString();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return data;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Pauses execution until the object finishes asynchronous preloading.
|
|
194
|
-
*
|
|
195
|
-
* @param timeoutMs - Maximum milliseconds to wait before rejecting.
|
|
196
|
-
* @throws {DEMError} Throws DEMErrorCode.PRELOAD_TIMEOUT on timeout or OBJECT_LOAD_FAILED on failure.
|
|
197
|
-
*/
|
|
198
|
-
async waitForPreloaded(timeoutMs = 15000) {
|
|
199
|
-
if (this.loadError)
|
|
200
|
-
throw new DEMError(DEMErrorCode.OBJECT_LOAD_FAILED, this.loadError);
|
|
201
|
-
if (this.isLoaded)
|
|
202
|
-
return;
|
|
203
|
-
await new Promise((resolve, reject) => {
|
|
204
|
-
const timer = setTimeout(() => {
|
|
205
|
-
const errorMsg = `Timeout waiting for object preloading (${this.className})`;
|
|
206
|
-
this.loadError = errorMsg;
|
|
207
|
-
this.isLoading = false;
|
|
208
|
-
reject(new DEMError(DEMErrorCode.PRELOAD_TIMEOUT, errorMsg));
|
|
209
|
-
}, timeoutMs);
|
|
210
|
-
this.emitter.once(EVENT_INTERNAL_PRE_LOADED + this.EmitterID, (failed, reason) => {
|
|
211
|
-
clearTimeout(timer);
|
|
212
|
-
if (failed)
|
|
213
|
-
reject(new DEMError(DEMErrorCode.OBJECT_LOAD_FAILED, reason));
|
|
214
|
-
else
|
|
215
|
-
resolve();
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Emits creation event to the server socket and awaits populated entity response.
|
|
221
|
-
*
|
|
222
|
-
* @param data - Initial data payload.
|
|
223
|
-
*/
|
|
224
183
|
handleNewObject(data) {
|
|
225
184
|
this.isLoading = true;
|
|
226
|
-
if (!this.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
+
}
|
|
233
201
|
}
|
|
234
|
-
let payload = data;
|
|
235
202
|
try {
|
|
236
|
-
|
|
237
|
-
payload = JSON.parse(JSON.stringify(data));
|
|
238
|
-
}
|
|
203
|
+
data = _.cloneDeep(data);
|
|
239
204
|
}
|
|
240
|
-
catch (
|
|
241
|
-
this.loggers.
|
|
205
|
+
catch (error) {
|
|
206
|
+
this.loggers.error("Most likely cycled object: " + error.message);
|
|
207
|
+
this.loggers.error(error.stack);
|
|
242
208
|
}
|
|
243
|
-
this.socket.emit(
|
|
244
|
-
if (this.loadError)
|
|
245
|
-
return;
|
|
246
|
-
if (!res) {
|
|
247
|
-
const errorMsg = `No response received from server when creating ${this.className}`;
|
|
248
|
-
this.isLoading = false;
|
|
249
|
-
this.loadError = errorMsg;
|
|
250
|
-
this.loggers.error?.(errorMsg);
|
|
251
|
-
this.emitter.emit(EVENT_INTERNAL_PRE_LOADED + this.EmitterID, true, errorMsg);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
209
|
+
this.socket.emit("new" + this.className, data, (res) => {
|
|
254
210
|
if (!res.success) {
|
|
255
211
|
this.isLoading = false;
|
|
256
|
-
this.
|
|
257
|
-
this.
|
|
258
|
-
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);
|
|
259
214
|
return;
|
|
260
215
|
}
|
|
261
216
|
this.data = res.data;
|
|
262
|
-
this.generateSettersAndGetters();
|
|
263
217
|
this.isLoading = false;
|
|
264
|
-
this.
|
|
218
|
+
this.loggers.debug("Created new object: " + this.data._id);
|
|
219
|
+
this.emitter.emit("pre-loaded" + this.EmitterID);
|
|
265
220
|
if (!this.isServer)
|
|
266
221
|
this.openSockets();
|
|
267
222
|
});
|
|
268
223
|
}
|
|
269
|
-
/**
|
|
270
|
-
* Returns a deep clone of the entity's extracted data with reference objects converted to IDs.
|
|
271
|
-
*
|
|
272
|
-
* @returns Serialized entity representation.
|
|
273
|
-
*/
|
|
274
224
|
get extractedData() {
|
|
275
|
-
const extracted = processIsRefProperties(this.data, this, null, [], {}, this.loggers).newData;
|
|
225
|
+
const extracted = processIsRefProperties(this.data, this.classProp.prototype, null, [], {}, this.loggers).newData;
|
|
276
226
|
return _.cloneDeep(extracted);
|
|
277
227
|
}
|
|
278
|
-
/**
|
|
279
|
-
* Indicates whether the entity has finished loading its data.
|
|
280
|
-
*
|
|
281
|
-
* @returns True if loaded.
|
|
282
|
-
*/
|
|
283
228
|
get isLoaded() {
|
|
284
229
|
return !this.isLoading;
|
|
285
230
|
}
|
|
286
|
-
/**
|
|
287
|
-
* Asynchronously awaits preloading and loads all missing reference links.
|
|
288
|
-
*
|
|
289
|
-
* @returns Promise resolving to true when completed.
|
|
290
|
-
*/
|
|
291
231
|
async isPreLoadedAsync() {
|
|
292
|
-
await this.
|
|
232
|
+
await this.loadShit();
|
|
293
233
|
this.generateSettersAndGetters();
|
|
294
234
|
return true;
|
|
295
235
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
*/
|
|
299
|
-
async loadMissingReferences() {
|
|
300
|
-
if (!this.isServer)
|
|
236
|
+
loadMissingReferences() {
|
|
237
|
+
if (this.referencesLoaded)
|
|
301
238
|
return;
|
|
302
|
-
this.
|
|
303
|
-
|
|
239
|
+
this.referencesLoaded = true;
|
|
240
|
+
this.checkForMissingRefs();
|
|
304
241
|
this.generateSettersAndGetters();
|
|
305
242
|
}
|
|
306
243
|
openSockets() {
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const res = await this.handleUpdateRequest(update);
|
|
311
|
-
if (ack && typeof ack === "function")
|
|
312
|
-
ack(res);
|
|
313
|
-
return res;
|
|
244
|
+
const event = "update" + this.className + this.data._id.toString();
|
|
245
|
+
this.socket.on(event, async (update) => {
|
|
246
|
+
await this.handleUpdateRequest(update);
|
|
314
247
|
});
|
|
315
248
|
}
|
|
316
249
|
async handleUpdateRequest(update) {
|
|
317
250
|
try {
|
|
318
251
|
await this.setValue__(update.key, update.value, true);
|
|
319
|
-
|
|
320
|
-
|
|
252
|
+
this.loggers.debug(`Applied patch ${update.key} set to ${update.value}`);
|
|
253
|
+
// Return success with the applied patch
|
|
321
254
|
return { success: true, data: undefined, message: "" };
|
|
322
255
|
}
|
|
323
256
|
catch (error) {
|
|
324
|
-
this.loggers.error
|
|
257
|
+
this.loggers.error(`[${this.data._id}] Error applying patch: ` +
|
|
258
|
+
error.message +
|
|
259
|
+
"\n" +
|
|
260
|
+
error.stack);
|
|
325
261
|
return {
|
|
326
262
|
success: false,
|
|
327
|
-
message: "Error applying update: " +
|
|
328
|
-
(error instanceof Error ? error.message : String(error)),
|
|
263
|
+
message: "Error applying update: " + error.message,
|
|
329
264
|
};
|
|
330
265
|
}
|
|
331
266
|
}
|
|
332
|
-
_gettersGenerated = false;
|
|
333
|
-
writeQueue = Promise.resolve();
|
|
334
|
-
get updateEventName() {
|
|
335
|
-
const id = this.data?._id ?? this._id;
|
|
336
|
-
return EVENT_UPDATE + this.className + (id ? id.toString() : "");
|
|
337
|
-
}
|
|
338
|
-
getRawId(key) {
|
|
339
|
-
if (!this.data)
|
|
340
|
-
return undefined;
|
|
341
|
-
const val = this.data[key];
|
|
342
|
-
if (!val)
|
|
343
|
-
return undefined;
|
|
344
|
-
if (typeof val === "string")
|
|
345
|
-
return val;
|
|
346
|
-
if (typeof val === "object" && val !== null && val._id) {
|
|
347
|
-
return val._id.toString();
|
|
348
|
-
}
|
|
349
|
-
return String(val);
|
|
350
|
-
}
|
|
351
267
|
generateSettersAndGetters() {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
+
});
|
|
381
301
|
}
|
|
382
|
-
return value;
|
|
383
302
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
findReference(id, key) {
|
|
392
|
-
if (!id)
|
|
393
|
-
return undefined;
|
|
394
|
-
const idStr = typeof id === "string" ? id : id.toString();
|
|
395
|
-
const cached = globalCache.objects[idStr];
|
|
396
|
-
if (cached?.object)
|
|
397
|
-
return cached.object;
|
|
398
|
-
const cacheKey = `${this.className}:${key}`;
|
|
399
|
-
const cachedManager = this.parentManager?.cache?.references?.[cacheKey];
|
|
400
|
-
if (cachedManager) {
|
|
401
|
-
const res = cachedManager.getObject(idStr);
|
|
402
|
-
if (res)
|
|
403
|
-
return res;
|
|
404
|
-
}
|
|
405
|
-
if (this.parentManager?.managers) {
|
|
406
|
-
for (const manager of Object.values(this.parentManager.managers)) {
|
|
407
|
-
const result = manager.getObject(idStr);
|
|
408
|
-
if (result) {
|
|
409
|
-
if (this.parentManager.cache?.references) {
|
|
410
|
-
this.parentManager.cache.references[cacheKey] = manager;
|
|
411
|
-
}
|
|
412
|
-
return result;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
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;
|
|
415
310
|
}
|
|
416
311
|
return undefined;
|
|
417
312
|
}
|
|
418
|
-
/**
|
|
419
|
-
* Mutates property value and synchronizes change to the server via socket.
|
|
420
|
-
*
|
|
421
|
-
* @param key - Property key to modify.
|
|
422
|
-
* @param val - Value to assign.
|
|
423
|
-
* @returns Promise resolving to modification result.
|
|
424
|
-
*/
|
|
425
313
|
async setValue(key, val) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
.then(() => this.setValueQueueInternal(key, val, silent, noGet, noUpdate, isParentUpdate));
|
|
443
|
-
return this.writeQueue;
|
|
444
|
-
}
|
|
445
|
-
async setValueQueueInternal(key, val, silent = false, noGet = false, noUpdate = false, isParentUpdate = false) {
|
|
446
|
-
const rootProp = key.split(".")[0];
|
|
447
|
-
if (key === "__proto__" ||
|
|
448
|
-
key === "constructor" ||
|
|
449
|
-
key === "prototype" ||
|
|
450
|
-
(this.properties && !this.properties.includes(rootProp) && rootProp !== "_id")) {
|
|
451
|
-
return { success: false, msg: `Invalid property key: ${key}` };
|
|
452
|
-
}
|
|
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);
|
|
453
330
|
try {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
if (pointer && !isParentUpdate && !silent && !this.isServer) {
|
|
457
|
-
throw new DEMError(DEMErrorCode.CANNOT_SET_REF_DIRECTLY, "Cannot set value of a reference pointer directly.");
|
|
458
|
-
}
|
|
459
|
-
let valueToStore = val;
|
|
460
|
-
if (isRef) {
|
|
461
|
-
valueToStore = Array.isArray(val)
|
|
462
|
-
? val.map((v) => v?._id?.toString() ??
|
|
463
|
-
v?.toString() ??
|
|
464
|
-
v)
|
|
465
|
-
: (val?._id?.toString() ??
|
|
466
|
-
val?.toString() ??
|
|
467
|
-
val);
|
|
468
|
-
}
|
|
469
|
-
const currentVal = this.getValue(key);
|
|
470
|
-
const currentValId = Array.isArray(currentVal)
|
|
471
|
-
? currentVal.map((v) => v?._id?.toString() ??
|
|
472
|
-
v?.toString() ??
|
|
473
|
-
v)
|
|
474
|
-
: (currentVal?._id?.toString() ??
|
|
475
|
-
currentVal?.toString());
|
|
476
|
-
if (_.isEqual(currentValId, valueToStore))
|
|
477
|
-
return { success: true, msg: "Successfully set " + key + " to " + val };
|
|
331
|
+
if (val instanceof AutoUpdatedClientObject)
|
|
332
|
+
val = val.extractedData._id;
|
|
478
333
|
const path = key.split(".");
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
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;
|
|
490
398
|
}
|
|
491
|
-
obj = obj[currentKey];
|
|
492
399
|
}
|
|
400
|
+
throw new Error(`Property ${lastPath} not found in class ${this.className}, did you mean ${nearest ?? "--No similar prop found--"}?`);
|
|
493
401
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
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 ");
|
|
500
440
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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;
|
|
506
461
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
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];
|
|
510
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();
|
|
511
489
|
}
|
|
512
490
|
return {
|
|
513
|
-
|
|
514
|
-
msg:
|
|
491
|
+
success: true,
|
|
492
|
+
msg: "Successfully set " + key + " to " + val,
|
|
515
493
|
};
|
|
516
494
|
}
|
|
517
495
|
catch (error) {
|
|
518
|
-
this.loggers.error
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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);
|
|
522
505
|
return {
|
|
523
506
|
success: false,
|
|
524
|
-
|
|
525
|
-
|
|
507
|
+
msg: message +
|
|
508
|
+
"\n Random error here: " +
|
|
509
|
+
error.message +
|
|
510
|
+
"\n" +
|
|
511
|
+
error.stack,
|
|
526
512
|
};
|
|
527
513
|
}
|
|
528
514
|
}
|
|
529
|
-
async
|
|
530
|
-
if (
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
}
|
|
549
|
-
return {
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
const obj = manager.getObject(id);
|
|
554
|
-
if (obj)
|
|
555
|
-
return obj;
|
|
556
|
-
}
|
|
557
|
-
return null;
|
|
558
|
-
}
|
|
559
|
-
async findAndLoadReferences(lastPath, value) {
|
|
560
|
-
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);
|
|
561
539
|
if (isRef) {
|
|
562
540
|
for (const id of Array.isArray(value) ? value : [value]) {
|
|
563
|
-
if (!id)
|
|
564
|
-
continue;
|
|
565
541
|
let result;
|
|
566
542
|
for (const manager of Object.values(this.parentManager.managers)) {
|
|
567
543
|
result = manager.getObject(id?.toString());
|
|
568
544
|
if (result)
|
|
569
545
|
break;
|
|
570
546
|
}
|
|
571
|
-
if (result
|
|
572
|
-
|
|
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;
|
|
573
555
|
}
|
|
556
|
+
this.referencesLoaded = false;
|
|
557
|
+
result.loadMissingReferences();
|
|
574
558
|
}
|
|
575
559
|
}
|
|
576
560
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
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
|
+
}
|
|
584
580
|
}
|
|
585
|
-
|
|
586
|
-
this.loggers.info?.(`[${_id}] ${this.className} object wiped`);
|
|
581
|
+
return value;
|
|
587
582
|
}
|
|
588
|
-
|
|
589
|
-
this.
|
|
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
|
+
}
|
|
590
626
|
}
|
|
591
|
-
async
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
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) || [];
|
|
598
644
|
for (const key of props) {
|
|
599
645
|
if (typeof key !== "string")
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
if (pointer &&
|
|
605
|
-
obj === (this.data) &&
|
|
606
|
-
obj[key] &&
|
|
607
|
-
!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])
|
|
608
650
|
await this.createdWithParent(pointer.split(":"), obj[key]);
|
|
651
|
+
if (isRef) {
|
|
652
|
+
await this.handleLoad(obj, key, alreadySeen);
|
|
609
653
|
}
|
|
610
|
-
|
|
611
|
-
alreadySeen.add(obj[key]);
|
|
612
|
-
const val = obj[key];
|
|
613
|
-
if (val &&
|
|
614
|
-
typeof val === "object" &&
|
|
615
|
-
!(val instanceof Date) &&
|
|
616
|
-
!(val instanceof ObjectId)) {
|
|
617
|
-
const nestedProto = Object.getPrototypeOf(val);
|
|
618
|
-
if (nestedProto && !alreadySeen.has(val)) {
|
|
619
|
-
alreadySeen.add(val);
|
|
620
|
-
await this.loadForceReferences(val, nestedProto, alreadySeen);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
654
|
+
await this.checkRecursiveReferenceLoading(obj, key, alreadySeen);
|
|
623
655
|
}
|
|
624
656
|
}
|
|
625
|
-
async
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
}
|
|
634
|
-
const obj = manager.getObject(parentId);
|
|
635
|
-
if (!obj) {
|
|
636
|
-
this.loggers.warn?.(`createdWithParent: Parent object not found for ID ${parentId} in manager ${pointer[0]}`);
|
|
637
|
-
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
|
+
}
|
|
638
665
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
const
|
|
647
|
-
if (
|
|
648
|
-
|
|
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);
|
|
649
677
|
break;
|
|
650
678
|
}
|
|
651
679
|
}
|
|
652
|
-
if (!alreadyIncluded) {
|
|
653
|
-
this.loggers.debug?.(`createdWithParent: Adding myId to parent array`);
|
|
654
|
-
await obj.setValue__(pointer[1], [...rawVal, myId], false, false, false, true);
|
|
655
|
-
}
|
|
656
680
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
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");
|
|
662
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
|
+
]);
|
|
663
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());
|
|
664
724
|
}
|
|
665
|
-
/**
|
|
666
|
-
* Destroys the entity and notifies server socket of deletion.
|
|
667
|
-
*
|
|
668
|
-
* @param once - Internal flag preventing infinite recursion.
|
|
669
|
-
* @returns Promise resolving to deletion outcome.
|
|
670
|
-
*/
|
|
671
725
|
async destroy(once = false) {
|
|
672
|
-
if (!once)
|
|
673
|
-
return await this.parentManager.deleteObject(this.data._id
|
|
674
|
-
|
|
675
|
-
|
|
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();
|
|
676
747
|
resolve({
|
|
677
|
-
success:
|
|
678
|
-
|
|
679
|
-
message: res.message ?? "",
|
|
748
|
+
success: true,
|
|
749
|
+
message: "Deleted",
|
|
680
750
|
});
|
|
681
751
|
});
|
|
682
752
|
});
|
|
753
|
+
return res;
|
|
683
754
|
}
|
|
684
|
-
|
|
755
|
+
checkForMissingRefs() {
|
|
685
756
|
for (const prop of this.properties) {
|
|
686
|
-
|
|
687
|
-
if (pointer
|
|
688
|
-
|
|
689
|
-
if (
|
|
690
|
-
|
|
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);
|
|
691
763
|
}
|
|
692
764
|
}
|
|
693
765
|
}
|
|
694
|
-
|
|
695
|
-
this.checkedMissingProperties ??= {};
|
|
696
|
-
if (this.checkedMissingProperties[prop])
|
|
697
|
-
return;
|
|
698
|
-
this.checkedMissingProperties[prop] = true;
|
|
766
|
+
findMissingObjectReference(prop, pointer) {
|
|
699
767
|
const ac = this.parentManager.managers[pointer[0]];
|
|
700
768
|
if (!ac)
|
|
701
|
-
|
|
702
|
-
const
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
const
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
if (id === targetId) {
|
|
716
|
-
this.data[prop] = obj._id;
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
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;
|
|
719
783
|
}
|
|
784
|
+
found = eData = eData[pathPart];
|
|
720
785
|
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
this.data[prop] = obj._id;
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
786
|
+
if (found) {
|
|
787
|
+
this.data[prop] = obj._id;
|
|
788
|
+
return;
|
|
727
789
|
}
|
|
728
790
|
}
|
|
729
791
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
*/
|
|
733
|
-
async contactChildren() {
|
|
734
|
-
if (!this.isServer)
|
|
792
|
+
wipeSelf() {
|
|
793
|
+
if (this.data.Wiped)
|
|
735
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() {
|
|
736
803
|
for (const prop of this.properties) {
|
|
737
|
-
const
|
|
738
|
-
const
|
|
739
|
-
if (
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
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
|
+
}
|
|
750
818
|
}
|
|
819
|
+
else
|
|
820
|
+
this.getValue(prop)?.loadMissingReferences();
|
|
751
821
|
}
|
|
752
822
|
}
|
|
753
|
-
this.generateSettersAndGetters();
|
|
754
|
-
}
|
|
755
|
-
async onUpdate(noUpdate = false, key) {
|
|
756
|
-
// Placeholder for server-side override
|
|
757
|
-
}
|
|
758
|
-
async onDeletion() {
|
|
759
|
-
// Placeholder for server-side override
|
|
760
823
|
}
|
|
761
824
|
}
|
|
762
|
-
|
|
763
|
-
* Traverses entity object and transforms referenced objects into string identifiers.
|
|
764
|
-
*
|
|
765
|
-
* @param instance - Raw entity data record.
|
|
766
|
-
* @param target - Reflection prototype target.
|
|
767
|
-
* @param prefix - Dot-notated property key prefix.
|
|
768
|
-
* @param allProps - Accumulated array of discovered property paths.
|
|
769
|
-
* @param newData - Output object receiving sanitized data.
|
|
770
|
-
* @param loggers - Logging interfaces.
|
|
771
|
-
* @returns Object containing all property paths and transformed newData.
|
|
772
|
-
*/
|
|
773
|
-
export function processIsRefProperties(instance, target, prefix, allProps, newData, loggers) {
|
|
825
|
+
export function processIsRefProperties(instance, target, prefix = null, allProps = [], newData = {}, loggers = console) {
|
|
774
826
|
const props = Reflect.getMetadata("props", target) || [];
|
|
775
827
|
for (const prop of props) {
|
|
776
828
|
const path = prefix ? `${prefix}.${prop}` : prop;
|
|
777
829
|
allProps.push(path);
|
|
778
|
-
newData[prop] =
|
|
779
|
-
instance[prop]
|
|
780
|
-
|
|
781
|
-
: instance[prop];
|
|
830
|
+
newData[prop] = ObjectId.isValid(instance[prop])
|
|
831
|
+
? instance[prop]?.toString()
|
|
832
|
+
: instance[prop];
|
|
782
833
|
if (Reflect.getMetadata("isRef", target, prop)) {
|
|
783
834
|
if (Array.isArray(instance[prop]))
|
|
784
835
|
newData[prop] = instance[prop]
|
|
785
|
-
.map((item) => item?._id?.toString() ??
|
|
786
|
-
item?.toString())
|
|
836
|
+
.map((item) => item?._id?.toString() ?? item?.toString() ?? undefined)
|
|
787
837
|
.filter(Boolean);
|
|
788
838
|
else
|
|
789
839
|
newData[prop] =
|
|
790
840
|
instance[prop]?._id?.toString() ??
|
|
791
|
-
instance[prop]?.toString()
|
|
841
|
+
instance[prop]?.toString() ??
|
|
842
|
+
undefined;
|
|
792
843
|
}
|
|
793
844
|
const type = Reflect.getMetadata("design:type", target, prop);
|
|
794
845
|
if (type?.prototype) {
|
|
795
846
|
const nestedProps = Reflect.getMetadata("props", type.prototype);
|
|
796
847
|
if (nestedProps && instance[prop]) {
|
|
797
|
-
newData[prop] = processIsRefProperties(instance[prop], type.prototype, path, allProps,
|
|
848
|
+
newData[prop] = processIsRefProperties(instance[prop], type.prototype, path, allProps, undefined, loggers).newData;
|
|
798
849
|
}
|
|
799
850
|
}
|
|
800
851
|
}
|
|
801
852
|
return { allProps, newData };
|
|
802
853
|
}
|
|
803
|
-
/**
|
|
804
|
-
* Compiles V8 fast-shape property getters and setters on the class prototype.
|
|
805
|
-
*
|
|
806
|
-
* @param classParam - Constructor function of the target entity class.
|
|
807
|
-
* @returns Cached metadata object with properties list, refProps set, and refsToMap.
|
|
808
|
-
*/
|
|
809
|
-
export function setupClassAccessors(classParam) {
|
|
810
|
-
if (!classParam) {
|
|
811
|
-
return { properties: [], refProps: new Set(), refsToMap: new Map() };
|
|
812
|
-
}
|
|
813
|
-
if (classParam.__metaCache) {
|
|
814
|
-
return classParam.__metaCache;
|
|
815
|
-
}
|
|
816
|
-
const allProps = new Set();
|
|
817
|
-
const refProps = new Set();
|
|
818
|
-
const refsToMap = new Map();
|
|
819
|
-
let proto_ = classParam.prototype;
|
|
820
|
-
while (proto_ && proto_ !== Object.prototype) {
|
|
821
|
-
const props = Reflect.getMetadata("props", proto_) ||
|
|
822
|
-
Reflect.getOwnMetadata("props", proto_) ||
|
|
823
|
-
[];
|
|
824
|
-
for (const p of props) {
|
|
825
|
-
if (typeof p === "string") {
|
|
826
|
-
allProps.add(p);
|
|
827
|
-
const isRef = Reflect.getMetadata("isRef", proto_, p) || Reflect.getOwnMetadata("isRef", proto_, p);
|
|
828
|
-
if (isRef)
|
|
829
|
-
refProps.add(p);
|
|
830
|
-
const refsTo = Reflect.getMetadata("refsTo", proto_, p) || Reflect.getOwnMetadata("refsTo", proto_, p);
|
|
831
|
-
if (refsTo)
|
|
832
|
-
refsToMap.set(p, refsTo);
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
proto_ = Object.getPrototypeOf(proto_);
|
|
836
|
-
}
|
|
837
|
-
const properties = Array.from(allProps);
|
|
838
|
-
for (const key of properties) {
|
|
839
|
-
const isRef = refProps.has(key);
|
|
840
|
-
Object.defineProperty(classParam.prototype, key, {
|
|
841
|
-
get() {
|
|
842
|
-
if (!this.data)
|
|
843
|
-
return undefined;
|
|
844
|
-
let val = this.data[key];
|
|
845
|
-
if (val === null)
|
|
846
|
-
val = undefined;
|
|
847
|
-
if (isRef && val) {
|
|
848
|
-
if (Array.isArray(val)) {
|
|
849
|
-
const result = [];
|
|
850
|
-
for (let i = 0; i < val.length; i++) {
|
|
851
|
-
const item = val[i];
|
|
852
|
-
if (item) {
|
|
853
|
-
const ref = this.findReference(item, key);
|
|
854
|
-
if (ref)
|
|
855
|
-
result.push(ref);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
return result;
|
|
859
|
-
}
|
|
860
|
-
else {
|
|
861
|
-
return this.findReference(val, key);
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
return val;
|
|
865
|
-
},
|
|
866
|
-
set(v) {
|
|
867
|
-
if (this.data) {
|
|
868
|
-
let valueToSet = v;
|
|
869
|
-
if (isRef && v) {
|
|
870
|
-
if (Array.isArray(v)) {
|
|
871
|
-
valueToSet = v.map((item) => item && item._id
|
|
872
|
-
? item._id.toString()
|
|
873
|
-
: item?.toString());
|
|
874
|
-
}
|
|
875
|
-
else {
|
|
876
|
-
valueToSet = v._id
|
|
877
|
-
? v._id.toString()
|
|
878
|
-
: v.toString();
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
this.data[key] = valueToSet;
|
|
882
|
-
}
|
|
883
|
-
},
|
|
884
|
-
enumerable: true,
|
|
885
|
-
configurable: true,
|
|
886
|
-
});
|
|
887
|
-
}
|
|
888
|
-
const meta = { properties, refProps, refsToMap };
|
|
889
|
-
classParam.__metaCache = meta;
|
|
890
|
-
classParam.__propsCache = properties;
|
|
891
|
-
classParam.__refPropsCache = Array.from(refProps);
|
|
892
|
-
return meta;
|
|
893
|
-
}
|
|
894
|
-
/**
|
|
895
|
-
* Traverses prototype chain recursively to resolve metadata key.
|
|
896
|
-
*
|
|
897
|
-
* @param metaKey - Reflection metadata key.
|
|
898
|
-
* @param proto - Prototype object.
|
|
899
|
-
* @param prop - Property name on prototype.
|
|
900
|
-
* @returns Metadata value or undefined.
|
|
901
|
-
*/
|
|
902
854
|
export function getMetadataRecursive(metaKey, proto, prop) {
|
|
903
855
|
while (proto) {
|
|
904
856
|
const meta = Reflect.getMetadata(metaKey, proto, prop);
|
|
@@ -908,4 +860,5 @@ export function getMetadataRecursive(metaKey, proto, prop) {
|
|
|
908
860
|
}
|
|
909
861
|
return undefined;
|
|
910
862
|
}
|
|
863
|
+
//# sourceMappingURL=AutoUpdatedClientObjectClass.js.map
|
|
911
864
|
//# sourceMappingURL=AutoUpdatedClientObjectClass.js.map
|