@futdevpro/nts-dynamo 1.15.64 → 1.15.68
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/.c8rc.json +26 -26
- package/.copilot/patterns.json +7 -7
- package/.cursor/rules/__assistant_guide.mdc +30 -30
- package/.cursor/rules/__main.mdc +64 -64
- package/.cursor/rules/_ag_backend-structure.mdc +85 -85
- package/.cursor/rules/_ag_backend.mdc +16 -16
- package/.cursor/rules/_ag_debug.mdc +7 -7
- package/.cursor/rules/_ag_documentation_writing_rules.mdc +372 -372
- package/.cursor/rules/_ag_file-refactoring.mdc +113 -113
- package/.cursor/rules/_ag_fixes_rules.mdc +5 -5
- package/.cursor/rules/_ag_frontend-structure.mdc +86 -86
- package/.cursor/rules/_ag_frontend.mdc +39 -39
- package/.cursor/rules/_ag_import-rules.mdc +44 -44
- package/.cursor/rules/_ag_naming.mdc +115 -115
- package/.cursor/rules/_ag_running_commands.mdc +4 -4
- package/.cursor/rules/_ag_server-controller.mdc +5 -5
- package/.cursor/rules/_ag_should-be.mdc +6 -6
- package/.cursor/rules/_ag_swearing.mdc +47 -47
- package/.cursor/rules/ai_development_guide.md +60 -60
- package/.cursor/rules/ai_directives.md +114 -114
- package/.cursor/rules/cursor-rules.md +160 -160
- package/.cursor/rules/default-command.mdc +464 -464
- package/.cursor/rules/error_code_pattern.md +39 -39
- package/.cursor/rules/saved rule mcp server use.md +15 -15
- package/.dynamo/pipeline.cicd.config.json +180 -180
- package/.dynamo/version-bump.config.json +5 -5
- package/.github/workflows/main.yml +438 -438
- package/.husky/pre-commit +3 -3
- package/.vscode/settings.json +10 -10
- package/HOWTO.md +15 -15
- package/LICENSE +21 -21
- package/README.md +678 -678
- package/__documentations/2026-04-28-logs-module.md +49 -49
- package/__documentations/2026-05-17-oai-compatible-providers.md +229 -229
- package/__documentations/2026-05-17-static-client-serving-howto.md +144 -144
- package/__documentations/2026-06-01-fr041-cors-middleware.md +96 -96
- package/__documentations/2026-06-01-fr047-p2p3-function-calling.md +81 -81
- package/__documentations/2026-06-15-fr193-memory-guard.md +73 -73
- package/__documentations/nts-integration-tests-2026-03-17.md +26 -26
- package/_specifications/BACKLOG.md +92 -92
- package/_specifications/TODO.md +15 -15
- package/_specifications/agent.md +138 -138
- package/build/_collections/archive.util.d.ts +12 -12
- package/build/_collections/archive.util.js +18 -18
- package/build/_collections/atlas-default-db-options.const.d.ts +2 -2
- package/build/_collections/atlas-default-db-options.const.js +9 -9
- package/build/_collections/default-fallback-cache-max-age.const.d.ts +2 -2
- package/build/_collections/default-fallback-cache-max-age.const.js +5 -5
- package/build/_collections/default-not-found-page.const.d.ts +5 -5
- package/build/_collections/default-not-found-page.const.js +24 -24
- package/build/_collections/default-socket-path.const.d.ts +2 -2
- package/build/_collections/default-socket-path.const.js +5 -5
- package/build/_collections/get-environment-settings.util.d.ts +2 -2
- package/build/_collections/get-environment-settings.util.js +43 -43
- package/build/_collections/global-settings.const.d.ts +6 -6
- package/build/_collections/global-settings.const.js +69 -69
- package/build/_collections/mongo-reconnect-guard.util.d.ts +73 -73
- package/build/_collections/mongo-reconnect-guard.util.js +110 -110
- package/build/_collections/star.controller.d.ts +7 -7
- package/build/_collections/star.controller.js +97 -97
- package/build/_enums/data-model-type.enum.d.ts +13 -13
- package/build/_enums/data-model-type.enum.js +17 -17
- package/build/_enums/data-service-function.enum.d.ts +18 -18
- package/build/_enums/data-service-function.enum.js +24 -24
- package/build/_enums/predefined-data-types.enum.d.ts +15 -15
- package/build/_enums/predefined-data-types.enum.js +19 -19
- package/build/_enums/route-security.enum.d.ts +11 -11
- package/build/_enums/route-security.enum.js +15 -15
- package/build/_models/control-models/api-call-params.control-model.d.ts +79 -79
- package/build/_models/control-models/api-call-params.control-model.js +101 -101
- package/build/_models/control-models/app-ext-system-controls.control-model.d.ts +6 -6
- package/build/_models/control-models/app-ext-system-controls.control-model.js +10 -10
- package/build/_models/control-models/app-params.control-model.d.ts +51 -51
- package/build/_models/control-models/app-params.control-model.js +119 -119
- package/build/_models/control-models/app-system-controls.control-model.d.ts +7 -7
- package/build/_models/control-models/app-system-controls.control-model.js +11 -11
- package/build/_models/control-models/endpoint-params.control-model.d.ts +114 -114
- package/build/_models/control-models/endpoint-params.control-model.js +442 -442
- package/build/_models/control-models/http-settings.control-model.d.ts +17 -17
- package/build/_models/control-models/http-settings.control-model.js +34 -34
- package/build/_models/control-models/system-control.control-model.d.ts +5 -5
- package/build/_models/control-models/system-control.control-model.js +11 -11
- package/build/_models/interfaces/certification-settings.interface.d.ts +5 -5
- package/build/_models/interfaces/certification-settings.interface.js +2 -2
- package/build/_models/interfaces/compare-data-options.interface.d.ts +26 -26
- package/build/_models/interfaces/compare-data-options.interface.js +2 -2
- package/build/_models/interfaces/compare-data-result.interface.d.ts +12 -12
- package/build/_models/interfaces/compare-data-result.interface.js +2 -2
- package/build/_models/interfaces/cors-settings.interface.d.ts +51 -51
- package/build/_models/interfaces/cors-settings.interface.js +2 -2
- package/build/_models/interfaces/environment-settings.interface.d.ts +34 -34
- package/build/_models/interfaces/environment-settings.interface.js +2 -2
- package/build/_models/interfaces/global-log-settings.interface.d.ts +145 -145
- package/build/_models/interfaces/global-log-settings.interface.js +2 -2
- package/build/_models/interfaces/global-service-settings.interface.d.ts +30 -30
- package/build/_models/interfaces/global-service-settings.interface.js +2 -2
- package/build/_models/interfaces/global-settings.interface.d.ts +161 -161
- package/build/_models/interfaces/global-settings.interface.js +2 -2
- package/build/_models/interfaces/routing-module-settings.interface.d.ts +19 -19
- package/build/_models/interfaces/routing-module-settings.interface.js +2 -2
- package/build/_models/interfaces/static-client-settings.interface.d.ts +28 -28
- package/build/_models/interfaces/static-client-settings.interface.js +2 -2
- package/build/_models/types/db-update.type.d.ts +129 -129
- package/build/_models/types/db-update.type.js +2 -2
- package/build/_modules/admin-auth/_models/admin-api-key-config.interface.d.ts +31 -31
- package/build/_modules/admin-auth/_models/admin-api-key-config.interface.js +2 -2
- package/build/_modules/admin-auth/admin-api-key.auth-service.d.ts +89 -89
- package/build/_modules/admin-auth/admin-api-key.auth-service.js +194 -194
- package/build/_modules/admin-auth/index.d.ts +2 -2
- package/build/_modules/admin-auth/index.js +5 -5
- package/build/_modules/ai/_models/ai-input-interfaces.d.ts +53 -53
- package/build/_modules/ai/_models/ai-input-interfaces.js +5 -5
- package/build/_modules/ai/_models/ai-test-generation-result.interface.d.ts +16 -16
- package/build/_modules/ai/_models/ai-test-generation-result.interface.js +2 -2
- package/build/_modules/ai/_models/interfaces/dynts-ai-cost-event-callback.interface.d.ts +13 -13
- package/build/_modules/ai/_models/interfaces/dynts-ai-cost-event-callback.interface.js +2 -2
- package/build/_modules/ai/_models/interfaces/dynts-ai-cost-event.interface.d.ts +49 -49
- package/build/_modules/ai/_models/interfaces/dynts-ai-cost-event.interface.js +2 -2
- package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.d.ts +35 -35
- package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.js +117 -117
- package/build/_modules/ai/_modules/anthropic/index.d.ts +2 -2
- package/build/_modules/ai/_modules/anthropic/index.js +7 -7
- package/build/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.d.ts +84 -84
- package/build/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.js +467 -467
- package/build/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.d.ts +109 -109
- package/build/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.js +418 -418
- package/build/_modules/ai/_modules/document-ai/_collections/dai-document.util.d.ts +28 -28
- package/build/_modules/ai/_modules/document-ai/_collections/dai-document.util.js +73 -73
- package/build/_modules/ai/_modules/document-ai/_enums/dai-compare-result-type.enum.d.ts +6 -6
- package/build/_modules/ai/_modules/document-ai/_enums/dai-compare-result-type.enum.js +10 -10
- package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.d.ts +51 -51
- package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.js +132 -132
- package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.d.ts +47 -47
- package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.js +136 -136
- package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-document.data-model.d.ts +17 -17
- package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-document.data-model.js +76 -76
- package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-code-chunk.interface.d.ts +49 -49
- package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-code-chunk.interface.js +2 -2
- package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-chunk-compare-result.interface.d.ts +8 -8
- package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-chunk-compare-result.interface.js +2 -2
- package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-page-compare-result.interface.d.ts +11 -11
- package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-page-compare-result.interface.js +2 -2
- package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-document-compare-result.interface.d.ts +12 -12
- package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-document-compare-result.interface.js +2 -2
- package/build/_modules/ai/_modules/document-ai/index.d.ts +12 -12
- package/build/_modules/ai/_modules/document-ai/index.js +27 -27
- package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.d.ts +34 -34
- package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.js +128 -128
- package/build/_modules/ai/_modules/fdp-ai/index.d.ts +2 -2
- package/build/_modules/ai/_modules/fdp-ai/index.js +7 -7
- package/build/_modules/ai/_modules/open-ai/_collections/oai-global-settings.const.d.ts +2 -2
- package/build/_modules/ai/_modules/open-ai/_collections/oai-global-settings.const.js +8 -8
- package/build/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.d.ts +2 -2
- package/build/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.js +74 -74
- package/build/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.d.ts +2 -2
- package/build/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.js +67 -67
- package/build/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.js +42 -42
- package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-global-settings.interface.d.ts +5 -5
- package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-global-settings.interface.js +2 -2
- package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.js +6 -6
- package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.d.ts +51 -51
- package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.js +2 -2
- package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.d.ts +21 -21
- package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.js +187 -187
- package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.d.ts +26 -26
- package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.js +278 -278
- package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.d.ts +22 -22
- package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.js +322 -322
- package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.d.ts +119 -119
- package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.js +480 -480
- package/build/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.d.ts +25 -25
- package/build/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.js +103 -103
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts +169 -169
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.js +479 -479
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.d.ts +201 -201
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.js +579 -579
- package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.d.ts +39 -39
- package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.js +110 -110
- package/build/_modules/ai/_modules/open-ai/index.d.ts +14 -14
- package/build/_modules/ai/_modules/open-ai/index.js +55 -55
- package/build/_modules/ai/_services/ai-embedding-mock.service.d.ts +80 -80
- package/build/_modules/ai/_services/ai-embedding-mock.service.js +166 -166
- package/build/_modules/ai/_services/ai-embedding-provider.registry.d.ts +51 -51
- package/build/_modules/ai/_services/ai-embedding-provider.registry.js +78 -78
- package/build/_modules/ai/_services/ai-embedding.service-base.d.ts +41 -41
- package/build/_modules/ai/_services/ai-embedding.service-base.js +11 -11
- package/build/_modules/ai/_services/ai-llm-chat.service-base.d.ts +39 -39
- package/build/_modules/ai/_services/ai-llm-chat.service-base.js +11 -11
- package/build/_modules/ai/_services/ai-llm.service-base.d.ts +132 -132
- package/build/_modules/ai/_services/ai-llm.service-base.js +313 -313
- package/build/_modules/ai/_services/ai-provider.service-base.d.ts +46 -46
- package/build/_modules/ai/_services/ai-provider.service-base.js +43 -43
- package/build/_modules/ai/_services/ai-user-key.service-base.d.ts +44 -44
- package/build/_modules/ai/_services/ai-user-key.service-base.js +14 -14
- package/build/_modules/ai/_services/lmstudio-embedding.control-service.d.ts +110 -110
- package/build/_modules/ai/_services/lmstudio-embedding.control-service.js +297 -297
- package/build/_modules/ai/index.d.ts +13 -13
- package/build/_modules/ai/index.js +22 -22
- package/build/_modules/assistant/_collections/ass-global-settings.const.d.ts +2 -2
- package/build/_modules/assistant/_collections/ass-global-settings.const.js +14 -14
- package/build/_modules/assistant/_collections/ass.util.d.ts +15 -15
- package/build/_modules/assistant/_collections/ass.util.js +42 -42
- package/build/_modules/assistant/_models/ass-global-settings.interface.d.ts +13 -13
- package/build/_modules/assistant/_models/ass-global-settings.interface.js +2 -2
- package/build/_modules/assistant/_services/ass-io.control-service.d.ts +19 -19
- package/build/_modules/assistant/_services/ass-io.control-service.js +57 -57
- package/build/_modules/assistant/_services/ass-main.control-service.d.ts +32 -32
- package/build/_modules/assistant/_services/ass-main.control-service.js +65 -65
- package/build/_modules/assistant/index.d.ts +6 -6
- package/build/_modules/assistant/index.js +18 -18
- package/build/_modules/bot/_collections/bot-default-commands.const.d.ts +2 -2
- package/build/_modules/bot/_collections/bot-default-commands.const.js +13 -13
- package/build/_modules/bot/_collections/bot-global-settings.const.d.ts +2 -2
- package/build/_modules/bot/_collections/bot-global-settings.const.js +31 -31
- package/build/_modules/bot/_models/bot-channel-wrapper.interface.d.ts +25 -25
- package/build/_modules/bot/_models/bot-channel-wrapper.interface.js +38 -38
- package/build/_modules/bot/_models/bot-command.interface.d.ts +7 -7
- package/build/_modules/bot/_models/bot-command.interface.js +2 -2
- package/build/_modules/bot/_models/bot-global-settings.interface.d.ts +85 -85
- package/build/_modules/bot/_models/bot-global-settings.interface.js +2 -2
- package/build/_modules/bot/_models/bot-last-mention-date.interface.d.ts +6 -6
- package/build/_modules/bot/_models/bot-last-mention-date.interface.js +2 -2
- package/build/_modules/bot/_models/bot-last-message-date.interface.d.ts +5 -5
- package/build/_modules/bot/_models/bot-last-message-date.interface.js +2 -2
- package/build/_modules/bot/_models/bot-message-wrapper.interface.d.ts +37 -37
- package/build/_modules/bot/_models/bot-message-wrapper.interface.js +54 -54
- package/build/_modules/bot/_models/bot-user-wrapper.interface.d.ts +23 -23
- package/build/_modules/bot/_models/bot-user-wrapper.interface.js +28 -28
- package/build/_modules/bot/_modules/discord-bot/_models/dib-platform.types.js +10 -10
- package/build/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.d.ts +69 -69
- package/build/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.js +497 -497
- package/build/_modules/bot/_modules/discord-bot/index.d.ts +1 -1
- package/build/_modules/bot/_modules/discord-bot/index.js +12 -12
- package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.d.ts +16 -16
- package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.js +42 -42
- package/build/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.d.ts +9 -9
- package/build/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.js +2 -2
- package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.d.ts +59 -59
- package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.js +349 -349
- package/build/_modules/bot/_modules/dynamo-bot/index.d.ts +3 -3
- package/build/_modules/bot/_modules/dynamo-bot/index.js +15 -15
- package/build/_modules/bot/_modules/slack-bot/_models/slb-platform.types.d.ts +6 -6
- package/build/_modules/bot/_modules/slack-bot/_models/slb-platform.types.js +2 -2
- package/build/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.d.ts +56 -56
- package/build/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.js +137 -137
- package/build/_modules/bot/_modules/slack-bot/index.d.ts +2 -2
- package/build/_modules/bot/_modules/slack-bot/index.js +12 -12
- package/build/_modules/bot/_modules/teams-bot/_models/teb-platform.types.d.ts +6 -6
- package/build/_modules/bot/_modules/teams-bot/_models/teb-platform.types.js +2 -2
- package/build/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.d.ts +56 -56
- package/build/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.js +137 -137
- package/build/_modules/bot/_modules/teams-bot/index.d.ts +2 -2
- package/build/_modules/bot/_modules/teams-bot/index.js +12 -12
- package/build/_modules/bot/_services/bot-commands.control-service.d.ts +12 -12
- package/build/_modules/bot/_services/bot-commands.control-service.js +117 -117
- package/build/_modules/bot/_services/bot-io.control-service.d.ts +23 -23
- package/build/_modules/bot/_services/bot-io.control-service.js +226 -226
- package/build/_modules/bot/_services/bot-main.control-service.d.ts +35 -35
- package/build/_modules/bot/_services/bot-main.control-service.js +195 -195
- package/build/_modules/bot/_services/bot-messaging-provider.service-base.d.ts +71 -71
- package/build/_modules/bot/_services/bot-messaging-provider.service-base.js +15 -15
- package/build/_modules/bot/_services/bot-routines.control-service.d.ts +13 -13
- package/build/_modules/bot/_services/bot-routines.control-service.js +59 -59
- package/build/_modules/bot/index.d.ts +17 -17
- package/build/_modules/bot/index.js +36 -36
- package/build/_modules/custom-data/custom-data.controller.d.ts +5 -5
- package/build/_modules/custom-data/custom-data.controller.js +56 -56
- package/build/_modules/custom-data/custom-data.data-service.d.ts +5 -5
- package/build/_modules/custom-data/custom-data.data-service.js +11 -11
- package/build/_modules/custom-data/get-custom-data-routing-module.util.d.ts +3 -3
- package/build/_modules/custom-data/get-custom-data-routing-module.util.js +16 -16
- package/build/_modules/custom-data/index.d.ts +4 -4
- package/build/_modules/custom-data/index.js +9 -9
- package/build/_modules/data-readers/_collections/dynts-sqlite-reader.util.d.ts +58 -58
- package/build/_modules/data-readers/_collections/dynts-sqlite-reader.util.js +168 -168
- package/build/_modules/data-readers/_models/interfaces/dynts-sqlite-reader.interface.d.ts +31 -31
- package/build/_modules/data-readers/_models/interfaces/dynts-sqlite-reader.interface.js +7 -7
- package/build/_modules/data-readers/index.d.ts +2 -2
- package/build/_modules/data-readers/index.js +10 -10
- package/build/_modules/defaults/_collections/default-endpoints.util.d.ts +248 -248
- package/build/_modules/defaults/_collections/default-endpoints.util.js +386 -386
- package/build/_modules/defaults/_models/default-user.data-model.d.ts +19 -19
- package/build/_modules/defaults/_models/default-user.data-model.js +72 -72
- package/build/_modules/defaults/_services/default-auth.service.d.ts +50 -50
- package/build/_modules/defaults/_services/default-auth.service.js +158 -158
- package/build/_modules/defaults/_services/default-socket-events.service.d.ts +23 -23
- package/build/_modules/defaults/_services/default-socket-events.service.js +60 -60
- package/build/_modules/defaults/_services/default-user.data-service.d.ts +24 -24
- package/build/_modules/defaults/_services/default-user.data-service.js +87 -87
- package/build/_modules/defaults/index.d.ts +5 -5
- package/build/_modules/defaults/index.js +17 -17
- package/build/_modules/discord-assistant/_collections/dias-global-settings.const.d.ts +2 -2
- package/build/_modules/discord-assistant/_collections/dias-global-settings.const.js +16 -16
- package/build/_modules/discord-assistant/_collections/dias.util.d.ts +31 -31
- package/build/_modules/discord-assistant/_collections/dias.util.js +85 -85
- package/build/_modules/discord-assistant/_models/dias-global-settings.interface.d.ts +17 -17
- package/build/_modules/discord-assistant/_models/dias-global-settings.interface.js +2 -2
- package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.d.ts +8 -8
- package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.js +46 -46
- package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts +17 -17
- package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js +123 -123
- package/build/_modules/discord-assistant/_services/dias-io.control-service.d.ts +10 -10
- package/build/_modules/discord-assistant/_services/dias-io.control-service.js +49 -49
- package/build/_modules/discord-assistant/_services/dias-main.control-service.d.ts +3 -3
- package/build/_modules/discord-assistant/_services/dias-main.control-service.js +7 -7
- package/build/_modules/discord-assistant/_services/dias.service-base.d.ts +18 -18
- package/build/_modules/discord-assistant/_services/dias.service-base.js +46 -46
- package/build/_modules/discord-assistant/index.d.ts +11 -11
- package/build/_modules/discord-assistant/index.js +24 -24
- package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.d.ts +3 -3
- package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.js +7 -7
- package/build/_modules/discord-assistant-voiced/index.d.ts +2 -2
- package/build/_modules/discord-assistant-voiced/index.js +28 -28
- package/build/_modules/discord-bot/_collections/dibo-default-commands.const.d.ts +2 -2
- package/build/_modules/discord-bot/_collections/dibo-default-commands.const.js +12 -12
- package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts +2 -2
- package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.js +43 -43
- package/build/_modules/discord-bot/_collections/dibo-operations.util.d.ts +22 -22
- package/build/_modules/discord-bot/_collections/dibo-operations.util.js +275 -275
- package/build/_modules/discord-bot/_models/dibo-command.interface.d.ts +7 -7
- package/build/_modules/discord-bot/_models/dibo-command.interface.js +2 -2
- package/build/_modules/discord-bot/_models/dibo-global-settings.interface.d.ts +87 -87
- package/build/_modules/discord-bot/_models/dibo-global-settings.interface.js +2 -2
- package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.d.ts +6 -6
- package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.js +2 -2
- package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.d.ts +5 -5
- package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.js +2 -2
- package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts +11 -11
- package/build/_modules/discord-bot/_services/dibo-commands.control-service.js +109 -109
- package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts +21 -21
- package/build/_modules/discord-bot/_services/dibo-io.control-service.js +218 -218
- package/build/_modules/discord-bot/_services/dibo-main.control-service.d.ts +89 -89
- package/build/_modules/discord-bot/_services/dibo-main.control-service.js +363 -363
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts +13 -13
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.js +73 -73
- package/build/_modules/discord-bot/index.d.ts +11 -11
- package/build/_modules/discord-bot/index.js +30 -30
- package/build/_modules/local-vector-search/_enums/lvs-search-mode.enum.d.ts +34 -34
- package/build/_modules/local-vector-search/_enums/lvs-search-mode.enum.js +38 -38
- package/build/_modules/local-vector-search/_models/data-models/lvs-vector-persist.data-model.d.ts +35 -35
- package/build/_modules/local-vector-search/_models/data-models/lvs-vector-persist.data-model.js +53 -53
- package/build/_modules/local-vector-search/_models/lvs-search-result.interface.d.ts +16 -16
- package/build/_modules/local-vector-search/_models/lvs-search-result.interface.js +2 -2
- package/build/_modules/local-vector-search/_services/lvs-bm25.util.d.ts +88 -88
- package/build/_modules/local-vector-search/_services/lvs-bm25.util.js +189 -189
- package/build/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.d.ts +26 -26
- package/build/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.js +197 -197
- package/build/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.d.ts +145 -145
- package/build/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.js +294 -294
- package/build/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.d.ts +69 -69
- package/build/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.js +122 -122
- package/build/_modules/local-vector-search/_services/lvs-vector-persist.data-service.d.ts +42 -42
- package/build/_modules/local-vector-search/_services/lvs-vector-persist.data-service.js +71 -71
- package/build/_modules/local-vector-search/_services/lvs-vector-pool.control-service.d.ts +70 -70
- package/build/_modules/local-vector-search/_services/lvs-vector-pool.control-service.js +181 -181
- package/build/_modules/local-vector-search/index.d.ts +8 -8
- package/build/_modules/local-vector-search/index.js +15 -15
- package/build/_modules/logs/_models/file-log-entry.interface.d.ts +13 -13
- package/build/_modules/logs/_models/file-log-entry.interface.js +2 -2
- package/build/_modules/logs/_models/file-log-read-result.interface.d.ts +35 -35
- package/build/_modules/logs/_models/file-log-read-result.interface.js +2 -2
- package/build/_modules/logs/file-log.service.d.ts +132 -132
- package/build/_modules/logs/file-log.service.js +444 -444
- package/build/_modules/logs/file-logs.controller.d.ts +40 -40
- package/build/_modules/logs/file-logs.controller.js +138 -138
- package/build/_modules/logs/get-file-logs-routing-module.util.d.ts +31 -31
- package/build/_modules/logs/get-file-logs-routing-module.util.js +37 -37
- package/build/_modules/logs/get-logs-routing-module.util.d.ts +18 -18
- package/build/_modules/logs/get-logs-routing-module.util.js +31 -31
- package/build/_modules/logs/index.d.ts +8 -8
- package/build/_modules/logs/index.js +15 -15
- package/build/_modules/logs/log-buffer.service.d.ts +37 -37
- package/build/_modules/logs/log-buffer.service.js +96 -96
- package/build/_modules/logs/logs.controller.d.ts +26 -26
- package/build/_modules/logs/logs.controller.js +89 -89
- package/build/_modules/logs/logs.service.d.ts +39 -39
- package/build/_modules/logs/logs.service.js +96 -96
- package/build/_modules/mcp/_models/interfaces/dynts-mcp.interface.d.ts +108 -108
- package/build/_modules/mcp/_models/interfaces/dynts-mcp.interface.js +13 -13
- package/build/_modules/mcp/_services/dynts-mcp-server.service-base.d.ts +70 -70
- package/build/_modules/mcp/_services/dynts-mcp-server.service-base.js +98 -98
- package/build/_modules/mcp/_services/dynts-mcp.adapter.d.ts +56 -56
- package/build/_modules/mcp/_services/dynts-mcp.adapter.js +138 -138
- package/build/_modules/mcp/index.d.ts +3 -3
- package/build/_modules/mcp/index.js +12 -12
- package/build/_modules/messaging/_collections/get-messaging-routing-module.util.d.ts +7 -7
- package/build/_modules/messaging/_collections/get-messaging-routing-module.util.js +20 -20
- package/build/_modules/messaging/_collections/msg-global-settings.const.d.ts +5 -5
- package/build/_modules/messaging/_collections/msg-global-settings.const.js +22 -22
- package/build/_modules/messaging/_collections/msg.util.d.ts +24 -24
- package/build/_modules/messaging/_collections/msg.util.js +62 -62
- package/build/_modules/messaging/_models/msg-global-settings.interface.d.ts +28 -28
- package/build/_modules/messaging/_models/msg-global-settings.interface.js +2 -2
- package/build/_modules/messaging/_services/msg-conversation.data-service.d.ts +28 -28
- package/build/_modules/messaging/_services/msg-conversation.data-service.js +109 -109
- package/build/_modules/messaging/_services/msg-events.service.d.ts +61 -61
- package/build/_modules/messaging/_services/msg-events.service.js +203 -203
- package/build/_modules/messaging/_services/msg-integration.control-service.js +180 -180
- package/build/_modules/messaging/_services/msg-main.control-service.d.ts +62 -62
- package/build/_modules/messaging/_services/msg-main.control-service.js +428 -428
- package/build/_modules/messaging/_services/msg-message.data-service.d.ts +28 -28
- package/build/_modules/messaging/_services/msg-message.data-service.js +103 -103
- package/build/_modules/messaging/_services/msg.controller.d.ts +12 -12
- package/build/_modules/messaging/_services/msg.controller.js +256 -256
- package/build/_modules/messaging/index.d.ts +10 -10
- package/build/_modules/messaging/index.js +27 -27
- package/build/_modules/mock/app-extended-server.mock.d.ts +41 -41
- package/build/_modules/mock/app-extended-server.mock.js +169 -169
- package/build/_modules/mock/app-integration-test.mock.d.ts +19 -19
- package/build/_modules/mock/app-integration-test.mock.js +45 -45
- package/build/_modules/mock/app-params.mock.d.ts +2 -2
- package/build/_modules/mock/app-params.mock.js +9 -9
- package/build/_modules/mock/app-server.mock.d.ts +41 -41
- package/build/_modules/mock/app-server.mock.js +148 -148
- package/build/_modules/mock/auth-service.mock.d.ts +10 -10
- package/build/_modules/mock/auth-service.mock.js +19 -19
- package/build/_modules/mock/controller.mock.d.ts +5 -5
- package/build/_modules/mock/controller.mock.js +14 -14
- package/build/_modules/mock/data-model.mock.d.ts +26 -26
- package/build/_modules/mock/data-model.mock.js +72 -72
- package/build/_modules/mock/email-service-collection.mock.d.ts +7 -7
- package/build/_modules/mock/email-service-collection.mock.js +12 -12
- package/build/_modules/mock/email-service.mock.d.ts +4 -4
- package/build/_modules/mock/email-service.mock.js +20 -20
- package/build/_modules/mock/endpoint.mock.d.ts +8 -8
- package/build/_modules/mock/endpoint.mock.js +79 -79
- package/build/_modules/mock/socket-client.mock.d.ts +9 -9
- package/build/_modules/mock/socket-client.mock.js +38 -38
- package/build/_modules/mock/socket-server.mock.d.ts +15 -15
- package/build/_modules/mock/socket-server.mock.js +32 -32
- package/build/_modules/oauth2/_routes/oauth2.controller.d.ts +16 -16
- package/build/_modules/oauth2/_routes/oauth2.controller.js +96 -96
- package/build/_modules/oauth2/_services/oauth2.auth-service.d.ts +30 -30
- package/build/_modules/oauth2/_services/oauth2.auth-service.js +215 -215
- package/build/_modules/oauth2/_services/oauth2.control-service.d.ts +132 -132
- package/build/_modules/oauth2/_services/oauth2.control-service.js +576 -576
- package/build/_modules/oauth2/index.d.ts +3 -3
- package/build/_modules/oauth2/index.js +14 -14
- package/build/_modules/rate-limit/_models/rate-limit-config.interface.d.ts +61 -61
- package/build/_modules/rate-limit/_models/rate-limit-config.interface.js +2 -2
- package/build/_modules/rate-limit/_models/rate-limit-policy.interface.d.ts +15 -15
- package/build/_modules/rate-limit/_models/rate-limit-policy.interface.js +2 -2
- package/build/_modules/rate-limit/index.d.ts +3 -3
- package/build/_modules/rate-limit/index.js +5 -5
- package/build/_modules/rate-limit/rate-limit.middleware.d.ts +132 -132
- package/build/_modules/rate-limit/rate-limit.middleware.js +289 -289
- package/build/_modules/scoped-config/_enums/dynts-scoped-config-level.enum.d.ts +18 -18
- package/build/_modules/scoped-config/_enums/dynts-scoped-config-level.enum.js +22 -22
- package/build/_modules/scoped-config/_models/data-models/dynts-scoped-config.data-model.d.ts +43 -43
- package/build/_modules/scoped-config/_models/data-models/dynts-scoped-config.data-model.js +67 -67
- package/build/_modules/scoped-config/_models/interfaces/dynts-scoped-config.interface.d.ts +88 -88
- package/build/_modules/scoped-config/_models/interfaces/dynts-scoped-config.interface.js +11 -11
- package/build/_modules/scoped-config/_services/dynts-scoped-config.control-service.d.ts +83 -83
- package/build/_modules/scoped-config/_services/dynts-scoped-config.control-service.js +219 -219
- package/build/_modules/scoped-config/_services/dynts-scoped-config.data-service.d.ts +53 -53
- package/build/_modules/scoped-config/_services/dynts-scoped-config.data-service.js +75 -75
- package/build/_modules/scoped-config/index.d.ts +5 -5
- package/build/_modules/scoped-config/index.js +14 -14
- package/build/_modules/server/errors/errors.control-service.d.ts +21 -19
- package/build/_modules/server/errors/errors.control-service.d.ts.map +1 -1
- package/build/_modules/server/errors/errors.control-service.js +10 -10
- package/build/_modules/server/errors/errors.control-service.js.map +1 -1
- package/build/_modules/server/errors/errors.controller.d.ts +100 -99
- package/build/_modules/server/errors/errors.controller.d.ts.map +1 -1
- package/build/_modules/server/errors/errors.controller.js +355 -313
- package/build/_modules/server/errors/errors.controller.js.map +1 -1
- package/build/_modules/server/errors/errors.data-service.d.ts +64 -47
- package/build/_modules/server/errors/errors.data-service.d.ts.map +1 -1
- package/build/_modules/server/errors/errors.data-service.js +628 -552
- package/build/_modules/server/errors/errors.data-service.js.map +1 -1
- package/build/_modules/server/index.d.ts +7 -7
- package/build/_modules/server/index.js +26 -26
- package/build/_modules/server/server-status/server-status-snapshot.control-service.d.ts +4 -4
- package/build/_modules/server/server-status/server-status-snapshot.control-service.js +7 -7
- package/build/_modules/server/server-status/server-status-snapshot.data-service.d.ts +6 -6
- package/build/_modules/server/server-status/server-status-snapshot.data-service.js +22 -22
- package/build/_modules/server/server-status/server-status.control-service.d.ts +74 -74
- package/build/_modules/server/server-status/server-status.control-service.js +234 -234
- package/build/_modules/server/server-status/server-status.controller.d.ts +84 -84
- package/build/_modules/server/server-status/server-status.controller.js +172 -172
- package/build/_modules/socket/_enums/socket-security.enum.d.ts +10 -10
- package/build/_modules/socket/_enums/socket-security.enum.js +14 -14
- package/build/_modules/socket/_models/socket-client-service-params.control-model.d.ts +8 -8
- package/build/_modules/socket/_models/socket-client-service-params.control-model.js +16 -16
- package/build/_modules/socket/_models/socket-presence.control-model.d.ts +25 -25
- package/build/_modules/socket/_models/socket-presence.control-model.js +139 -139
- package/build/_modules/socket/_models/socket-server-service-params.control-model.d.ts +12 -12
- package/build/_modules/socket/_models/socket-server-service-params.control-model.js +20 -20
- package/build/_modules/socket/_services/socket-client.service.d.ts +37 -37
- package/build/_modules/socket/_services/socket-client.service.js +196 -196
- package/build/_modules/socket/_services/socket-server.service.d.ts +94 -94
- package/build/_modules/socket/_services/socket-server.service.js +689 -689
- package/build/_modules/socket/app-extended.server.d.ts +145 -145
- package/build/_modules/socket/app-extended.server.js +506 -506
- package/build/_modules/socket/index.d.ts +8 -8
- package/build/_modules/socket/index.js +35 -35
- package/build/_modules/test/get-test-routing-module.util.d.ts +3 -3
- package/build/_modules/test/get-test-routing-module.util.js +16 -16
- package/build/_modules/test/index.d.ts +3 -3
- package/build/_modules/test/index.js +11 -11
- package/build/_modules/test/test.controller.d.ts +5 -5
- package/build/_modules/test/test.controller.js +103 -103
- package/build/_modules/usage/get-usage-routing-module.util.d.ts +3 -3
- package/build/_modules/usage/get-usage-routing-module.util.js +16 -16
- package/build/_modules/usage/index.d.ts +4 -4
- package/build/_modules/usage/index.js +13 -13
- package/build/_modules/usage/usage.controller.d.ts +6 -6
- package/build/_modules/usage/usage.controller.js +95 -95
- package/build/_modules/usage/usage.data-service.d.ts +17 -17
- package/build/_modules/usage/usage.data-service.js +135 -135
- package/build/_services/base/api.service-base.d.ts +9 -9
- package/build/_services/base/api.service-base.js +46 -46
- package/build/_services/base/archive-data.service.d.ts +25 -25
- package/build/_services/base/archive-data.service.js +140 -140
- package/build/_services/base/data.service.d.ts +381 -381
- package/build/_services/base/data.service.js +2068 -2068
- package/build/_services/base/db.service.d.ts +393 -393
- package/build/_services/base/db.service.js +1256 -1256
- package/build/_services/base/singleton.service-base.d.ts +8 -8
- package/build/_services/base/singleton.service-base.js +21 -21
- package/build/_services/base/singleton.service.d.ts +11 -11
- package/build/_services/base/singleton.service.js +31 -31
- package/build/_services/core/api.service.d.ts +45 -45
- package/build/_services/core/api.service.js +436 -436
- package/build/_services/core/auth.service.d.ts +129 -129
- package/build/_services/core/auth.service.js +59 -59
- package/build/_services/core/email.service.d.ts +77 -77
- package/build/_services/core/email.service.js +489 -489
- package/build/_services/core/global.service.d.ts +76 -76
- package/build/_services/core/global.service.js +370 -370
- package/build/_services/core/memory-guard.service.d.ts +110 -110
- package/build/_services/core/memory-guard.service.js +197 -197
- package/build/_services/core/service-collection.service.d.ts +4 -4
- package/build/_services/core/service-collection.service.js +7 -7
- package/build/_services/route/controller.service.d.ts +124 -124
- package/build/_services/route/controller.service.js +95 -95
- package/build/_services/route/routing-module.service.d.ts +80 -80
- package/build/_services/route/routing-module.service.js +250 -250
- package/build/_services/server/app.server.d.ts +352 -352
- package/build/_services/server/app.server.js +1323 -1323
- package/build/_services/shared.static-service.d.ts +36 -36
- package/build/_services/shared.static-service.js +72 -72
- package/build/index.d.ts +43 -43
- package/build/index.js +80 -80
- package/eslint.config.js +3 -3
- package/nodemon.json +24 -24
- package/package.json +416 -417
- package/pnpm-workspace.yaml +5 -5
- package/scripts/run-coverage-tests.js +28 -28
- package/spec/support/helpers/spec-reporter-loader.js +359 -359
- package/spec/support/helpers/ts-node-helper.js +93 -93
- package/spec/support/jasmine.coverage.json +24 -24
- package/spec/support/jasmine.json +24 -24
- package/src/_collections/archive.util.spec.ts +57 -57
- package/src/_collections/archive.util.ts +18 -18
- package/src/_collections/atlas-default-db-options.const.ts +9 -9
- package/src/_collections/default-fallback-cache-max-age.const.spec.ts +11 -11
- package/src/_collections/default-fallback-cache-max-age.const.ts +2 -2
- package/src/_collections/default-not-found-page.const.spec.ts +19 -19
- package/src/_collections/default-not-found-page.const.ts +22 -22
- package/src/_collections/default-socket-path.const.spec.ts +12 -12
- package/src/_collections/default-socket-path.const.ts +2 -2
- package/src/_collections/get-environment-settings.util.spec.ts +210 -210
- package/src/_collections/get-environment-settings.util.ts +48 -48
- package/src/_collections/global-settings.const.ts +89 -89
- package/src/_collections/mongo-reconnect-guard.util.spec.ts +52 -52
- package/src/_collections/mongo-reconnect-guard.util.ts +172 -172
- package/src/_collections/sample.env +21 -21
- package/src/_collections/star.controller.spec.ts +224 -224
- package/src/_collections/star.controller.ts +129 -129
- package/src/_enums/data-model-type.enum.ts +14 -14
- package/src/_enums/data-service-function.enum.ts +24 -24
- package/src/_enums/predefined-data-types.enum.ts +16 -16
- package/src/_enums/route-security.enum.ts +12 -12
- package/src/_models/control-models/api-call-params.control-model.spec.ts +152 -152
- package/src/_models/control-models/api-call-params.control-model.ts +142 -142
- package/src/_models/control-models/app-ext-system-controls.control-model.spec.ts +52 -52
- package/src/_models/control-models/app-ext-system-controls.control-model.ts +9 -9
- package/src/_models/control-models/app-params.control-model.spec.ts +225 -225
- package/src/_models/control-models/app-params.control-model.ts +136 -136
- package/src/_models/control-models/app-system-controls.control-model.spec.ts +31 -31
- package/src/_models/control-models/app-system-controls.control-model.ts +9 -9
- package/src/_models/control-models/endpoint-params.control-model.spec.ts +627 -627
- package/src/_models/control-models/endpoint-params.control-model.ts +627 -627
- package/src/_models/control-models/http-settings.control-model.spec.ts +77 -77
- package/src/_models/control-models/http-settings.control-model.ts +37 -37
- package/src/_models/control-models/system-control.control-model.spec.ts +27 -27
- package/src/_models/control-models/system-control.control-model.ts +12 -12
- package/src/_models/interfaces/certification-settings.interface.ts +7 -7
- package/src/_models/interfaces/compare-data-options.interface.ts +27 -27
- package/src/_models/interfaces/compare-data-result.interface.ts +12 -12
- package/src/_models/interfaces/cors-settings.interface.spec.ts +52 -52
- package/src/_models/interfaces/cors-settings.interface.ts +56 -56
- package/src/_models/interfaces/environment-settings.interface.ts +59 -59
- package/src/_models/interfaces/global-log-settings.interface.ts +171 -171
- package/src/_models/interfaces/global-service-settings.interface.ts +47 -47
- package/src/_models/interfaces/global-settings.interface.ts +185 -185
- package/src/_models/interfaces/routing-module-settings.interface.ts +21 -21
- package/src/_models/interfaces/static-client-settings.interface.spec.ts +29 -29
- package/src/_models/interfaces/static-client-settings.interface.ts +28 -28
- package/src/_models/types/db-update.type.ts +100 -100
- package/src/_modules/admin-auth/_models/admin-api-key-config.interface.ts +33 -33
- package/src/_modules/admin-auth/admin-api-key.auth-service.spec.ts +200 -200
- package/src/_modules/admin-auth/admin-api-key.auth-service.ts +220 -220
- package/src/_modules/admin-auth/index.ts +2 -2
- package/src/_modules/ai/_models/ai-input-interfaces.ts +117 -117
- package/src/_modules/ai/_models/ai-test-generation-result.interface.ts +16 -16
- package/src/_modules/ai/_models/interfaces/dynts-ai-cost-event-callback.interface.ts +14 -14
- package/src/_modules/ai/_models/interfaces/dynts-ai-cost-event.interface.ts +56 -56
- package/src/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.ts +138 -138
- package/src/_modules/ai/_modules/anthropic/index.ts +5 -5
- package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.spec.ts +242 -242
- package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.ts +639 -639
- package/src/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.spec.ts +295 -295
- package/src/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.ts +552 -552
- package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.spec.ts +209 -209
- package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.ts +85 -85
- package/src/_modules/ai/_modules/document-ai/_enums/dai-compare-result-type.enum.ts +7 -7
- package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.ts +146 -146
- package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.ts +162 -162
- package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-document.data-model.ts +99 -99
- package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-code-chunk.interface.ts +68 -68
- package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-chunk-compare-result.interface.ts +18 -18
- package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-page-compare-result.interface.ts +19 -19
- package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-document-compare-result.interface.ts +25 -25
- package/src/_modules/ai/_modules/document-ai/index.ts +30 -30
- package/src/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.ts +189 -189
- package/src/_modules/ai/_modules/fdp-ai/index.ts +5 -5
- package/src/_modules/ai/_modules/open-ai/_collections/oai-global-settings.const.ts +9 -9
- package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.ts +82 -82
- package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.ts +75 -75
- package/src/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.ts +45 -45
- package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-global-settings.interface.ts +7 -7
- package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.ts +7 -7
- package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.ts +57 -57
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.ts +292 -292
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.ts +572 -572
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.spec.ts +342 -342
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.ts +435 -435
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.spec.ts +550 -550
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.ts +630 -630
- package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.spec.ts +332 -332
- package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.ts +132 -132
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.spec.ts +462 -462
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.ts +634 -634
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.spec.ts +489 -489
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.tools.spec.ts +173 -173
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.ts +1033 -1033
- package/src/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.ts +157 -157
- package/src/_modules/ai/_modules/open-ai/index.ts +74 -74
- package/src/_modules/ai/_services/ai-embedding-mock.service.spec.ts +115 -115
- package/src/_modules/ai/_services/ai-embedding-mock.service.ts +233 -233
- package/src/_modules/ai/_services/ai-embedding-provider.registry.spec.ts +110 -110
- package/src/_modules/ai/_services/ai-embedding-provider.registry.ts +114 -114
- package/src/_modules/ai/_services/ai-embedding.service-base.spec.ts +98 -98
- package/src/_modules/ai/_services/ai-embedding.service-base.ts +48 -48
- package/src/_modules/ai/_services/ai-llm-chat.service-base.spec.ts +229 -229
- package/src/_modules/ai/_services/ai-llm-chat.service-base.ts +68 -68
- package/src/_modules/ai/_services/ai-llm.service-base.spec.ts +250 -250
- package/src/_modules/ai/_services/ai-llm.service-base.ts +519 -519
- package/src/_modules/ai/_services/ai-provider.service-base.spec.ts +158 -158
- package/src/_modules/ai/_services/ai-provider.service-base.ts +67 -67
- package/src/_modules/ai/_services/ai-user-key.service-base.ts +59 -59
- package/src/_modules/ai/_services/lmstudio-embedding.control-service.spec.ts +197 -197
- package/src/_modules/ai/_services/lmstudio-embedding.control-service.ts +399 -399
- package/src/_modules/ai/index.ts +23 -23
- package/src/_modules/assistant/_collections/ass-global-settings.const.ts +13 -13
- package/src/_modules/assistant/_collections/ass.util.spec.ts +176 -176
- package/src/_modules/assistant/_collections/ass.util.ts +50 -50
- package/src/_modules/assistant/_models/ass-global-settings.interface.ts +15 -15
- package/src/_modules/assistant/_services/ass-io.control-service.spec.ts +140 -140
- package/src/_modules/assistant/_services/ass-io.control-service.ts +74 -74
- package/src/_modules/assistant/_services/ass-main.control-service.spec.ts +192 -192
- package/src/_modules/assistant/_services/ass-main.control-service.ts +107 -107
- package/src/_modules/assistant/index.ts +19 -19
- package/src/_modules/bot/_collections/bot-default-commands.const.ts +12 -12
- package/src/_modules/bot/_collections/bot-global-settings.const.ts +39 -39
- package/src/_modules/bot/_models/bot-channel-wrapper.interface.ts +62 -62
- package/src/_modules/bot/_models/bot-command.interface.ts +8 -8
- package/src/_modules/bot/_models/bot-global-settings.interface.ts +96 -96
- package/src/_modules/bot/_models/bot-last-mention-date.interface.ts +6 -6
- package/src/_modules/bot/_models/bot-last-message-date.interface.ts +5 -5
- package/src/_modules/bot/_models/bot-message-wrapper.interface.ts +90 -90
- package/src/_modules/bot/_models/bot-user-wrapper.interface.ts +41 -41
- package/src/_modules/bot/_modules/discord-bot/_models/dib-platform.types.ts +9 -9
- package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.spec.ts +431 -431
- package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.ts +641 -641
- package/src/_modules/bot/_modules/discord-bot/index.ts +12 -12
- package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.spec.ts +160 -160
- package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.ts +55 -55
- package/src/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.ts +15 -15
- package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.spec.ts +374 -374
- package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.ts +447 -447
- package/src/_modules/bot/_modules/dynamo-bot/index.ts +15 -15
- package/src/_modules/bot/_modules/slack-bot/_models/slb-platform.types.ts +9 -9
- package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.spec.ts +344 -344
- package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.ts +197 -197
- package/src/_modules/bot/_modules/slack-bot/index.ts +12 -12
- package/src/_modules/bot/_modules/teams-bot/_models/teb-platform.types.ts +9 -9
- package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.spec.ts +345 -345
- package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.ts +197 -197
- package/src/_modules/bot/_modules/teams-bot/index.ts +11 -11
- package/src/_modules/bot/_services/bot-commands.control-service.spec.ts +116 -116
- package/src/_modules/bot/_services/bot-commands.control-service.ts +158 -158
- package/src/_modules/bot/_services/bot-io.control-service.spec.ts +285 -285
- package/src/_modules/bot/_services/bot-io.control-service.ts +329 -329
- package/src/_modules/bot/_services/bot-main.control-service.spec.ts +208 -208
- package/src/_modules/bot/_services/bot-main.control-service.ts +489 -489
- package/src/_modules/bot/_services/bot-messaging-provider.service-base.spec.ts +349 -349
- package/src/_modules/bot/_services/bot-messaging-provider.service-base.ts +158 -158
- package/src/_modules/bot/_services/bot-routines.control-service.spec.ts +111 -111
- package/src/_modules/bot/_services/bot-routines.control-service.ts +78 -78
- package/src/_modules/bot/index.ts +37 -37
- package/src/_modules/custom-data/custom-data.controller.spec.ts +49 -49
- package/src/_modules/custom-data/custom-data.controller.ts +67 -67
- package/src/_modules/custom-data/custom-data.data-service.spec.ts +54 -54
- package/src/_modules/custom-data/custom-data.data-service.ts +21 -21
- package/src/_modules/custom-data/get-custom-data-routing-module.util.spec.ts +28 -28
- package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +24 -24
- package/src/_modules/custom-data/index.ts +9 -9
- package/src/_modules/data-readers/_collections/dynts-sqlite-reader.util.spec.ts +176 -176
- package/src/_modules/data-readers/_collections/dynts-sqlite-reader.util.ts +203 -203
- package/src/_modules/data-readers/_models/interfaces/dynts-sqlite-reader.interface.ts +33 -33
- package/src/_modules/data-readers/index.ts +11 -11
- package/src/_modules/defaults/_collections/default-endpoints.util.ts +487 -487
- package/src/_modules/defaults/_models/default-user.data-model.ts +72 -72
- package/src/_modules/defaults/_services/default-auth.service.spec.ts +269 -269
- package/src/_modules/defaults/_services/default-auth.service.ts +177 -177
- package/src/_modules/defaults/_services/default-socket-events.service.spec.ts +42 -42
- package/src/_modules/defaults/_services/default-socket-events.service.ts +61 -61
- package/src/_modules/defaults/_services/default-user.data-service.spec.ts +187 -187
- package/src/_modules/defaults/_services/default-user.data-service.ts +98 -98
- package/src/_modules/defaults/index.ts +17 -17
- package/src/_modules/discord-assistant/_collections/dias-global-settings.const.ts +19 -19
- package/src/_modules/discord-assistant/_collections/dias.util.spec.ts +366 -366
- package/src/_modules/discord-assistant/_collections/dias.util.ts +132 -132
- package/src/_modules/discord-assistant/_models/dias-global-settings.interface.ts +19 -19
- package/src/_modules/discord-assistant/_models/dias-knowledge.data-model.ts +52 -52
- package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +177 -177
- package/src/_modules/discord-assistant/_services/dias-io.control-service.spec.ts +108 -108
- package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +69 -69
- package/src/_modules/discord-assistant/_services/dias-main.control-service.spec.ts +22 -22
- package/src/_modules/discord-assistant/_services/dias-main.control-service.ts +27 -27
- package/src/_modules/discord-assistant/_services/dias.service-base.spec.ts +195 -195
- package/src/_modules/discord-assistant/_services/dias.service-base.ts +76 -76
- package/src/_modules/discord-assistant/index.ts +38 -38
- package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.spec.ts +34 -34
- package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.ts +11 -11
- package/src/_modules/discord-assistant-voiced/index.ts +36 -36
- package/src/_modules/discord-bot/_collections/dibo-default-commands.const.ts +16 -16
- package/src/_modules/discord-bot/_collections/dibo-global-settings.conts.ts +55 -55
- package/src/_modules/discord-bot/_collections/dibo-operations.util.spec.ts +214 -214
- package/src/_modules/discord-bot/_collections/dibo-operations.util.ts +387 -387
- package/src/_modules/discord-bot/_models/dibo-command.interface.ts +12 -12
- package/src/_modules/discord-bot/_models/dibo-global-settings.interface.ts +98 -98
- package/src/_modules/discord-bot/_models/dibo-last-mention-date.inteface.ts +7 -7
- package/src/_modules/discord-bot/_models/dibo-last-message-date.interface.ts +6 -6
- package/src/_modules/discord-bot/_services/dibo-commands.control-service.spec.ts +154 -154
- package/src/_modules/discord-bot/_services/dibo-commands.control-service.ts +153 -153
- package/src/_modules/discord-bot/_services/dibo-io.control-service.spec.ts +264 -264
- package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +306 -306
- package/src/_modules/discord-bot/_services/dibo-main.control-service.spec.ts +408 -408
- package/src/_modules/discord-bot/_services/dibo-main.control-service.ts +487 -487
- package/src/_modules/discord-bot/_services/dibo-routines.control-service.spec.ts +105 -105
- package/src/_modules/discord-bot/_services/dibo-routines.control-service.ts +97 -97
- package/src/_modules/discord-bot/index.ts +36 -36
- package/src/_modules/local-vector-search/_enums/lvs-search-mode.enum.ts +35 -35
- package/src/_modules/local-vector-search/_models/data-models/lvs-vector-persist.data-model.ts +60 -60
- package/src/_modules/local-vector-search/_models/lvs-search-result.interface.ts +17 -17
- package/src/_modules/local-vector-search/_services/lvs-bm25.util.spec.ts +159 -159
- package/src/_modules/local-vector-search/_services/lvs-bm25.util.ts +206 -206
- package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.spec.ts +418 -418
- package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.ts +276 -276
- package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.spec.ts +480 -480
- package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.ts +416 -416
- package/src/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.spec.ts +198 -198
- package/src/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.ts +150 -150
- package/src/_modules/local-vector-search/_services/lvs-vector-persist.data-service.spec.ts +167 -167
- package/src/_modules/local-vector-search/_services/lvs-vector-persist.data-service.ts +108 -108
- package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.spec.ts +393 -393
- package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.ts +220 -220
- package/src/_modules/local-vector-search/index.ts +16 -16
- package/src/_modules/logs/_models/file-log-entry.interface.ts +13 -13
- package/src/_modules/logs/_models/file-log-read-result.interface.ts +37 -37
- package/src/_modules/logs/file-log.service.spec.ts +341 -341
- package/src/_modules/logs/file-log.service.ts +466 -466
- package/src/_modules/logs/file-logs.controller.spec.ts +245 -245
- package/src/_modules/logs/file-logs.controller.ts +165 -165
- package/src/_modules/logs/get-file-logs-routing-module.util.ts +51 -51
- package/src/_modules/logs/get-logs-routing-module.util.ts +36 -36
- package/src/_modules/logs/index.ts +11 -11
- package/src/_modules/logs/log-buffer.service.ts +101 -101
- package/src/_modules/logs/logs.controller.ts +109 -109
- package/src/_modules/logs/logs.service.ts +100 -100
- package/src/_modules/mcp/_models/interfaces/dynts-mcp.interface.ts +111 -111
- package/src/_modules/mcp/_services/dynts-mcp-server.service-base.spec.ts +151 -151
- package/src/_modules/mcp/_services/dynts-mcp-server.service-base.ts +125 -125
- package/src/_modules/mcp/_services/dynts-mcp.adapter.ts +168 -168
- package/src/_modules/mcp/index.ts +13 -13
- package/src/_modules/messaging/README.md +354 -354
- package/src/_modules/messaging/_collections/get-messaging-routing-module.util.ts +26 -26
- package/src/_modules/messaging/_collections/msg-global-settings.const.ts +22 -22
- package/src/_modules/messaging/_collections/msg.util.spec.ts +226 -226
- package/src/_modules/messaging/_collections/msg.util.ts +83 -83
- package/src/_modules/messaging/_models/msg-global-settings.interface.ts +37 -37
- package/src/_modules/messaging/_services/msg-conversation.data-service.ts +146 -146
- package/src/_modules/messaging/_services/msg-events.service.spec.ts +219 -219
- package/src/_modules/messaging/_services/msg-events.service.ts +267 -267
- package/src/_modules/messaging/_services/msg-integration.control-service.ts +179 -179
- package/src/_modules/messaging/_services/msg-main.control-service.spec.ts +147 -147
- package/src/_modules/messaging/_services/msg-main.control-service.ts +571 -571
- package/src/_modules/messaging/_services/msg-message.data-service.ts +129 -129
- package/src/_modules/messaging/_services/msg.controller.spec.ts +201 -201
- package/src/_modules/messaging/_services/msg.controller.ts +370 -370
- package/src/_modules/messaging/index.ts +30 -30
- package/src/_modules/mock/app-extended-server.mock.ts +201 -201
- package/src/_modules/mock/app-integration-test.mock.ts +51 -51
- package/src/_modules/mock/app-params.mock.spec.ts +21 -21
- package/src/_modules/mock/app-params.mock.ts +9 -9
- package/src/_modules/mock/app-server.mock.ts +188 -188
- package/src/_modules/mock/auth-service.mock.spec.ts +47 -47
- package/src/_modules/mock/auth-service.mock.ts +28 -28
- package/src/_modules/mock/controller.mock.spec.ts +26 -26
- package/src/_modules/mock/controller.mock.ts +16 -16
- package/src/_modules/mock/data-model.mock.spec.ts +111 -111
- package/src/_modules/mock/data-model.mock.ts +82 -82
- package/src/_modules/mock/email-service-collection.mock.spec.ts +24 -24
- package/src/_modules/mock/email-service-collection.mock.ts +15 -15
- package/src/_modules/mock/email-service.mock.spec.ts +17 -17
- package/src/_modules/mock/email-service.mock.ts +20 -20
- package/src/_modules/mock/email-template.mock.html +14 -14
- package/src/_modules/mock/endpoint.mock.ts +91 -91
- package/src/_modules/mock/socket-client.mock.spec.ts +40 -40
- package/src/_modules/mock/socket-client.mock.ts +45 -45
- package/src/_modules/mock/socket-server.mock.spec.ts +44 -44
- package/src/_modules/mock/socket-server.mock.ts +46 -46
- package/src/_modules/oauth2/_routes/oauth2.controller.spec.ts +107 -107
- package/src/_modules/oauth2/_routes/oauth2.controller.ts +98 -98
- package/src/_modules/oauth2/_services/oauth2.auth-service.spec.ts +254 -254
- package/src/_modules/oauth2/_services/oauth2.auth-service.ts +232 -232
- package/src/_modules/oauth2/_services/oauth2.control-service.spec.ts +585 -585
- package/src/_modules/oauth2/_services/oauth2.control-service.ts +653 -653
- package/src/_modules/oauth2/index.ts +17 -17
- package/src/_modules/rate-limit/_models/rate-limit-config.interface.ts +69 -69
- package/src/_modules/rate-limit/_models/rate-limit-policy.interface.ts +16 -16
- package/src/_modules/rate-limit/index.ts +3 -3
- package/src/_modules/rate-limit/rate-limit.middleware.spec.ts +264 -264
- package/src/_modules/rate-limit/rate-limit.middleware.ts +343 -343
- package/src/_modules/scoped-config/_enums/dynts-scoped-config-level.enum.ts +22 -22
- package/src/_modules/scoped-config/_models/data-models/dynts-scoped-config.data-model.ts +82 -82
- package/src/_modules/scoped-config/_models/interfaces/dynts-scoped-config.interface.ts +107 -107
- package/src/_modules/scoped-config/_services/dynts-scoped-config.control-service.spec.ts +312 -312
- package/src/_modules/scoped-config/_services/dynts-scoped-config.control-service.ts +311 -311
- package/src/_modules/scoped-config/_services/dynts-scoped-config.data-service.spec.ts +123 -123
- package/src/_modules/scoped-config/_services/dynts-scoped-config.data-service.ts +108 -108
- package/src/_modules/scoped-config/index.ts +17 -17
- package/src/_modules/server/errors/errors.control-service.spec.ts +246 -238
- package/src/_modules/server/errors/errors.control-service.ts +100 -85
- package/src/_modules/server/errors/errors.controller.spec.ts +249 -241
- package/src/_modules/server/errors/errors.controller.ts +489 -431
- package/src/_modules/server/errors/errors.data-service.spec.ts +480 -361
- package/src/_modules/server/errors/errors.data-service.ts +816 -722
- package/src/_modules/server/index.ts +30 -30
- package/src/_modules/server/server-status/server-status-snapshot.control-service.spec.ts +70 -70
- package/src/_modules/server/server-status/server-status-snapshot.control-service.ts +17 -17
- package/src/_modules/server/server-status/server-status-snapshot.data-service.spec.ts +77 -77
- package/src/_modules/server/server-status/server-status-snapshot.data-service.ts +37 -37
- package/src/_modules/server/server-status/server-status.control-service.spec.ts +584 -576
- package/src/_modules/server/server-status/server-status.control-service.ts +396 -396
- package/src/_modules/server/server-status/server-status.controller.spec.ts +248 -240
- package/src/_modules/server/server-status/server-status.controller.ts +253 -253
- package/src/_modules/socket/_enums/socket-security.enum.ts +11 -11
- package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +32 -32
- package/src/_modules/socket/_models/socket-client-service-params.control-model.ts +22 -22
- package/src/_modules/socket/_models/socket-presence.control-model.spec.ts +164 -164
- package/src/_modules/socket/_models/socket-presence.control-model.ts +210 -210
- package/src/_modules/socket/_models/socket-server-service-params.control-model.spec.ts +46 -46
- package/src/_modules/socket/_models/socket-server-service-params.control-model.ts +22 -22
- package/src/_modules/socket/_services/socket-client.service.spec.ts +15 -15
- package/src/_modules/socket/_services/socket-client.service.ts +260 -260
- package/src/_modules/socket/_services/socket-server.service.spec.ts +11 -11
- package/src/_modules/socket/_services/socket-server.service.ts +1068 -1068
- package/src/_modules/socket/app-extended.integration.spec.ts +85 -85
- package/src/_modules/socket/app-extended.server.ts +630 -630
- package/src/_modules/socket/index.ts +42 -42
- package/src/_modules/test/get-test-routing-module.util.spec.ts +28 -28
- package/src/_modules/test/get-test-routing-module.util.ts +23 -23
- package/src/_modules/test/index.ts +11 -11
- package/src/_modules/test/test.controller.spec.ts +72 -72
- package/src/_modules/test/test.controller.ts +115 -115
- package/src/_modules/usage/get-usage-routing-module.util.ts +22 -22
- package/src/_modules/usage/index.ts +15 -15
- package/src/_modules/usage/usage.controller.spec.ts +81 -81
- package/src/_modules/usage/usage.controller.ts +126 -126
- package/src/_modules/usage/usage.data-service.spec.ts +332 -332
- package/src/_modules/usage/usage.data-service.ts +185 -185
- package/src/_services/base/api.service-base.spec.ts +125 -125
- package/src/_services/base/api.service-base.ts +74 -74
- package/src/_services/base/archive-data.service.spec.ts +196 -196
- package/src/_services/base/archive-data.service.ts +216 -216
- package/src/_services/base/data.service.spec.ts +674 -674
- package/src/_services/base/data.service.ts +2719 -2719
- package/src/_services/base/db.service.spec.ts +73 -73
- package/src/_services/base/db.service.ts +1575 -1575
- package/src/_services/base/singleton.service-base.spec.ts +28 -28
- package/src/_services/base/singleton.service-base.ts +24 -24
- package/src/_services/base/singleton.service.spec.ts +114 -114
- package/src/_services/base/singleton.service.ts +38 -38
- package/src/_services/core/api.service.spec.ts +140 -140
- package/src/_services/core/api.service.ts +607 -607
- package/src/_services/core/auth.service.spec.ts +159 -159
- package/src/_services/core/auth.service.ts +174 -174
- package/src/_services/core/email.service.spec.ts +85 -85
- package/src/_services/core/email.service.ts +742 -742
- package/src/_services/core/global.service.spec.ts +292 -292
- package/src/_services/core/global.service.ts +475 -475
- package/src/_services/core/memory-guard.service.spec.ts +165 -165
- package/src/_services/core/memory-guard.service.ts +281 -281
- package/src/_services/core/service-collection.service.spec.ts +46 -46
- package/src/_services/core/service-collection.service.ts +6 -6
- package/src/_services/route/controller.service.spec.ts +53 -53
- package/src/_services/route/controller.service.ts +148 -148
- package/src/_services/route/routing-module.service.spec.ts +98 -98
- package/src/_services/route/routing-module.service.ts +330 -330
- package/src/_services/server/app.server.ts +1747 -1747
- package/src/_services/shared.static-service.spec.ts +99 -99
- package/src/_services/shared.static-service.ts +78 -78
- package/src/index.ts +96 -96
- package/tsconfig.app.json +12 -12
- package/tsconfig.json +42 -42
- package/.dynamo/logs/cicd-pipeline/output.log +0 -2771
- package/.dynamo/logs/cicd-pipeline/status.json +0 -94
|
@@ -1,2069 +1,2069 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DyNTS_DataService = void 0;
|
|
4
|
-
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
5
|
-
const archive_util_1 = require("../../_collections/archive.util");
|
|
6
|
-
const global_settings_const_1 = require("../../_collections/global-settings.const");
|
|
7
|
-
const global_service_1 = require("../core/global.service");
|
|
8
|
-
/**
|
|
9
|
-
* `DyFM_Metadata` field-ek amik auto-discovery modban (fields opcio nelkul)
|
|
10
|
-
* KI vannak hagyva a compareData()-bol. Ezek normal mukodes kozben kezelt
|
|
11
|
-
* mezok (id-allocation, audit timestamps, audit usernames) — szemantikus
|
|
12
|
-
* adatvaltozas-ellenorzeshez irrelevansak.
|
|
13
|
-
*
|
|
14
|
-
* Explicit `fields: ['_id']`-vel meg vizsgaltathato, ha valamiert kell.
|
|
15
|
-
*/
|
|
16
|
-
const COMPARE_DATA_METADATA_SKIP_FIELDS = new Set([
|
|
17
|
-
'_id',
|
|
18
|
-
'__created',
|
|
19
|
-
'__createdBy',
|
|
20
|
-
'__lastModified',
|
|
21
|
-
'__lastModifiedBy',
|
|
22
|
-
]);
|
|
23
|
-
// TODO: 2 type of archiving service system: within list, or separate db elements
|
|
24
|
-
/**
|
|
25
|
-
* Basic Data Service that is connected to the relevant DBServices
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* export class UserMatchStatisticsService extends DyNTS_DataService<UserMatchStatistics> {
|
|
29
|
-
* constructor(
|
|
30
|
-
* set: {
|
|
31
|
-
* data?: UserMatchStatistics,
|
|
32
|
-
* issuer: string,
|
|
33
|
-
* }
|
|
34
|
-
* ) {
|
|
35
|
-
* super(
|
|
36
|
-
* new UserMatchStatistics(set?.data),
|
|
37
|
-
* userMatchStatisticsModelParams
|
|
38
|
-
* );
|
|
39
|
-
* this.issuer = set.issuer;
|
|
40
|
-
* }
|
|
41
|
-
* }
|
|
42
|
-
*/
|
|
43
|
-
class DyNTS_DataService {
|
|
44
|
-
data;
|
|
45
|
-
dataParams;
|
|
46
|
-
issuer;
|
|
47
|
-
serviceName;
|
|
48
|
-
serviceNameShortCode;
|
|
49
|
-
/** error code base */
|
|
50
|
-
ecBase = `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|`;
|
|
51
|
-
dataDBService;
|
|
52
|
-
haveArchiveDataService;
|
|
53
|
-
/* data: T; */
|
|
54
|
-
/** @deprecated */
|
|
55
|
-
dataList = [];
|
|
56
|
-
/* issuer: string; */
|
|
57
|
-
depSettings = [];
|
|
58
|
-
/* depKeys: string[] = [];
|
|
59
|
-
depDBServiceKeys: string[] = [];
|
|
60
|
-
depKeyIsUnique: boolean[] = [];
|
|
61
|
-
depKeyIsRequired: boolean[] = []; */
|
|
62
|
-
depDataDBService;
|
|
63
|
-
/* dataParams: DyFM_DataModel_Params<T>; */
|
|
64
|
-
defaultErrorUserMsg = `We encountered an unhandled Data Service Error, ` +
|
|
65
|
-
`\nplease contact the responsible development team.`;
|
|
66
|
-
defaultValidationErrorUserMsg = `We encountered an unhandled Validation Error, ` +
|
|
67
|
-
`\nplease contact the responsible development team.`;
|
|
68
|
-
constructor(
|
|
69
|
-
/**
|
|
70
|
-
* Initial data, this will be used by functions on default
|
|
71
|
-
* @deprecated
|
|
72
|
-
*/
|
|
73
|
-
data,
|
|
74
|
-
/**
|
|
75
|
-
* DB data prams will be used to connect to usable dbService on GlobalService
|
|
76
|
-
*/
|
|
77
|
-
/* dataParams: DyFM_DataModel_Params, */
|
|
78
|
-
dataParams,
|
|
79
|
-
/**
|
|
80
|
-
* Initial set for issuer to be able to follow the issuer's activity
|
|
81
|
-
*/
|
|
82
|
-
issuer) {
|
|
83
|
-
this.data = data;
|
|
84
|
-
this.dataParams = dataParams;
|
|
85
|
-
this.issuer = issuer;
|
|
86
|
-
try {
|
|
87
|
-
this.serviceName = this.constructor?.name;
|
|
88
|
-
this.serviceNameShortCode = fsm_dynamo_1.DyFM_String.anyNameToShortCode(this.serviceName);
|
|
89
|
-
this.ecBase = `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|${this.serviceNameShortCode}|`;
|
|
90
|
-
this.dataDBService = global_service_1.DyNTS_GlobalService.getDBService(this.dataParams);
|
|
91
|
-
/* this.data = data; */
|
|
92
|
-
/* this.dataParams = dataParams; */
|
|
93
|
-
this.haveArchiveDataService = this.dataParams.addArchive;
|
|
94
|
-
this.lookForDependencyDataSettings();
|
|
95
|
-
/* this.issuer = issuer; */
|
|
96
|
-
/* DyNTS_GlobalService.addDataService(this); */
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
100
|
-
...this._getDefaultErrorSettings('constructor', error),
|
|
101
|
-
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-C00`,
|
|
102
|
-
message: `The dataService construction failed for "${this.dataParams?.dataName}". ` +
|
|
103
|
-
`at "${this.serviceName}" (${this.constructor.name})` +
|
|
104
|
-
`\nMaybe you forgot to add the dbService to the GlobalService?` +
|
|
105
|
-
`\nOr just trying to use a dependencyDataName that is not present in this db...`,
|
|
106
|
-
level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
|
|
107
|
-
});
|
|
108
|
-
/* DyFM_Log.error(
|
|
109
|
-
`\nDyNTS_DataService ERROR: ` +
|
|
110
|
-
`\nThe dataService construction failed for ` +
|
|
111
|
-
`${this.dataParams?.dataName}. ${this.serviceName} (${this.constructor.name})` +
|
|
112
|
-
`\nMaybe you forgot to add the dbService to the GlobalService?` +
|
|
113
|
-
`\n\n`,
|
|
114
|
-
new Error()
|
|
115
|
-
); */
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
getArchiveDataService() {
|
|
119
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
120
|
-
...this._getDefaultErrorSettings('getArchiveDataService', new Error('getArchiveDataService is not implemented!')),
|
|
121
|
-
errorCode: `${this.ecBase}DyNTS-DS-GAD0`,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* returns all data from database to service dataList
|
|
126
|
-
*/
|
|
127
|
-
async getAll(dontSetToService) {
|
|
128
|
-
try {
|
|
129
|
-
const dataListExists = await this.dataDBService.getAll().catch((error) => {
|
|
130
|
-
if (error?.errorCode?.includes('DBS-GA1')) {
|
|
131
|
-
fsm_dynamo_1.DyFM_Log.warn(`getAll "${this.dataParams.dataName}" didn't found any.`);
|
|
132
|
-
return [];
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
throw error;
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
if (!dontSetToService) {
|
|
139
|
-
this.dataList = dataListExists;
|
|
140
|
-
}
|
|
141
|
-
return dataListExists;
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
145
|
-
...this._getDefaultErrorSettings('getAll', error),
|
|
146
|
-
errorCode: `${this.ecBase}DyNTS-DS-GA0`,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* @description
|
|
152
|
-
* returns data from database by id
|
|
153
|
-
* also if dontSetToService is false or not setted,
|
|
154
|
-
* the data will be saved to the service, even if its not found
|
|
155
|
-
*
|
|
156
|
-
* if the data is not found, it will try to find it from the archive
|
|
157
|
-
* unless skipArchiveLoad is set to true
|
|
158
|
-
*
|
|
159
|
-
* @remarks
|
|
160
|
-
* If you need to get-save a data, if possible,
|
|
161
|
-
* use db-service update instead.
|
|
162
|
-
*
|
|
163
|
-
* @param {string} id
|
|
164
|
-
* (using id from service.data, if not provided)
|
|
165
|
-
* @param dontSetToService
|
|
166
|
-
*
|
|
167
|
-
* @return {T} data: T
|
|
168
|
-
*/
|
|
169
|
-
async getDataById(id, dontSetToService, skipArchiveLoad) {
|
|
170
|
-
try {
|
|
171
|
-
id = id ?? this.data?._id;
|
|
172
|
-
if (!id) {
|
|
173
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
174
|
-
...this._getDefaultErrorSettings('getDataById', new Error(`getDataById failed, ID is missing! ` +
|
|
175
|
-
`(maybe you wanted to use getDataByDependencyId() instead...) ` +
|
|
176
|
-
`(${this.dataParams.dataName})`)),
|
|
177
|
-
errorCode: `${this.ecBase}DyNTS-DS-GI1`,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
let dataExists = await this.dataDBService.getDataById(id);
|
|
181
|
-
if (!dataExists && this.haveArchiveDataService && !skipArchiveLoad) {
|
|
182
|
-
const archiveDataService = this.getArchiveDataService();
|
|
183
|
-
dataExists = await archiveDataService.getDataByOriginalId(id, true);
|
|
184
|
-
}
|
|
185
|
-
if (!dontSetToService) {
|
|
186
|
-
this.data = dataExists;
|
|
187
|
-
}
|
|
188
|
-
return dataExists;
|
|
189
|
-
}
|
|
190
|
-
catch (error) {
|
|
191
|
-
if (error?.errorCode == `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-GI1`) {
|
|
192
|
-
throw error;
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
196
|
-
...this._getDefaultErrorSettings('getDataById', error),
|
|
197
|
-
errorCode: `${this.ecBase}DyNTS-DS-GI0`,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async getDataByIds(ids, dontSetToService) {
|
|
203
|
-
try {
|
|
204
|
-
if (!ids) {
|
|
205
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
206
|
-
...this._getDefaultErrorSettings('getDataByIds', new Error(`getDataByIds failed, ids is missing! (${this.dataParams.dataName})`)),
|
|
207
|
-
errorCode: `${this.ecBase}DyNTS-DS-GIS1`,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
if (ids.length === 0) {
|
|
211
|
-
return [];
|
|
212
|
-
}
|
|
213
|
-
const dataList = await this.dataDBService.find({ _id: { $in: ids } });
|
|
214
|
-
if (!dontSetToService) {
|
|
215
|
-
this.dataList = dataList;
|
|
216
|
-
}
|
|
217
|
-
return dataList;
|
|
218
|
-
}
|
|
219
|
-
catch (error) {
|
|
220
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
221
|
-
...this._getDefaultErrorSettings('getDataByIds', error),
|
|
222
|
-
errorCode: `${this.ecBase}DyNTS-DS-GIS0`,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
async getDataListByIds(ids, dontSetToService) {
|
|
227
|
-
try {
|
|
228
|
-
const dataList = await this.dataDBService.getDataListByIds(ids);
|
|
229
|
-
if (!dontSetToService) {
|
|
230
|
-
this.dataList = dataList;
|
|
231
|
-
}
|
|
232
|
-
return dataList;
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
236
|
-
...this._getDefaultErrorSettings('getDataListByIds', error),
|
|
237
|
-
errorCode: `${this.ecBase}DyNTS-DS-GIL0`,
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
getDependencyIdsFilter(dependencyIds) {
|
|
242
|
-
if (!this.depSettings.length) {
|
|
243
|
-
fsm_dynamo_1.DyFM_Log.warn(`❌ getDataByDependencyId failed, dependencyKey is missing from service! ` +
|
|
244
|
-
`(${this.dataParams.dataName})` +
|
|
245
|
-
`\n 📍 ${this.dataParams.stackLocation}`);
|
|
246
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
247
|
-
...this._getDefaultErrorSettings('getDataByDependencyId', new Error(`getDataByDependencyId failed, dependencyKey is missing from service! ` +
|
|
248
|
-
`(${this.dataParams.dataName})`)),
|
|
249
|
-
errorCode: `${this.ecBase}DyNTS-DS-GD1`,
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
if (typeof dependencyIds === 'string') {
|
|
253
|
-
if (this.depSettings.length === 1) {
|
|
254
|
-
dependencyIds = { [this.depSettings[0].key]: dependencyIds };
|
|
255
|
-
}
|
|
256
|
-
else if (this.depSettings.length > 1) {
|
|
257
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
258
|
-
...this._getDefaultErrorSettings('getDataByDependencyId', new Error(`getDataByDependencyId failed, there are multiple dependencyKeys, ` +
|
|
259
|
-
`so you need to provide a map of dependencyKeys! ` +
|
|
260
|
-
`(${this.dataParams.dataName})`)),
|
|
261
|
-
errorCode: `${this.ecBase}DyNTS-DS-GD2`,
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
else if (!dependencyIds) {
|
|
266
|
-
dependencyIds = {};
|
|
267
|
-
this.depSettings.forEach((depSetting) => {
|
|
268
|
-
if (this.data?.[depSetting.key]) {
|
|
269
|
-
dependencyIds[depSetting.key] = this.data?.[depSetting.key];
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
if (!dependencyIds ||
|
|
274
|
-
this.depSettings.every((depSetting) => !dependencyIds[depSetting.key])) {
|
|
275
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
276
|
-
...this._getDefaultErrorSettings('getDataByDependencyId', new Error(`getDataByDependencyId failed, dependencyId is missing! ` +
|
|
277
|
-
`(${this.dataParams.dataName})`)),
|
|
278
|
-
errorCode: `${this.ecBase}DyNTS-DS-GD3`,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
return dependencyIds;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* returns data from database by dependencyId to the service
|
|
285
|
-
* (using id from service.data, if not provided)
|
|
286
|
-
* @param dependencyIds
|
|
287
|
-
*/
|
|
288
|
-
async getDataByDependencyId(dependencyIds, dontSetToService) {
|
|
289
|
-
try {
|
|
290
|
-
const dependencyIdsFilter = this.getDependencyIdsFilter(dependencyIds);
|
|
291
|
-
const dataExists = await this.dataDBService.getDataByDependencyId(dependencyIdsFilter).catch((error) => {
|
|
292
|
-
if (error?.errorCode?.includes('DBS-GD2')) {
|
|
293
|
-
fsm_dynamo_1.DyFM_Log.warn(`getDataByDependencyId failed; "${this.dataParams.dataName}" ` +
|
|
294
|
-
`(${JSON.stringify(dependencyIds)}) didn't found any.`);
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
throw error;
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
if (!dontSetToService) {
|
|
302
|
-
this.data = dataExists;
|
|
303
|
-
}
|
|
304
|
-
return dataExists;
|
|
305
|
-
}
|
|
306
|
-
catch (error) {
|
|
307
|
-
if ([
|
|
308
|
-
`${this.ecBase}DyNTS-DS0-GD1`,
|
|
309
|
-
`${this.ecBase}DyNTS-DS0-GD2`
|
|
310
|
-
].includes(error?.errorCode)) {
|
|
311
|
-
throw error;
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
315
|
-
...this._getDefaultErrorSettings('getDataByDependencyId', error),
|
|
316
|
-
errorCode: `${this.ecBase}DyNTS-DS-GD0`,
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
async getDataListByDependencyIds(dependencyIds, dontSetToService, dependencyKey) {
|
|
322
|
-
try {
|
|
323
|
-
if (!this.depSettings.length) {
|
|
324
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
325
|
-
...this._getDefaultErrorSettings('getDataListByDependencyIds', new Error(`getDataListByDependencyIds failed, dependencyKey is missing from service! ` +
|
|
326
|
-
`(${this.dataParams.dataName})`)),
|
|
327
|
-
errorCode: `${this.ecBase}DyNTS-DS-GDS1`,
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
if (!dependencyKey) {
|
|
331
|
-
if (this.depSettings.length === 1) {
|
|
332
|
-
dependencyKey = this.depSettings[0].key;
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
336
|
-
...this._getDefaultErrorSettings('getDataListByDependencyIds', new Error(`getDataListByDependencyIds failed, dependencyKey is missing! ` +
|
|
337
|
-
`since there are multiple dependencyKeys, you need to provide one! ` +
|
|
338
|
-
`(${this.dataParams.dataName})`)),
|
|
339
|
-
errorCode: `${this.ecBase}DyNTS-DS-GDS2`,
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
if (!dependencyIds) {
|
|
344
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
345
|
-
...this._getDefaultErrorSettings('getDataListByDependencyIds', new Error(`getDataListByDependencyIds failed, dependencyIds is missing! ` +
|
|
346
|
-
`(${this.dataParams.dataName})`)),
|
|
347
|
-
errorCode: `${this.ecBase}DyNTS-DS-GDS3`,
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
if (dependencyIds.length === 0) {
|
|
351
|
-
return [];
|
|
352
|
-
}
|
|
353
|
-
const dataList = await this.dataDBService.getDataListByDependencyIds(dependencyKey, dependencyIds);
|
|
354
|
-
if (!dontSetToService) {
|
|
355
|
-
this.dataList = dataList;
|
|
356
|
-
}
|
|
357
|
-
return dataList;
|
|
358
|
-
}
|
|
359
|
-
catch (error) {
|
|
360
|
-
if ([
|
|
361
|
-
`${this.ecBase}DyNTS-DS0-GDS1`,
|
|
362
|
-
`${this.ecBase}DyNTS-DS0-GDS2`
|
|
363
|
-
].includes(error?.errorCode)) {
|
|
364
|
-
throw error;
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
368
|
-
...this._getDefaultErrorSettings('getDataListByDependencyIds', error),
|
|
369
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GDS0`,
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* returns dataList from database by dependencyId to the service
|
|
376
|
-
* @param dependencyIds
|
|
377
|
-
*/
|
|
378
|
-
async getDataListByDependencyId(dependencyIds, dontSetToService) {
|
|
379
|
-
try {
|
|
380
|
-
const dependencyIdsFilter = this.getDependencyIdsFilter(dependencyIds);
|
|
381
|
-
const dataListExists = await this.dataDBService.getDataListByDependencyId(dependencyIdsFilter).catch((error) => {
|
|
382
|
-
if (error?.errorCode?.includes('DBS-GLD2')) {
|
|
383
|
-
fsm_dynamo_1.DyFM_Log.warn(`getDataListByDependencyId "${this.dataParams.dataName}" ` +
|
|
384
|
-
`(${JSON.stringify(dependencyIdsFilter)}) didn't found any.`);
|
|
385
|
-
return [];
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
throw error;
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
if (!dontSetToService) {
|
|
392
|
-
this.dataList = dataListExists;
|
|
393
|
-
}
|
|
394
|
-
return dataListExists;
|
|
395
|
-
}
|
|
396
|
-
catch (error) {
|
|
397
|
-
if ([
|
|
398
|
-
`${this.ecBase}DyNTS-DS0-GLD1`,
|
|
399
|
-
`${this.ecBase}DyNTS-DS0-GLD2`
|
|
400
|
-
].includes(error?.errorCode)) {
|
|
401
|
-
throw error;
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
405
|
-
...this._getDefaultErrorSettings('getDataListByDependencyId', error),
|
|
406
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GLD0`,
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
*
|
|
413
|
-
* // findOne desc:
|
|
414
|
-
*
|
|
415
|
-
* Find the data first by any of its parameters,
|
|
416
|
-
* also if dontSetToService is false or not setted,
|
|
417
|
-
* the data will be saved to the service, even if non found
|
|
418
|
-
*
|
|
419
|
-
* @param filter if you can, use unique parameters for find!
|
|
420
|
-
*
|
|
421
|
-
* @example
|
|
422
|
-
* // by email:
|
|
423
|
-
* { email: email }
|
|
424
|
-
* //
|
|
425
|
-
* @example
|
|
426
|
-
* // or by id that is in list:
|
|
427
|
-
* { userIds: { $in: this.userId } }
|
|
428
|
-
* // or by userIds:
|
|
429
|
-
* { userId: { $in: userIds } }
|
|
430
|
-
* //
|
|
431
|
-
* @example
|
|
432
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
433
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
434
|
-
* // further tools (syntax matches with $gt):
|
|
435
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
436
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
437
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
438
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
439
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
440
|
-
* //
|
|
441
|
-
* @returns {T} data: T
|
|
442
|
-
*/
|
|
443
|
-
async findData(filterBy, dontSetToService) {
|
|
444
|
-
try {
|
|
445
|
-
const dataExists = await this.dataDBService.findOne(filterBy).catch((error) => {
|
|
446
|
-
if (error?.errorCode?.includes('DBS-FO1')) {
|
|
447
|
-
fsm_dynamo_1.DyFM_Log.warn(`findData "${this.dataParams.dataName}" didn't found any.`);
|
|
448
|
-
return null;
|
|
449
|
-
}
|
|
450
|
-
else {
|
|
451
|
-
throw error;
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
if (!dontSetToService) {
|
|
455
|
-
this.data = dataExists;
|
|
456
|
-
}
|
|
457
|
-
return dataExists;
|
|
458
|
-
}
|
|
459
|
-
catch (error) {
|
|
460
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
461
|
-
...this._getDefaultErrorSettings('findData', error),
|
|
462
|
-
errorCode: `${this.ecBase}DyNTS-DS0-FD0`,
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
getDataByQuery = this.findData;
|
|
467
|
-
/**
|
|
468
|
-
*
|
|
469
|
-
* // find desc:
|
|
470
|
-
*
|
|
471
|
-
* Find the data first by any of its parameters,
|
|
472
|
-
* also if dontSetToService is false or not setted,
|
|
473
|
-
* the data will be saved to the service, even if non found
|
|
474
|
-
*
|
|
475
|
-
* @param filter if you can, use unique parameters for find!
|
|
476
|
-
*
|
|
477
|
-
* @example
|
|
478
|
-
* // by email:
|
|
479
|
-
* { email: email }
|
|
480
|
-
* //
|
|
481
|
-
* @example
|
|
482
|
-
* // or by id that is in list:
|
|
483
|
-
* { userIds: { $in: this.userId } }
|
|
484
|
-
* // or by userIds:
|
|
485
|
-
* { userId: { $in: userIds } }
|
|
486
|
-
* //
|
|
487
|
-
* @example
|
|
488
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
489
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
490
|
-
* // further tools (syntax matches with $gt):
|
|
491
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
492
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
493
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
494
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
495
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
496
|
-
* //
|
|
497
|
-
* @returns {T[]} dataList: T[]
|
|
498
|
-
*/
|
|
499
|
-
async findDataList(filterBy, dontSetToService) {
|
|
500
|
-
try {
|
|
501
|
-
const dataListExists = await this.dataDBService.find(filterBy).catch((error) => {
|
|
502
|
-
if (error?.errorCode?.includes('DBS-F1')) {
|
|
503
|
-
fsm_dynamo_1.DyFM_Log.warn(`findDataList "${this.dataParams.dataName}" didn't found any.`);
|
|
504
|
-
return [];
|
|
505
|
-
}
|
|
506
|
-
else {
|
|
507
|
-
throw error;
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
if (!dontSetToService) {
|
|
511
|
-
this.dataList = dataListExists;
|
|
512
|
-
}
|
|
513
|
-
return dataListExists;
|
|
514
|
-
}
|
|
515
|
-
catch (error) {
|
|
516
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
517
|
-
...this._getDefaultErrorSettings('findDataList', error),
|
|
518
|
-
errorCode: `${this.ecBase}DyNTS-DS0-FDS0`,
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* This function uses the dataDBService.updateOne function.
|
|
524
|
-
* This uses updateBy if setted, or data._id if its setted or this.data[this.dependencyKey]
|
|
525
|
-
* @param set
|
|
526
|
-
*
|
|
527
|
-
* // updateOne desc:
|
|
528
|
-
*
|
|
529
|
-
* Find the data first by any of its parameters, throws error if not found
|
|
530
|
-
* @param filter This uses the basic Mongoose updateOne.
|
|
531
|
-
* If you can, use unique parameters for find!
|
|
532
|
-
* @example
|
|
533
|
-
* // by email:
|
|
534
|
-
* { email: email }
|
|
535
|
-
* //
|
|
536
|
-
* @example
|
|
537
|
-
* // or by id that is in list:
|
|
538
|
-
* { userIds: { $in: this.userId } }
|
|
539
|
-
* // or by userIds:
|
|
540
|
-
* { userId: { $in: userIds } }
|
|
541
|
-
* //
|
|
542
|
-
* @example
|
|
543
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
544
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
545
|
-
* // further tools (syntax matches with $gt):
|
|
546
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
547
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
548
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
549
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
550
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
551
|
-
* //
|
|
552
|
-
*
|
|
553
|
-
* @param update this uses the basic Mongoose updateOne
|
|
554
|
-
* @example
|
|
555
|
-
* // increase a specific value (here by 15):
|
|
556
|
-
* { $inc: { popularity: 15 } }
|
|
557
|
-
* //
|
|
558
|
-
* @example
|
|
559
|
-
* // or add element to a list:
|
|
560
|
-
* { $push: { reactions: this.newReaction }
|
|
561
|
-
* // or add multiple elements to a list
|
|
562
|
-
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
563
|
-
* //
|
|
564
|
-
* @example
|
|
565
|
-
* // or all at once
|
|
566
|
-
* {
|
|
567
|
-
* $inc: { popularity: this.newVote.amount },
|
|
568
|
-
* emailVerified: true,
|
|
569
|
-
* $push: { reactions: this.newReaction }
|
|
570
|
-
* }
|
|
571
|
-
* // further tools (syntax matches with $inc):
|
|
572
|
-
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
573
|
-
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
574
|
-
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
575
|
-
* $mul: // Multiplies the value of the field by the specified amount.
|
|
576
|
-
* $rename: // Renames a field.
|
|
577
|
-
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
578
|
-
* //
|
|
579
|
-
*/
|
|
580
|
-
async updateData(set, dontUpdateModified) {
|
|
581
|
-
try {
|
|
582
|
-
if (set.filterBy) {
|
|
583
|
-
await this.dataDBService.updateOne(set.filterBy, set.update, this.issuer, dontUpdateModified);
|
|
584
|
-
}
|
|
585
|
-
else if (this.data._id) {
|
|
586
|
-
await this.dataDBService.updateOne({ _id: this.data._id }, set.update, this.issuer, dontUpdateModified);
|
|
587
|
-
}
|
|
588
|
-
else if (this.depSettings.length &&
|
|
589
|
-
this.depSettings.some((depSetting) => this.data[depSetting.key])) {
|
|
590
|
-
const dependencyIdsFilter = {};
|
|
591
|
-
this.depSettings.forEach((depSetting) => {
|
|
592
|
-
if (this.data[depSetting.key]) {
|
|
593
|
-
dependencyIdsFilter[depSetting.key] = this.data[depSetting.key];
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
await this.dataDBService.updateOne(dependencyIdsFilter, set.update, this.issuer, dontUpdateModified);
|
|
597
|
-
}
|
|
598
|
-
else {
|
|
599
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
600
|
-
...this._getDefaultErrorSettings('updateData', new Error(`no usable parameter provided for updateData; no updateBy, no id, no dependencyId ` +
|
|
601
|
-
`(${this.dataParams.dataName})`)),
|
|
602
|
-
errorCode: `${this.ecBase}DyNTS-DS0-UD1`,
|
|
603
|
-
additionalContent: {
|
|
604
|
-
data: this.data,
|
|
605
|
-
filterBy: set.filterBy,
|
|
606
|
-
},
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
catch (error) {
|
|
611
|
-
if (error?.errorCode?.includes('DS0-UD1')) {
|
|
612
|
-
throw error;
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
616
|
-
...this._getDefaultErrorSettings('updateData', error),
|
|
617
|
-
errorCode: `${this.ecBase}DyNTS-DS0-UD0`,
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
ensureData(data) {
|
|
623
|
-
if (!data && this.data) {
|
|
624
|
-
data = this.data;
|
|
625
|
-
}
|
|
626
|
-
if (!data) {
|
|
627
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
628
|
-
...this._getDefaultErrorSettings('ensureData', new Error(`no data to save! (${this.dataParams.dataName})`)),
|
|
629
|
-
errorCode: `${this.ecBase}DyNTS-DS0-ED0`,
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
return data;
|
|
633
|
-
}
|
|
634
|
-
async patchData(data) {
|
|
635
|
-
try {
|
|
636
|
-
if (!data._id) {
|
|
637
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
638
|
-
...this._getDefaultErrorSettings('patchData', new Error(`no ID to patch data! (${this.dataParams.dataName})`)),
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
const dataExists = await this.getDataById(data._id, true);
|
|
642
|
-
if (!dataExists) {
|
|
643
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
644
|
-
...this._getDefaultErrorSettings('patchData', new Error(`data not found! (${this.dataParams.dataName})`)),
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
|
-
for (const key in this.depSettings) {
|
|
648
|
-
if (data[key] && data[key] !== dataExists[key]) {
|
|
649
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
650
|
-
...this._getDefaultErrorSettings('patchData', new Error(`Cannot patch data: dependency data mismatch! (${this.dataParams.dataName})`)),
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
fsm_dynamo_1.DyFM_Object.cleanAssign(dataExists, data);
|
|
655
|
-
await this.validateForSave(dataExists);
|
|
656
|
-
return await this.dataDBService.modifyData(dataExists, this.issuer);
|
|
657
|
-
}
|
|
658
|
-
catch (error) {
|
|
659
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
660
|
-
...this._getDefaultErrorSettings('patchData', error),
|
|
661
|
-
errorCode: `${this.ecBase}DyNTS-DS0-PD0`,
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* modifies data if the data have ID and already exists in the DB,
|
|
667
|
-
* creates new if the ID is not present or cant find in DB,
|
|
668
|
-
* and if dependency data setted up, will check before creation,
|
|
669
|
-
*
|
|
670
|
-
* @warning
|
|
671
|
-
* but the proper way to update data, if you use update method instead,
|
|
672
|
-
* this way, you can avoid data override errors
|
|
673
|
-
* (when you simultaneously trying to change the same data's
|
|
674
|
-
* different values from different flows)
|
|
675
|
-
*/
|
|
676
|
-
async saveData(data, dontSetToService, dontUpdateModified) {
|
|
677
|
-
try {
|
|
678
|
-
data = this.ensureData(data);
|
|
679
|
-
await this.validateForSave(data);
|
|
680
|
-
if (!data._id) {
|
|
681
|
-
if (this.depSettings.length &&
|
|
682
|
-
this.depSettings.some((depSetting) => !data[depSetting.key])) {
|
|
683
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
684
|
-
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: dependency data id missing from data ` +
|
|
685
|
-
`(key: ${this.depSettings.map((depSetting) => depSetting.key).join(', ')}, ` +
|
|
686
|
-
`${this.dataParams.dataName})`)),
|
|
687
|
-
errorCode: `${this.ecBase}DyNTS-DS0-SD1`,
|
|
688
|
-
additionalContent: {
|
|
689
|
-
data: data,
|
|
690
|
-
},
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
// if ID of dependencyID is not present, data not exists, create new data
|
|
694
|
-
data = await this.dataDBService.createData(data, this.issuer);
|
|
695
|
-
if (!dontSetToService) {
|
|
696
|
-
this.data = data;
|
|
697
|
-
}
|
|
698
|
-
return data;
|
|
699
|
-
}
|
|
700
|
-
let dataExists;
|
|
701
|
-
// check if data already exists with the specific ID
|
|
702
|
-
if (data._id) {
|
|
703
|
-
dataExists = await this.getDataById(data._id, true);
|
|
704
|
-
if (!dataExists) {
|
|
705
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
706
|
-
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: provided ID not exists ` +
|
|
707
|
-
`(id: "${data._id}", ${this.dataParams.dataName})`)),
|
|
708
|
-
errorCode: `${this.ecBase}DyNTS-DS0-SD2`,
|
|
709
|
-
additionalContent: {
|
|
710
|
-
data: data,
|
|
711
|
-
},
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
// if data exists do modify
|
|
715
|
-
data = await this.dataDBService.modifyData(data, this.issuer, dontUpdateModified);
|
|
716
|
-
if (!dontSetToService) {
|
|
717
|
-
this.data = data;
|
|
718
|
-
}
|
|
719
|
-
return data;
|
|
720
|
-
}
|
|
721
|
-
if (this.depSettings.length) {
|
|
722
|
-
if (this.depSettings.some((depSetting) => !data[depSetting.key])) {
|
|
723
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
724
|
-
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: dependency data id missing from data ` +
|
|
725
|
-
`(key: ${this.depSettings.map((depSetting) => depSetting.key).join(', ')}, ` +
|
|
726
|
-
`${this.dataParams.dataName})`)),
|
|
727
|
-
errorCode: `${this.ecBase}DyNTS-DS0-SD3`,
|
|
728
|
-
additionalContent: {
|
|
729
|
-
data: data,
|
|
730
|
-
},
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
if (this.depSettings.some((depSetting) => depSetting.keyIsRequired)) {
|
|
734
|
-
await fsm_dynamo_1.DyFM_Array.asyncForEach(this.depSettings, async (depSetting) => {
|
|
735
|
-
if (depSetting.keyIsRequired) {
|
|
736
|
-
if (!data[depSetting.key]) {
|
|
737
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
738
|
-
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: dependency data id missing from data ` +
|
|
739
|
-
`(key: ${depSetting.key}, ${this.dataParams.dataName})`)),
|
|
740
|
-
errorCode: `${this.ecBase}DyNTS-DS0-SD4`,
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
const dependencyExists = await this.getDependencyDataDBService(depSetting.dbServiceKey)
|
|
744
|
-
.getDataById(data[depSetting.key])
|
|
745
|
-
.catch();
|
|
746
|
-
if (!dependencyExists) {
|
|
747
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
748
|
-
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: dependency data not exists ` +
|
|
749
|
-
`(key: ${depSetting.key}, id: "${data[depSetting.key]}", ` +
|
|
750
|
-
`${this.dataParams.dataName})`)),
|
|
751
|
-
errorCode: `${this.ecBase}DyNTS-DS0-SD4`,
|
|
752
|
-
});
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
/* the db is handling the unique key, so no need to check it here
|
|
758
|
-
if (this.depKeyIsUnique) {
|
|
759
|
-
dataExists = await this.getDataByDependencyId(data[this.depKeys], true);
|
|
760
|
-
|
|
761
|
-
if (dataExists) {
|
|
762
|
-
// if data exists do modify
|
|
763
|
-
data = await this.dataDBService.modifyData(data, this.issuer, dontUpdateModified);
|
|
764
|
-
|
|
765
|
-
if (!dontSetToService) {
|
|
766
|
-
this.data = data;
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
return data;
|
|
770
|
-
|
|
771
|
-
}
|
|
772
|
-
} */
|
|
773
|
-
}
|
|
774
|
-
// if data not exists create new data
|
|
775
|
-
data = await this.dataDBService.createData(data, this.issuer);
|
|
776
|
-
if (!data._id) {
|
|
777
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
778
|
-
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: data creation failed ` +
|
|
779
|
-
`(${this.dataParams.dataName})`)),
|
|
780
|
-
errorCode: `${this.ecBase}DyNTS-DS0-SD5`,
|
|
781
|
-
additionalContent: {
|
|
782
|
-
data: data,
|
|
783
|
-
},
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
if (!dontSetToService) {
|
|
787
|
-
this.data = data;
|
|
788
|
-
}
|
|
789
|
-
return data;
|
|
790
|
-
}
|
|
791
|
-
catch (error) {
|
|
792
|
-
if ([
|
|
793
|
-
`${this.ecBase}DyNTS-DS0-SD1`,
|
|
794
|
-
`${this.ecBase}DyNTS-DS0-SD2`,
|
|
795
|
-
`${this.ecBase}DyNTS-DS0-SD3`,
|
|
796
|
-
`${this.ecBase}DyNTS-DS0-SD4`,
|
|
797
|
-
`${this.ecBase}DyNTS-DS0-SD5`,
|
|
798
|
-
].includes(error?.errorCode)) {
|
|
799
|
-
throw error;
|
|
800
|
-
}
|
|
801
|
-
else {
|
|
802
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
803
|
-
...this._getDefaultErrorSettings('saveData', error),
|
|
804
|
-
errorCode: `${this.ecBase}DyNTS-DS0-SD0`,
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
/**
|
|
810
|
-
* markes data as deleted, if can be archived, will be archived as well
|
|
811
|
-
* if absolute is true, permanently deletes data from database by data._id
|
|
812
|
-
*/
|
|
813
|
-
async deleteData(id, absolute) {
|
|
814
|
-
try {
|
|
815
|
-
if (!id && this.data._id) {
|
|
816
|
-
id = this.data._id;
|
|
817
|
-
}
|
|
818
|
-
if (!id) {
|
|
819
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
820
|
-
...this._getDefaultErrorSettings('deleteData', new Error(`deleteData failed, ID is missing! (${this.dataParams.dataName})`)),
|
|
821
|
-
errorCode: `${this.ecBase}DyNTS-DS0-DD1`,
|
|
822
|
-
});
|
|
823
|
-
}
|
|
824
|
-
this.data = await this.getDataById(id, true);
|
|
825
|
-
if (!this.data) {
|
|
826
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
827
|
-
...this._getDefaultErrorSettings('deleteData', new Error(`deleteData failed, data not found! (${this.dataParams.dataName})`)),
|
|
828
|
-
errorCode: `${this.ecBase}DyNTS-DS0-DD2`,
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
if (this.haveArchiveDataService) {
|
|
832
|
-
const archive_DS = this.getArchiveDataService();
|
|
833
|
-
await this.dataDBService.trueDeleteDataById(id);
|
|
834
|
-
this.data._deleted = new Date();
|
|
835
|
-
this.data._deletedBy = this.issuer;
|
|
836
|
-
this.data._originalId = this.data._id;
|
|
837
|
-
this.data._archived = new Date();
|
|
838
|
-
delete this.data._id;
|
|
839
|
-
await archive_DS.saveData(this.data, true);
|
|
840
|
-
}
|
|
841
|
-
else if (absolute) {
|
|
842
|
-
await this.dataDBService.trueDeleteDataById(id);
|
|
843
|
-
delete this.data._id;
|
|
844
|
-
}
|
|
845
|
-
else {
|
|
846
|
-
await this.dataDBService.markDeletedById(id, this.issuer);
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
catch (error) {
|
|
850
|
-
if (error?.errorCode?.includes('DS0-DD1')) {
|
|
851
|
-
throw error;
|
|
852
|
-
}
|
|
853
|
-
else {
|
|
854
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
855
|
-
...this._getDefaultErrorSettings('deleteData', error),
|
|
856
|
-
errorCode: `${this.ecBase}DyNTS-DS0-DD0`,
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
async deleteAllData(absolute) {
|
|
862
|
-
try {
|
|
863
|
-
this.dataList = await this.getAll(true);
|
|
864
|
-
if (this.haveArchiveDataService) {
|
|
865
|
-
const archive_DS = this.getArchiveDataService();
|
|
866
|
-
await this.dataDBService.trueDeleteAllData();
|
|
867
|
-
await fsm_dynamo_1.DyFM_Array.asyncForEachAllAtOnce(this.dataList, async (data) => {
|
|
868
|
-
data._deleted = new Date();
|
|
869
|
-
data._deletedBy = this.issuer;
|
|
870
|
-
data._originalId = data._id;
|
|
871
|
-
data._archived = new Date();
|
|
872
|
-
delete data._id;
|
|
873
|
-
await archive_DS.saveData(data, true);
|
|
874
|
-
});
|
|
875
|
-
}
|
|
876
|
-
else if (absolute) {
|
|
877
|
-
await this.dataDBService.trueDeleteAllData();
|
|
878
|
-
this.dataList.forEach((data) => {
|
|
879
|
-
delete data._id;
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
else {
|
|
883
|
-
await fsm_dynamo_1.DyFM_Array.asyncForEachAllAtOnce(this.dataList, async (data) => {
|
|
884
|
-
await this.dataDBService.markDeletedById(data._id, this.issuer);
|
|
885
|
-
});
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
catch (error) {
|
|
889
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
890
|
-
...this._getDefaultErrorSettings('deleteAllData', error),
|
|
891
|
-
errorCode: `${this.ecBase}DyNTS-DS0-DAD0`,
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
restoreDeletedData(id) {
|
|
896
|
-
try {
|
|
897
|
-
if (!id && this.data._id) {
|
|
898
|
-
id = this.data._id;
|
|
899
|
-
}
|
|
900
|
-
if (!id) {
|
|
901
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
902
|
-
...this._getDefaultErrorSettings('restoreDeletedData', new Error(`restoreDeletedData failed, ID is missing! (${this.dataParams.dataName})`)),
|
|
903
|
-
errorCode: `${this.ecBase}DyNTS-DS0-RD1`,
|
|
904
|
-
});
|
|
905
|
-
}
|
|
906
|
-
let archive_DS;
|
|
907
|
-
try {
|
|
908
|
-
archive_DS = global_service_1.DyNTS_GlobalService.getDBServiceByKey((0, archive_util_1.DyNTS_getArchivedDBName)(this.dataParams.dataName));
|
|
909
|
-
}
|
|
910
|
-
catch (error) { }
|
|
911
|
-
if (archive_DS) {
|
|
912
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
913
|
-
...this._getDefaultErrorSettings('restoreDeletedData', new Error(`restoreDeletedData failed, archive service is setted up, ` +
|
|
914
|
-
`archived restoration not implemented yet! ` +
|
|
915
|
-
`(request implementation, and restore by yourself)`)),
|
|
916
|
-
errorCode: `${this.ecBase}DyNTS-DS0-RD2`,
|
|
917
|
-
});
|
|
918
|
-
}
|
|
919
|
-
return this.dataDBService.restoreDeletedById(id, this.issuer);
|
|
920
|
-
}
|
|
921
|
-
catch (error) {
|
|
922
|
-
if (error?.errorCode?.includes('DS0-RD1')) {
|
|
923
|
-
throw error;
|
|
924
|
-
}
|
|
925
|
-
else {
|
|
926
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
927
|
-
...this._getDefaultErrorSettings('restoreDeletedData', error),
|
|
928
|
-
errorCode: `${this.ecBase}DyNTS-DS0-RD0`,
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
/**
|
|
934
|
-
* validation of data, for modify and create, by the ModelParams
|
|
935
|
-
*/
|
|
936
|
-
async validateForSave(data) {
|
|
937
|
-
try {
|
|
938
|
-
data = this.ensureData(data);
|
|
939
|
-
if (!data) {
|
|
940
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
941
|
-
...this._getDefaultErrorSettings('validateForSave', new Error('No data to validate! (validateForSave)')),
|
|
942
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VBP0`,
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
await this.validateDataByPropertyParams(data, this.dataParams.properties);
|
|
946
|
-
}
|
|
947
|
-
catch (error) {
|
|
948
|
-
if (error?.errorCode?.includes?.('DyNTS-DS0-VBP') || error?.errorCode?.includes?.('DyNTS-DS0-VP')) {
|
|
949
|
-
throw error;
|
|
950
|
-
}
|
|
951
|
-
else {
|
|
952
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
953
|
-
...this._getDefaultErrorSettings('validateForSave', error),
|
|
954
|
-
status: 522,
|
|
955
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VD0`,
|
|
956
|
-
});
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
validateDataByPropertyParams(data, properties, isSubObjectOf) {
|
|
961
|
-
try {
|
|
962
|
-
if (!data) {
|
|
963
|
-
if (isSubObjectOf?.required) {
|
|
964
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
965
|
-
...this._getDefaultErrorSettings('validateDataByPropertyParams', new Error(`validateData failed, data is required! ` +
|
|
966
|
-
`(${isSubObjectOf?.key ? `${isSubObjectOf.key}.` : ''}${this.dataParams.dataName})` +
|
|
967
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
968
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VDP1`,
|
|
969
|
-
});
|
|
970
|
-
}
|
|
971
|
-
else {
|
|
972
|
-
return;
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
else if (isSubObjectOf?.forbidden) {
|
|
976
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
977
|
-
...this._getDefaultErrorSettings('validateDataByPropertyParams', new Error(`validateData failed, data is forbidden! ` +
|
|
978
|
-
`(${isSubObjectOf?.key ? `${isSubObjectOf.key}.` : ''}${this.dataParams.dataName})` +
|
|
979
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
980
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VDP2`,
|
|
981
|
-
additionalContent: {
|
|
982
|
-
data: data,
|
|
983
|
-
},
|
|
984
|
-
});
|
|
985
|
-
}
|
|
986
|
-
const validationErrors = [];
|
|
987
|
-
Object.values(properties).forEach((propertyParams) => {
|
|
988
|
-
try {
|
|
989
|
-
this.validateProperty(data, data[propertyParams.key], propertyParams, isSubObjectOf);
|
|
990
|
-
}
|
|
991
|
-
catch (error) {
|
|
992
|
-
validationErrors.push(error);
|
|
993
|
-
}
|
|
994
|
-
});
|
|
995
|
-
if (validationErrors.length > 0) {
|
|
996
|
-
if (validationErrors.length === 1) {
|
|
997
|
-
throw validationErrors[0];
|
|
998
|
-
}
|
|
999
|
-
else {
|
|
1000
|
-
const validationErrorsSet = {};
|
|
1001
|
-
validationErrors.forEach((error) => {
|
|
1002
|
-
Object.keys(error.validationErrors).forEach((key) => {
|
|
1003
|
-
validationErrors[key] = error.validationErrors[key];
|
|
1004
|
-
});
|
|
1005
|
-
});
|
|
1006
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1007
|
-
...this._getDefaultErrorSettings('validateByPropertyParams', new Error(`Validation failed! (multiple validation errors for ${this.dataParams.dataName})` +
|
|
1008
|
-
validationErrors.map((error) => `\n ${fsm_dynamo_1.DyFM_Error.getAnyMessage(error)}`).join(''))),
|
|
1009
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VDP3`,
|
|
1010
|
-
errors: validationErrors,
|
|
1011
|
-
validationErrors: validationErrorsSet,
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
catch (error) {
|
|
1017
|
-
if (error?.errorCode?.includes?.('DyNTS-DS0-VDP')) {
|
|
1018
|
-
throw error;
|
|
1019
|
-
}
|
|
1020
|
-
else {
|
|
1021
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1022
|
-
...this._getDefaultErrorSettings('validateByPropertyParams', error),
|
|
1023
|
-
status: 522,
|
|
1024
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VDP0`,
|
|
1025
|
-
});
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
getPropertyKey(propertyParams, isSubObjectOf) {
|
|
1030
|
-
return (isSubObjectOf && isSubObjectOf.key !== propertyParams.key) ?
|
|
1031
|
-
`${isSubObjectOf.key}.${propertyParams.key}` : propertyParams.key;
|
|
1032
|
-
}
|
|
1033
|
-
validateProperty(data, propertyValue, propertyParams, isSubObjectOf) {
|
|
1034
|
-
// basic required validations
|
|
1035
|
-
if (propertyParams.required && (propertyValue === null ||
|
|
1036
|
-
propertyValue === undefined)) {
|
|
1037
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1038
|
-
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is missing! ` +
|
|
1039
|
-
`(required in "${this.dataParams.dataName}" dataParams) ` +
|
|
1040
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1041
|
-
status: 522,
|
|
1042
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VP1`,
|
|
1043
|
-
userMessage: this.defaultValidationErrorUserMsg,
|
|
1044
|
-
validationErrors: {
|
|
1045
|
-
[propertyParams.key]: {
|
|
1046
|
-
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is missing! ` +
|
|
1047
|
-
`(required in "${this.dataParams.dataName}" dataParams) ` +
|
|
1048
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1049
|
-
code: `${this.ecBase}DyNTS-DS0-VP1`,
|
|
1050
|
-
userMessage: 'The property is required and must be a valid value!',
|
|
1051
|
-
},
|
|
1052
|
-
},
|
|
1053
|
-
__localStack: this.dataParams.stackLocation,
|
|
1054
|
-
additionalContent: {
|
|
1055
|
-
data: data,
|
|
1056
|
-
},
|
|
1057
|
-
});
|
|
1058
|
-
}
|
|
1059
|
-
else if (propertyParams.forbidden &&
|
|
1060
|
-
propertyValue !== undefined) {
|
|
1061
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1062
|
-
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is forbidden! ` +
|
|
1063
|
-
`(${this.dataParams.dataName}) ` +
|
|
1064
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1065
|
-
status: 522,
|
|
1066
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VP2`,
|
|
1067
|
-
userMessage: this.defaultValidationErrorUserMsg,
|
|
1068
|
-
validationErrors: {
|
|
1069
|
-
[propertyParams.key]: {
|
|
1070
|
-
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is forbidden! ` +
|
|
1071
|
-
`(${this.dataParams.dataName}) ` +
|
|
1072
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1073
|
-
code: `${this.ecBase}DyNTS-DS0-VP2`,
|
|
1074
|
-
userMessage: 'The property modification is forbidden!',
|
|
1075
|
-
},
|
|
1076
|
-
},
|
|
1077
|
-
__localStack: this.dataParams.stackLocation,
|
|
1078
|
-
additionalContent: {
|
|
1079
|
-
data: data,
|
|
1080
|
-
},
|
|
1081
|
-
});
|
|
1082
|
-
}
|
|
1083
|
-
// specific Date validation
|
|
1084
|
-
switch (propertyParams.type) {
|
|
1085
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.date:
|
|
1086
|
-
const date = new Date(propertyValue);
|
|
1087
|
-
if (propertyParams.required && (!(date instanceof Date) ||
|
|
1088
|
-
date.toString() === 'Invalid Date' ||
|
|
1089
|
-
isNaN(date.getTime()) ||
|
|
1090
|
-
date.toString() === new Date(0).toString())) {
|
|
1091
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1092
|
-
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid date! ` +
|
|
1093
|
-
`(${this.dataParams.dataName})` +
|
|
1094
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1095
|
-
status: 522,
|
|
1096
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VP3`,
|
|
1097
|
-
userMessage: this.defaultValidationErrorUserMsg,
|
|
1098
|
-
validationErrors: {
|
|
1099
|
-
[propertyParams.key]: {
|
|
1100
|
-
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid date! ` +
|
|
1101
|
-
`(${this.dataParams.dataName})` +
|
|
1102
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1103
|
-
code: `${this.ecBase}DyNTS-DS0-VP3`,
|
|
1104
|
-
userMessage: 'The property is required and must be a valid date!',
|
|
1105
|
-
},
|
|
1106
|
-
},
|
|
1107
|
-
__localStack: this.dataParams.stackLocation,
|
|
1108
|
-
additionalContent: {
|
|
1109
|
-
data: data,
|
|
1110
|
-
},
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
break;
|
|
1114
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.number:
|
|
1115
|
-
if (propertyParams.required && isNaN(propertyValue)) {
|
|
1116
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1117
|
-
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid number! ` +
|
|
1118
|
-
`(${this.dataParams.dataName})` +
|
|
1119
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1120
|
-
status: 522,
|
|
1121
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VP4`,
|
|
1122
|
-
userMessage: this.defaultValidationErrorUserMsg,
|
|
1123
|
-
validationErrors: {
|
|
1124
|
-
[propertyParams.key]: {
|
|
1125
|
-
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid number! ` +
|
|
1126
|
-
`(${this.dataParams.dataName})` +
|
|
1127
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1128
|
-
code: `${this.ecBase}DyNTS-DS0-VP4`,
|
|
1129
|
-
userMessage: 'The property is required and must be a valid number!',
|
|
1130
|
-
},
|
|
1131
|
-
},
|
|
1132
|
-
__localStack: this.dataParams.stackLocation,
|
|
1133
|
-
additionalContent: {
|
|
1134
|
-
data: data,
|
|
1135
|
-
},
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
break;
|
|
1139
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.string:
|
|
1140
|
-
if (propertyParams.required && typeof propertyValue !== 'string') {
|
|
1141
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1142
|
-
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid string! ` +
|
|
1143
|
-
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1144
|
-
`(${this.dataParams.dataName})` +
|
|
1145
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1146
|
-
status: 522,
|
|
1147
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VP5`,
|
|
1148
|
-
userMessage: this.defaultValidationErrorUserMsg,
|
|
1149
|
-
validationErrors: {
|
|
1150
|
-
[propertyParams.key]: {
|
|
1151
|
-
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid string! ` +
|
|
1152
|
-
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1153
|
-
`(${this.dataParams.dataName})` +
|
|
1154
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1155
|
-
code: `${this.ecBase}DyNTS-DS0-VP5`,
|
|
1156
|
-
userMessage: 'The property is required and must be a valid string!',
|
|
1157
|
-
},
|
|
1158
|
-
},
|
|
1159
|
-
__localStack: this.dataParams.stackLocation,
|
|
1160
|
-
additionalContent: {
|
|
1161
|
-
data: data,
|
|
1162
|
-
},
|
|
1163
|
-
});
|
|
1164
|
-
}
|
|
1165
|
-
break;
|
|
1166
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.boolean:
|
|
1167
|
-
if (propertyParams.required && typeof propertyValue !== 'boolean') {
|
|
1168
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1169
|
-
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid boolean! ` +
|
|
1170
|
-
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1171
|
-
`(${this.dataParams.dataName})` +
|
|
1172
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1173
|
-
status: 522,
|
|
1174
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VP6`,
|
|
1175
|
-
userMessage: this.defaultValidationErrorUserMsg,
|
|
1176
|
-
validationErrors: {
|
|
1177
|
-
[propertyParams.key]: {
|
|
1178
|
-
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid boolean! ` +
|
|
1179
|
-
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1180
|
-
`(${this.dataParams.dataName})` +
|
|
1181
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1182
|
-
code: `${this.ecBase}DyNTS-DS0-VP6`,
|
|
1183
|
-
userMessage: 'The property is required and must be a valid boolean!',
|
|
1184
|
-
},
|
|
1185
|
-
},
|
|
1186
|
-
__localStack: this.dataParams.stackLocation,
|
|
1187
|
-
});
|
|
1188
|
-
}
|
|
1189
|
-
break;
|
|
1190
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.object:
|
|
1191
|
-
if (propertyParams.required && typeof propertyValue !== 'object') {
|
|
1192
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1193
|
-
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid object! ` +
|
|
1194
|
-
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1195
|
-
`(${this.dataParams.dataName})` +
|
|
1196
|
-
data?.name ? `\n That failed data's name: ${data.name}` : '')),
|
|
1197
|
-
status: 522,
|
|
1198
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VP7`,
|
|
1199
|
-
userMessage: this.defaultValidationErrorUserMsg,
|
|
1200
|
-
validationErrors: {
|
|
1201
|
-
[propertyParams.key]: {
|
|
1202
|
-
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid object! ` +
|
|
1203
|
-
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1204
|
-
`(${this.dataParams.dataName})` +
|
|
1205
|
-
data?.name ? `\n That failed data's name: ${data.name}` : '',
|
|
1206
|
-
code: `${this.ecBase}DyNTS-DS0-VP7`,
|
|
1207
|
-
userMessage: 'The property is required and must be an object!',
|
|
1208
|
-
},
|
|
1209
|
-
},
|
|
1210
|
-
__localStack: this.dataParams.stackLocation,
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1213
|
-
if (propertyParams.subObjectParams) {
|
|
1214
|
-
this.validateDataByPropertyParams(propertyValue, propertyParams.subObjectParams, propertyParams);
|
|
1215
|
-
}
|
|
1216
|
-
break;
|
|
1217
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.array:
|
|
1218
|
-
if (propertyParams.required && (!Array.isArray(propertyValue) || !propertyValue.length)) {
|
|
1219
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1220
|
-
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid array! ` +
|
|
1221
|
-
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1222
|
-
`(${this.dataParams.dataName})` +
|
|
1223
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1224
|
-
status: 522,
|
|
1225
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VP8`,
|
|
1226
|
-
userMessage: this.defaultValidationErrorUserMsg,
|
|
1227
|
-
validationErrors: {
|
|
1228
|
-
[propertyParams.key]: {
|
|
1229
|
-
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid array! ` +
|
|
1230
|
-
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1231
|
-
`(${this.dataParams.dataName})` +
|
|
1232
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1233
|
-
code: `${this.ecBase}DyNTS-DS0-VP8`,
|
|
1234
|
-
userMessage: 'The property is required and must be a valid array!',
|
|
1235
|
-
},
|
|
1236
|
-
},
|
|
1237
|
-
__localStack: this.dataParams.stackLocation,
|
|
1238
|
-
});
|
|
1239
|
-
}
|
|
1240
|
-
if (propertyParams.subObjectParams) {
|
|
1241
|
-
propertyValue.forEach((item) => {
|
|
1242
|
-
this.validateDataByPropertyParams(item, propertyParams.subObjectParams, propertyParams);
|
|
1243
|
-
});
|
|
1244
|
-
}
|
|
1245
|
-
break;
|
|
1246
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.function:
|
|
1247
|
-
fsm_dynamo_1.DyFM_Log.warn('validateProperty: function type is not supported yet! ' +
|
|
1248
|
-
'(it will be skipped, but you still can use it in additionalValidators)');
|
|
1249
|
-
/* if (propertyParams.required && typeof propertyValue !== 'function') {
|
|
1250
|
-
throw new DyFM_Error({
|
|
1251
|
-
...this._getDefaultErrorSettings(
|
|
1252
|
-
'validateProperty',
|
|
1253
|
-
new Error(
|
|
1254
|
-
`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid function! ` +
|
|
1255
|
-
`(${this.dataParams.dataName})` +
|
|
1256
|
-
((data as any)?.name ? `\n The failed data's name: ${(data as any).name}` : '')
|
|
1257
|
-
)
|
|
1258
|
-
),
|
|
1259
|
-
|
|
1260
|
-
status: 522,
|
|
1261
|
-
errorCode: `${this.ecBase}VP9`,
|
|
1262
|
-
userMessage: this.defaultValidationErrorUserMsg,
|
|
1263
|
-
validationErrors: {
|
|
1264
|
-
[propertyParams.key]: {
|
|
1265
|
-
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid function! ` +
|
|
1266
|
-
`(${this.dataParams.dataName})` +
|
|
1267
|
-
((data as any)?.name ? `\n The failed data's name: ${(data as any).name}` : ''),
|
|
1268
|
-
code: `${this.ecBase}DyNTS-DS0-VP9`,
|
|
1269
|
-
userMessage: 'The property is required and must be a valid function!',
|
|
1270
|
-
},
|
|
1271
|
-
},
|
|
1272
|
-
__localStack: this.dataParams.stackLocation,
|
|
1273
|
-
});
|
|
1274
|
-
} */
|
|
1275
|
-
break;
|
|
1276
|
-
default:
|
|
1277
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1278
|
-
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid property type! ` +
|
|
1279
|
-
`(type: ${propertyParams.type}, nonBasicType: ${propertyParams.nonBasicType}) ` +
|
|
1280
|
-
`(value type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1281
|
-
`(${this.dataParams.dataName})` +
|
|
1282
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1283
|
-
status: 522,
|
|
1284
|
-
errorCode: `${this.ecBase}DyNTS-DS0-VP10`,
|
|
1285
|
-
userMessage: this.defaultValidationErrorUserMsg,
|
|
1286
|
-
validationErrors: {
|
|
1287
|
-
[propertyParams.key]: {
|
|
1288
|
-
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid property type! ` +
|
|
1289
|
-
`(type: ${propertyParams.type}, nonBasicType: ${propertyParams.nonBasicType}) ` +
|
|
1290
|
-
`(value type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1291
|
-
`(${this.dataParams.dataName})` +
|
|
1292
|
-
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1293
|
-
code: `${this.ecBase}DyNTS-DS0-VP10`,
|
|
1294
|
-
userMessage: 'The property is required and must be a valid property type!',
|
|
1295
|
-
},
|
|
1296
|
-
},
|
|
1297
|
-
__localStack: this.dataParams.stackLocation,
|
|
1298
|
-
});
|
|
1299
|
-
}
|
|
1300
|
-
// call additional validators
|
|
1301
|
-
if (propertyParams.additionalValidators) {
|
|
1302
|
-
for (let j = 0; j < propertyParams.additionalValidators.length; j++) {
|
|
1303
|
-
propertyParams.additionalValidators[j](propertyValue, data);
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
/**
|
|
1308
|
-
* Search the data list based on the search query
|
|
1309
|
-
* Sorts and filters the data list based on the search query
|
|
1310
|
-
*
|
|
1311
|
-
* NOTE: For more simple and with better performance and if you don't need sorting, use findDataList instead.
|
|
1312
|
-
*
|
|
1313
|
-
* @example
|
|
1314
|
-
* ```ts
|
|
1315
|
-
* const searchResult = await this.searchData({
|
|
1316
|
-
* filterBy: {
|
|
1317
|
-
* name: 'John Doe',
|
|
1318
|
-
* },
|
|
1319
|
-
* sortBy: [
|
|
1320
|
-
* { key: 'name', order: 1 },
|
|
1321
|
-
* ],
|
|
1322
|
-
* });
|
|
1323
|
-
* ```
|
|
1324
|
-
*/
|
|
1325
|
-
async searchData(query, dataList) {
|
|
1326
|
-
try {
|
|
1327
|
-
const searchResult = await this.sortAndFilterDataList(query, dataList);
|
|
1328
|
-
if (query.page !== undefined && query.pageSize !== undefined) {
|
|
1329
|
-
const start = query.page * query.pageSize;
|
|
1330
|
-
const end = start + query.pageSize;
|
|
1331
|
-
searchResult.results = searchResult.results.slice(start, end);
|
|
1332
|
-
}
|
|
1333
|
-
return searchResult;
|
|
1334
|
-
}
|
|
1335
|
-
catch (error) {
|
|
1336
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1337
|
-
...this._getDefaultErrorSettings('searchData', error),
|
|
1338
|
-
errorCode: `${this.ecBase}DyNTS-DS0-SD0`,
|
|
1339
|
-
});
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
async sortAndFilterDataList(query, dataList) {
|
|
1343
|
-
try {
|
|
1344
|
-
if (!query.filterBy) {
|
|
1345
|
-
query.filterBy = {};
|
|
1346
|
-
}
|
|
1347
|
-
if (!query.page) {
|
|
1348
|
-
query.page = 0;
|
|
1349
|
-
}
|
|
1350
|
-
if (!query.pageSize) {
|
|
1351
|
-
fsm_dynamo_1.DyFM_Log.warn(`searchData pageSize is not setted, setting to ${global_settings_const_1.DyNTS_global_settings.defaultPageSize}.`);
|
|
1352
|
-
query.pageSize = global_settings_const_1.DyNTS_global_settings.defaultPageSize;
|
|
1353
|
-
}
|
|
1354
|
-
if (!query.sortBy?.length) {
|
|
1355
|
-
query.sortBy = [{ key: '__lastModified', order: -1 }];
|
|
1356
|
-
}
|
|
1357
|
-
query.sortBy.reverse();
|
|
1358
|
-
let preFilter = {};
|
|
1359
|
-
Object.keys(query.filterBy).forEach((key) => {
|
|
1360
|
-
if (typeof query.filterBy[key] === 'object' &&
|
|
1361
|
-
Object.keys(query.filterBy[key]).includes('$')) {
|
|
1362
|
-
preFilter[key] = query.filterBy[key];
|
|
1363
|
-
delete query.filterBy[key];
|
|
1364
|
-
}
|
|
1365
|
-
});
|
|
1366
|
-
if (!dataList) {
|
|
1367
|
-
if (Object.keys(preFilter).length) {
|
|
1368
|
-
dataList = await this.findDataList(preFilter);
|
|
1369
|
-
}
|
|
1370
|
-
else {
|
|
1371
|
-
dataList = await this.getAll();
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1374
|
-
else {
|
|
1375
|
-
if (Object.keys(preFilter).length) {
|
|
1376
|
-
fsm_dynamo_1.DyFM_Log.H_warn('prefilters not supported when dataList is set! (will be ignored the following keys: ' +
|
|
1377
|
-
Object.keys(preFilter).map((key) => `"${key}"`).join(', ') +
|
|
1378
|
-
')');
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
const filterKeys = Object.keys(query.filterBy);
|
|
1382
|
-
const filterFunctionsByKey = {};
|
|
1383
|
-
const addFilterKeys = [];
|
|
1384
|
-
const removeFilterKeys = [];
|
|
1385
|
-
filterKeys.forEach((key) => {
|
|
1386
|
-
const filterBy = query.filterBy[key];
|
|
1387
|
-
if (filterBy.isSpecialNestSearch) {
|
|
1388
|
-
filterBy.nestedPropertySearches.forEach((nestSearch) => {
|
|
1389
|
-
const nestKey = nestSearch.nestKeys.join('.');
|
|
1390
|
-
filterFunctionsByKey[nestKey] = this.getFilterFunctionForKey(nestKey, nestSearch.search, nestSearch.valueType);
|
|
1391
|
-
query.filterBy[nestKey] = nestSearch;
|
|
1392
|
-
addFilterKeys.push(nestKey);
|
|
1393
|
-
});
|
|
1394
|
-
removeFilterKeys.push(key);
|
|
1395
|
-
}
|
|
1396
|
-
else {
|
|
1397
|
-
filterFunctionsByKey[key] = this.getFilterFunctionForKey(key, filterBy);
|
|
1398
|
-
}
|
|
1399
|
-
});
|
|
1400
|
-
addFilterKeys.forEach((key) => {
|
|
1401
|
-
filterKeys.push(key);
|
|
1402
|
-
});
|
|
1403
|
-
removeFilterKeys.forEach((key) => {
|
|
1404
|
-
filterKeys.splice(filterKeys.indexOf(key), 1);
|
|
1405
|
-
});
|
|
1406
|
-
query.sortBy.forEach((sort) => {
|
|
1407
|
-
dataList.sort(this.getSortFunctionForKey(sort));
|
|
1408
|
-
});
|
|
1409
|
-
if (filterKeys.some((key) => key.includes('.'))) {
|
|
1410
|
-
const keyResolvers = {};
|
|
1411
|
-
filterKeys.forEach((key) => {
|
|
1412
|
-
if (key.includes('.')) {
|
|
1413
|
-
if (!query.filterBy[key].nestKeys) {
|
|
1414
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1415
|
-
...this._getDefaultErrorSettings('searchData', new Error(`searchData failed, nestKeys missing from nestedPropertySearch! ` +
|
|
1416
|
-
`(${this.dataParams.dataName})`)),
|
|
1417
|
-
errorCode: `${this.ecBase}DyNTS-DS0-SD1`,
|
|
1418
|
-
});
|
|
1419
|
-
}
|
|
1420
|
-
keyResolvers[key] = this.getKeyResolver(query.filterBy[key].nestKeys);
|
|
1421
|
-
}
|
|
1422
|
-
else {
|
|
1423
|
-
keyResolvers[key] = (data) => data[key];
|
|
1424
|
-
}
|
|
1425
|
-
});
|
|
1426
|
-
if (filterKeys.some((key) => query.filterBy[key].isSpecialNestSearch)) {
|
|
1427
|
-
dataList = dataList.filter((data) => filterKeys.every((key) => query.filterBy[key].isSpecialNestSearch ?
|
|
1428
|
-
keyResolvers[key](data).some((dataProperty) => filterFunctionsByKey[key](dataProperty)) :
|
|
1429
|
-
filterFunctionsByKey[key](keyResolvers[key](data))));
|
|
1430
|
-
}
|
|
1431
|
-
else {
|
|
1432
|
-
dataList = dataList.filter((data) => filterKeys.every((key) => filterFunctionsByKey[key](keyResolvers[key](data))));
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
else {
|
|
1436
|
-
dataList = dataList.filter((data) => filterKeys.every((key) => filterFunctionsByKey[key](data[key])));
|
|
1437
|
-
}
|
|
1438
|
-
return {
|
|
1439
|
-
results: dataList,
|
|
1440
|
-
totalItems: dataList.length,
|
|
1441
|
-
};
|
|
1442
|
-
}
|
|
1443
|
-
catch (error) {
|
|
1444
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1445
|
-
...this._getDefaultErrorSettings('searchData', error),
|
|
1446
|
-
errorCode: `${this.ecBase}DyNTS-DS0-SD0`,
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
getFilterFunctionForKey(key, searchValue, propertyType) {
|
|
1451
|
-
try {
|
|
1452
|
-
if (searchValue === undefined) {
|
|
1453
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1454
|
-
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, searchValue is missing for key: "${key}" ` +
|
|
1455
|
-
`(${this.dataParams.dataName})`)),
|
|
1456
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GFF1`,
|
|
1457
|
-
});
|
|
1458
|
-
}
|
|
1459
|
-
if (key.includes('.')) {
|
|
1460
|
-
if (!propertyType) {
|
|
1461
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1462
|
-
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, propertyType is missing for key: "${key}" ` +
|
|
1463
|
-
`(${this.dataParams.dataName})`)),
|
|
1464
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GFF3`,
|
|
1465
|
-
});
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
else {
|
|
1469
|
-
if (!this.dataParams.properties[key]) {
|
|
1470
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1471
|
-
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, key not found in dataParams: "${key}" ` +
|
|
1472
|
-
`(${this.dataParams.dataName})`)),
|
|
1473
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GFF2`,
|
|
1474
|
-
});
|
|
1475
|
-
}
|
|
1476
|
-
propertyType = this.dataParams.properties[key].type;
|
|
1477
|
-
}
|
|
1478
|
-
switch (propertyType) {
|
|
1479
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.string:
|
|
1480
|
-
if (typeof searchValue !== 'string') {
|
|
1481
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1482
|
-
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, searchValue is not a string! ` +
|
|
1483
|
-
`(${this.dataParams.dataName})`)),
|
|
1484
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GFF4`,
|
|
1485
|
-
});
|
|
1486
|
-
}
|
|
1487
|
-
if (Array.isArray(searchValue)) {
|
|
1488
|
-
const lowerCaseSearchValueArray = searchValue.filter((searchString) => Boolean(searchString)).map((searchString) => searchString.toLowerCase());
|
|
1489
|
-
return (dataProperty) => {
|
|
1490
|
-
// Convert to string if not already a string (handles numbers, etc.)
|
|
1491
|
-
const dataPropertyAsString = dataProperty != null ? String(dataProperty) : '';
|
|
1492
|
-
return lowerCaseSearchValueArray.some((searchString) => dataPropertyAsString?.toLowerCase().includes(searchString));
|
|
1493
|
-
};
|
|
1494
|
-
}
|
|
1495
|
-
else {
|
|
1496
|
-
const lowerCaseSearchValue = searchValue?.toLowerCase();
|
|
1497
|
-
if (!lowerCaseSearchValue) {
|
|
1498
|
-
return (dataProperty) => !dataProperty;
|
|
1499
|
-
}
|
|
1500
|
-
return (dataProperty) => {
|
|
1501
|
-
// Convert to string if not already a string (handles numbers, etc.)
|
|
1502
|
-
const dataPropertyAsString = dataProperty != null ? String(dataProperty) : '';
|
|
1503
|
-
return dataPropertyAsString?.toLowerCase().includes(lowerCaseSearchValue);
|
|
1504
|
-
};
|
|
1505
|
-
}
|
|
1506
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.date:
|
|
1507
|
-
if (searchValue.isRange) {
|
|
1508
|
-
if (searchValue.from === undefined ||
|
|
1509
|
-
searchValue.from === null) {
|
|
1510
|
-
const toAsNumber = +new Date(searchValue.to);
|
|
1511
|
-
return (dataProperty) => +new Date(dataProperty) <= toAsNumber;
|
|
1512
|
-
}
|
|
1513
|
-
else if (searchValue.to === undefined ||
|
|
1514
|
-
searchValue.to === null) {
|
|
1515
|
-
const fromAsNumber = +new Date(searchValue.from);
|
|
1516
|
-
return (dataProperty) => +new Date(dataProperty) >= fromAsNumber;
|
|
1517
|
-
}
|
|
1518
|
-
const rangeAsNumber = new fsm_dynamo_1.DyFM_RangeValue(+new Date(searchValue.from), +new Date(searchValue.to));
|
|
1519
|
-
return (dataProperty) => fsm_dynamo_1.DyFM_RangeValue.isInRange(+new Date(dataProperty), rangeAsNumber);
|
|
1520
|
-
}
|
|
1521
|
-
if (Array.isArray(searchValue)) {
|
|
1522
|
-
const searchValueAsNumberArray = searchValue.map((date) => +new Date(date));
|
|
1523
|
-
return (dataProperty) => searchValueAsNumberArray.includes(+new Date(dataProperty));
|
|
1524
|
-
}
|
|
1525
|
-
const searchValueAsNumber = +new Date(searchValue);
|
|
1526
|
-
return (dataProperty) => +new Date(dataProperty) === searchValueAsNumber;
|
|
1527
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.number:
|
|
1528
|
-
if (searchValue.isRange) {
|
|
1529
|
-
if (searchValue.from === undefined ||
|
|
1530
|
-
searchValue.from === null) {
|
|
1531
|
-
return (dataProperty) => dataProperty <= searchValue.to;
|
|
1532
|
-
}
|
|
1533
|
-
else if (searchValue.to === undefined ||
|
|
1534
|
-
searchValue.to === null) {
|
|
1535
|
-
return (dataProperty) => dataProperty >= searchValue.from;
|
|
1536
|
-
}
|
|
1537
|
-
return (dataProperty) => fsm_dynamo_1.DyFM_RangeValue.isInRange(dataProperty, searchValue);
|
|
1538
|
-
}
|
|
1539
|
-
if (Array.isArray(searchValue)) {
|
|
1540
|
-
return (dataProperty) => searchValue.includes(dataProperty);
|
|
1541
|
-
}
|
|
1542
|
-
return (dataProperty) => dataProperty === searchValue;
|
|
1543
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.boolean:
|
|
1544
|
-
return (dataProperty) => dataProperty === searchValue;
|
|
1545
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.object:
|
|
1546
|
-
if (Array.isArray(searchValue)) {
|
|
1547
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1548
|
-
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, array search not implemented for this type ` +
|
|
1549
|
-
`(${this.dataParams.dataName})`)),
|
|
1550
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GFF5`,
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
return (dataProperty) => {
|
|
1554
|
-
const searchValueKeys = Object.keys(searchValue);
|
|
1555
|
-
const stringifiedSearchValue = {};
|
|
1556
|
-
try {
|
|
1557
|
-
searchValueKeys.forEach((key) => {
|
|
1558
|
-
stringifiedSearchValue[key] = JSON.stringify(searchValue[key]);
|
|
1559
|
-
});
|
|
1560
|
-
}
|
|
1561
|
-
catch (error) {
|
|
1562
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1563
|
-
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, object search failed! ` +
|
|
1564
|
-
`(${this.dataParams.dataName})`)),
|
|
1565
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GFF6`,
|
|
1566
|
-
additionalContent: {
|
|
1567
|
-
searchValue: searchValue,
|
|
1568
|
-
},
|
|
1569
|
-
});
|
|
1570
|
-
}
|
|
1571
|
-
return searchValueKeys.every((key) => {
|
|
1572
|
-
try {
|
|
1573
|
-
return stringifiedSearchValue[key] === JSON.stringify(dataProperty[key]);
|
|
1574
|
-
}
|
|
1575
|
-
catch (error) {
|
|
1576
|
-
console.error('object filter returning false, bc of an error', 'searchValue:', searchValue, 'dataProperty:', dataProperty, 'key:', key, 'error:', error);
|
|
1577
|
-
return false;
|
|
1578
|
-
}
|
|
1579
|
-
});
|
|
1580
|
-
};
|
|
1581
|
-
default:
|
|
1582
|
-
if (searchValue.isRange) {
|
|
1583
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1584
|
-
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, range search not implemented for this type ` +
|
|
1585
|
-
`(${this.dataParams.dataName})`)),
|
|
1586
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GFF7`,
|
|
1587
|
-
});
|
|
1588
|
-
}
|
|
1589
|
-
if (Array.isArray(searchValue)) {
|
|
1590
|
-
return (dataProperty) => searchValue.includes(dataProperty);
|
|
1591
|
-
}
|
|
1592
|
-
return (dataProperty) => dataProperty === searchValue;
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
catch (error) {
|
|
1596
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1597
|
-
...this._getDefaultErrorSettings('getFilterFunctionForKey', error),
|
|
1598
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GFF0`,
|
|
1599
|
-
additionalContent: {
|
|
1600
|
-
key: key,
|
|
1601
|
-
searchValue: searchValue,
|
|
1602
|
-
propertyType: propertyType,
|
|
1603
|
-
},
|
|
1604
|
-
});
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
/**
|
|
1608
|
-
* Get the value of a nested key.
|
|
1609
|
-
* @param nestKeys - The nested keys to resolve.
|
|
1610
|
-
* @returns The value of the nested key.
|
|
1611
|
-
*/
|
|
1612
|
-
getKeyResolver(nestKeys) {
|
|
1613
|
-
return (data) => {
|
|
1614
|
-
let value = data;
|
|
1615
|
-
nestKeys.forEach((nestKey) => {
|
|
1616
|
-
if (!value) {
|
|
1617
|
-
return;
|
|
1618
|
-
}
|
|
1619
|
-
if (nestKey === '*') {
|
|
1620
|
-
// Wildcard: ha value egy tömb, akkor minden elemet visszaadunk
|
|
1621
|
-
// A következő nestKey minden elemre alkalmazva lesz
|
|
1622
|
-
if (Array.isArray(value)) {
|
|
1623
|
-
// value marad tömb, a következő nestKey minden elemre alkalmazva lesz
|
|
1624
|
-
// Nem változtatjuk meg a value-t, hogy a következő iterációban
|
|
1625
|
-
// a tömb minden elemére alkalmazva legyen a következő nestKey
|
|
1626
|
-
}
|
|
1627
|
-
else if (value && typeof value === 'object') {
|
|
1628
|
-
// Ha objektum, akkor az értékeit adja vissza tömbként
|
|
1629
|
-
value = Object.values(value);
|
|
1630
|
-
}
|
|
1631
|
-
else {
|
|
1632
|
-
// Egyébként undefined
|
|
1633
|
-
value = undefined;
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
else if (Array.isArray(value)) {
|
|
1637
|
-
// Ha value tömb, akkor minden elemre alkalmazzuk a nestKey-t
|
|
1638
|
-
if (!isNaN(+nestKey)) {
|
|
1639
|
-
value = value[+nestKey];
|
|
1640
|
-
}
|
|
1641
|
-
else {
|
|
1642
|
-
value = value.map((element) => element ? element[nestKey] : element);
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
else {
|
|
1646
|
-
value = value[nestKey];
|
|
1647
|
-
}
|
|
1648
|
-
});
|
|
1649
|
-
return value;
|
|
1650
|
-
};
|
|
1651
|
-
}
|
|
1652
|
-
/**
|
|
1653
|
-
* Get the sort function for a key.
|
|
1654
|
-
* @param sortSettings - The sort settings.
|
|
1655
|
-
* @returns The sort function for the key.
|
|
1656
|
-
*/
|
|
1657
|
-
getSortFunctionForKey(sortSettings) {
|
|
1658
|
-
let keyResolver;
|
|
1659
|
-
let valueType;
|
|
1660
|
-
if (!this.dataParams.properties[sortSettings.key] &&
|
|
1661
|
-
!sortSettings.isNestedPropertySort) {
|
|
1662
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1663
|
-
...this._getDefaultErrorSettings('getSortFunctionForKey', new Error(`getSortFunctionForKey failed, key not found in dataParams ` +
|
|
1664
|
-
`(${this.dataParams.dataName})`)),
|
|
1665
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GSF1`,
|
|
1666
|
-
});
|
|
1667
|
-
}
|
|
1668
|
-
if (sortSettings.isNestedPropertySort) {
|
|
1669
|
-
keyResolver = this.getKeyResolver(sortSettings.nestKeys);
|
|
1670
|
-
valueType = sortSettings.valueType;
|
|
1671
|
-
}
|
|
1672
|
-
else {
|
|
1673
|
-
keyResolver = (data) => data[sortSettings.key];
|
|
1674
|
-
valueType = this.dataParams.properties[sortSettings.key].type;
|
|
1675
|
-
}
|
|
1676
|
-
if (!valueType) {
|
|
1677
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1678
|
-
...this._getDefaultErrorSettings('getSortFunctionForKey', new Error(`getSortFunctionForKey failed, valueType is missing! ` +
|
|
1679
|
-
`(${this.dataParams.dataName})`)),
|
|
1680
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GSF1`,
|
|
1681
|
-
});
|
|
1682
|
-
}
|
|
1683
|
-
const sortValue = (sortSettings.order === 1 ||
|
|
1684
|
-
sortSettings.order === 'asc' ||
|
|
1685
|
-
sortSettings.order === 'ascending') ? 1 : -1;
|
|
1686
|
-
switch (valueType) {
|
|
1687
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.string:
|
|
1688
|
-
return (a, b) => {
|
|
1689
|
-
a = keyResolver(a);
|
|
1690
|
-
b = keyResolver(b);
|
|
1691
|
-
return a.localeCompare(b) * sortValue;
|
|
1692
|
-
};
|
|
1693
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.date:
|
|
1694
|
-
return (a, b) => {
|
|
1695
|
-
const aNum = +new Date(keyResolver(a));
|
|
1696
|
-
const bNum = +new Date(keyResolver(b));
|
|
1697
|
-
if (aNum < bNum) {
|
|
1698
|
-
return -sortValue;
|
|
1699
|
-
}
|
|
1700
|
-
else if (aNum > bNum) {
|
|
1701
|
-
return sortValue;
|
|
1702
|
-
}
|
|
1703
|
-
else {
|
|
1704
|
-
return 0;
|
|
1705
|
-
}
|
|
1706
|
-
};
|
|
1707
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.number:
|
|
1708
|
-
return (a, b) => {
|
|
1709
|
-
a = keyResolver(a);
|
|
1710
|
-
b = keyResolver(b);
|
|
1711
|
-
if (a < b) {
|
|
1712
|
-
return -sortValue;
|
|
1713
|
-
}
|
|
1714
|
-
else if (a > b) {
|
|
1715
|
-
return sortValue;
|
|
1716
|
-
}
|
|
1717
|
-
else {
|
|
1718
|
-
return 0;
|
|
1719
|
-
}
|
|
1720
|
-
};
|
|
1721
|
-
case fsm_dynamo_1.DyFM_BasicProperty_Type.boolean:
|
|
1722
|
-
return (a, b) => {
|
|
1723
|
-
a = keyResolver(a);
|
|
1724
|
-
b = keyResolver(b);
|
|
1725
|
-
if (a === b) {
|
|
1726
|
-
return 0;
|
|
1727
|
-
}
|
|
1728
|
-
if (a) {
|
|
1729
|
-
return sortValue;
|
|
1730
|
-
}
|
|
1731
|
-
return -sortValue;
|
|
1732
|
-
};
|
|
1733
|
-
default:
|
|
1734
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1735
|
-
...this._getDefaultErrorSettings('getSortFunctionForKey', new Error(`getSortFunctionForKey failed, sorting not implemented for this type ` +
|
|
1736
|
-
`(${this.dataParams.dataName}, ${valueType})`)),
|
|
1737
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GSF2`,
|
|
1738
|
-
});
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
/* private getSortFunctionForNestedKeys<T>(
|
|
1742
|
-
sortSettings: DyFM_DSNestedPropertySort
|
|
1743
|
-
): (a: T, b: T) => number {
|
|
1744
|
-
const nestedPropertyResolver: (data) => any = this.getKeyResolver(sortSettings.nestKeys);
|
|
1745
|
-
|
|
1746
|
-
const sortValue: 1 | -1 = (
|
|
1747
|
-
sortSettings.order === 1 ||
|
|
1748
|
-
sortSettings.order === 'asc' ||
|
|
1749
|
-
sortSettings.order === 'ascending'
|
|
1750
|
-
) ? 1 : -1;
|
|
1751
|
-
|
|
1752
|
-
switch (sortSettings.valueType) {
|
|
1753
|
-
case DyFM_BasicProperty_Type.string:
|
|
1754
|
-
return (a: T, b: T): number => {
|
|
1755
|
-
a = nestedPropertyResolver(a);
|
|
1756
|
-
b = nestedPropertyResolver(b);
|
|
1757
|
-
|
|
1758
|
-
return (a as string).localeCompare(b as string) * sortValue
|
|
1759
|
-
};
|
|
1760
|
-
|
|
1761
|
-
case DyFM_BasicProperty_Type.date:
|
|
1762
|
-
return (a: T, b: T): number => {
|
|
1763
|
-
a = nestedPropertyResolver(a);
|
|
1764
|
-
b = nestedPropertyResolver(b);
|
|
1765
|
-
|
|
1766
|
-
if (+new Date(a) < +new Date(b)) {
|
|
1767
|
-
return -sortValue;
|
|
1768
|
-
} else if (+new Date(a) > +new Date(b)) {
|
|
1769
|
-
return sortValue;
|
|
1770
|
-
} else {
|
|
1771
|
-
return 0;
|
|
1772
|
-
}
|
|
1773
|
-
};
|
|
1774
|
-
|
|
1775
|
-
case DyFM_BasicProperty_Type.number:
|
|
1776
|
-
return (a: T, b: T): number => {
|
|
1777
|
-
a = nestedPropertyResolver(a);
|
|
1778
|
-
b = nestedPropertyResolver(b);
|
|
1779
|
-
|
|
1780
|
-
if (a < b) {
|
|
1781
|
-
return -sortValue;
|
|
1782
|
-
} else if (a > b) {
|
|
1783
|
-
return sortValue;
|
|
1784
|
-
} else {
|
|
1785
|
-
return 0;
|
|
1786
|
-
}
|
|
1787
|
-
};
|
|
1788
|
-
|
|
1789
|
-
case DyFM_BasicProperty_Type.boolean:
|
|
1790
|
-
return (a: T, b: T): number => {
|
|
1791
|
-
a = nestedPropertyResolver(a);
|
|
1792
|
-
b = nestedPropertyResolver(b);
|
|
1793
|
-
|
|
1794
|
-
if (a === b) {
|
|
1795
|
-
return 0;
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
|
-
if (a) {
|
|
1799
|
-
return sortValue;
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
|
-
return -sortValue;
|
|
1803
|
-
};
|
|
1804
|
-
|
|
1805
|
-
default:
|
|
1806
|
-
throw new DyFM_Error({
|
|
1807
|
-
...this._getDefaultErrorSettings(
|
|
1808
|
-
'getSortFunctionForKey',
|
|
1809
|
-
new Error(
|
|
1810
|
-
`getSortFunctionForKey failed, sorting not implemented for this type ` +
|
|
1811
|
-
`(${this.dataParams.dataName}, ${this.dataParams.properties[key].type})`
|
|
1812
|
-
)
|
|
1813
|
-
),
|
|
1814
|
-
|
|
1815
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GSF2`,
|
|
1816
|
-
});
|
|
1817
|
-
}
|
|
1818
|
-
} */
|
|
1819
|
-
/**
|
|
1820
|
-
* setting up dependency dataHook by DynamoNTSDataModelParams
|
|
1821
|
-
*/
|
|
1822
|
-
lookForDependencyDataSettings() {
|
|
1823
|
-
const dependencyParams = Object.values(this.dataParams.properties).filter((modelParams) => Boolean(modelParams.dependencyDataName));
|
|
1824
|
-
this.depSettings.push(...dependencyParams.map((dependencyParams) => ({
|
|
1825
|
-
key: dependencyParams.key,
|
|
1826
|
-
dbServiceKey: dependencyParams.dependencyDataName,
|
|
1827
|
-
keyIsUnique: dependencyParams.unique,
|
|
1828
|
-
keyIsRequired: dependencyParams.required,
|
|
1829
|
-
})));
|
|
1830
|
-
if (this.depSettings.length === 1) {
|
|
1831
|
-
this.depDataDBService = global_service_1.DyNTS_GlobalService.getDBServiceByKey(this.depSettings[0].dbServiceKey);
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
/**
|
|
1835
|
-
*
|
|
1836
|
-
* @returns
|
|
1837
|
-
*/
|
|
1838
|
-
getDependencyDataDBService(dBServiceKey) {
|
|
1839
|
-
if (!dBServiceKey && !this.depDataDBService) {
|
|
1840
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1841
|
-
...this._getDefaultErrorSettings('getDependencyDataDBService', new Error(`getDependencyDataDBService was unsuccessful, service key not setted up! ` +
|
|
1842
|
-
`(key: ${this.depSettings.map((depSetting) => depSetting.key).join(', ')}, ` +
|
|
1843
|
-
`(${this.dataParams.dataName})`)),
|
|
1844
|
-
status: 500,
|
|
1845
|
-
errorCode: `${this.ecBase}DyNTS-DS0-GDDB0`,
|
|
1846
|
-
});
|
|
1847
|
-
}
|
|
1848
|
-
if (this.depDataDBService) {
|
|
1849
|
-
return this.depDataDBService;
|
|
1850
|
-
}
|
|
1851
|
-
else {
|
|
1852
|
-
this.depDataDBService = global_service_1.DyNTS_GlobalService.getDBServiceByKey(dBServiceKey);
|
|
1853
|
-
return this.depDataDBService;
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
getProvidedData(data) {
|
|
1857
|
-
return data;
|
|
1858
|
-
}
|
|
1859
|
-
getProvidedDataList(dataList) {
|
|
1860
|
-
return dataList;
|
|
1861
|
-
}
|
|
1862
|
-
_getDefaultErrorSettings(fnName, error) {
|
|
1863
|
-
return {
|
|
1864
|
-
status: error?.___status ?? 500,
|
|
1865
|
-
message: error?.message ??
|
|
1866
|
-
error?._message ??
|
|
1867
|
-
`${fnName} was UNSUCCESSFUL (NTS; ${this.dataParams.dataName})`,
|
|
1868
|
-
addECToUserMsg: !error?.__userMessage,
|
|
1869
|
-
userMessage: error?.__userMessage ?? this.defaultErrorUserMsg,
|
|
1870
|
-
issuer: this.issuer,
|
|
1871
|
-
issuerService: this.serviceName + ` (${this?.constructor?.name}-DyNTS_DataService)`,
|
|
1872
|
-
systemVersion: global_settings_const_1.DyNTS_global_settings.systemVersion,
|
|
1873
|
-
error: error,
|
|
1874
|
-
};
|
|
1875
|
-
}
|
|
1876
|
-
getDefaultErrorSettings(fnName, error,
|
|
1877
|
-
/** @deprecated we wont support the separate user message in the future, use the message instead */
|
|
1878
|
-
useMessageAsUserMessage = true) {
|
|
1879
|
-
return {
|
|
1880
|
-
status: error?.___status ?? 500,
|
|
1881
|
-
message: error?.message ??
|
|
1882
|
-
error?._message ??
|
|
1883
|
-
`${fnName} was UNSUCCESSFUL (${global_settings_const_1.DyNTS_global_settings.systemShortCodeName})`,
|
|
1884
|
-
addECToUserMsg: !error?.__userMessage,
|
|
1885
|
-
userMessage: error?.__userMessage ??
|
|
1886
|
-
(useMessageAsUserMessage ? error?.message : this.defaultErrorUserMsg),
|
|
1887
|
-
issuer: this.issuer,
|
|
1888
|
-
issuerService: this.constructor?.name,
|
|
1889
|
-
systemVersion: global_settings_const_1.DyNTS_global_settings.systemVersion,
|
|
1890
|
-
error: error,
|
|
1891
|
-
};
|
|
1892
|
-
}
|
|
1893
|
-
// ════════════════════════════════════════════════════════════════════════
|
|
1894
|
-
// GENERIC DATA COMPARE (FR-001)
|
|
1895
|
-
// ════════════════════════════════════════════════════════════════════════
|
|
1896
|
-
/**
|
|
1897
|
-
* Generic, field-szintu osszehasonlitas ket adat-objektum kozott.
|
|
1898
|
-
*
|
|
1899
|
-
* **Auto-discovery mod** (`options.fields` nelkul): a metodus mindket
|
|
1900
|
-
* objektum kulcs-uniojan iter, KIVEVE a `DyFM_Metadata` skip-listet
|
|
1901
|
-
* (`_id`, `__created`, `__createdBy`, `__lastModified`, `__lastModifiedBy`).
|
|
1902
|
-
*
|
|
1903
|
-
* **Scope-szukito mod** (`options.fields = [...]`): KIZAROLAG a felsorolt
|
|
1904
|
-
* mezoket vizsgalja. A skip-list IGNORALODIK — explicit fields override.
|
|
1905
|
-
*
|
|
1906
|
-
* **Custom comparator** (`options.customComparators`): per-field override
|
|
1907
|
-
* a default deep-equal helyett (pl. set-equality array-ekre,
|
|
1908
|
-
* case-insensitive string compare-re). A custom function `true`-val signal-ozza
|
|
1909
|
-
* az equality-t.
|
|
1910
|
-
*
|
|
1911
|
-
* **Return:** `'equal'` ha minden vizsgalt field egyezik; `'modified'` ha
|
|
1912
|
-
* legalabb egy elter — ilyenkor `changedFields` tartalmazza a TELJES
|
|
1913
|
-
* mismatch-listat (nem early-return).
|
|
1914
|
-
*
|
|
1915
|
-
* **Throws:**
|
|
1916
|
-
* - `newData` vagy `oldData` null/undefined → `DyFM_Error(400, DyNTS-DS0-CD1)`
|
|
1917
|
-
* - `options.fields = []` ures array → `DyFM_Error(400, DyNTS-DS0-CD2)`
|
|
1918
|
-
*
|
|
1919
|
-
* **Sync method** (nincs I/O szukseglet); a host wrappel-i ha async kell.
|
|
1920
|
-
*
|
|
1921
|
-
* @example
|
|
1922
|
-
* const result = userService.compareData(newUser, oldUser);
|
|
1923
|
-
* if (result.result === 'modified') {
|
|
1924
|
-
* console.log('Changed:', result.changedFields);
|
|
1925
|
-
* }
|
|
1926
|
-
*
|
|
1927
|
-
* @example // Scope-szukites + custom comparator
|
|
1928
|
-
* userService.compareData(newUser, oldUser, {
|
|
1929
|
-
* fields: ['email', 'roles'],
|
|
1930
|
-
* customComparators: {
|
|
1931
|
-
* roles: (a, b) => new Set(a).size === new Set([...a, ...b]).size,
|
|
1932
|
-
* },
|
|
1933
|
-
* });
|
|
1934
|
-
*/
|
|
1935
|
-
compareData(newData, oldData, options) {
|
|
1936
|
-
// Input guard
|
|
1937
|
-
if (newData === null || newData === undefined || oldData === null || oldData === undefined) {
|
|
1938
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1939
|
-
...this.getDefaultErrorSettings('compareData', new Error('newData/oldData required')),
|
|
1940
|
-
status: 400,
|
|
1941
|
-
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-CD1`,
|
|
1942
|
-
message: 'compareData: newData and oldData are required (both must be non-null/undefined)',
|
|
1943
|
-
});
|
|
1944
|
-
}
|
|
1945
|
-
if (options?.fields !== undefined && options.fields.length === 0) {
|
|
1946
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
1947
|
-
...this.getDefaultErrorSettings('compareData', new Error('options.fields must not be empty')),
|
|
1948
|
-
status: 400,
|
|
1949
|
-
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-CD2`,
|
|
1950
|
-
message: 'compareData: options.fields must not be an empty array',
|
|
1951
|
-
});
|
|
1952
|
-
}
|
|
1953
|
-
const fieldsToCheck = this._resolveCompareFields(newData, oldData, options);
|
|
1954
|
-
const comparators = options?.customComparators ?? {};
|
|
1955
|
-
const changedFields = [];
|
|
1956
|
-
for (const field of fieldsToCheck) {
|
|
1957
|
-
const a = newData[field];
|
|
1958
|
-
const b = oldData[field];
|
|
1959
|
-
const isEqual = comparators[field]
|
|
1960
|
-
? comparators[field](a, b)
|
|
1961
|
-
: this._deepEqual(a, b);
|
|
1962
|
-
if (!isEqual) {
|
|
1963
|
-
changedFields.push(field);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
if (changedFields.length === 0) {
|
|
1967
|
-
return { result: 'equal' };
|
|
1968
|
-
}
|
|
1969
|
-
return { result: 'modified', changedFields: changedFields };
|
|
1970
|
-
}
|
|
1971
|
-
/**
|
|
1972
|
-
* Eldonti az osszehasonlitando fields-listat:
|
|
1973
|
-
* - explicit `options.fields` esetan annak masolata (skip-list ignoralt)
|
|
1974
|
-
* - egyebkent `Object.keys(newData) UNION Object.keys(oldData)` minus skip-list
|
|
1975
|
-
*/
|
|
1976
|
-
_resolveCompareFields(newData, oldData, options) {
|
|
1977
|
-
if (options?.fields !== undefined) {
|
|
1978
|
-
// Explicit fields — copy-spread (defensive against caller mutation mid-flight)
|
|
1979
|
-
return [...options.fields];
|
|
1980
|
-
}
|
|
1981
|
-
const keySet = new Set();
|
|
1982
|
-
for (const k of Object.keys(newData)) {
|
|
1983
|
-
keySet.add(k);
|
|
1984
|
-
}
|
|
1985
|
-
for (const k of Object.keys(oldData)) {
|
|
1986
|
-
keySet.add(k);
|
|
1987
|
-
}
|
|
1988
|
-
const result = [];
|
|
1989
|
-
for (const k of keySet) {
|
|
1990
|
-
if (COMPARE_DATA_METADATA_SKIP_FIELDS.has(k)) {
|
|
1991
|
-
continue;
|
|
1992
|
-
}
|
|
1993
|
-
result.push(k);
|
|
1994
|
-
}
|
|
1995
|
-
return result;
|
|
1996
|
-
}
|
|
1997
|
-
/**
|
|
1998
|
-
* Deep-equal helper.
|
|
1999
|
-
*
|
|
2000
|
-
* - Primitive (`string`/`number`/`boolean`/`null`/`undefined`): `===` / `Object.is`
|
|
2001
|
-
* (a `NaN === NaN` esetet `Object.is` kezeli helyesen)
|
|
2002
|
-
* - `Date`: `.getTime()` egyenloseg (kulonbozo Date instance-ok same-time-mal egyenlonek)
|
|
2003
|
-
* - Array: length + index-szerinti rekurziv deep-equal
|
|
2004
|
-
* - POJO: keys-union + per-key rekurzio
|
|
2005
|
-
* - Egyeb (RegExp / Map / Set / Buffer): `Object.is` fallback (reference compare)
|
|
2006
|
-
*
|
|
2007
|
-
* NEM kezelt: cyclic references — a hivo objektum-grafja flat / fa kell legyen
|
|
2008
|
-
* (a tipikus FDP data-model esete; cycle eseten stack overflow lesz, ami ertelmes
|
|
2009
|
-
* jelzes a programozonak).
|
|
2010
|
-
*/
|
|
2011
|
-
_deepEqual(a, b) {
|
|
2012
|
-
if (a === b) {
|
|
2013
|
-
return true;
|
|
2014
|
-
}
|
|
2015
|
-
if (Object.is(a, b)) {
|
|
2016
|
-
return true;
|
|
2017
|
-
}
|
|
2018
|
-
// Null/undefined es a masik nem ugyanaz → false
|
|
2019
|
-
if (a === null || a === undefined || b === null || b === undefined) {
|
|
2020
|
-
return false;
|
|
2021
|
-
}
|
|
2022
|
-
// Date
|
|
2023
|
-
if (a instanceof Date && b instanceof Date) {
|
|
2024
|
-
return a.getTime() === b.getTime();
|
|
2025
|
-
}
|
|
2026
|
-
if (a instanceof Date || b instanceof Date) {
|
|
2027
|
-
return false;
|
|
2028
|
-
}
|
|
2029
|
-
// Array
|
|
2030
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
2031
|
-
if (a.length !== b.length) {
|
|
2032
|
-
return false;
|
|
2033
|
-
}
|
|
2034
|
-
for (let i = 0; i < a.length; i++) {
|
|
2035
|
-
if (!this._deepEqual(a[i], b[i])) {
|
|
2036
|
-
return false;
|
|
2037
|
-
}
|
|
2038
|
-
}
|
|
2039
|
-
return true;
|
|
2040
|
-
}
|
|
2041
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
2042
|
-
return false;
|
|
2043
|
-
}
|
|
2044
|
-
// POJO (Object.prototype) — keys union, per-key compare
|
|
2045
|
-
if (typeof a === 'object' && typeof b === 'object') {
|
|
2046
|
-
const keysA = Object.keys(a);
|
|
2047
|
-
const keysB = Object.keys(b);
|
|
2048
|
-
if (keysA.length !== keysB.length) {
|
|
2049
|
-
return false;
|
|
2050
|
-
}
|
|
2051
|
-
const keysAset = new Set(keysA);
|
|
2052
|
-
for (const k of keysB) {
|
|
2053
|
-
if (!keysAset.has(k)) {
|
|
2054
|
-
return false;
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
for (const k of keysA) {
|
|
2058
|
-
if (!this._deepEqual(a[k], b[k])) {
|
|
2059
|
-
return false;
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
return true;
|
|
2063
|
-
}
|
|
2064
|
-
// Fallback (function, symbol, BigInt, stb.) — strict equality mar nem stimmelt
|
|
2065
|
-
return false;
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
exports.DyNTS_DataService = DyNTS_DataService;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DyNTS_DataService = void 0;
|
|
4
|
+
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
5
|
+
const archive_util_1 = require("../../_collections/archive.util");
|
|
6
|
+
const global_settings_const_1 = require("../../_collections/global-settings.const");
|
|
7
|
+
const global_service_1 = require("../core/global.service");
|
|
8
|
+
/**
|
|
9
|
+
* `DyFM_Metadata` field-ek amik auto-discovery modban (fields opcio nelkul)
|
|
10
|
+
* KI vannak hagyva a compareData()-bol. Ezek normal mukodes kozben kezelt
|
|
11
|
+
* mezok (id-allocation, audit timestamps, audit usernames) — szemantikus
|
|
12
|
+
* adatvaltozas-ellenorzeshez irrelevansak.
|
|
13
|
+
*
|
|
14
|
+
* Explicit `fields: ['_id']`-vel meg vizsgaltathato, ha valamiert kell.
|
|
15
|
+
*/
|
|
16
|
+
const COMPARE_DATA_METADATA_SKIP_FIELDS = new Set([
|
|
17
|
+
'_id',
|
|
18
|
+
'__created',
|
|
19
|
+
'__createdBy',
|
|
20
|
+
'__lastModified',
|
|
21
|
+
'__lastModifiedBy',
|
|
22
|
+
]);
|
|
23
|
+
// TODO: 2 type of archiving service system: within list, or separate db elements
|
|
24
|
+
/**
|
|
25
|
+
* Basic Data Service that is connected to the relevant DBServices
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* export class UserMatchStatisticsService extends DyNTS_DataService<UserMatchStatistics> {
|
|
29
|
+
* constructor(
|
|
30
|
+
* set: {
|
|
31
|
+
* data?: UserMatchStatistics,
|
|
32
|
+
* issuer: string,
|
|
33
|
+
* }
|
|
34
|
+
* ) {
|
|
35
|
+
* super(
|
|
36
|
+
* new UserMatchStatistics(set?.data),
|
|
37
|
+
* userMatchStatisticsModelParams
|
|
38
|
+
* );
|
|
39
|
+
* this.issuer = set.issuer;
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
*/
|
|
43
|
+
class DyNTS_DataService {
|
|
44
|
+
data;
|
|
45
|
+
dataParams;
|
|
46
|
+
issuer;
|
|
47
|
+
serviceName;
|
|
48
|
+
serviceNameShortCode;
|
|
49
|
+
/** error code base */
|
|
50
|
+
ecBase = `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|`;
|
|
51
|
+
dataDBService;
|
|
52
|
+
haveArchiveDataService;
|
|
53
|
+
/* data: T; */
|
|
54
|
+
/** @deprecated */
|
|
55
|
+
dataList = [];
|
|
56
|
+
/* issuer: string; */
|
|
57
|
+
depSettings = [];
|
|
58
|
+
/* depKeys: string[] = [];
|
|
59
|
+
depDBServiceKeys: string[] = [];
|
|
60
|
+
depKeyIsUnique: boolean[] = [];
|
|
61
|
+
depKeyIsRequired: boolean[] = []; */
|
|
62
|
+
depDataDBService;
|
|
63
|
+
/* dataParams: DyFM_DataModel_Params<T>; */
|
|
64
|
+
defaultErrorUserMsg = `We encountered an unhandled Data Service Error, ` +
|
|
65
|
+
`\nplease contact the responsible development team.`;
|
|
66
|
+
defaultValidationErrorUserMsg = `We encountered an unhandled Validation Error, ` +
|
|
67
|
+
`\nplease contact the responsible development team.`;
|
|
68
|
+
constructor(
|
|
69
|
+
/**
|
|
70
|
+
* Initial data, this will be used by functions on default
|
|
71
|
+
* @deprecated
|
|
72
|
+
*/
|
|
73
|
+
data,
|
|
74
|
+
/**
|
|
75
|
+
* DB data prams will be used to connect to usable dbService on GlobalService
|
|
76
|
+
*/
|
|
77
|
+
/* dataParams: DyFM_DataModel_Params, */
|
|
78
|
+
dataParams,
|
|
79
|
+
/**
|
|
80
|
+
* Initial set for issuer to be able to follow the issuer's activity
|
|
81
|
+
*/
|
|
82
|
+
issuer) {
|
|
83
|
+
this.data = data;
|
|
84
|
+
this.dataParams = dataParams;
|
|
85
|
+
this.issuer = issuer;
|
|
86
|
+
try {
|
|
87
|
+
this.serviceName = this.constructor?.name;
|
|
88
|
+
this.serviceNameShortCode = fsm_dynamo_1.DyFM_String.anyNameToShortCode(this.serviceName);
|
|
89
|
+
this.ecBase = `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|${this.serviceNameShortCode}|`;
|
|
90
|
+
this.dataDBService = global_service_1.DyNTS_GlobalService.getDBService(this.dataParams);
|
|
91
|
+
/* this.data = data; */
|
|
92
|
+
/* this.dataParams = dataParams; */
|
|
93
|
+
this.haveArchiveDataService = this.dataParams.addArchive;
|
|
94
|
+
this.lookForDependencyDataSettings();
|
|
95
|
+
/* this.issuer = issuer; */
|
|
96
|
+
/* DyNTS_GlobalService.addDataService(this); */
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
100
|
+
...this._getDefaultErrorSettings('constructor', error),
|
|
101
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-C00`,
|
|
102
|
+
message: `The dataService construction failed for "${this.dataParams?.dataName}". ` +
|
|
103
|
+
`at "${this.serviceName}" (${this.constructor.name})` +
|
|
104
|
+
`\nMaybe you forgot to add the dbService to the GlobalService?` +
|
|
105
|
+
`\nOr just trying to use a dependencyDataName that is not present in this db...`,
|
|
106
|
+
level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
|
|
107
|
+
});
|
|
108
|
+
/* DyFM_Log.error(
|
|
109
|
+
`\nDyNTS_DataService ERROR: ` +
|
|
110
|
+
`\nThe dataService construction failed for ` +
|
|
111
|
+
`${this.dataParams?.dataName}. ${this.serviceName} (${this.constructor.name})` +
|
|
112
|
+
`\nMaybe you forgot to add the dbService to the GlobalService?` +
|
|
113
|
+
`\n\n`,
|
|
114
|
+
new Error()
|
|
115
|
+
); */
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
getArchiveDataService() {
|
|
119
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
120
|
+
...this._getDefaultErrorSettings('getArchiveDataService', new Error('getArchiveDataService is not implemented!')),
|
|
121
|
+
errorCode: `${this.ecBase}DyNTS-DS-GAD0`,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* returns all data from database to service dataList
|
|
126
|
+
*/
|
|
127
|
+
async getAll(dontSetToService) {
|
|
128
|
+
try {
|
|
129
|
+
const dataListExists = await this.dataDBService.getAll().catch((error) => {
|
|
130
|
+
if (error?.errorCode?.includes('DBS-GA1')) {
|
|
131
|
+
fsm_dynamo_1.DyFM_Log.warn(`getAll "${this.dataParams.dataName}" didn't found any.`);
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
if (!dontSetToService) {
|
|
139
|
+
this.dataList = dataListExists;
|
|
140
|
+
}
|
|
141
|
+
return dataListExists;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
145
|
+
...this._getDefaultErrorSettings('getAll', error),
|
|
146
|
+
errorCode: `${this.ecBase}DyNTS-DS-GA0`,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @description
|
|
152
|
+
* returns data from database by id
|
|
153
|
+
* also if dontSetToService is false or not setted,
|
|
154
|
+
* the data will be saved to the service, even if its not found
|
|
155
|
+
*
|
|
156
|
+
* if the data is not found, it will try to find it from the archive
|
|
157
|
+
* unless skipArchiveLoad is set to true
|
|
158
|
+
*
|
|
159
|
+
* @remarks
|
|
160
|
+
* If you need to get-save a data, if possible,
|
|
161
|
+
* use db-service update instead.
|
|
162
|
+
*
|
|
163
|
+
* @param {string} id
|
|
164
|
+
* (using id from service.data, if not provided)
|
|
165
|
+
* @param dontSetToService
|
|
166
|
+
*
|
|
167
|
+
* @return {T} data: T
|
|
168
|
+
*/
|
|
169
|
+
async getDataById(id, dontSetToService, skipArchiveLoad) {
|
|
170
|
+
try {
|
|
171
|
+
id = id ?? this.data?._id;
|
|
172
|
+
if (!id) {
|
|
173
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
174
|
+
...this._getDefaultErrorSettings('getDataById', new Error(`getDataById failed, ID is missing! ` +
|
|
175
|
+
`(maybe you wanted to use getDataByDependencyId() instead...) ` +
|
|
176
|
+
`(${this.dataParams.dataName})`)),
|
|
177
|
+
errorCode: `${this.ecBase}DyNTS-DS-GI1`,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
let dataExists = await this.dataDBService.getDataById(id);
|
|
181
|
+
if (!dataExists && this.haveArchiveDataService && !skipArchiveLoad) {
|
|
182
|
+
const archiveDataService = this.getArchiveDataService();
|
|
183
|
+
dataExists = await archiveDataService.getDataByOriginalId(id, true);
|
|
184
|
+
}
|
|
185
|
+
if (!dontSetToService) {
|
|
186
|
+
this.data = dataExists;
|
|
187
|
+
}
|
|
188
|
+
return dataExists;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
if (error?.errorCode == `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-GI1`) {
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
196
|
+
...this._getDefaultErrorSettings('getDataById', error),
|
|
197
|
+
errorCode: `${this.ecBase}DyNTS-DS-GI0`,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async getDataByIds(ids, dontSetToService) {
|
|
203
|
+
try {
|
|
204
|
+
if (!ids) {
|
|
205
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
206
|
+
...this._getDefaultErrorSettings('getDataByIds', new Error(`getDataByIds failed, ids is missing! (${this.dataParams.dataName})`)),
|
|
207
|
+
errorCode: `${this.ecBase}DyNTS-DS-GIS1`,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (ids.length === 0) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
const dataList = await this.dataDBService.find({ _id: { $in: ids } });
|
|
214
|
+
if (!dontSetToService) {
|
|
215
|
+
this.dataList = dataList;
|
|
216
|
+
}
|
|
217
|
+
return dataList;
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
221
|
+
...this._getDefaultErrorSettings('getDataByIds', error),
|
|
222
|
+
errorCode: `${this.ecBase}DyNTS-DS-GIS0`,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async getDataListByIds(ids, dontSetToService) {
|
|
227
|
+
try {
|
|
228
|
+
const dataList = await this.dataDBService.getDataListByIds(ids);
|
|
229
|
+
if (!dontSetToService) {
|
|
230
|
+
this.dataList = dataList;
|
|
231
|
+
}
|
|
232
|
+
return dataList;
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
236
|
+
...this._getDefaultErrorSettings('getDataListByIds', error),
|
|
237
|
+
errorCode: `${this.ecBase}DyNTS-DS-GIL0`,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
getDependencyIdsFilter(dependencyIds) {
|
|
242
|
+
if (!this.depSettings.length) {
|
|
243
|
+
fsm_dynamo_1.DyFM_Log.warn(`❌ getDataByDependencyId failed, dependencyKey is missing from service! ` +
|
|
244
|
+
`(${this.dataParams.dataName})` +
|
|
245
|
+
`\n 📍 ${this.dataParams.stackLocation}`);
|
|
246
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
247
|
+
...this._getDefaultErrorSettings('getDataByDependencyId', new Error(`getDataByDependencyId failed, dependencyKey is missing from service! ` +
|
|
248
|
+
`(${this.dataParams.dataName})`)),
|
|
249
|
+
errorCode: `${this.ecBase}DyNTS-DS-GD1`,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
if (typeof dependencyIds === 'string') {
|
|
253
|
+
if (this.depSettings.length === 1) {
|
|
254
|
+
dependencyIds = { [this.depSettings[0].key]: dependencyIds };
|
|
255
|
+
}
|
|
256
|
+
else if (this.depSettings.length > 1) {
|
|
257
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
258
|
+
...this._getDefaultErrorSettings('getDataByDependencyId', new Error(`getDataByDependencyId failed, there are multiple dependencyKeys, ` +
|
|
259
|
+
`so you need to provide a map of dependencyKeys! ` +
|
|
260
|
+
`(${this.dataParams.dataName})`)),
|
|
261
|
+
errorCode: `${this.ecBase}DyNTS-DS-GD2`,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
else if (!dependencyIds) {
|
|
266
|
+
dependencyIds = {};
|
|
267
|
+
this.depSettings.forEach((depSetting) => {
|
|
268
|
+
if (this.data?.[depSetting.key]) {
|
|
269
|
+
dependencyIds[depSetting.key] = this.data?.[depSetting.key];
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
if (!dependencyIds ||
|
|
274
|
+
this.depSettings.every((depSetting) => !dependencyIds[depSetting.key])) {
|
|
275
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
276
|
+
...this._getDefaultErrorSettings('getDataByDependencyId', new Error(`getDataByDependencyId failed, dependencyId is missing! ` +
|
|
277
|
+
`(${this.dataParams.dataName})`)),
|
|
278
|
+
errorCode: `${this.ecBase}DyNTS-DS-GD3`,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return dependencyIds;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* returns data from database by dependencyId to the service
|
|
285
|
+
* (using id from service.data, if not provided)
|
|
286
|
+
* @param dependencyIds
|
|
287
|
+
*/
|
|
288
|
+
async getDataByDependencyId(dependencyIds, dontSetToService) {
|
|
289
|
+
try {
|
|
290
|
+
const dependencyIdsFilter = this.getDependencyIdsFilter(dependencyIds);
|
|
291
|
+
const dataExists = await this.dataDBService.getDataByDependencyId(dependencyIdsFilter).catch((error) => {
|
|
292
|
+
if (error?.errorCode?.includes('DBS-GD2')) {
|
|
293
|
+
fsm_dynamo_1.DyFM_Log.warn(`getDataByDependencyId failed; "${this.dataParams.dataName}" ` +
|
|
294
|
+
`(${JSON.stringify(dependencyIds)}) didn't found any.`);
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
if (!dontSetToService) {
|
|
302
|
+
this.data = dataExists;
|
|
303
|
+
}
|
|
304
|
+
return dataExists;
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
if ([
|
|
308
|
+
`${this.ecBase}DyNTS-DS0-GD1`,
|
|
309
|
+
`${this.ecBase}DyNTS-DS0-GD2`
|
|
310
|
+
].includes(error?.errorCode)) {
|
|
311
|
+
throw error;
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
315
|
+
...this._getDefaultErrorSettings('getDataByDependencyId', error),
|
|
316
|
+
errorCode: `${this.ecBase}DyNTS-DS-GD0`,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
async getDataListByDependencyIds(dependencyIds, dontSetToService, dependencyKey) {
|
|
322
|
+
try {
|
|
323
|
+
if (!this.depSettings.length) {
|
|
324
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
325
|
+
...this._getDefaultErrorSettings('getDataListByDependencyIds', new Error(`getDataListByDependencyIds failed, dependencyKey is missing from service! ` +
|
|
326
|
+
`(${this.dataParams.dataName})`)),
|
|
327
|
+
errorCode: `${this.ecBase}DyNTS-DS-GDS1`,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
if (!dependencyKey) {
|
|
331
|
+
if (this.depSettings.length === 1) {
|
|
332
|
+
dependencyKey = this.depSettings[0].key;
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
336
|
+
...this._getDefaultErrorSettings('getDataListByDependencyIds', new Error(`getDataListByDependencyIds failed, dependencyKey is missing! ` +
|
|
337
|
+
`since there are multiple dependencyKeys, you need to provide one! ` +
|
|
338
|
+
`(${this.dataParams.dataName})`)),
|
|
339
|
+
errorCode: `${this.ecBase}DyNTS-DS-GDS2`,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (!dependencyIds) {
|
|
344
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
345
|
+
...this._getDefaultErrorSettings('getDataListByDependencyIds', new Error(`getDataListByDependencyIds failed, dependencyIds is missing! ` +
|
|
346
|
+
`(${this.dataParams.dataName})`)),
|
|
347
|
+
errorCode: `${this.ecBase}DyNTS-DS-GDS3`,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
if (dependencyIds.length === 0) {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
const dataList = await this.dataDBService.getDataListByDependencyIds(dependencyKey, dependencyIds);
|
|
354
|
+
if (!dontSetToService) {
|
|
355
|
+
this.dataList = dataList;
|
|
356
|
+
}
|
|
357
|
+
return dataList;
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
if ([
|
|
361
|
+
`${this.ecBase}DyNTS-DS0-GDS1`,
|
|
362
|
+
`${this.ecBase}DyNTS-DS0-GDS2`
|
|
363
|
+
].includes(error?.errorCode)) {
|
|
364
|
+
throw error;
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
368
|
+
...this._getDefaultErrorSettings('getDataListByDependencyIds', error),
|
|
369
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GDS0`,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* returns dataList from database by dependencyId to the service
|
|
376
|
+
* @param dependencyIds
|
|
377
|
+
*/
|
|
378
|
+
async getDataListByDependencyId(dependencyIds, dontSetToService) {
|
|
379
|
+
try {
|
|
380
|
+
const dependencyIdsFilter = this.getDependencyIdsFilter(dependencyIds);
|
|
381
|
+
const dataListExists = await this.dataDBService.getDataListByDependencyId(dependencyIdsFilter).catch((error) => {
|
|
382
|
+
if (error?.errorCode?.includes('DBS-GLD2')) {
|
|
383
|
+
fsm_dynamo_1.DyFM_Log.warn(`getDataListByDependencyId "${this.dataParams.dataName}" ` +
|
|
384
|
+
`(${JSON.stringify(dependencyIdsFilter)}) didn't found any.`);
|
|
385
|
+
return [];
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
throw error;
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
if (!dontSetToService) {
|
|
392
|
+
this.dataList = dataListExists;
|
|
393
|
+
}
|
|
394
|
+
return dataListExists;
|
|
395
|
+
}
|
|
396
|
+
catch (error) {
|
|
397
|
+
if ([
|
|
398
|
+
`${this.ecBase}DyNTS-DS0-GLD1`,
|
|
399
|
+
`${this.ecBase}DyNTS-DS0-GLD2`
|
|
400
|
+
].includes(error?.errorCode)) {
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
405
|
+
...this._getDefaultErrorSettings('getDataListByDependencyId', error),
|
|
406
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GLD0`,
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
*
|
|
413
|
+
* // findOne desc:
|
|
414
|
+
*
|
|
415
|
+
* Find the data first by any of its parameters,
|
|
416
|
+
* also if dontSetToService is false or not setted,
|
|
417
|
+
* the data will be saved to the service, even if non found
|
|
418
|
+
*
|
|
419
|
+
* @param filter if you can, use unique parameters for find!
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* // by email:
|
|
423
|
+
* { email: email }
|
|
424
|
+
* //
|
|
425
|
+
* @example
|
|
426
|
+
* // or by id that is in list:
|
|
427
|
+
* { userIds: { $in: this.userId } }
|
|
428
|
+
* // or by userIds:
|
|
429
|
+
* { userId: { $in: userIds } }
|
|
430
|
+
* //
|
|
431
|
+
* @example
|
|
432
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
433
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
434
|
+
* // further tools (syntax matches with $gt):
|
|
435
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
436
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
437
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
438
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
439
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
440
|
+
* //
|
|
441
|
+
* @returns {T} data: T
|
|
442
|
+
*/
|
|
443
|
+
async findData(filterBy, dontSetToService) {
|
|
444
|
+
try {
|
|
445
|
+
const dataExists = await this.dataDBService.findOne(filterBy).catch((error) => {
|
|
446
|
+
if (error?.errorCode?.includes('DBS-FO1')) {
|
|
447
|
+
fsm_dynamo_1.DyFM_Log.warn(`findData "${this.dataParams.dataName}" didn't found any.`);
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
throw error;
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
if (!dontSetToService) {
|
|
455
|
+
this.data = dataExists;
|
|
456
|
+
}
|
|
457
|
+
return dataExists;
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
461
|
+
...this._getDefaultErrorSettings('findData', error),
|
|
462
|
+
errorCode: `${this.ecBase}DyNTS-DS0-FD0`,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
getDataByQuery = this.findData;
|
|
467
|
+
/**
|
|
468
|
+
*
|
|
469
|
+
* // find desc:
|
|
470
|
+
*
|
|
471
|
+
* Find the data first by any of its parameters,
|
|
472
|
+
* also if dontSetToService is false or not setted,
|
|
473
|
+
* the data will be saved to the service, even if non found
|
|
474
|
+
*
|
|
475
|
+
* @param filter if you can, use unique parameters for find!
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* // by email:
|
|
479
|
+
* { email: email }
|
|
480
|
+
* //
|
|
481
|
+
* @example
|
|
482
|
+
* // or by id that is in list:
|
|
483
|
+
* { userIds: { $in: this.userId } }
|
|
484
|
+
* // or by userIds:
|
|
485
|
+
* { userId: { $in: userIds } }
|
|
486
|
+
* //
|
|
487
|
+
* @example
|
|
488
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
489
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
490
|
+
* // further tools (syntax matches with $gt):
|
|
491
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
492
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
493
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
494
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
495
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
496
|
+
* //
|
|
497
|
+
* @returns {T[]} dataList: T[]
|
|
498
|
+
*/
|
|
499
|
+
async findDataList(filterBy, dontSetToService) {
|
|
500
|
+
try {
|
|
501
|
+
const dataListExists = await this.dataDBService.find(filterBy).catch((error) => {
|
|
502
|
+
if (error?.errorCode?.includes('DBS-F1')) {
|
|
503
|
+
fsm_dynamo_1.DyFM_Log.warn(`findDataList "${this.dataParams.dataName}" didn't found any.`);
|
|
504
|
+
return [];
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
throw error;
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
if (!dontSetToService) {
|
|
511
|
+
this.dataList = dataListExists;
|
|
512
|
+
}
|
|
513
|
+
return dataListExists;
|
|
514
|
+
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
517
|
+
...this._getDefaultErrorSettings('findDataList', error),
|
|
518
|
+
errorCode: `${this.ecBase}DyNTS-DS0-FDS0`,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* This function uses the dataDBService.updateOne function.
|
|
524
|
+
* This uses updateBy if setted, or data._id if its setted or this.data[this.dependencyKey]
|
|
525
|
+
* @param set
|
|
526
|
+
*
|
|
527
|
+
* // updateOne desc:
|
|
528
|
+
*
|
|
529
|
+
* Find the data first by any of its parameters, throws error if not found
|
|
530
|
+
* @param filter This uses the basic Mongoose updateOne.
|
|
531
|
+
* If you can, use unique parameters for find!
|
|
532
|
+
* @example
|
|
533
|
+
* // by email:
|
|
534
|
+
* { email: email }
|
|
535
|
+
* //
|
|
536
|
+
* @example
|
|
537
|
+
* // or by id that is in list:
|
|
538
|
+
* { userIds: { $in: this.userId } }
|
|
539
|
+
* // or by userIds:
|
|
540
|
+
* { userId: { $in: userIds } }
|
|
541
|
+
* //
|
|
542
|
+
* @example
|
|
543
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
544
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
545
|
+
* // further tools (syntax matches with $gt):
|
|
546
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
547
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
548
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
549
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
550
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
551
|
+
* //
|
|
552
|
+
*
|
|
553
|
+
* @param update this uses the basic Mongoose updateOne
|
|
554
|
+
* @example
|
|
555
|
+
* // increase a specific value (here by 15):
|
|
556
|
+
* { $inc: { popularity: 15 } }
|
|
557
|
+
* //
|
|
558
|
+
* @example
|
|
559
|
+
* // or add element to a list:
|
|
560
|
+
* { $push: { reactions: this.newReaction }
|
|
561
|
+
* // or add multiple elements to a list
|
|
562
|
+
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
563
|
+
* //
|
|
564
|
+
* @example
|
|
565
|
+
* // or all at once
|
|
566
|
+
* {
|
|
567
|
+
* $inc: { popularity: this.newVote.amount },
|
|
568
|
+
* emailVerified: true,
|
|
569
|
+
* $push: { reactions: this.newReaction }
|
|
570
|
+
* }
|
|
571
|
+
* // further tools (syntax matches with $inc):
|
|
572
|
+
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
573
|
+
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
574
|
+
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
575
|
+
* $mul: // Multiplies the value of the field by the specified amount.
|
|
576
|
+
* $rename: // Renames a field.
|
|
577
|
+
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
578
|
+
* //
|
|
579
|
+
*/
|
|
580
|
+
async updateData(set, dontUpdateModified) {
|
|
581
|
+
try {
|
|
582
|
+
if (set.filterBy) {
|
|
583
|
+
await this.dataDBService.updateOne(set.filterBy, set.update, this.issuer, dontUpdateModified);
|
|
584
|
+
}
|
|
585
|
+
else if (this.data._id) {
|
|
586
|
+
await this.dataDBService.updateOne({ _id: this.data._id }, set.update, this.issuer, dontUpdateModified);
|
|
587
|
+
}
|
|
588
|
+
else if (this.depSettings.length &&
|
|
589
|
+
this.depSettings.some((depSetting) => this.data[depSetting.key])) {
|
|
590
|
+
const dependencyIdsFilter = {};
|
|
591
|
+
this.depSettings.forEach((depSetting) => {
|
|
592
|
+
if (this.data[depSetting.key]) {
|
|
593
|
+
dependencyIdsFilter[depSetting.key] = this.data[depSetting.key];
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
await this.dataDBService.updateOne(dependencyIdsFilter, set.update, this.issuer, dontUpdateModified);
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
600
|
+
...this._getDefaultErrorSettings('updateData', new Error(`no usable parameter provided for updateData; no updateBy, no id, no dependencyId ` +
|
|
601
|
+
`(${this.dataParams.dataName})`)),
|
|
602
|
+
errorCode: `${this.ecBase}DyNTS-DS0-UD1`,
|
|
603
|
+
additionalContent: {
|
|
604
|
+
data: this.data,
|
|
605
|
+
filterBy: set.filterBy,
|
|
606
|
+
},
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
catch (error) {
|
|
611
|
+
if (error?.errorCode?.includes('DS0-UD1')) {
|
|
612
|
+
throw error;
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
616
|
+
...this._getDefaultErrorSettings('updateData', error),
|
|
617
|
+
errorCode: `${this.ecBase}DyNTS-DS0-UD0`,
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
ensureData(data) {
|
|
623
|
+
if (!data && this.data) {
|
|
624
|
+
data = this.data;
|
|
625
|
+
}
|
|
626
|
+
if (!data) {
|
|
627
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
628
|
+
...this._getDefaultErrorSettings('ensureData', new Error(`no data to save! (${this.dataParams.dataName})`)),
|
|
629
|
+
errorCode: `${this.ecBase}DyNTS-DS0-ED0`,
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
return data;
|
|
633
|
+
}
|
|
634
|
+
async patchData(data) {
|
|
635
|
+
try {
|
|
636
|
+
if (!data._id) {
|
|
637
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
638
|
+
...this._getDefaultErrorSettings('patchData', new Error(`no ID to patch data! (${this.dataParams.dataName})`)),
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
const dataExists = await this.getDataById(data._id, true);
|
|
642
|
+
if (!dataExists) {
|
|
643
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
644
|
+
...this._getDefaultErrorSettings('patchData', new Error(`data not found! (${this.dataParams.dataName})`)),
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
for (const key in this.depSettings) {
|
|
648
|
+
if (data[key] && data[key] !== dataExists[key]) {
|
|
649
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
650
|
+
...this._getDefaultErrorSettings('patchData', new Error(`Cannot patch data: dependency data mismatch! (${this.dataParams.dataName})`)),
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
fsm_dynamo_1.DyFM_Object.cleanAssign(dataExists, data);
|
|
655
|
+
await this.validateForSave(dataExists);
|
|
656
|
+
return await this.dataDBService.modifyData(dataExists, this.issuer);
|
|
657
|
+
}
|
|
658
|
+
catch (error) {
|
|
659
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
660
|
+
...this._getDefaultErrorSettings('patchData', error),
|
|
661
|
+
errorCode: `${this.ecBase}DyNTS-DS0-PD0`,
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* modifies data if the data have ID and already exists in the DB,
|
|
667
|
+
* creates new if the ID is not present or cant find in DB,
|
|
668
|
+
* and if dependency data setted up, will check before creation,
|
|
669
|
+
*
|
|
670
|
+
* @warning
|
|
671
|
+
* but the proper way to update data, if you use update method instead,
|
|
672
|
+
* this way, you can avoid data override errors
|
|
673
|
+
* (when you simultaneously trying to change the same data's
|
|
674
|
+
* different values from different flows)
|
|
675
|
+
*/
|
|
676
|
+
async saveData(data, dontSetToService, dontUpdateModified) {
|
|
677
|
+
try {
|
|
678
|
+
data = this.ensureData(data);
|
|
679
|
+
await this.validateForSave(data);
|
|
680
|
+
if (!data._id) {
|
|
681
|
+
if (this.depSettings.length &&
|
|
682
|
+
this.depSettings.some((depSetting) => !data[depSetting.key])) {
|
|
683
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
684
|
+
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: dependency data id missing from data ` +
|
|
685
|
+
`(key: ${this.depSettings.map((depSetting) => depSetting.key).join(', ')}, ` +
|
|
686
|
+
`${this.dataParams.dataName})`)),
|
|
687
|
+
errorCode: `${this.ecBase}DyNTS-DS0-SD1`,
|
|
688
|
+
additionalContent: {
|
|
689
|
+
data: data,
|
|
690
|
+
},
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
// if ID of dependencyID is not present, data not exists, create new data
|
|
694
|
+
data = await this.dataDBService.createData(data, this.issuer);
|
|
695
|
+
if (!dontSetToService) {
|
|
696
|
+
this.data = data;
|
|
697
|
+
}
|
|
698
|
+
return data;
|
|
699
|
+
}
|
|
700
|
+
let dataExists;
|
|
701
|
+
// check if data already exists with the specific ID
|
|
702
|
+
if (data._id) {
|
|
703
|
+
dataExists = await this.getDataById(data._id, true);
|
|
704
|
+
if (!dataExists) {
|
|
705
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
706
|
+
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: provided ID not exists ` +
|
|
707
|
+
`(id: "${data._id}", ${this.dataParams.dataName})`)),
|
|
708
|
+
errorCode: `${this.ecBase}DyNTS-DS0-SD2`,
|
|
709
|
+
additionalContent: {
|
|
710
|
+
data: data,
|
|
711
|
+
},
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
// if data exists do modify
|
|
715
|
+
data = await this.dataDBService.modifyData(data, this.issuer, dontUpdateModified);
|
|
716
|
+
if (!dontSetToService) {
|
|
717
|
+
this.data = data;
|
|
718
|
+
}
|
|
719
|
+
return data;
|
|
720
|
+
}
|
|
721
|
+
if (this.depSettings.length) {
|
|
722
|
+
if (this.depSettings.some((depSetting) => !data[depSetting.key])) {
|
|
723
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
724
|
+
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: dependency data id missing from data ` +
|
|
725
|
+
`(key: ${this.depSettings.map((depSetting) => depSetting.key).join(', ')}, ` +
|
|
726
|
+
`${this.dataParams.dataName})`)),
|
|
727
|
+
errorCode: `${this.ecBase}DyNTS-DS0-SD3`,
|
|
728
|
+
additionalContent: {
|
|
729
|
+
data: data,
|
|
730
|
+
},
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
if (this.depSettings.some((depSetting) => depSetting.keyIsRequired)) {
|
|
734
|
+
await fsm_dynamo_1.DyFM_Array.asyncForEach(this.depSettings, async (depSetting) => {
|
|
735
|
+
if (depSetting.keyIsRequired) {
|
|
736
|
+
if (!data[depSetting.key]) {
|
|
737
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
738
|
+
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: dependency data id missing from data ` +
|
|
739
|
+
`(key: ${depSetting.key}, ${this.dataParams.dataName})`)),
|
|
740
|
+
errorCode: `${this.ecBase}DyNTS-DS0-SD4`,
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
const dependencyExists = await this.getDependencyDataDBService(depSetting.dbServiceKey)
|
|
744
|
+
.getDataById(data[depSetting.key])
|
|
745
|
+
.catch();
|
|
746
|
+
if (!dependencyExists) {
|
|
747
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
748
|
+
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: dependency data not exists ` +
|
|
749
|
+
`(key: ${depSetting.key}, id: "${data[depSetting.key]}", ` +
|
|
750
|
+
`${this.dataParams.dataName})`)),
|
|
751
|
+
errorCode: `${this.ecBase}DyNTS-DS0-SD4`,
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
/* the db is handling the unique key, so no need to check it here
|
|
758
|
+
if (this.depKeyIsUnique) {
|
|
759
|
+
dataExists = await this.getDataByDependencyId(data[this.depKeys], true);
|
|
760
|
+
|
|
761
|
+
if (dataExists) {
|
|
762
|
+
// if data exists do modify
|
|
763
|
+
data = await this.dataDBService.modifyData(data, this.issuer, dontUpdateModified);
|
|
764
|
+
|
|
765
|
+
if (!dontSetToService) {
|
|
766
|
+
this.data = data;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
return data;
|
|
770
|
+
|
|
771
|
+
}
|
|
772
|
+
} */
|
|
773
|
+
}
|
|
774
|
+
// if data not exists create new data
|
|
775
|
+
data = await this.dataDBService.createData(data, this.issuer);
|
|
776
|
+
if (!data._id) {
|
|
777
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
778
|
+
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: data creation failed ` +
|
|
779
|
+
`(${this.dataParams.dataName})`)),
|
|
780
|
+
errorCode: `${this.ecBase}DyNTS-DS0-SD5`,
|
|
781
|
+
additionalContent: {
|
|
782
|
+
data: data,
|
|
783
|
+
},
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
if (!dontSetToService) {
|
|
787
|
+
this.data = data;
|
|
788
|
+
}
|
|
789
|
+
return data;
|
|
790
|
+
}
|
|
791
|
+
catch (error) {
|
|
792
|
+
if ([
|
|
793
|
+
`${this.ecBase}DyNTS-DS0-SD1`,
|
|
794
|
+
`${this.ecBase}DyNTS-DS0-SD2`,
|
|
795
|
+
`${this.ecBase}DyNTS-DS0-SD3`,
|
|
796
|
+
`${this.ecBase}DyNTS-DS0-SD4`,
|
|
797
|
+
`${this.ecBase}DyNTS-DS0-SD5`,
|
|
798
|
+
].includes(error?.errorCode)) {
|
|
799
|
+
throw error;
|
|
800
|
+
}
|
|
801
|
+
else {
|
|
802
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
803
|
+
...this._getDefaultErrorSettings('saveData', error),
|
|
804
|
+
errorCode: `${this.ecBase}DyNTS-DS0-SD0`,
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* markes data as deleted, if can be archived, will be archived as well
|
|
811
|
+
* if absolute is true, permanently deletes data from database by data._id
|
|
812
|
+
*/
|
|
813
|
+
async deleteData(id, absolute) {
|
|
814
|
+
try {
|
|
815
|
+
if (!id && this.data._id) {
|
|
816
|
+
id = this.data._id;
|
|
817
|
+
}
|
|
818
|
+
if (!id) {
|
|
819
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
820
|
+
...this._getDefaultErrorSettings('deleteData', new Error(`deleteData failed, ID is missing! (${this.dataParams.dataName})`)),
|
|
821
|
+
errorCode: `${this.ecBase}DyNTS-DS0-DD1`,
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
this.data = await this.getDataById(id, true);
|
|
825
|
+
if (!this.data) {
|
|
826
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
827
|
+
...this._getDefaultErrorSettings('deleteData', new Error(`deleteData failed, data not found! (${this.dataParams.dataName})`)),
|
|
828
|
+
errorCode: `${this.ecBase}DyNTS-DS0-DD2`,
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
if (this.haveArchiveDataService) {
|
|
832
|
+
const archive_DS = this.getArchiveDataService();
|
|
833
|
+
await this.dataDBService.trueDeleteDataById(id);
|
|
834
|
+
this.data._deleted = new Date();
|
|
835
|
+
this.data._deletedBy = this.issuer;
|
|
836
|
+
this.data._originalId = this.data._id;
|
|
837
|
+
this.data._archived = new Date();
|
|
838
|
+
delete this.data._id;
|
|
839
|
+
await archive_DS.saveData(this.data, true);
|
|
840
|
+
}
|
|
841
|
+
else if (absolute) {
|
|
842
|
+
await this.dataDBService.trueDeleteDataById(id);
|
|
843
|
+
delete this.data._id;
|
|
844
|
+
}
|
|
845
|
+
else {
|
|
846
|
+
await this.dataDBService.markDeletedById(id, this.issuer);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
catch (error) {
|
|
850
|
+
if (error?.errorCode?.includes('DS0-DD1')) {
|
|
851
|
+
throw error;
|
|
852
|
+
}
|
|
853
|
+
else {
|
|
854
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
855
|
+
...this._getDefaultErrorSettings('deleteData', error),
|
|
856
|
+
errorCode: `${this.ecBase}DyNTS-DS0-DD0`,
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
async deleteAllData(absolute) {
|
|
862
|
+
try {
|
|
863
|
+
this.dataList = await this.getAll(true);
|
|
864
|
+
if (this.haveArchiveDataService) {
|
|
865
|
+
const archive_DS = this.getArchiveDataService();
|
|
866
|
+
await this.dataDBService.trueDeleteAllData();
|
|
867
|
+
await fsm_dynamo_1.DyFM_Array.asyncForEachAllAtOnce(this.dataList, async (data) => {
|
|
868
|
+
data._deleted = new Date();
|
|
869
|
+
data._deletedBy = this.issuer;
|
|
870
|
+
data._originalId = data._id;
|
|
871
|
+
data._archived = new Date();
|
|
872
|
+
delete data._id;
|
|
873
|
+
await archive_DS.saveData(data, true);
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
else if (absolute) {
|
|
877
|
+
await this.dataDBService.trueDeleteAllData();
|
|
878
|
+
this.dataList.forEach((data) => {
|
|
879
|
+
delete data._id;
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
else {
|
|
883
|
+
await fsm_dynamo_1.DyFM_Array.asyncForEachAllAtOnce(this.dataList, async (data) => {
|
|
884
|
+
await this.dataDBService.markDeletedById(data._id, this.issuer);
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
catch (error) {
|
|
889
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
890
|
+
...this._getDefaultErrorSettings('deleteAllData', error),
|
|
891
|
+
errorCode: `${this.ecBase}DyNTS-DS0-DAD0`,
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
restoreDeletedData(id) {
|
|
896
|
+
try {
|
|
897
|
+
if (!id && this.data._id) {
|
|
898
|
+
id = this.data._id;
|
|
899
|
+
}
|
|
900
|
+
if (!id) {
|
|
901
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
902
|
+
...this._getDefaultErrorSettings('restoreDeletedData', new Error(`restoreDeletedData failed, ID is missing! (${this.dataParams.dataName})`)),
|
|
903
|
+
errorCode: `${this.ecBase}DyNTS-DS0-RD1`,
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
let archive_DS;
|
|
907
|
+
try {
|
|
908
|
+
archive_DS = global_service_1.DyNTS_GlobalService.getDBServiceByKey((0, archive_util_1.DyNTS_getArchivedDBName)(this.dataParams.dataName));
|
|
909
|
+
}
|
|
910
|
+
catch (error) { }
|
|
911
|
+
if (archive_DS) {
|
|
912
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
913
|
+
...this._getDefaultErrorSettings('restoreDeletedData', new Error(`restoreDeletedData failed, archive service is setted up, ` +
|
|
914
|
+
`archived restoration not implemented yet! ` +
|
|
915
|
+
`(request implementation, and restore by yourself)`)),
|
|
916
|
+
errorCode: `${this.ecBase}DyNTS-DS0-RD2`,
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
return this.dataDBService.restoreDeletedById(id, this.issuer);
|
|
920
|
+
}
|
|
921
|
+
catch (error) {
|
|
922
|
+
if (error?.errorCode?.includes('DS0-RD1')) {
|
|
923
|
+
throw error;
|
|
924
|
+
}
|
|
925
|
+
else {
|
|
926
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
927
|
+
...this._getDefaultErrorSettings('restoreDeletedData', error),
|
|
928
|
+
errorCode: `${this.ecBase}DyNTS-DS0-RD0`,
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* validation of data, for modify and create, by the ModelParams
|
|
935
|
+
*/
|
|
936
|
+
async validateForSave(data) {
|
|
937
|
+
try {
|
|
938
|
+
data = this.ensureData(data);
|
|
939
|
+
if (!data) {
|
|
940
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
941
|
+
...this._getDefaultErrorSettings('validateForSave', new Error('No data to validate! (validateForSave)')),
|
|
942
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VBP0`,
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
await this.validateDataByPropertyParams(data, this.dataParams.properties);
|
|
946
|
+
}
|
|
947
|
+
catch (error) {
|
|
948
|
+
if (error?.errorCode?.includes?.('DyNTS-DS0-VBP') || error?.errorCode?.includes?.('DyNTS-DS0-VP')) {
|
|
949
|
+
throw error;
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
953
|
+
...this._getDefaultErrorSettings('validateForSave', error),
|
|
954
|
+
status: 522,
|
|
955
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VD0`,
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
validateDataByPropertyParams(data, properties, isSubObjectOf) {
|
|
961
|
+
try {
|
|
962
|
+
if (!data) {
|
|
963
|
+
if (isSubObjectOf?.required) {
|
|
964
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
965
|
+
...this._getDefaultErrorSettings('validateDataByPropertyParams', new Error(`validateData failed, data is required! ` +
|
|
966
|
+
`(${isSubObjectOf?.key ? `${isSubObjectOf.key}.` : ''}${this.dataParams.dataName})` +
|
|
967
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
968
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VDP1`,
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
else {
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
else if (isSubObjectOf?.forbidden) {
|
|
976
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
977
|
+
...this._getDefaultErrorSettings('validateDataByPropertyParams', new Error(`validateData failed, data is forbidden! ` +
|
|
978
|
+
`(${isSubObjectOf?.key ? `${isSubObjectOf.key}.` : ''}${this.dataParams.dataName})` +
|
|
979
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
980
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VDP2`,
|
|
981
|
+
additionalContent: {
|
|
982
|
+
data: data,
|
|
983
|
+
},
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
const validationErrors = [];
|
|
987
|
+
Object.values(properties).forEach((propertyParams) => {
|
|
988
|
+
try {
|
|
989
|
+
this.validateProperty(data, data[propertyParams.key], propertyParams, isSubObjectOf);
|
|
990
|
+
}
|
|
991
|
+
catch (error) {
|
|
992
|
+
validationErrors.push(error);
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
if (validationErrors.length > 0) {
|
|
996
|
+
if (validationErrors.length === 1) {
|
|
997
|
+
throw validationErrors[0];
|
|
998
|
+
}
|
|
999
|
+
else {
|
|
1000
|
+
const validationErrorsSet = {};
|
|
1001
|
+
validationErrors.forEach((error) => {
|
|
1002
|
+
Object.keys(error.validationErrors).forEach((key) => {
|
|
1003
|
+
validationErrors[key] = error.validationErrors[key];
|
|
1004
|
+
});
|
|
1005
|
+
});
|
|
1006
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1007
|
+
...this._getDefaultErrorSettings('validateByPropertyParams', new Error(`Validation failed! (multiple validation errors for ${this.dataParams.dataName})` +
|
|
1008
|
+
validationErrors.map((error) => `\n ${fsm_dynamo_1.DyFM_Error.getAnyMessage(error)}`).join(''))),
|
|
1009
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VDP3`,
|
|
1010
|
+
errors: validationErrors,
|
|
1011
|
+
validationErrors: validationErrorsSet,
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
catch (error) {
|
|
1017
|
+
if (error?.errorCode?.includes?.('DyNTS-DS0-VDP')) {
|
|
1018
|
+
throw error;
|
|
1019
|
+
}
|
|
1020
|
+
else {
|
|
1021
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1022
|
+
...this._getDefaultErrorSettings('validateByPropertyParams', error),
|
|
1023
|
+
status: 522,
|
|
1024
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VDP0`,
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
getPropertyKey(propertyParams, isSubObjectOf) {
|
|
1030
|
+
return (isSubObjectOf && isSubObjectOf.key !== propertyParams.key) ?
|
|
1031
|
+
`${isSubObjectOf.key}.${propertyParams.key}` : propertyParams.key;
|
|
1032
|
+
}
|
|
1033
|
+
validateProperty(data, propertyValue, propertyParams, isSubObjectOf) {
|
|
1034
|
+
// basic required validations
|
|
1035
|
+
if (propertyParams.required && (propertyValue === null ||
|
|
1036
|
+
propertyValue === undefined)) {
|
|
1037
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1038
|
+
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is missing! ` +
|
|
1039
|
+
`(required in "${this.dataParams.dataName}" dataParams) ` +
|
|
1040
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1041
|
+
status: 522,
|
|
1042
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VP1`,
|
|
1043
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1044
|
+
validationErrors: {
|
|
1045
|
+
[propertyParams.key]: {
|
|
1046
|
+
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is missing! ` +
|
|
1047
|
+
`(required in "${this.dataParams.dataName}" dataParams) ` +
|
|
1048
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1049
|
+
code: `${this.ecBase}DyNTS-DS0-VP1`,
|
|
1050
|
+
userMessage: 'The property is required and must be a valid value!',
|
|
1051
|
+
},
|
|
1052
|
+
},
|
|
1053
|
+
__localStack: this.dataParams.stackLocation,
|
|
1054
|
+
additionalContent: {
|
|
1055
|
+
data: data,
|
|
1056
|
+
},
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
else if (propertyParams.forbidden &&
|
|
1060
|
+
propertyValue !== undefined) {
|
|
1061
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1062
|
+
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is forbidden! ` +
|
|
1063
|
+
`(${this.dataParams.dataName}) ` +
|
|
1064
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1065
|
+
status: 522,
|
|
1066
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VP2`,
|
|
1067
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1068
|
+
validationErrors: {
|
|
1069
|
+
[propertyParams.key]: {
|
|
1070
|
+
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is forbidden! ` +
|
|
1071
|
+
`(${this.dataParams.dataName}) ` +
|
|
1072
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1073
|
+
code: `${this.ecBase}DyNTS-DS0-VP2`,
|
|
1074
|
+
userMessage: 'The property modification is forbidden!',
|
|
1075
|
+
},
|
|
1076
|
+
},
|
|
1077
|
+
__localStack: this.dataParams.stackLocation,
|
|
1078
|
+
additionalContent: {
|
|
1079
|
+
data: data,
|
|
1080
|
+
},
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
// specific Date validation
|
|
1084
|
+
switch (propertyParams.type) {
|
|
1085
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.date:
|
|
1086
|
+
const date = new Date(propertyValue);
|
|
1087
|
+
if (propertyParams.required && (!(date instanceof Date) ||
|
|
1088
|
+
date.toString() === 'Invalid Date' ||
|
|
1089
|
+
isNaN(date.getTime()) ||
|
|
1090
|
+
date.toString() === new Date(0).toString())) {
|
|
1091
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1092
|
+
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid date! ` +
|
|
1093
|
+
`(${this.dataParams.dataName})` +
|
|
1094
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1095
|
+
status: 522,
|
|
1096
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VP3`,
|
|
1097
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1098
|
+
validationErrors: {
|
|
1099
|
+
[propertyParams.key]: {
|
|
1100
|
+
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid date! ` +
|
|
1101
|
+
`(${this.dataParams.dataName})` +
|
|
1102
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1103
|
+
code: `${this.ecBase}DyNTS-DS0-VP3`,
|
|
1104
|
+
userMessage: 'The property is required and must be a valid date!',
|
|
1105
|
+
},
|
|
1106
|
+
},
|
|
1107
|
+
__localStack: this.dataParams.stackLocation,
|
|
1108
|
+
additionalContent: {
|
|
1109
|
+
data: data,
|
|
1110
|
+
},
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
break;
|
|
1114
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.number:
|
|
1115
|
+
if (propertyParams.required && isNaN(propertyValue)) {
|
|
1116
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1117
|
+
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid number! ` +
|
|
1118
|
+
`(${this.dataParams.dataName})` +
|
|
1119
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1120
|
+
status: 522,
|
|
1121
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VP4`,
|
|
1122
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1123
|
+
validationErrors: {
|
|
1124
|
+
[propertyParams.key]: {
|
|
1125
|
+
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid number! ` +
|
|
1126
|
+
`(${this.dataParams.dataName})` +
|
|
1127
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1128
|
+
code: `${this.ecBase}DyNTS-DS0-VP4`,
|
|
1129
|
+
userMessage: 'The property is required and must be a valid number!',
|
|
1130
|
+
},
|
|
1131
|
+
},
|
|
1132
|
+
__localStack: this.dataParams.stackLocation,
|
|
1133
|
+
additionalContent: {
|
|
1134
|
+
data: data,
|
|
1135
|
+
},
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
break;
|
|
1139
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.string:
|
|
1140
|
+
if (propertyParams.required && typeof propertyValue !== 'string') {
|
|
1141
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1142
|
+
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid string! ` +
|
|
1143
|
+
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1144
|
+
`(${this.dataParams.dataName})` +
|
|
1145
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1146
|
+
status: 522,
|
|
1147
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VP5`,
|
|
1148
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1149
|
+
validationErrors: {
|
|
1150
|
+
[propertyParams.key]: {
|
|
1151
|
+
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid string! ` +
|
|
1152
|
+
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1153
|
+
`(${this.dataParams.dataName})` +
|
|
1154
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1155
|
+
code: `${this.ecBase}DyNTS-DS0-VP5`,
|
|
1156
|
+
userMessage: 'The property is required and must be a valid string!',
|
|
1157
|
+
},
|
|
1158
|
+
},
|
|
1159
|
+
__localStack: this.dataParams.stackLocation,
|
|
1160
|
+
additionalContent: {
|
|
1161
|
+
data: data,
|
|
1162
|
+
},
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
break;
|
|
1166
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.boolean:
|
|
1167
|
+
if (propertyParams.required && typeof propertyValue !== 'boolean') {
|
|
1168
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1169
|
+
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid boolean! ` +
|
|
1170
|
+
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1171
|
+
`(${this.dataParams.dataName})` +
|
|
1172
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1173
|
+
status: 522,
|
|
1174
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VP6`,
|
|
1175
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1176
|
+
validationErrors: {
|
|
1177
|
+
[propertyParams.key]: {
|
|
1178
|
+
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid boolean! ` +
|
|
1179
|
+
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1180
|
+
`(${this.dataParams.dataName})` +
|
|
1181
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1182
|
+
code: `${this.ecBase}DyNTS-DS0-VP6`,
|
|
1183
|
+
userMessage: 'The property is required and must be a valid boolean!',
|
|
1184
|
+
},
|
|
1185
|
+
},
|
|
1186
|
+
__localStack: this.dataParams.stackLocation,
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
break;
|
|
1190
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.object:
|
|
1191
|
+
if (propertyParams.required && typeof propertyValue !== 'object') {
|
|
1192
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1193
|
+
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid object! ` +
|
|
1194
|
+
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1195
|
+
`(${this.dataParams.dataName})` +
|
|
1196
|
+
data?.name ? `\n That failed data's name: ${data.name}` : '')),
|
|
1197
|
+
status: 522,
|
|
1198
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VP7`,
|
|
1199
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1200
|
+
validationErrors: {
|
|
1201
|
+
[propertyParams.key]: {
|
|
1202
|
+
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid object! ` +
|
|
1203
|
+
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1204
|
+
`(${this.dataParams.dataName})` +
|
|
1205
|
+
data?.name ? `\n That failed data's name: ${data.name}` : '',
|
|
1206
|
+
code: `${this.ecBase}DyNTS-DS0-VP7`,
|
|
1207
|
+
userMessage: 'The property is required and must be an object!',
|
|
1208
|
+
},
|
|
1209
|
+
},
|
|
1210
|
+
__localStack: this.dataParams.stackLocation,
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
if (propertyParams.subObjectParams) {
|
|
1214
|
+
this.validateDataByPropertyParams(propertyValue, propertyParams.subObjectParams, propertyParams);
|
|
1215
|
+
}
|
|
1216
|
+
break;
|
|
1217
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.array:
|
|
1218
|
+
if (propertyParams.required && (!Array.isArray(propertyValue) || !propertyValue.length)) {
|
|
1219
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1220
|
+
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid array! ` +
|
|
1221
|
+
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1222
|
+
`(${this.dataParams.dataName})` +
|
|
1223
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1224
|
+
status: 522,
|
|
1225
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VP8`,
|
|
1226
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1227
|
+
validationErrors: {
|
|
1228
|
+
[propertyParams.key]: {
|
|
1229
|
+
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid array! ` +
|
|
1230
|
+
`(type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1231
|
+
`(${this.dataParams.dataName})` +
|
|
1232
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1233
|
+
code: `${this.ecBase}DyNTS-DS0-VP8`,
|
|
1234
|
+
userMessage: 'The property is required and must be a valid array!',
|
|
1235
|
+
},
|
|
1236
|
+
},
|
|
1237
|
+
__localStack: this.dataParams.stackLocation,
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
if (propertyParams.subObjectParams) {
|
|
1241
|
+
propertyValue.forEach((item) => {
|
|
1242
|
+
this.validateDataByPropertyParams(item, propertyParams.subObjectParams, propertyParams);
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
break;
|
|
1246
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.function:
|
|
1247
|
+
fsm_dynamo_1.DyFM_Log.warn('validateProperty: function type is not supported yet! ' +
|
|
1248
|
+
'(it will be skipped, but you still can use it in additionalValidators)');
|
|
1249
|
+
/* if (propertyParams.required && typeof propertyValue !== 'function') {
|
|
1250
|
+
throw new DyFM_Error({
|
|
1251
|
+
...this._getDefaultErrorSettings(
|
|
1252
|
+
'validateProperty',
|
|
1253
|
+
new Error(
|
|
1254
|
+
`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid function! ` +
|
|
1255
|
+
`(${this.dataParams.dataName})` +
|
|
1256
|
+
((data as any)?.name ? `\n The failed data's name: ${(data as any).name}` : '')
|
|
1257
|
+
)
|
|
1258
|
+
),
|
|
1259
|
+
|
|
1260
|
+
status: 522,
|
|
1261
|
+
errorCode: `${this.ecBase}VP9`,
|
|
1262
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1263
|
+
validationErrors: {
|
|
1264
|
+
[propertyParams.key]: {
|
|
1265
|
+
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid function! ` +
|
|
1266
|
+
`(${this.dataParams.dataName})` +
|
|
1267
|
+
((data as any)?.name ? `\n The failed data's name: ${(data as any).name}` : ''),
|
|
1268
|
+
code: `${this.ecBase}DyNTS-DS0-VP9`,
|
|
1269
|
+
userMessage: 'The property is required and must be a valid function!',
|
|
1270
|
+
},
|
|
1271
|
+
},
|
|
1272
|
+
__localStack: this.dataParams.stackLocation,
|
|
1273
|
+
});
|
|
1274
|
+
} */
|
|
1275
|
+
break;
|
|
1276
|
+
default:
|
|
1277
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1278
|
+
...this._getDefaultErrorSettings('validateProperty', new Error(`validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid property type! ` +
|
|
1279
|
+
`(type: ${propertyParams.type}, nonBasicType: ${propertyParams.nonBasicType}) ` +
|
|
1280
|
+
`(value type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1281
|
+
`(${this.dataParams.dataName})` +
|
|
1282
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''))),
|
|
1283
|
+
status: 522,
|
|
1284
|
+
errorCode: `${this.ecBase}DyNTS-DS0-VP10`,
|
|
1285
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1286
|
+
validationErrors: {
|
|
1287
|
+
[propertyParams.key]: {
|
|
1288
|
+
message: `validateProperty failed, "${this.getPropertyKey(propertyParams, isSubObjectOf)}" is not a valid property type! ` +
|
|
1289
|
+
`(type: ${propertyParams.type}, nonBasicType: ${propertyParams.nonBasicType}) ` +
|
|
1290
|
+
`(value type: ${typeof propertyValue}, value: "${propertyValue}") ` +
|
|
1291
|
+
`(${this.dataParams.dataName})` +
|
|
1292
|
+
(data?.name ? `\n The failed data's name: ${data.name}` : ''),
|
|
1293
|
+
code: `${this.ecBase}DyNTS-DS0-VP10`,
|
|
1294
|
+
userMessage: 'The property is required and must be a valid property type!',
|
|
1295
|
+
},
|
|
1296
|
+
},
|
|
1297
|
+
__localStack: this.dataParams.stackLocation,
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
// call additional validators
|
|
1301
|
+
if (propertyParams.additionalValidators) {
|
|
1302
|
+
for (let j = 0; j < propertyParams.additionalValidators.length; j++) {
|
|
1303
|
+
propertyParams.additionalValidators[j](propertyValue, data);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Search the data list based on the search query
|
|
1309
|
+
* Sorts and filters the data list based on the search query
|
|
1310
|
+
*
|
|
1311
|
+
* NOTE: For more simple and with better performance and if you don't need sorting, use findDataList instead.
|
|
1312
|
+
*
|
|
1313
|
+
* @example
|
|
1314
|
+
* ```ts
|
|
1315
|
+
* const searchResult = await this.searchData({
|
|
1316
|
+
* filterBy: {
|
|
1317
|
+
* name: 'John Doe',
|
|
1318
|
+
* },
|
|
1319
|
+
* sortBy: [
|
|
1320
|
+
* { key: 'name', order: 1 },
|
|
1321
|
+
* ],
|
|
1322
|
+
* });
|
|
1323
|
+
* ```
|
|
1324
|
+
*/
|
|
1325
|
+
async searchData(query, dataList) {
|
|
1326
|
+
try {
|
|
1327
|
+
const searchResult = await this.sortAndFilterDataList(query, dataList);
|
|
1328
|
+
if (query.page !== undefined && query.pageSize !== undefined) {
|
|
1329
|
+
const start = query.page * query.pageSize;
|
|
1330
|
+
const end = start + query.pageSize;
|
|
1331
|
+
searchResult.results = searchResult.results.slice(start, end);
|
|
1332
|
+
}
|
|
1333
|
+
return searchResult;
|
|
1334
|
+
}
|
|
1335
|
+
catch (error) {
|
|
1336
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1337
|
+
...this._getDefaultErrorSettings('searchData', error),
|
|
1338
|
+
errorCode: `${this.ecBase}DyNTS-DS0-SD0`,
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
async sortAndFilterDataList(query, dataList) {
|
|
1343
|
+
try {
|
|
1344
|
+
if (!query.filterBy) {
|
|
1345
|
+
query.filterBy = {};
|
|
1346
|
+
}
|
|
1347
|
+
if (!query.page) {
|
|
1348
|
+
query.page = 0;
|
|
1349
|
+
}
|
|
1350
|
+
if (!query.pageSize) {
|
|
1351
|
+
fsm_dynamo_1.DyFM_Log.warn(`searchData pageSize is not setted, setting to ${global_settings_const_1.DyNTS_global_settings.defaultPageSize}.`);
|
|
1352
|
+
query.pageSize = global_settings_const_1.DyNTS_global_settings.defaultPageSize;
|
|
1353
|
+
}
|
|
1354
|
+
if (!query.sortBy?.length) {
|
|
1355
|
+
query.sortBy = [{ key: '__lastModified', order: -1 }];
|
|
1356
|
+
}
|
|
1357
|
+
query.sortBy.reverse();
|
|
1358
|
+
let preFilter = {};
|
|
1359
|
+
Object.keys(query.filterBy).forEach((key) => {
|
|
1360
|
+
if (typeof query.filterBy[key] === 'object' &&
|
|
1361
|
+
Object.keys(query.filterBy[key]).includes('$')) {
|
|
1362
|
+
preFilter[key] = query.filterBy[key];
|
|
1363
|
+
delete query.filterBy[key];
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
if (!dataList) {
|
|
1367
|
+
if (Object.keys(preFilter).length) {
|
|
1368
|
+
dataList = await this.findDataList(preFilter);
|
|
1369
|
+
}
|
|
1370
|
+
else {
|
|
1371
|
+
dataList = await this.getAll();
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
else {
|
|
1375
|
+
if (Object.keys(preFilter).length) {
|
|
1376
|
+
fsm_dynamo_1.DyFM_Log.H_warn('prefilters not supported when dataList is set! (will be ignored the following keys: ' +
|
|
1377
|
+
Object.keys(preFilter).map((key) => `"${key}"`).join(', ') +
|
|
1378
|
+
')');
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
const filterKeys = Object.keys(query.filterBy);
|
|
1382
|
+
const filterFunctionsByKey = {};
|
|
1383
|
+
const addFilterKeys = [];
|
|
1384
|
+
const removeFilterKeys = [];
|
|
1385
|
+
filterKeys.forEach((key) => {
|
|
1386
|
+
const filterBy = query.filterBy[key];
|
|
1387
|
+
if (filterBy.isSpecialNestSearch) {
|
|
1388
|
+
filterBy.nestedPropertySearches.forEach((nestSearch) => {
|
|
1389
|
+
const nestKey = nestSearch.nestKeys.join('.');
|
|
1390
|
+
filterFunctionsByKey[nestKey] = this.getFilterFunctionForKey(nestKey, nestSearch.search, nestSearch.valueType);
|
|
1391
|
+
query.filterBy[nestKey] = nestSearch;
|
|
1392
|
+
addFilterKeys.push(nestKey);
|
|
1393
|
+
});
|
|
1394
|
+
removeFilterKeys.push(key);
|
|
1395
|
+
}
|
|
1396
|
+
else {
|
|
1397
|
+
filterFunctionsByKey[key] = this.getFilterFunctionForKey(key, filterBy);
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
addFilterKeys.forEach((key) => {
|
|
1401
|
+
filterKeys.push(key);
|
|
1402
|
+
});
|
|
1403
|
+
removeFilterKeys.forEach((key) => {
|
|
1404
|
+
filterKeys.splice(filterKeys.indexOf(key), 1);
|
|
1405
|
+
});
|
|
1406
|
+
query.sortBy.forEach((sort) => {
|
|
1407
|
+
dataList.sort(this.getSortFunctionForKey(sort));
|
|
1408
|
+
});
|
|
1409
|
+
if (filterKeys.some((key) => key.includes('.'))) {
|
|
1410
|
+
const keyResolvers = {};
|
|
1411
|
+
filterKeys.forEach((key) => {
|
|
1412
|
+
if (key.includes('.')) {
|
|
1413
|
+
if (!query.filterBy[key].nestKeys) {
|
|
1414
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1415
|
+
...this._getDefaultErrorSettings('searchData', new Error(`searchData failed, nestKeys missing from nestedPropertySearch! ` +
|
|
1416
|
+
`(${this.dataParams.dataName})`)),
|
|
1417
|
+
errorCode: `${this.ecBase}DyNTS-DS0-SD1`,
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
keyResolvers[key] = this.getKeyResolver(query.filterBy[key].nestKeys);
|
|
1421
|
+
}
|
|
1422
|
+
else {
|
|
1423
|
+
keyResolvers[key] = (data) => data[key];
|
|
1424
|
+
}
|
|
1425
|
+
});
|
|
1426
|
+
if (filterKeys.some((key) => query.filterBy[key].isSpecialNestSearch)) {
|
|
1427
|
+
dataList = dataList.filter((data) => filterKeys.every((key) => query.filterBy[key].isSpecialNestSearch ?
|
|
1428
|
+
keyResolvers[key](data).some((dataProperty) => filterFunctionsByKey[key](dataProperty)) :
|
|
1429
|
+
filterFunctionsByKey[key](keyResolvers[key](data))));
|
|
1430
|
+
}
|
|
1431
|
+
else {
|
|
1432
|
+
dataList = dataList.filter((data) => filterKeys.every((key) => filterFunctionsByKey[key](keyResolvers[key](data))));
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
else {
|
|
1436
|
+
dataList = dataList.filter((data) => filterKeys.every((key) => filterFunctionsByKey[key](data[key])));
|
|
1437
|
+
}
|
|
1438
|
+
return {
|
|
1439
|
+
results: dataList,
|
|
1440
|
+
totalItems: dataList.length,
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
catch (error) {
|
|
1444
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1445
|
+
...this._getDefaultErrorSettings('searchData', error),
|
|
1446
|
+
errorCode: `${this.ecBase}DyNTS-DS0-SD0`,
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
getFilterFunctionForKey(key, searchValue, propertyType) {
|
|
1451
|
+
try {
|
|
1452
|
+
if (searchValue === undefined) {
|
|
1453
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1454
|
+
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, searchValue is missing for key: "${key}" ` +
|
|
1455
|
+
`(${this.dataParams.dataName})`)),
|
|
1456
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GFF1`,
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
if (key.includes('.')) {
|
|
1460
|
+
if (!propertyType) {
|
|
1461
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1462
|
+
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, propertyType is missing for key: "${key}" ` +
|
|
1463
|
+
`(${this.dataParams.dataName})`)),
|
|
1464
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GFF3`,
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
else {
|
|
1469
|
+
if (!this.dataParams.properties[key]) {
|
|
1470
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1471
|
+
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, key not found in dataParams: "${key}" ` +
|
|
1472
|
+
`(${this.dataParams.dataName})`)),
|
|
1473
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GFF2`,
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
propertyType = this.dataParams.properties[key].type;
|
|
1477
|
+
}
|
|
1478
|
+
switch (propertyType) {
|
|
1479
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.string:
|
|
1480
|
+
if (typeof searchValue !== 'string') {
|
|
1481
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1482
|
+
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, searchValue is not a string! ` +
|
|
1483
|
+
`(${this.dataParams.dataName})`)),
|
|
1484
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GFF4`,
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
if (Array.isArray(searchValue)) {
|
|
1488
|
+
const lowerCaseSearchValueArray = searchValue.filter((searchString) => Boolean(searchString)).map((searchString) => searchString.toLowerCase());
|
|
1489
|
+
return (dataProperty) => {
|
|
1490
|
+
// Convert to string if not already a string (handles numbers, etc.)
|
|
1491
|
+
const dataPropertyAsString = dataProperty != null ? String(dataProperty) : '';
|
|
1492
|
+
return lowerCaseSearchValueArray.some((searchString) => dataPropertyAsString?.toLowerCase().includes(searchString));
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
else {
|
|
1496
|
+
const lowerCaseSearchValue = searchValue?.toLowerCase();
|
|
1497
|
+
if (!lowerCaseSearchValue) {
|
|
1498
|
+
return (dataProperty) => !dataProperty;
|
|
1499
|
+
}
|
|
1500
|
+
return (dataProperty) => {
|
|
1501
|
+
// Convert to string if not already a string (handles numbers, etc.)
|
|
1502
|
+
const dataPropertyAsString = dataProperty != null ? String(dataProperty) : '';
|
|
1503
|
+
return dataPropertyAsString?.toLowerCase().includes(lowerCaseSearchValue);
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.date:
|
|
1507
|
+
if (searchValue.isRange) {
|
|
1508
|
+
if (searchValue.from === undefined ||
|
|
1509
|
+
searchValue.from === null) {
|
|
1510
|
+
const toAsNumber = +new Date(searchValue.to);
|
|
1511
|
+
return (dataProperty) => +new Date(dataProperty) <= toAsNumber;
|
|
1512
|
+
}
|
|
1513
|
+
else if (searchValue.to === undefined ||
|
|
1514
|
+
searchValue.to === null) {
|
|
1515
|
+
const fromAsNumber = +new Date(searchValue.from);
|
|
1516
|
+
return (dataProperty) => +new Date(dataProperty) >= fromAsNumber;
|
|
1517
|
+
}
|
|
1518
|
+
const rangeAsNumber = new fsm_dynamo_1.DyFM_RangeValue(+new Date(searchValue.from), +new Date(searchValue.to));
|
|
1519
|
+
return (dataProperty) => fsm_dynamo_1.DyFM_RangeValue.isInRange(+new Date(dataProperty), rangeAsNumber);
|
|
1520
|
+
}
|
|
1521
|
+
if (Array.isArray(searchValue)) {
|
|
1522
|
+
const searchValueAsNumberArray = searchValue.map((date) => +new Date(date));
|
|
1523
|
+
return (dataProperty) => searchValueAsNumberArray.includes(+new Date(dataProperty));
|
|
1524
|
+
}
|
|
1525
|
+
const searchValueAsNumber = +new Date(searchValue);
|
|
1526
|
+
return (dataProperty) => +new Date(dataProperty) === searchValueAsNumber;
|
|
1527
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.number:
|
|
1528
|
+
if (searchValue.isRange) {
|
|
1529
|
+
if (searchValue.from === undefined ||
|
|
1530
|
+
searchValue.from === null) {
|
|
1531
|
+
return (dataProperty) => dataProperty <= searchValue.to;
|
|
1532
|
+
}
|
|
1533
|
+
else if (searchValue.to === undefined ||
|
|
1534
|
+
searchValue.to === null) {
|
|
1535
|
+
return (dataProperty) => dataProperty >= searchValue.from;
|
|
1536
|
+
}
|
|
1537
|
+
return (dataProperty) => fsm_dynamo_1.DyFM_RangeValue.isInRange(dataProperty, searchValue);
|
|
1538
|
+
}
|
|
1539
|
+
if (Array.isArray(searchValue)) {
|
|
1540
|
+
return (dataProperty) => searchValue.includes(dataProperty);
|
|
1541
|
+
}
|
|
1542
|
+
return (dataProperty) => dataProperty === searchValue;
|
|
1543
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.boolean:
|
|
1544
|
+
return (dataProperty) => dataProperty === searchValue;
|
|
1545
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.object:
|
|
1546
|
+
if (Array.isArray(searchValue)) {
|
|
1547
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1548
|
+
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, array search not implemented for this type ` +
|
|
1549
|
+
`(${this.dataParams.dataName})`)),
|
|
1550
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GFF5`,
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
return (dataProperty) => {
|
|
1554
|
+
const searchValueKeys = Object.keys(searchValue);
|
|
1555
|
+
const stringifiedSearchValue = {};
|
|
1556
|
+
try {
|
|
1557
|
+
searchValueKeys.forEach((key) => {
|
|
1558
|
+
stringifiedSearchValue[key] = JSON.stringify(searchValue[key]);
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
catch (error) {
|
|
1562
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1563
|
+
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, object search failed! ` +
|
|
1564
|
+
`(${this.dataParams.dataName})`)),
|
|
1565
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GFF6`,
|
|
1566
|
+
additionalContent: {
|
|
1567
|
+
searchValue: searchValue,
|
|
1568
|
+
},
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
return searchValueKeys.every((key) => {
|
|
1572
|
+
try {
|
|
1573
|
+
return stringifiedSearchValue[key] === JSON.stringify(dataProperty[key]);
|
|
1574
|
+
}
|
|
1575
|
+
catch (error) {
|
|
1576
|
+
console.error('object filter returning false, bc of an error', 'searchValue:', searchValue, 'dataProperty:', dataProperty, 'key:', key, 'error:', error);
|
|
1577
|
+
return false;
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
};
|
|
1581
|
+
default:
|
|
1582
|
+
if (searchValue.isRange) {
|
|
1583
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1584
|
+
...this._getDefaultErrorSettings('getFilterFunctionForKey', new Error(`getFilterFunctionForKey failed, range search not implemented for this type ` +
|
|
1585
|
+
`(${this.dataParams.dataName})`)),
|
|
1586
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GFF7`,
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
if (Array.isArray(searchValue)) {
|
|
1590
|
+
return (dataProperty) => searchValue.includes(dataProperty);
|
|
1591
|
+
}
|
|
1592
|
+
return (dataProperty) => dataProperty === searchValue;
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
catch (error) {
|
|
1596
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1597
|
+
...this._getDefaultErrorSettings('getFilterFunctionForKey', error),
|
|
1598
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GFF0`,
|
|
1599
|
+
additionalContent: {
|
|
1600
|
+
key: key,
|
|
1601
|
+
searchValue: searchValue,
|
|
1602
|
+
propertyType: propertyType,
|
|
1603
|
+
},
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
/**
|
|
1608
|
+
* Get the value of a nested key.
|
|
1609
|
+
* @param nestKeys - The nested keys to resolve.
|
|
1610
|
+
* @returns The value of the nested key.
|
|
1611
|
+
*/
|
|
1612
|
+
getKeyResolver(nestKeys) {
|
|
1613
|
+
return (data) => {
|
|
1614
|
+
let value = data;
|
|
1615
|
+
nestKeys.forEach((nestKey) => {
|
|
1616
|
+
if (!value) {
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
if (nestKey === '*') {
|
|
1620
|
+
// Wildcard: ha value egy tömb, akkor minden elemet visszaadunk
|
|
1621
|
+
// A következő nestKey minden elemre alkalmazva lesz
|
|
1622
|
+
if (Array.isArray(value)) {
|
|
1623
|
+
// value marad tömb, a következő nestKey minden elemre alkalmazva lesz
|
|
1624
|
+
// Nem változtatjuk meg a value-t, hogy a következő iterációban
|
|
1625
|
+
// a tömb minden elemére alkalmazva legyen a következő nestKey
|
|
1626
|
+
}
|
|
1627
|
+
else if (value && typeof value === 'object') {
|
|
1628
|
+
// Ha objektum, akkor az értékeit adja vissza tömbként
|
|
1629
|
+
value = Object.values(value);
|
|
1630
|
+
}
|
|
1631
|
+
else {
|
|
1632
|
+
// Egyébként undefined
|
|
1633
|
+
value = undefined;
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
else if (Array.isArray(value)) {
|
|
1637
|
+
// Ha value tömb, akkor minden elemre alkalmazzuk a nestKey-t
|
|
1638
|
+
if (!isNaN(+nestKey)) {
|
|
1639
|
+
value = value[+nestKey];
|
|
1640
|
+
}
|
|
1641
|
+
else {
|
|
1642
|
+
value = value.map((element) => element ? element[nestKey] : element);
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
else {
|
|
1646
|
+
value = value[nestKey];
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
return value;
|
|
1650
|
+
};
|
|
1651
|
+
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Get the sort function for a key.
|
|
1654
|
+
* @param sortSettings - The sort settings.
|
|
1655
|
+
* @returns The sort function for the key.
|
|
1656
|
+
*/
|
|
1657
|
+
getSortFunctionForKey(sortSettings) {
|
|
1658
|
+
let keyResolver;
|
|
1659
|
+
let valueType;
|
|
1660
|
+
if (!this.dataParams.properties[sortSettings.key] &&
|
|
1661
|
+
!sortSettings.isNestedPropertySort) {
|
|
1662
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1663
|
+
...this._getDefaultErrorSettings('getSortFunctionForKey', new Error(`getSortFunctionForKey failed, key not found in dataParams ` +
|
|
1664
|
+
`(${this.dataParams.dataName})`)),
|
|
1665
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GSF1`,
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
if (sortSettings.isNestedPropertySort) {
|
|
1669
|
+
keyResolver = this.getKeyResolver(sortSettings.nestKeys);
|
|
1670
|
+
valueType = sortSettings.valueType;
|
|
1671
|
+
}
|
|
1672
|
+
else {
|
|
1673
|
+
keyResolver = (data) => data[sortSettings.key];
|
|
1674
|
+
valueType = this.dataParams.properties[sortSettings.key].type;
|
|
1675
|
+
}
|
|
1676
|
+
if (!valueType) {
|
|
1677
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1678
|
+
...this._getDefaultErrorSettings('getSortFunctionForKey', new Error(`getSortFunctionForKey failed, valueType is missing! ` +
|
|
1679
|
+
`(${this.dataParams.dataName})`)),
|
|
1680
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GSF1`,
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
const sortValue = (sortSettings.order === 1 ||
|
|
1684
|
+
sortSettings.order === 'asc' ||
|
|
1685
|
+
sortSettings.order === 'ascending') ? 1 : -1;
|
|
1686
|
+
switch (valueType) {
|
|
1687
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.string:
|
|
1688
|
+
return (a, b) => {
|
|
1689
|
+
a = keyResolver(a);
|
|
1690
|
+
b = keyResolver(b);
|
|
1691
|
+
return a.localeCompare(b) * sortValue;
|
|
1692
|
+
};
|
|
1693
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.date:
|
|
1694
|
+
return (a, b) => {
|
|
1695
|
+
const aNum = +new Date(keyResolver(a));
|
|
1696
|
+
const bNum = +new Date(keyResolver(b));
|
|
1697
|
+
if (aNum < bNum) {
|
|
1698
|
+
return -sortValue;
|
|
1699
|
+
}
|
|
1700
|
+
else if (aNum > bNum) {
|
|
1701
|
+
return sortValue;
|
|
1702
|
+
}
|
|
1703
|
+
else {
|
|
1704
|
+
return 0;
|
|
1705
|
+
}
|
|
1706
|
+
};
|
|
1707
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.number:
|
|
1708
|
+
return (a, b) => {
|
|
1709
|
+
a = keyResolver(a);
|
|
1710
|
+
b = keyResolver(b);
|
|
1711
|
+
if (a < b) {
|
|
1712
|
+
return -sortValue;
|
|
1713
|
+
}
|
|
1714
|
+
else if (a > b) {
|
|
1715
|
+
return sortValue;
|
|
1716
|
+
}
|
|
1717
|
+
else {
|
|
1718
|
+
return 0;
|
|
1719
|
+
}
|
|
1720
|
+
};
|
|
1721
|
+
case fsm_dynamo_1.DyFM_BasicProperty_Type.boolean:
|
|
1722
|
+
return (a, b) => {
|
|
1723
|
+
a = keyResolver(a);
|
|
1724
|
+
b = keyResolver(b);
|
|
1725
|
+
if (a === b) {
|
|
1726
|
+
return 0;
|
|
1727
|
+
}
|
|
1728
|
+
if (a) {
|
|
1729
|
+
return sortValue;
|
|
1730
|
+
}
|
|
1731
|
+
return -sortValue;
|
|
1732
|
+
};
|
|
1733
|
+
default:
|
|
1734
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1735
|
+
...this._getDefaultErrorSettings('getSortFunctionForKey', new Error(`getSortFunctionForKey failed, sorting not implemented for this type ` +
|
|
1736
|
+
`(${this.dataParams.dataName}, ${valueType})`)),
|
|
1737
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GSF2`,
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
/* private getSortFunctionForNestedKeys<T>(
|
|
1742
|
+
sortSettings: DyFM_DSNestedPropertySort
|
|
1743
|
+
): (a: T, b: T) => number {
|
|
1744
|
+
const nestedPropertyResolver: (data) => any = this.getKeyResolver(sortSettings.nestKeys);
|
|
1745
|
+
|
|
1746
|
+
const sortValue: 1 | -1 = (
|
|
1747
|
+
sortSettings.order === 1 ||
|
|
1748
|
+
sortSettings.order === 'asc' ||
|
|
1749
|
+
sortSettings.order === 'ascending'
|
|
1750
|
+
) ? 1 : -1;
|
|
1751
|
+
|
|
1752
|
+
switch (sortSettings.valueType) {
|
|
1753
|
+
case DyFM_BasicProperty_Type.string:
|
|
1754
|
+
return (a: T, b: T): number => {
|
|
1755
|
+
a = nestedPropertyResolver(a);
|
|
1756
|
+
b = nestedPropertyResolver(b);
|
|
1757
|
+
|
|
1758
|
+
return (a as string).localeCompare(b as string) * sortValue
|
|
1759
|
+
};
|
|
1760
|
+
|
|
1761
|
+
case DyFM_BasicProperty_Type.date:
|
|
1762
|
+
return (a: T, b: T): number => {
|
|
1763
|
+
a = nestedPropertyResolver(a);
|
|
1764
|
+
b = nestedPropertyResolver(b);
|
|
1765
|
+
|
|
1766
|
+
if (+new Date(a) < +new Date(b)) {
|
|
1767
|
+
return -sortValue;
|
|
1768
|
+
} else if (+new Date(a) > +new Date(b)) {
|
|
1769
|
+
return sortValue;
|
|
1770
|
+
} else {
|
|
1771
|
+
return 0;
|
|
1772
|
+
}
|
|
1773
|
+
};
|
|
1774
|
+
|
|
1775
|
+
case DyFM_BasicProperty_Type.number:
|
|
1776
|
+
return (a: T, b: T): number => {
|
|
1777
|
+
a = nestedPropertyResolver(a);
|
|
1778
|
+
b = nestedPropertyResolver(b);
|
|
1779
|
+
|
|
1780
|
+
if (a < b) {
|
|
1781
|
+
return -sortValue;
|
|
1782
|
+
} else if (a > b) {
|
|
1783
|
+
return sortValue;
|
|
1784
|
+
} else {
|
|
1785
|
+
return 0;
|
|
1786
|
+
}
|
|
1787
|
+
};
|
|
1788
|
+
|
|
1789
|
+
case DyFM_BasicProperty_Type.boolean:
|
|
1790
|
+
return (a: T, b: T): number => {
|
|
1791
|
+
a = nestedPropertyResolver(a);
|
|
1792
|
+
b = nestedPropertyResolver(b);
|
|
1793
|
+
|
|
1794
|
+
if (a === b) {
|
|
1795
|
+
return 0;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
if (a) {
|
|
1799
|
+
return sortValue;
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
return -sortValue;
|
|
1803
|
+
};
|
|
1804
|
+
|
|
1805
|
+
default:
|
|
1806
|
+
throw new DyFM_Error({
|
|
1807
|
+
...this._getDefaultErrorSettings(
|
|
1808
|
+
'getSortFunctionForKey',
|
|
1809
|
+
new Error(
|
|
1810
|
+
`getSortFunctionForKey failed, sorting not implemented for this type ` +
|
|
1811
|
+
`(${this.dataParams.dataName}, ${this.dataParams.properties[key].type})`
|
|
1812
|
+
)
|
|
1813
|
+
),
|
|
1814
|
+
|
|
1815
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GSF2`,
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1818
|
+
} */
|
|
1819
|
+
/**
|
|
1820
|
+
* setting up dependency dataHook by DynamoNTSDataModelParams
|
|
1821
|
+
*/
|
|
1822
|
+
lookForDependencyDataSettings() {
|
|
1823
|
+
const dependencyParams = Object.values(this.dataParams.properties).filter((modelParams) => Boolean(modelParams.dependencyDataName));
|
|
1824
|
+
this.depSettings.push(...dependencyParams.map((dependencyParams) => ({
|
|
1825
|
+
key: dependencyParams.key,
|
|
1826
|
+
dbServiceKey: dependencyParams.dependencyDataName,
|
|
1827
|
+
keyIsUnique: dependencyParams.unique,
|
|
1828
|
+
keyIsRequired: dependencyParams.required,
|
|
1829
|
+
})));
|
|
1830
|
+
if (this.depSettings.length === 1) {
|
|
1831
|
+
this.depDataDBService = global_service_1.DyNTS_GlobalService.getDBServiceByKey(this.depSettings[0].dbServiceKey);
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
*
|
|
1836
|
+
* @returns
|
|
1837
|
+
*/
|
|
1838
|
+
getDependencyDataDBService(dBServiceKey) {
|
|
1839
|
+
if (!dBServiceKey && !this.depDataDBService) {
|
|
1840
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1841
|
+
...this._getDefaultErrorSettings('getDependencyDataDBService', new Error(`getDependencyDataDBService was unsuccessful, service key not setted up! ` +
|
|
1842
|
+
`(key: ${this.depSettings.map((depSetting) => depSetting.key).join(', ')}, ` +
|
|
1843
|
+
`(${this.dataParams.dataName})`)),
|
|
1844
|
+
status: 500,
|
|
1845
|
+
errorCode: `${this.ecBase}DyNTS-DS0-GDDB0`,
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
if (this.depDataDBService) {
|
|
1849
|
+
return this.depDataDBService;
|
|
1850
|
+
}
|
|
1851
|
+
else {
|
|
1852
|
+
this.depDataDBService = global_service_1.DyNTS_GlobalService.getDBServiceByKey(dBServiceKey);
|
|
1853
|
+
return this.depDataDBService;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
getProvidedData(data) {
|
|
1857
|
+
return data;
|
|
1858
|
+
}
|
|
1859
|
+
getProvidedDataList(dataList) {
|
|
1860
|
+
return dataList;
|
|
1861
|
+
}
|
|
1862
|
+
_getDefaultErrorSettings(fnName, error) {
|
|
1863
|
+
return {
|
|
1864
|
+
status: error?.___status ?? 500,
|
|
1865
|
+
message: error?.message ??
|
|
1866
|
+
error?._message ??
|
|
1867
|
+
`${fnName} was UNSUCCESSFUL (NTS; ${this.dataParams.dataName})`,
|
|
1868
|
+
addECToUserMsg: !error?.__userMessage,
|
|
1869
|
+
userMessage: error?.__userMessage ?? this.defaultErrorUserMsg,
|
|
1870
|
+
issuer: this.issuer,
|
|
1871
|
+
issuerService: this.serviceName + ` (${this?.constructor?.name}-DyNTS_DataService)`,
|
|
1872
|
+
systemVersion: global_settings_const_1.DyNTS_global_settings.systemVersion,
|
|
1873
|
+
error: error,
|
|
1874
|
+
};
|
|
1875
|
+
}
|
|
1876
|
+
getDefaultErrorSettings(fnName, error,
|
|
1877
|
+
/** @deprecated we wont support the separate user message in the future, use the message instead */
|
|
1878
|
+
useMessageAsUserMessage = true) {
|
|
1879
|
+
return {
|
|
1880
|
+
status: error?.___status ?? 500,
|
|
1881
|
+
message: error?.message ??
|
|
1882
|
+
error?._message ??
|
|
1883
|
+
`${fnName} was UNSUCCESSFUL (${global_settings_const_1.DyNTS_global_settings.systemShortCodeName})`,
|
|
1884
|
+
addECToUserMsg: !error?.__userMessage,
|
|
1885
|
+
userMessage: error?.__userMessage ??
|
|
1886
|
+
(useMessageAsUserMessage ? error?.message : this.defaultErrorUserMsg),
|
|
1887
|
+
issuer: this.issuer,
|
|
1888
|
+
issuerService: this.constructor?.name,
|
|
1889
|
+
systemVersion: global_settings_const_1.DyNTS_global_settings.systemVersion,
|
|
1890
|
+
error: error,
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
1894
|
+
// GENERIC DATA COMPARE (FR-001)
|
|
1895
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
1896
|
+
/**
|
|
1897
|
+
* Generic, field-szintu osszehasonlitas ket adat-objektum kozott.
|
|
1898
|
+
*
|
|
1899
|
+
* **Auto-discovery mod** (`options.fields` nelkul): a metodus mindket
|
|
1900
|
+
* objektum kulcs-uniojan iter, KIVEVE a `DyFM_Metadata` skip-listet
|
|
1901
|
+
* (`_id`, `__created`, `__createdBy`, `__lastModified`, `__lastModifiedBy`).
|
|
1902
|
+
*
|
|
1903
|
+
* **Scope-szukito mod** (`options.fields = [...]`): KIZAROLAG a felsorolt
|
|
1904
|
+
* mezoket vizsgalja. A skip-list IGNORALODIK — explicit fields override.
|
|
1905
|
+
*
|
|
1906
|
+
* **Custom comparator** (`options.customComparators`): per-field override
|
|
1907
|
+
* a default deep-equal helyett (pl. set-equality array-ekre,
|
|
1908
|
+
* case-insensitive string compare-re). A custom function `true`-val signal-ozza
|
|
1909
|
+
* az equality-t.
|
|
1910
|
+
*
|
|
1911
|
+
* **Return:** `'equal'` ha minden vizsgalt field egyezik; `'modified'` ha
|
|
1912
|
+
* legalabb egy elter — ilyenkor `changedFields` tartalmazza a TELJES
|
|
1913
|
+
* mismatch-listat (nem early-return).
|
|
1914
|
+
*
|
|
1915
|
+
* **Throws:**
|
|
1916
|
+
* - `newData` vagy `oldData` null/undefined → `DyFM_Error(400, DyNTS-DS0-CD1)`
|
|
1917
|
+
* - `options.fields = []` ures array → `DyFM_Error(400, DyNTS-DS0-CD2)`
|
|
1918
|
+
*
|
|
1919
|
+
* **Sync method** (nincs I/O szukseglet); a host wrappel-i ha async kell.
|
|
1920
|
+
*
|
|
1921
|
+
* @example
|
|
1922
|
+
* const result = userService.compareData(newUser, oldUser);
|
|
1923
|
+
* if (result.result === 'modified') {
|
|
1924
|
+
* console.log('Changed:', result.changedFields);
|
|
1925
|
+
* }
|
|
1926
|
+
*
|
|
1927
|
+
* @example // Scope-szukites + custom comparator
|
|
1928
|
+
* userService.compareData(newUser, oldUser, {
|
|
1929
|
+
* fields: ['email', 'roles'],
|
|
1930
|
+
* customComparators: {
|
|
1931
|
+
* roles: (a, b) => new Set(a).size === new Set([...a, ...b]).size,
|
|
1932
|
+
* },
|
|
1933
|
+
* });
|
|
1934
|
+
*/
|
|
1935
|
+
compareData(newData, oldData, options) {
|
|
1936
|
+
// Input guard
|
|
1937
|
+
if (newData === null || newData === undefined || oldData === null || oldData === undefined) {
|
|
1938
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1939
|
+
...this.getDefaultErrorSettings('compareData', new Error('newData/oldData required')),
|
|
1940
|
+
status: 400,
|
|
1941
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-CD1`,
|
|
1942
|
+
message: 'compareData: newData and oldData are required (both must be non-null/undefined)',
|
|
1943
|
+
});
|
|
1944
|
+
}
|
|
1945
|
+
if (options?.fields !== undefined && options.fields.length === 0) {
|
|
1946
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
1947
|
+
...this.getDefaultErrorSettings('compareData', new Error('options.fields must not be empty')),
|
|
1948
|
+
status: 400,
|
|
1949
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-CD2`,
|
|
1950
|
+
message: 'compareData: options.fields must not be an empty array',
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
1953
|
+
const fieldsToCheck = this._resolveCompareFields(newData, oldData, options);
|
|
1954
|
+
const comparators = options?.customComparators ?? {};
|
|
1955
|
+
const changedFields = [];
|
|
1956
|
+
for (const field of fieldsToCheck) {
|
|
1957
|
+
const a = newData[field];
|
|
1958
|
+
const b = oldData[field];
|
|
1959
|
+
const isEqual = comparators[field]
|
|
1960
|
+
? comparators[field](a, b)
|
|
1961
|
+
: this._deepEqual(a, b);
|
|
1962
|
+
if (!isEqual) {
|
|
1963
|
+
changedFields.push(field);
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
if (changedFields.length === 0) {
|
|
1967
|
+
return { result: 'equal' };
|
|
1968
|
+
}
|
|
1969
|
+
return { result: 'modified', changedFields: changedFields };
|
|
1970
|
+
}
|
|
1971
|
+
/**
|
|
1972
|
+
* Eldonti az osszehasonlitando fields-listat:
|
|
1973
|
+
* - explicit `options.fields` esetan annak masolata (skip-list ignoralt)
|
|
1974
|
+
* - egyebkent `Object.keys(newData) UNION Object.keys(oldData)` minus skip-list
|
|
1975
|
+
*/
|
|
1976
|
+
_resolveCompareFields(newData, oldData, options) {
|
|
1977
|
+
if (options?.fields !== undefined) {
|
|
1978
|
+
// Explicit fields — copy-spread (defensive against caller mutation mid-flight)
|
|
1979
|
+
return [...options.fields];
|
|
1980
|
+
}
|
|
1981
|
+
const keySet = new Set();
|
|
1982
|
+
for (const k of Object.keys(newData)) {
|
|
1983
|
+
keySet.add(k);
|
|
1984
|
+
}
|
|
1985
|
+
for (const k of Object.keys(oldData)) {
|
|
1986
|
+
keySet.add(k);
|
|
1987
|
+
}
|
|
1988
|
+
const result = [];
|
|
1989
|
+
for (const k of keySet) {
|
|
1990
|
+
if (COMPARE_DATA_METADATA_SKIP_FIELDS.has(k)) {
|
|
1991
|
+
continue;
|
|
1992
|
+
}
|
|
1993
|
+
result.push(k);
|
|
1994
|
+
}
|
|
1995
|
+
return result;
|
|
1996
|
+
}
|
|
1997
|
+
/**
|
|
1998
|
+
* Deep-equal helper.
|
|
1999
|
+
*
|
|
2000
|
+
* - Primitive (`string`/`number`/`boolean`/`null`/`undefined`): `===` / `Object.is`
|
|
2001
|
+
* (a `NaN === NaN` esetet `Object.is` kezeli helyesen)
|
|
2002
|
+
* - `Date`: `.getTime()` egyenloseg (kulonbozo Date instance-ok same-time-mal egyenlonek)
|
|
2003
|
+
* - Array: length + index-szerinti rekurziv deep-equal
|
|
2004
|
+
* - POJO: keys-union + per-key rekurzio
|
|
2005
|
+
* - Egyeb (RegExp / Map / Set / Buffer): `Object.is` fallback (reference compare)
|
|
2006
|
+
*
|
|
2007
|
+
* NEM kezelt: cyclic references — a hivo objektum-grafja flat / fa kell legyen
|
|
2008
|
+
* (a tipikus FDP data-model esete; cycle eseten stack overflow lesz, ami ertelmes
|
|
2009
|
+
* jelzes a programozonak).
|
|
2010
|
+
*/
|
|
2011
|
+
_deepEqual(a, b) {
|
|
2012
|
+
if (a === b) {
|
|
2013
|
+
return true;
|
|
2014
|
+
}
|
|
2015
|
+
if (Object.is(a, b)) {
|
|
2016
|
+
return true;
|
|
2017
|
+
}
|
|
2018
|
+
// Null/undefined es a masik nem ugyanaz → false
|
|
2019
|
+
if (a === null || a === undefined || b === null || b === undefined) {
|
|
2020
|
+
return false;
|
|
2021
|
+
}
|
|
2022
|
+
// Date
|
|
2023
|
+
if (a instanceof Date && b instanceof Date) {
|
|
2024
|
+
return a.getTime() === b.getTime();
|
|
2025
|
+
}
|
|
2026
|
+
if (a instanceof Date || b instanceof Date) {
|
|
2027
|
+
return false;
|
|
2028
|
+
}
|
|
2029
|
+
// Array
|
|
2030
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
2031
|
+
if (a.length !== b.length) {
|
|
2032
|
+
return false;
|
|
2033
|
+
}
|
|
2034
|
+
for (let i = 0; i < a.length; i++) {
|
|
2035
|
+
if (!this._deepEqual(a[i], b[i])) {
|
|
2036
|
+
return false;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
return true;
|
|
2040
|
+
}
|
|
2041
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
2042
|
+
return false;
|
|
2043
|
+
}
|
|
2044
|
+
// POJO (Object.prototype) — keys union, per-key compare
|
|
2045
|
+
if (typeof a === 'object' && typeof b === 'object') {
|
|
2046
|
+
const keysA = Object.keys(a);
|
|
2047
|
+
const keysB = Object.keys(b);
|
|
2048
|
+
if (keysA.length !== keysB.length) {
|
|
2049
|
+
return false;
|
|
2050
|
+
}
|
|
2051
|
+
const keysAset = new Set(keysA);
|
|
2052
|
+
for (const k of keysB) {
|
|
2053
|
+
if (!keysAset.has(k)) {
|
|
2054
|
+
return false;
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
for (const k of keysA) {
|
|
2058
|
+
if (!this._deepEqual(a[k], b[k])) {
|
|
2059
|
+
return false;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
return true;
|
|
2063
|
+
}
|
|
2064
|
+
// Fallback (function, symbol, BigInt, stb.) — strict equality mar nem stimmelt
|
|
2065
|
+
return false;
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
exports.DyNTS_DataService = DyNTS_DataService;
|
|
2069
2069
|
//# sourceMappingURL=data.service.js.map
|