openloops 0.1.8 → 0.1.10
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/dist/chunk-XRJFNASX.mjs +14 -0
- package/dist/common/clients/index.js +26 -0
- package/dist/common/clients/index.mjs +3 -0
- package/dist/common/clients/llm-client.js +159 -0
- package/dist/common/clients/llm-client.mjs +126 -0
- package/dist/common/clients/sentry-client.js +87 -0
- package/dist/common/clients/sentry-client.mjs +53 -0
- package/dist/common/clients/serper-client.js +74 -0
- package/dist/common/clients/serper-client.mjs +41 -0
- package/dist/common/core/base.app.js +57 -0
- package/dist/common/core/base.app.mjs +34 -0
- package/dist/common/core/base.entity.js +208 -0
- package/dist/common/core/base.entity.mjs +179 -0
- package/dist/common/core/base.use-case.js +30 -0
- package/dist/common/core/base.use-case.mjs +7 -0
- package/dist/common/core/index.js +1 -0
- package/dist/common/core/index.mjs +0 -0
- package/dist/common/core/utils/delete-empty-fields.js +66 -0
- package/dist/common/core/utils/delete-empty-fields.mjs +43 -0
- package/dist/common/core/utils/flatten-object.js +45 -0
- package/dist/common/core/utils/flatten-object.mjs +22 -0
- package/dist/common/core/utils/index.js +26 -0
- package/dist/common/core/utils/index.mjs +3 -0
- package/dist/common/core/utils/is-plain-object.js +32 -0
- package/dist/common/core/utils/is-plain-object.mjs +9 -0
- package/dist/common/decorators/admin-only/admin-only.js +52 -0
- package/dist/common/decorators/admin-only/admin-only.mjs +28 -0
- package/dist/common/decorators/admin-only/index.js +22 -0
- package/dist/common/decorators/admin-only/index.mjs +1 -0
- package/dist/common/decorators/index.js +26 -0
- package/dist/common/decorators/index.mjs +3 -0
- package/dist/common/decorators/mask-in-logs/index.js +22 -0
- package/dist/common/decorators/mask-in-logs/index.mjs +1 -0
- package/dist/common/decorators/mask-in-logs/mask-in-logs.js +53 -0
- package/dist/common/decorators/mask-in-logs/mask-in-logs.mjs +29 -0
- package/dist/common/decorators/owner-only/index.js +22 -0
- package/dist/common/decorators/owner-only/index.mjs +1 -0
- package/dist/common/decorators/owner-only/owner-only.js +52 -0
- package/dist/common/decorators/owner-only/owner-only.mjs +28 -0
- package/dist/common/error/http-error.js +37 -0
- package/dist/common/error/http-error.mjs +14 -0
- package/dist/common/error/index.js +24 -0
- package/dist/common/error/index.mjs +2 -0
- package/dist/common/error/reportError.js +51 -0
- package/dist/common/error/reportError.mjs +28 -0
- package/dist/common/helpers/extract-json-from-text.js +63 -0
- package/dist/common/helpers/extract-json-from-text.mjs +40 -0
- package/dist/common/helpers/index.js +24 -0
- package/dist/common/helpers/index.mjs +2 -0
- package/dist/common/helpers/sanitize-string.js +45 -0
- package/dist/common/helpers/sanitize-string.mjs +12 -0
- package/dist/common/logger/index.js +22 -0
- package/dist/common/logger/index.mjs +1 -0
- package/dist/common/logger/pino.js +70 -0
- package/dist/common/logger/pino.mjs +36 -0
- package/dist/common/repositories/index.js +24 -0
- package/dist/common/repositories/index.mjs +2 -0
- package/dist/common/repositories/mongo-db.client.js +79 -0
- package/dist/common/repositories/mongo-db.client.mjs +57 -0
- package/dist/common/repositories/mongo-db.repository.js +219 -0
- package/dist/common/repositories/mongo-db.repository.mjs +196 -0
- package/dist/common/utils/secret-manager.js +105 -0
- package/dist/common/utils/secret-manager.mjs +71 -0
- package/dist/index.js +22 -7
- package/dist/index.mjs +1 -7
- package/dist/services/agent/core/agent-loop.js +29 -0
- package/dist/services/agent/core/agent-loop.mjs +6 -0
- package/dist/services/agent/core/agent-state.js +102 -0
- package/dist/services/agent/core/agent-state.mjs +78 -0
- package/dist/services/agent/core/agent.js +351 -0
- package/dist/services/agent/core/agent.mjs +327 -0
- package/dist/services/agent/core/index.js +26 -0
- package/dist/services/agent/core/index.mjs +3 -0
- package/dist/services/agent/loops/index.js +24 -0
- package/dist/services/agent/loops/index.mjs +2 -0
- package/dist/services/agent/loops/plan-execute/index.js +22 -0
- package/dist/services/agent/loops/plan-execute/index.mjs +1 -0
- package/dist/services/agent/loops/plan-execute/plan-execute-loop.js +242 -0
- package/dist/services/agent/loops/plan-execute/plan-execute-loop.mjs +226 -0
- package/dist/services/agent/loops/shared/index.js +22 -0
- package/dist/services/agent/loops/shared/index.mjs +1 -0
- package/dist/services/agent/loops/shared/skills/action-planner.js +68 -0
- package/dist/services/agent/loops/shared/skills/action-planner.mjs +45 -0
- package/dist/services/agent/loops/shared/skills/confirmation-gate.js +53 -0
- package/dist/services/agent/loops/shared/skills/confirmation-gate.mjs +30 -0
- package/dist/services/agent/loops/shared/skills/fast-responder.js +70 -0
- package/dist/services/agent/loops/shared/skills/fast-responder.mjs +47 -0
- package/dist/services/agent/loops/shared/skills/final-responder.js +57 -0
- package/dist/services/agent/loops/shared/skills/final-responder.mjs +34 -0
- package/dist/services/agent/loops/shared/skills/index.js +32 -0
- package/dist/services/agent/loops/shared/skills/index.mjs +6 -0
- package/dist/services/agent/loops/shared/skills/state-observer.js +57 -0
- package/dist/services/agent/loops/shared/skills/state-observer.mjs +34 -0
- package/dist/services/agent/loops/shared/skills/strategy-engine.js +60 -0
- package/dist/services/agent/loops/shared/skills/strategy-engine.mjs +37 -0
- package/dist/services/agent/modules/chats/entities/agent-action.entity.js +151 -0
- package/dist/services/agent/modules/chats/entities/agent-action.entity.mjs +128 -0
- package/dist/services/agent/modules/chats/entities/agent-task.entity.js +231 -0
- package/dist/services/agent/modules/chats/entities/agent-task.entity.mjs +207 -0
- package/dist/services/agent/modules/chats/entities/chat-context.entity.js +70 -0
- package/dist/services/agent/modules/chats/entities/chat-context.entity.mjs +47 -0
- package/dist/services/agent/modules/chats/entities/chat-message.entity.js +58 -0
- package/dist/services/agent/modules/chats/entities/chat-message.entity.mjs +35 -0
- package/dist/services/agent/modules/chats/entities/chat-settings.entity.js +63 -0
- package/dist/services/agent/modules/chats/entities/chat-settings.entity.mjs +40 -0
- package/dist/services/agent/modules/chats/entities/chat.entity.js +163 -0
- package/dist/services/agent/modules/chats/entities/chat.entity.mjs +140 -0
- package/dist/services/agent/modules/chats/entities/index.js +22 -0
- package/dist/services/agent/modules/chats/entities/index.mjs +1 -0
- package/dist/services/agent/modules/chats/lambdas/create-chat/create-chat.use-case.js +56 -0
- package/dist/services/agent/modules/chats/lambdas/create-chat/create-chat.use-case.mjs +27 -0
- package/dist/services/agent/modules/chats/lambdas/create-chat/index.js +22 -0
- package/dist/services/agent/modules/chats/lambdas/create-chat/index.mjs +1 -0
- package/dist/services/agent/modules/chats/lambdas/delete-chat/delete-chat.use-case.js +61 -0
- package/dist/services/agent/modules/chats/lambdas/delete-chat/delete-chat.use-case.mjs +32 -0
- package/dist/services/agent/modules/chats/lambdas/delete-chat/index.js +22 -0
- package/dist/services/agent/modules/chats/lambdas/delete-chat/index.mjs +1 -0
- package/dist/services/agent/modules/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.js +52 -0
- package/dist/services/agent/modules/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.mjs +23 -0
- package/dist/services/agent/modules/chats/lambdas/get-chat-by-id/index.js +22 -0
- package/dist/services/agent/modules/chats/lambdas/get-chat-by-id/index.mjs +1 -0
- package/dist/services/agent/modules/chats/lambdas/interrupt-execution/index.js +22 -0
- package/dist/services/agent/modules/chats/lambdas/interrupt-execution/index.mjs +1 -0
- package/dist/services/agent/modules/chats/lambdas/interrupt-execution/interrupt-execution.use-case.js +64 -0
- package/dist/services/agent/modules/chats/lambdas/interrupt-execution/interrupt-execution.use-case.mjs +35 -0
- package/dist/services/agent/modules/chats/lambdas/list-chats-by-props/index.js +22 -0
- package/dist/services/agent/modules/chats/lambdas/list-chats-by-props/index.mjs +1 -0
- package/dist/services/agent/modules/chats/lambdas/list-chats-by-props/list-chats-by-props.use-case.js +52 -0
- package/dist/services/agent/modules/chats/lambdas/list-chats-by-props/list-chats-by-props.use-case.mjs +23 -0
- package/dist/services/agent/modules/chats/lambdas/list-chats-by-user/index.js +22 -0
- package/dist/services/agent/modules/chats/lambdas/list-chats-by-user/index.mjs +1 -0
- package/dist/services/agent/modules/chats/lambdas/list-chats-by-user/list-chats-by-user.use-case.js +59 -0
- package/dist/services/agent/modules/chats/lambdas/list-chats-by-user/list-chats-by-user.use-case.mjs +30 -0
- package/dist/services/agent/modules/chats/lambdas/update-chat/index.js +22 -0
- package/dist/services/agent/modules/chats/lambdas/update-chat/index.mjs +1 -0
- package/dist/services/agent/modules/chats/lambdas/update-chat/update-chat.use-case.js +64 -0
- package/dist/services/agent/modules/chats/lambdas/update-chat/update-chat.use-case.mjs +35 -0
- package/dist/services/agent/modules/chats/repositories/chat.repository.js +67 -0
- package/dist/services/agent/modules/chats/repositories/chat.repository.mjs +38 -0
- package/dist/services/agent/modules/chats/repositories/index.js +22 -0
- package/dist/services/agent/modules/chats/repositories/index.mjs +1 -0
- package/dist/services/agent/modules/llmcalls/entities/index.js +22 -0
- package/dist/services/agent/modules/llmcalls/entities/index.mjs +1 -0
- package/dist/services/agent/modules/llmcalls/entities/llmcall.entity.js +71 -0
- package/dist/services/agent/modules/llmcalls/entities/llmcall.entity.mjs +48 -0
- package/dist/services/agent/modules/llmcalls/lambdas/create-llmcall/create-llmcall.use-case.js +56 -0
- package/dist/services/agent/modules/llmcalls/lambdas/create-llmcall/create-llmcall.use-case.mjs +27 -0
- package/dist/services/agent/modules/llmcalls/lambdas/create-llmcall/index.js +22 -0
- package/dist/services/agent/modules/llmcalls/lambdas/create-llmcall/index.mjs +1 -0
- package/dist/services/agent/modules/llmcalls/lambdas/delete-llmcall/delete-llmcall.use-case.js +61 -0
- package/dist/services/agent/modules/llmcalls/lambdas/delete-llmcall/delete-llmcall.use-case.mjs +32 -0
- package/dist/services/agent/modules/llmcalls/lambdas/delete-llmcall/index.js +22 -0
- package/dist/services/agent/modules/llmcalls/lambdas/delete-llmcall/index.mjs +1 -0
- package/dist/services/agent/modules/llmcalls/lambdas/get-llm-usage/get-llm-usage.use-case.js +123 -0
- package/dist/services/agent/modules/llmcalls/lambdas/get-llm-usage/get-llm-usage.use-case.mjs +94 -0
- package/dist/services/agent/modules/llmcalls/lambdas/get-llm-usage/index.js +22 -0
- package/dist/services/agent/modules/llmcalls/lambdas/get-llm-usage/index.mjs +1 -0
- package/dist/services/agent/modules/llmcalls/lambdas/get-llmcall-by-id/get-llmcall-by-id.use-case.js +52 -0
- package/dist/services/agent/modules/llmcalls/lambdas/get-llmcall-by-id/get-llmcall-by-id.use-case.mjs +23 -0
- package/dist/services/agent/modules/llmcalls/lambdas/get-llmcall-by-id/index.js +22 -0
- package/dist/services/agent/modules/llmcalls/lambdas/get-llmcall-by-id/index.mjs +1 -0
- package/dist/services/agent/modules/llmcalls/lambdas/list-llmcalls-by-props/index.js +22 -0
- package/dist/services/agent/modules/llmcalls/lambdas/list-llmcalls-by-props/index.mjs +1 -0
- package/dist/services/agent/modules/llmcalls/lambdas/list-llmcalls-by-props/list-llmcalls-by-props.use-case.js +52 -0
- package/dist/services/agent/modules/llmcalls/lambdas/list-llmcalls-by-props/list-llmcalls-by-props.use-case.mjs +23 -0
- package/dist/services/agent/modules/llmcalls/lambdas/update-llmcall/index.js +22 -0
- package/dist/services/agent/modules/llmcalls/lambdas/update-llmcall/index.mjs +1 -0
- package/dist/services/agent/modules/llmcalls/lambdas/update-llmcall/update-llmcall.use-case.js +62 -0
- package/dist/services/agent/modules/llmcalls/lambdas/update-llmcall/update-llmcall.use-case.mjs +33 -0
- package/dist/services/agent/modules/llmcalls/repositories/index.js +22 -0
- package/dist/services/agent/modules/llmcalls/repositories/index.mjs +1 -0
- package/dist/services/agent/modules/llmcalls/repositories/llmcall.repository.js +67 -0
- package/dist/services/agent/modules/llmcalls/repositories/llmcall.repository.mjs +38 -0
- package/dist/services/agent/modules/mcp-servers/entities/index.js +22 -0
- package/dist/services/agent/modules/mcp-servers/entities/index.mjs +1 -0
- package/dist/services/agent/modules/mcp-servers/entities/mcpserver.entity.js +79 -0
- package/dist/services/agent/modules/mcp-servers/entities/mcpserver.entity.mjs +56 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/create-mcpserver/create-mcpserver.use-case.js +56 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/create-mcpserver/create-mcpserver.use-case.mjs +27 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/create-mcpserver/index.js +22 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/create-mcpserver/index.mjs +1 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/delete-mcpserver/delete-mcpserver.use-case.js +61 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/delete-mcpserver/delete-mcpserver.use-case.mjs +32 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/delete-mcpserver/index.js +22 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/delete-mcpserver/index.mjs +1 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/get-mcpserver-by-id/get-mcpserver-by-id.use-case.js +52 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/get-mcpserver-by-id/get-mcpserver-by-id.use-case.mjs +23 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/get-mcpserver-by-id/index.js +22 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/get-mcpserver-by-id/index.mjs +1 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/list-mcpservers-by-user/index.js +22 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/list-mcpservers-by-user/index.mjs +1 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/list-mcpservers-by-user/list-mcpservers-by-user.use-case.js +59 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/list-mcpservers-by-user/list-mcpservers-by-user.use-case.mjs +30 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/update-mcpserver/index.js +22 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/update-mcpserver/index.mjs +1 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/update-mcpserver/update-mcpserver.use-case.js +61 -0
- package/dist/services/agent/modules/mcp-servers/lambdas/update-mcpserver/update-mcpserver.use-case.mjs +32 -0
- package/dist/services/agent/modules/mcp-servers/repositories/index.js +22 -0
- package/dist/services/agent/modules/mcp-servers/repositories/index.mjs +1 -0
- package/dist/services/agent/modules/mcp-servers/repositories/mcpserver.repository.js +67 -0
- package/dist/services/agent/modules/mcp-servers/repositories/mcpserver.repository.mjs +38 -0
- package/dist/services/agent/skills/index.js +24 -0
- package/dist/services/agent/skills/index.mjs +2 -0
- package/dist/services/agent/skills/shared/index.js +22 -0
- package/dist/services/agent/skills/shared/index.mjs +1 -0
- package/dist/services/agent/skills/shared/shared-rules.js +37 -0
- package/dist/services/agent/skills/shared/shared-rules.mjs +11 -0
- package/dist/services/agent/skills/skill-runner.js +121 -0
- package/dist/services/agent/skills/skill-runner.mjs +92 -0
- package/dist/services/agent/skills/skill.js +128 -0
- package/dist/services/agent/skills/skill.mjs +105 -0
- package/dist/services/agent/tools/core/call-ai/call-ai.skill.js +54 -0
- package/dist/services/agent/tools/core/call-ai/call-ai.skill.mjs +31 -0
- package/dist/services/agent/tools/core/call-ai/call-ai.tool.js +68 -0
- package/dist/services/agent/tools/core/call-ai/call-ai.tool.mjs +45 -0
- package/dist/services/agent/tools/core/call-ai/index.js +22 -0
- package/dist/services/agent/tools/core/call-ai/index.mjs +1 -0
- package/dist/services/agent/tools/core/index.js +24 -0
- package/dist/services/agent/tools/core/index.mjs +2 -0
- package/dist/services/agent/tools/core/web-search/index.js +22 -0
- package/dist/services/agent/tools/core/web-search/index.mjs +1 -0
- package/dist/services/agent/tools/core/web-search/web-search.tool.js +51 -0
- package/dist/services/agent/tools/core/web-search/web-search.tool.mjs +30 -0
- package/dist/services/agent/tools/index.js +24 -0
- package/dist/services/agent/tools/index.mjs +2 -0
- package/dist/services/agent/tools/tool.js +57 -0
- package/dist/services/agent/tools/tool.mjs +34 -0
- package/dist/services/agent/utils/rank-tools-by-keywords.js +65 -0
- package/dist/services/agent/utils/rank-tools-by-keywords.mjs +42 -0
- package/dist/services/app/core/app.js +60 -0
- package/dist/services/app/core/app.mjs +47 -0
- package/dist/services/app/core/current-session.js +124 -0
- package/dist/services/app/core/current-session.mjs +104 -0
- package/dist/services/app/core/current-user.js +84 -0
- package/dist/services/app/core/current-user.mjs +61 -0
- package/dist/services/app/core/index.js +26 -0
- package/dist/services/app/core/index.mjs +3 -0
- package/dist/services/app/modules/authentication/lambdas/login/index.js +22 -0
- package/dist/services/app/modules/authentication/lambdas/login/index.mjs +1 -0
- package/dist/services/app/modules/authentication/lambdas/login/login.use-case.js +89 -0
- package/dist/services/app/modules/authentication/lambdas/login/login.use-case.mjs +50 -0
- package/dist/services/app/modules/users/entities/index.js +22 -0
- package/dist/services/app/modules/users/entities/index.mjs +1 -0
- package/dist/services/app/modules/users/entities/user-acquisition.js +55 -0
- package/dist/services/app/modules/users/entities/user-acquisition.mjs +26 -0
- package/dist/services/app/modules/users/entities/user-country.js +44 -0
- package/dist/services/app/modules/users/entities/user-country.mjs +21 -0
- package/dist/services/app/modules/users/entities/user-currency.js +44 -0
- package/dist/services/app/modules/users/entities/user-currency.mjs +21 -0
- package/dist/services/app/modules/users/entities/user-email.value-object.js +43 -0
- package/dist/services/app/modules/users/entities/user-email.value-object.mjs +20 -0
- package/dist/services/app/modules/users/entities/user-language.js +44 -0
- package/dist/services/app/modules/users/entities/user-language.mjs +21 -0
- package/dist/services/app/modules/users/entities/user-marketing.js +53 -0
- package/dist/services/app/modules/users/entities/user-marketing.mjs +24 -0
- package/dist/services/app/modules/users/entities/user-notification-preferences.js +41 -0
- package/dist/services/app/modules/users/entities/user-notification-preferences.mjs +18 -0
- package/dist/services/app/modules/users/entities/user-password.value-object.js +69 -0
- package/dist/services/app/modules/users/entities/user-password.value-object.mjs +36 -0
- package/dist/services/app/modules/users/entities/user-permissions.js +59 -0
- package/dist/services/app/modules/users/entities/user-permissions.mjs +36 -0
- package/dist/services/app/modules/users/entities/user-preferences.js +69 -0
- package/dist/services/app/modules/users/entities/user-preferences.mjs +46 -0
- package/dist/services/app/modules/users/entities/user-report-preferences.js +56 -0
- package/dist/services/app/modules/users/entities/user-report-preferences.mjs +33 -0
- package/dist/services/app/modules/users/entities/user-report-schedule.js +41 -0
- package/dist/services/app/modules/users/entities/user-report-schedule.mjs +18 -0
- package/dist/services/app/modules/users/entities/user-timezone.js +44 -0
- package/dist/services/app/modules/users/entities/user-timezone.mjs +21 -0
- package/dist/services/app/modules/users/entities/user.entity.js +133 -0
- package/dist/services/app/modules/users/entities/user.entity.mjs +103 -0
- package/dist/services/app/modules/users/lambdas/create-user/create-user.use-case.js +58 -0
- package/dist/services/app/modules/users/lambdas/create-user/create-user.use-case.mjs +29 -0
- package/dist/services/app/modules/users/lambdas/create-user/index.js +22 -0
- package/dist/services/app/modules/users/lambdas/create-user/index.mjs +1 -0
- package/dist/services/app/modules/users/lambdas/delete-user/delete-user.use-case.js +61 -0
- package/dist/services/app/modules/users/lambdas/delete-user/delete-user.use-case.mjs +32 -0
- package/dist/services/app/modules/users/lambdas/delete-user/index.js +22 -0
- package/dist/services/app/modules/users/lambdas/delete-user/index.mjs +1 -0
- package/dist/services/app/modules/users/lambdas/get-user-by-id/get-user-by-id.use-case.js +52 -0
- package/dist/services/app/modules/users/lambdas/get-user-by-id/get-user-by-id.use-case.mjs +23 -0
- package/dist/services/app/modules/users/lambdas/get-user-by-id/index.js +22 -0
- package/dist/services/app/modules/users/lambdas/get-user-by-id/index.mjs +1 -0
- package/dist/services/app/modules/users/lambdas/list-users-by-props/index.js +22 -0
- package/dist/services/app/modules/users/lambdas/list-users-by-props/index.mjs +1 -0
- package/dist/services/app/modules/users/lambdas/list-users-by-props/list-users-by-props.use-case.js +52 -0
- package/dist/services/app/modules/users/lambdas/list-users-by-props/list-users-by-props.use-case.mjs +23 -0
- package/dist/services/app/modules/users/lambdas/update-user/index.js +22 -0
- package/dist/services/app/modules/users/lambdas/update-user/index.mjs +1 -0
- package/dist/services/app/modules/users/lambdas/update-user/update-user.use-case.js +62 -0
- package/dist/services/app/modules/users/lambdas/update-user/update-user.use-case.mjs +33 -0
- package/dist/services/app/modules/users/repositories/index.js +22 -0
- package/dist/services/app/modules/users/repositories/index.mjs +1 -0
- package/dist/services/app/modules/users/repositories/user.repository.js +83 -0
- package/dist/services/app/modules/users/repositories/user.repository.mjs +54 -0
- package/package.json +2 -2
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var sanitize_string_exports = {};
|
|
30
|
+
__export(sanitize_string_exports, {
|
|
31
|
+
sanitizeString: () => sanitizeString
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(sanitize_string_exports);
|
|
34
|
+
var import_sanitize_html = __toESM(require("sanitize-html"));
|
|
35
|
+
function sanitizeString(input = "") {
|
|
36
|
+
if (!input) return void 0;
|
|
37
|
+
return (0, import_sanitize_html.default)(input, {
|
|
38
|
+
allowedTags: [],
|
|
39
|
+
allowedAttributes: {}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
sanitizeString
|
|
45
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "../../chunk-XRJFNASX.mjs";
|
|
2
|
+
import sanitizeHtml from "sanitize-html";
|
|
3
|
+
function sanitizeString(input = "") {
|
|
4
|
+
if (!input) return void 0;
|
|
5
|
+
return sanitizeHtml(input, {
|
|
6
|
+
allowedTags: [],
|
|
7
|
+
allowedAttributes: {}
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
sanitizeString
|
|
12
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var logger_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(logger_exports);
|
|
18
|
+
__reExport(logger_exports, require("./pino"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./pino")
|
|
22
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./pino";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var pino_exports = {};
|
|
30
|
+
__export(pino_exports, {
|
|
31
|
+
Logger: () => Logger,
|
|
32
|
+
logger: () => logger
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(pino_exports);
|
|
35
|
+
var import_config = require("dotenv/config");
|
|
36
|
+
var import_pino = __toESM(require("pino"));
|
|
37
|
+
var import_pino_pretty = __toESM(require("pino-pretty"));
|
|
38
|
+
const stream = (0, import_pino_pretty.default)({ colorize: true });
|
|
39
|
+
class Logger {
|
|
40
|
+
IS_LOCAL = process.env.IS_LOCAL === "true" || process.env.NODE_ENV === "development";
|
|
41
|
+
logger = this.IS_LOCAL ? (0, import_pino.default)({ level: "debug" }, stream) : (0, import_pino.default)({ level: "info" });
|
|
42
|
+
log(level, obj, msg) {
|
|
43
|
+
if (typeof obj === "string") {
|
|
44
|
+
msg = obj;
|
|
45
|
+
obj = void 0;
|
|
46
|
+
}
|
|
47
|
+
this.logger[level](obj ?? {}, msg || "");
|
|
48
|
+
}
|
|
49
|
+
info(obj, msg) {
|
|
50
|
+
this.log("info", obj, msg);
|
|
51
|
+
}
|
|
52
|
+
warn(obj, msg) {
|
|
53
|
+
this.log("warn", obj, msg);
|
|
54
|
+
}
|
|
55
|
+
debug(obj, msg) {
|
|
56
|
+
this.log("debug", obj, msg);
|
|
57
|
+
}
|
|
58
|
+
error(obj, msg) {
|
|
59
|
+
this.log("error", obj, msg);
|
|
60
|
+
}
|
|
61
|
+
fatal(obj, msg) {
|
|
62
|
+
this.log("fatal", obj, msg);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const logger = new Logger();
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
Logger,
|
|
69
|
+
logger
|
|
70
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import "../../chunk-XRJFNASX.mjs";
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import pino from "pino";
|
|
4
|
+
import pretty from "pino-pretty";
|
|
5
|
+
const stream = pretty({ colorize: true });
|
|
6
|
+
class Logger {
|
|
7
|
+
IS_LOCAL = process.env.IS_LOCAL === "true" || process.env.NODE_ENV === "development";
|
|
8
|
+
logger = this.IS_LOCAL ? pino({ level: "debug" }, stream) : pino({ level: "info" });
|
|
9
|
+
log(level, obj, msg) {
|
|
10
|
+
if (typeof obj === "string") {
|
|
11
|
+
msg = obj;
|
|
12
|
+
obj = void 0;
|
|
13
|
+
}
|
|
14
|
+
this.logger[level](obj ?? {}, msg || "");
|
|
15
|
+
}
|
|
16
|
+
info(obj, msg) {
|
|
17
|
+
this.log("info", obj, msg);
|
|
18
|
+
}
|
|
19
|
+
warn(obj, msg) {
|
|
20
|
+
this.log("warn", obj, msg);
|
|
21
|
+
}
|
|
22
|
+
debug(obj, msg) {
|
|
23
|
+
this.log("debug", obj, msg);
|
|
24
|
+
}
|
|
25
|
+
error(obj, msg) {
|
|
26
|
+
this.log("error", obj, msg);
|
|
27
|
+
}
|
|
28
|
+
fatal(obj, msg) {
|
|
29
|
+
this.log("fatal", obj, msg);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const logger = new Logger();
|
|
33
|
+
export {
|
|
34
|
+
Logger,
|
|
35
|
+
logger
|
|
36
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var repositories_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(repositories_exports);
|
|
18
|
+
__reExport(repositories_exports, require("./mongo-db.repository"), module.exports);
|
|
19
|
+
__reExport(repositories_exports, require("./mongo-db.client"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./mongo-db.repository"),
|
|
23
|
+
...require("./mongo-db.client")
|
|
24
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var mongo_db_client_exports = {};
|
|
20
|
+
__export(mongo_db_client_exports, {
|
|
21
|
+
MongoClient: () => MongoClient,
|
|
22
|
+
getMongoDBClient: () => getMongoDBClient
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(mongo_db_client_exports);
|
|
25
|
+
var import_mongodb = require("mongodb");
|
|
26
|
+
var import_secret_manager = require("@common/utils/secret-manager");
|
|
27
|
+
var import_logger = require("@common/logger");
|
|
28
|
+
var import_error = require("@common/error");
|
|
29
|
+
class MongoClient {
|
|
30
|
+
client;
|
|
31
|
+
logger = import_logger.logger;
|
|
32
|
+
isConnected = false;
|
|
33
|
+
constructor(uri, options) {
|
|
34
|
+
if (!uri) throw new Error("[Mongo Client]: uri parameter is required");
|
|
35
|
+
this.client = new import_mongodb.MongoClient(uri, {
|
|
36
|
+
...options,
|
|
37
|
+
connectTimeoutMS: 5e3,
|
|
38
|
+
serverSelectionTimeoutMS: 5e3
|
|
39
|
+
});
|
|
40
|
+
this.logger.info("[Mongo Client] Client initialized");
|
|
41
|
+
}
|
|
42
|
+
async connect() {
|
|
43
|
+
if (!this.client) throw new Error("[Mongo Client]: Client is not initialized");
|
|
44
|
+
if (!this.isConnected) {
|
|
45
|
+
await this.client.connect();
|
|
46
|
+
this.isConnected = true;
|
|
47
|
+
this.logger.info("[Mongo Client]: Connected to MongoDB");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async close(force) {
|
|
51
|
+
await this.client.close(force || false);
|
|
52
|
+
this.isConnected = false;
|
|
53
|
+
}
|
|
54
|
+
async db(dbName, options) {
|
|
55
|
+
try {
|
|
56
|
+
await this.connect();
|
|
57
|
+
} catch (error) {
|
|
58
|
+
this.logger.error("[Mongo Client]: Error connecting to MongoDB");
|
|
59
|
+
await (0, import_error.reportError)(`Error connecting to MongoDB: ${error.message}`, { error });
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
return this.client.db(dbName, options);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const mongoDBClients = /* @__PURE__ */ new Map();
|
|
66
|
+
function getMongoDBClient(envVarName = "OPENLOOPS_DB_URI") {
|
|
67
|
+
if (!mongoDBClients.has(envVarName)) {
|
|
68
|
+
const connString = import_secret_manager.secretManager.get(envVarName);
|
|
69
|
+
if (connString) {
|
|
70
|
+
mongoDBClients.set(envVarName, new MongoClient(connString, {}));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return mongoDBClients.get(envVarName);
|
|
74
|
+
}
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
MongoClient,
|
|
78
|
+
getMongoDBClient
|
|
79
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import "../../chunk-XRJFNASX.mjs";
|
|
2
|
+
import {
|
|
3
|
+
MongoClient as BaseMongoCLient
|
|
4
|
+
} from "mongodb";
|
|
5
|
+
import { secretManager } from "@common/utils/secret-manager";
|
|
6
|
+
import { logger } from "@common/logger";
|
|
7
|
+
import { reportError } from "@common/error";
|
|
8
|
+
class MongoClient {
|
|
9
|
+
client;
|
|
10
|
+
logger = logger;
|
|
11
|
+
isConnected = false;
|
|
12
|
+
constructor(uri, options) {
|
|
13
|
+
if (!uri) throw new Error("[Mongo Client]: uri parameter is required");
|
|
14
|
+
this.client = new BaseMongoCLient(uri, {
|
|
15
|
+
...options,
|
|
16
|
+
connectTimeoutMS: 5e3,
|
|
17
|
+
serverSelectionTimeoutMS: 5e3
|
|
18
|
+
});
|
|
19
|
+
this.logger.info("[Mongo Client] Client initialized");
|
|
20
|
+
}
|
|
21
|
+
async connect() {
|
|
22
|
+
if (!this.client) throw new Error("[Mongo Client]: Client is not initialized");
|
|
23
|
+
if (!this.isConnected) {
|
|
24
|
+
await this.client.connect();
|
|
25
|
+
this.isConnected = true;
|
|
26
|
+
this.logger.info("[Mongo Client]: Connected to MongoDB");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async close(force) {
|
|
30
|
+
await this.client.close(force || false);
|
|
31
|
+
this.isConnected = false;
|
|
32
|
+
}
|
|
33
|
+
async db(dbName, options) {
|
|
34
|
+
try {
|
|
35
|
+
await this.connect();
|
|
36
|
+
} catch (error) {
|
|
37
|
+
this.logger.error("[Mongo Client]: Error connecting to MongoDB");
|
|
38
|
+
await reportError(`Error connecting to MongoDB: ${error.message}`, { error });
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
return this.client.db(dbName, options);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const mongoDBClients = /* @__PURE__ */ new Map();
|
|
45
|
+
function getMongoDBClient(envVarName = "OPENLOOPS_DB_URI") {
|
|
46
|
+
if (!mongoDBClients.has(envVarName)) {
|
|
47
|
+
const connString = secretManager.get(envVarName);
|
|
48
|
+
if (connString) {
|
|
49
|
+
mongoDBClients.set(envVarName, new MongoClient(connString, {}));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return mongoDBClients.get(envVarName);
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
MongoClient,
|
|
56
|
+
getMongoDBClient
|
|
57
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var mongo_db_repository_exports = {};
|
|
20
|
+
__export(mongo_db_repository_exports, {
|
|
21
|
+
MongoRepository: () => MongoRepository
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(mongo_db_repository_exports);
|
|
24
|
+
var import_mongodb = require("mongodb");
|
|
25
|
+
var import_error = require("@common/error");
|
|
26
|
+
var import_mongo_db = require("./mongo-db.client");
|
|
27
|
+
const DEFAULT_LIMIT = 10;
|
|
28
|
+
class MongoRepository {
|
|
29
|
+
database;
|
|
30
|
+
collection;
|
|
31
|
+
dbClient;
|
|
32
|
+
_where = { deletedAt: null, archivedAt: null };
|
|
33
|
+
report = import_error.reportError;
|
|
34
|
+
constructor(props) {
|
|
35
|
+
const { database, collection, envvar } = props || {};
|
|
36
|
+
if (!database) throw new Error("[Mongo Repository] Database name is required");
|
|
37
|
+
if (!collection) throw new Error("[Mongo Repository] Collection name is required");
|
|
38
|
+
this.dbClient = (0, import_mongo_db.getMongoDBClient)(envvar);
|
|
39
|
+
if (!this.dbClient) throw new Error("[Mongo Repository] Database client not found");
|
|
40
|
+
this.database = database;
|
|
41
|
+
this.collection = collection;
|
|
42
|
+
}
|
|
43
|
+
parseId(id) {
|
|
44
|
+
return typeof id === "string" && import_mongodb.ObjectId.isValid(id) ? new import_mongodb.ObjectId(id) : void 0;
|
|
45
|
+
}
|
|
46
|
+
cleanInput(value) {
|
|
47
|
+
return value?.replace(/[{}[\]()\/\\]/g, "");
|
|
48
|
+
}
|
|
49
|
+
clampLimit(limit) {
|
|
50
|
+
const n = Number(limit);
|
|
51
|
+
return !Number.isFinite(n) || n <= 0 ? DEFAULT_LIMIT : n;
|
|
52
|
+
}
|
|
53
|
+
async findOne({ where, select, options }) {
|
|
54
|
+
try {
|
|
55
|
+
const db = await this.dbClient.db(this.database);
|
|
56
|
+
const collection = db.collection(this.collection);
|
|
57
|
+
const result = await collection.findOne(
|
|
58
|
+
{ ...where, ...this._where },
|
|
59
|
+
{
|
|
60
|
+
...select ? { projection: select } : {},
|
|
61
|
+
...options
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
return result;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
await this.report(error);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async findMany({ where, select, options }) {
|
|
71
|
+
try {
|
|
72
|
+
const db = await this.dbClient.db(this.database);
|
|
73
|
+
const collection = db.collection(this.collection);
|
|
74
|
+
const { page = 1, limit = 10 } = options || {};
|
|
75
|
+
const _limit = this.clampLimit(limit);
|
|
76
|
+
const _skip = +page > 0 ? (+page - 1) * _limit : 0;
|
|
77
|
+
const result = await collection.find({ ...where, ...this._where }, { projection: select }).sort(options?.sortBy || { _id: -1 }).skip(_skip).limit(_limit).toArray();
|
|
78
|
+
return result;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
await this.report(error);
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async findAll({ where, select }) {
|
|
85
|
+
try {
|
|
86
|
+
const db = await this.dbClient.db(this.database);
|
|
87
|
+
const collection = db.collection(this.collection);
|
|
88
|
+
const result = await collection.find({ ...where, ...this._where }, { projection: select }).toArray();
|
|
89
|
+
return result;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
await this.report(error);
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async createOne({ payload }) {
|
|
96
|
+
if (!payload || Object.keys(payload).length === 0) throw new Error("[Mongo Repository] Payload is required for createOne operation");
|
|
97
|
+
try {
|
|
98
|
+
const db = await this.dbClient.db(this.database);
|
|
99
|
+
const collection = db.collection(this.collection);
|
|
100
|
+
const { insertedId } = await collection.insertOne({ ...payload, __v: 1 });
|
|
101
|
+
return insertedId;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
await this.report(error);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async createMany({ payload }) {
|
|
108
|
+
try {
|
|
109
|
+
const db = await this.dbClient.db(this.database);
|
|
110
|
+
const collection = db.collection(this.collection);
|
|
111
|
+
const { insertedIds } = await collection.insertMany(payload);
|
|
112
|
+
return insertedIds;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
await this.report(error);
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async updateOne({ where, payload, options }) {
|
|
119
|
+
if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for updateOne operation");
|
|
120
|
+
if (!payload || Object.keys(payload).length === 0) throw new Error("[Mongo Repository] Payload is required for updateOne operation");
|
|
121
|
+
try {
|
|
122
|
+
const db = await this.dbClient.db(this.database);
|
|
123
|
+
const collection = db.collection(this.collection);
|
|
124
|
+
const { _id, __v, createdAt, createdBy, toUnset, ...toSet } = payload;
|
|
125
|
+
const __payload = {
|
|
126
|
+
...toSet ? { $set: toSet } : {},
|
|
127
|
+
...toUnset ? { $unset: toUnset } : {}
|
|
128
|
+
};
|
|
129
|
+
const result = await collection.findOneAndUpdate(
|
|
130
|
+
{ ...where, ...this._where },
|
|
131
|
+
{
|
|
132
|
+
$inc: { __v: 1 },
|
|
133
|
+
...__payload
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
returnDocument: "after"
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
return result;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
await this.report(error);
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async updateMany({ where, payload }) {
|
|
146
|
+
try {
|
|
147
|
+
const db = await this.dbClient.db(this.database);
|
|
148
|
+
const collection = db.collection(this.collection);
|
|
149
|
+
const result = await collection.updateMany(
|
|
150
|
+
{ ...where, ...this._where },
|
|
151
|
+
{ $set: payload }
|
|
152
|
+
);
|
|
153
|
+
const countUpdated = result.modifiedCount;
|
|
154
|
+
return countUpdated;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
await this.report(error);
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async deleteOne({ where }) {
|
|
161
|
+
try {
|
|
162
|
+
const db = await this.dbClient.db(this.database);
|
|
163
|
+
const collection = db.collection(this.collection);
|
|
164
|
+
const { deletedCount } = await collection.deleteOne({ ...where });
|
|
165
|
+
return deletedCount;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
await this.report(error);
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async deleteMany({ where }) {
|
|
172
|
+
try {
|
|
173
|
+
const db = await this.dbClient.db(this.database);
|
|
174
|
+
const collection = db.collection(this.collection);
|
|
175
|
+
const { deletedCount } = await collection.deleteMany({ ...where });
|
|
176
|
+
return deletedCount;
|
|
177
|
+
} catch (error) {
|
|
178
|
+
await this.report(error);
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async count({ where, options }) {
|
|
183
|
+
try {
|
|
184
|
+
const db = await this.dbClient.db(this.database);
|
|
185
|
+
const collection = db.collection(this.collection);
|
|
186
|
+
const result = await collection.countDocuments({ ...where, ...options?.includeDeleted ? {} : this._where });
|
|
187
|
+
return result;
|
|
188
|
+
} catch (error) {
|
|
189
|
+
await this.report(error);
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async aggregate(pipeline) {
|
|
194
|
+
try {
|
|
195
|
+
const db = await this.dbClient.db(this.database);
|
|
196
|
+
const collection = db.collection(this.collection);
|
|
197
|
+
const result = await collection.aggregate(pipeline).toArray();
|
|
198
|
+
return result;
|
|
199
|
+
} catch (error) {
|
|
200
|
+
await this.report(error);
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async distinct(field, where) {
|
|
205
|
+
try {
|
|
206
|
+
const db = await this.dbClient.db(this.database);
|
|
207
|
+
const collection = db.collection(this.collection);
|
|
208
|
+
const result = await collection.distinct(field, { ...where, ...this._where });
|
|
209
|
+
return result;
|
|
210
|
+
} catch (error) {
|
|
211
|
+
await this.report(error);
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
217
|
+
0 && (module.exports = {
|
|
218
|
+
MongoRepository
|
|
219
|
+
});
|