openloops 0.10.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -2
- package/README.md +14 -20
- package/dist/clients/llm/llm-client.d.ts +2 -2
- package/dist/clients/llm/llm-client.js +17 -18
- package/dist/clients/llm/llm-client.mjs +12 -13
- package/dist/clients/llm/llm-types.d.ts +2 -2
- package/dist/clients/llm/model-resolution.js +4 -5
- package/dist/clients/llm/model-resolution.mjs +1 -2
- package/dist/clients/serper/serper-client.js +3 -4
- package/dist/clients/serper/serper-client.mjs +1 -2
- package/dist/clients/slack/slack-client.js +2 -2
- package/dist/clients/slack/slack-client.mjs +1 -1
- package/dist/common/utils/number-setting.js +2 -2
- package/dist/common/utils/number-setting.mjs +1 -1
- package/dist/db/indexes/index.js +1 -5
- package/dist/db/indexes/index.mjs +1 -5
- package/dist/guardrails/guard.d.ts +4 -4
- package/dist/harness/actor-profile.d.ts +2 -0
- package/dist/{common/error/error-reporter.js → harness/actor-profile.js} +10 -13
- package/dist/harness/actor-profile.mjs +9 -0
- package/dist/harness/agent-loop.d.ts +4 -5
- package/dist/harness/agent.d.ts +7 -7
- package/dist/harness/agent.js +46 -46
- package/dist/harness/agent.mjs +44 -44
- package/dist/harness/default-model.d.ts +20 -0
- package/dist/harness/default-model.js +72 -0
- package/dist/harness/default-model.mjs +46 -0
- package/dist/harness/index.d.ts +2 -0
- package/dist/harness/index.js +8 -1
- package/dist/harness/index.mjs +5 -1
- package/dist/harness/tool-pipeline.d.ts +1 -1
- package/dist/harness/tool-pipeline.js +3 -3
- package/dist/harness/tool-pipeline.mjs +1 -1
- package/dist/harness/usage-limit.d.ts +2 -2
- package/dist/harness/usage-limit.js +5 -3
- package/dist/harness/usage-limit.mjs +5 -3
- package/dist/harness/workspace.d.ts +3 -3
- package/dist/harness/workspace.js +8 -8
- package/dist/harness/workspace.mjs +8 -8
- package/dist/loops/agi/loop.js +2 -2
- package/dist/loops/agi/loop.mjs +2 -2
- package/dist/services/automations/entities/automation-run.entity.d.ts +1 -1
- package/dist/services/automations/entities/automation-run.entity.js +4 -4
- package/dist/services/automations/entities/automation-run.entity.mjs +1 -1
- package/dist/services/automations/entities/automation.entity.d.ts +1 -1
- package/dist/services/automations/entities/automation.entity.js +3 -3
- package/dist/services/automations/entities/automation.entity.mjs +1 -1
- package/dist/services/automations/repositories/automation-run.repository.d.ts +1 -1
- package/dist/services/automations/repositories/automation-run.repository.js +5 -6
- package/dist/services/automations/repositories/automation-run.repository.mjs +2 -3
- package/dist/services/automations/repositories/automation.repository.d.ts +1 -1
- package/dist/services/automations/repositories/automation.repository.js +5 -6
- package/dist/services/automations/repositories/automation.repository.mjs +2 -3
- package/dist/services/automations/runner/automation-runner.d.ts +4 -4
- package/dist/services/automations/runner/automation-runner.js +16 -15
- package/dist/services/automations/runner/automation-runner.mjs +11 -10
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.js +2 -2
- package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/claim-due-automations.use-case.js +3 -4
- package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +1 -2
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +2 -2
- package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/create-automation.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/create-automation.use-case.js +8 -8
- package/dist/services/automations/use-cases/create-automation.use-case.mjs +5 -5
- package/dist/services/automations/use-cases/delete-automation.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/delete-automation.use-case.js +8 -8
- package/dist/services/automations/use-cases/delete-automation.use-case.mjs +5 -5
- package/dist/services/automations/use-cases/finish-automation-run.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/finish-automation-run.use-case.js +2 -2
- package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.js +7 -7
- package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +4 -4
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +7 -7
- package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +4 -4
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.d.ts +2 -2
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +7 -7
- package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +4 -4
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.d.ts +2 -2
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.js +9 -9
- package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.mjs +6 -6
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.d.ts +2 -2
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.js +9 -9
- package/dist/services/automations/use-cases/list-automations-by-user.use-case.mjs +6 -6
- package/dist/services/automations/use-cases/preview-automation-runs.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/preview-automation-runs.use-case.js +2 -2
- package/dist/services/automations/use-cases/preview-automation-runs.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/receive-automation-event.use-case.js +3 -3
- package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +2 -2
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.js +2 -2
- package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +10 -11
- package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +7 -8
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +7 -7
- package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +4 -4
- package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/start-automation-run.use-case.js +5 -5
- package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +4 -4
- package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/sync-automation-run.use-case.js +2 -2
- package/dist/services/automations/use-cases/sync-automation-run.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/sync-automation-runs.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/sync-automation-runs.use-case.js +2 -2
- package/dist/services/automations/use-cases/sync-automation-runs.use-case.mjs +1 -1
- package/dist/services/automations/use-cases/update-automation.use-case.d.ts +1 -1
- package/dist/services/automations/use-cases/update-automation.use-case.js +8 -9
- package/dist/services/automations/use-cases/update-automation.use-case.mjs +4 -5
- package/dist/services/automations/utils/event-token.d.ts +1 -0
- package/dist/services/automations/utils/event-token.js +9 -6
- package/dist/services/automations/utils/event-token.mjs +3 -1
- package/dist/services/automations/utils/open-run.d.ts +1 -1
- package/dist/services/automations/utils/runner-scope.d.ts +1 -1
- package/dist/services/automations/utils/runner-scope.js +3 -3
- package/dist/services/automations/utils/runner-scope.mjs +1 -1
- package/dist/services/chats/entities/chat-message.entity.d.ts +1 -1
- package/dist/services/chats/entities/chat-message.entity.js +3 -3
- package/dist/services/chats/entities/chat-message.entity.mjs +1 -1
- package/dist/services/chats/entities/chat.entity.d.ts +1 -1
- package/dist/services/chats/entities/chat.entity.js +4 -4
- package/dist/services/chats/entities/chat.entity.mjs +1 -1
- package/dist/services/chats/repositories/chat.repository.d.ts +1 -1
- package/dist/services/chats/repositories/chat.repository.js +5 -6
- package/dist/services/chats/repositories/chat.repository.mjs +2 -3
- package/dist/services/chats/use-cases/create-chat.use-case.d.ts +1 -1
- package/dist/services/chats/use-cases/create-chat.use-case.js +7 -7
- package/dist/services/chats/use-cases/create-chat.use-case.mjs +4 -4
- package/dist/services/chats/use-cases/delete-chat.use-case.d.ts +1 -1
- package/dist/services/chats/use-cases/delete-chat.use-case.js +8 -8
- package/dist/services/chats/use-cases/delete-chat.use-case.mjs +5 -5
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.d.ts +2 -2
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.js +7 -7
- package/dist/services/chats/use-cases/get-chat-by-id.use-case.mjs +4 -4
- package/dist/services/chats/use-cases/interrupt-execution.use-case.d.ts +1 -1
- package/dist/services/chats/use-cases/interrupt-execution.use-case.js +7 -7
- package/dist/services/chats/use-cases/interrupt-execution.use-case.mjs +4 -4
- package/dist/services/chats/use-cases/list-chats-by-props.use-case.d.ts +2 -2
- package/dist/services/chats/use-cases/list-chats-by-props.use-case.js +7 -7
- package/dist/services/chats/use-cases/list-chats-by-props.use-case.mjs +4 -4
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.d.ts +2 -2
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +8 -8
- package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +5 -5
- package/dist/services/chats/use-cases/update-chat.use-case.d.ts +1 -1
- package/dist/services/chats/use-cases/update-chat.use-case.js +7 -7
- package/dist/services/chats/use-cases/update-chat.use-case.mjs +4 -4
- package/dist/services/llmcalls/entities/llmcall.entity.d.ts +1 -1
- package/dist/services/llmcalls/entities/llmcall.entity.js +4 -4
- package/dist/services/llmcalls/entities/llmcall.entity.mjs +1 -1
- package/dist/services/llmcalls/repositories/llmcall.repository.d.ts +1 -1
- package/dist/services/llmcalls/repositories/llmcall.repository.js +5 -6
- package/dist/services/llmcalls/repositories/llmcall.repository.mjs +2 -3
- package/dist/services/llmcalls/use-cases/create-llmcall.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/create-llmcall.use-case.js +7 -7
- package/dist/services/llmcalls/use-cases/create-llmcall.use-case.mjs +4 -4
- package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.js +8 -8
- package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.mjs +5 -5
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +9 -9
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +6 -6
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.js +9 -9
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +6 -6
- package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.d.ts +2 -2
- package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.js +12 -10
- package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.mjs +9 -7
- package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.js +7 -7
- package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.mjs +4 -4
- package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.d.ts +2 -2
- package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.js +5 -5
- package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.mjs +4 -4
- package/dist/services/llmcalls/use-cases/update-llmcall.use-case.d.ts +1 -1
- package/dist/services/llmcalls/use-cases/update-llmcall.use-case.js +7 -7
- package/dist/services/llmcalls/use-cases/update-llmcall.use-case.mjs +4 -4
- package/dist/services/mcp-servers/admin/admin-params.d.ts +5 -0
- package/dist/{common/logger/index.js → services/mcp-servers/admin/admin-params.js} +2 -8
- package/dist/services/mcp-servers/admin/admin-params.mjs +0 -0
- package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.d.ts +3 -2
- package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.js +7 -7
- package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.mjs +4 -4
- package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.d.ts +3 -2
- package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.js +7 -7
- package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.mjs +4 -4
- package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.d.ts +3 -2
- package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.js +7 -7
- package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.mjs +4 -4
- package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.d.ts +4 -3
- package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.js +7 -7
- package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.mjs +4 -4
- package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.d.ts +3 -2
- package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.js +8 -9
- package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.mjs +4 -5
- package/dist/services/mcp-servers/entities/mcpserver.entity.d.ts +1 -1
- package/dist/services/mcp-servers/entities/mcpserver.entity.js +2 -2
- package/dist/services/mcp-servers/entities/mcpserver.entity.mjs +1 -1
- package/dist/services/mcp-servers/repositories/mcpserver.repository.d.ts +1 -1
- package/dist/services/mcp-servers/repositories/mcpserver.repository.js +6 -7
- package/dist/services/mcp-servers/repositories/mcpserver.repository.mjs +2 -3
- package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.js +8 -8
- package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.mjs +5 -5
- package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.js +7 -7
- package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.mjs +4 -4
- package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.js +8 -8
- package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.mjs +5 -5
- package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.js +7 -7
- package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.mjs +4 -4
- package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.js +8 -8
- package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.mjs +5 -5
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.d.ts +2 -2
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.js +8 -8
- package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.mjs +5 -5
- package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.js +9 -10
- package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.mjs +5 -6
- package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.d.ts +1 -1
- package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.js +9 -10
- package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.mjs +4 -5
- package/dist/services/tasks/entities/agent-action.entity.d.ts +1 -1
- package/dist/services/tasks/entities/agent-action.entity.js +6 -7
- package/dist/services/tasks/entities/agent-action.entity.mjs +1 -2
- package/dist/services/tasks/entities/agent-task.entity.d.ts +1 -1
- package/dist/services/tasks/entities/agent-task.entity.js +4 -4
- package/dist/services/tasks/entities/agent-task.entity.mjs +1 -1
- package/dist/services/tasks/repositories/agent-action.repository.d.ts +1 -1
- package/dist/services/tasks/repositories/agent-action.repository.js +5 -6
- package/dist/services/tasks/repositories/agent-action.repository.mjs +2 -3
- package/dist/services/tasks/repositories/agent-task.repository.d.ts +1 -1
- package/dist/services/tasks/repositories/agent-task.repository.js +5 -6
- package/dist/services/tasks/repositories/agent-task.repository.mjs +2 -3
- package/dist/services/tasks/use-cases/create-agent-action.use-case.d.ts +1 -1
- package/dist/services/tasks/use-cases/create-agent-action.use-case.js +7 -7
- package/dist/services/tasks/use-cases/create-agent-action.use-case.mjs +4 -4
- package/dist/services/tasks/use-cases/create-agent-task.use-case.d.ts +1 -1
- package/dist/services/tasks/use-cases/create-agent-task.use-case.js +7 -7
- package/dist/services/tasks/use-cases/create-agent-task.use-case.mjs +4 -4
- package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.d.ts +1 -1
- package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.js +7 -7
- package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.mjs +4 -4
- package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.d.ts +2 -2
- package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.js +9 -10
- package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.mjs +6 -7
- package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.d.ts +2 -2
- package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.js +9 -10
- package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.mjs +6 -7
- package/dist/services/tasks/use-cases/update-agent-action.use-case.d.ts +1 -1
- package/dist/services/tasks/use-cases/update-agent-action.use-case.js +7 -7
- package/dist/services/tasks/use-cases/update-agent-action.use-case.mjs +4 -4
- package/dist/services/tasks/use-cases/update-agent-task.use-case.d.ts +1 -1
- package/dist/services/tasks/use-cases/update-agent-task.use-case.js +7 -7
- package/dist/services/tasks/use-cases/update-agent-task.use-case.mjs +4 -4
- package/dist/services/traces/entities/agent-trace-entry.entity.d.ts +1 -1
- package/dist/services/traces/entities/agent-trace-entry.entity.js +6 -6
- package/dist/services/traces/entities/agent-trace-entry.entity.mjs +1 -1
- package/dist/services/traces/repositories/agent-trace.repository.d.ts +1 -1
- package/dist/services/traces/repositories/agent-trace.repository.js +4 -4
- package/dist/services/traces/repositories/agent-trace.repository.mjs +2 -2
- package/dist/services/traces/use-cases/create-agent-traces.use-case.d.ts +1 -1
- package/dist/services/traces/use-cases/create-agent-traces.use-case.js +7 -7
- package/dist/services/traces/use-cases/create-agent-traces.use-case.mjs +4 -4
- package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.d.ts +2 -2
- package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.js +12 -13
- package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.mjs +6 -7
- package/dist/services/workspaces/entities/workspace-item.entity.d.ts +1 -1
- package/dist/services/workspaces/entities/workspace-item.entity.js +5 -5
- package/dist/services/workspaces/entities/workspace-item.entity.mjs +1 -1
- package/dist/services/workspaces/repositories/workspace-item.repository.d.ts +1 -1
- package/dist/services/workspaces/repositories/workspace-item.repository.js +5 -6
- package/dist/services/workspaces/repositories/workspace-item.repository.mjs +2 -3
- package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.d.ts +1 -1
- package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.js +11 -12
- package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.mjs +6 -7
- package/dist/services/workspaces/use-cases/get-workspace-item.use-case.d.ts +1 -1
- package/dist/services/workspaces/use-cases/get-workspace-item.use-case.js +11 -12
- package/dist/services/workspaces/use-cases/get-workspace-item.use-case.mjs +6 -7
- package/dist/services/workspaces/use-cases/list-workspace-items.use-case.d.ts +2 -2
- package/dist/services/workspaces/use-cases/list-workspace-items.use-case.js +11 -12
- package/dist/services/workspaces/use-cases/list-workspace-items.use-case.mjs +6 -7
- package/dist/services/workspaces/use-cases/save-workspace-item.use-case.d.ts +1 -1
- package/dist/services/workspaces/use-cases/save-workspace-item.use-case.js +10 -11
- package/dist/services/workspaces/use-cases/save-workspace-item.use-case.mjs +6 -7
- package/dist/services/workspaces/use-cases/search-workspace-items.use-case.d.ts +2 -2
- package/dist/services/workspaces/use-cases/search-workspace-items.use-case.js +11 -12
- package/dist/services/workspaces/use-cases/search-workspace-items.use-case.mjs +6 -7
- package/dist/skills/runtime-context.d.ts +3 -3
- package/dist/skills/runtime-context.js +24 -21
- package/dist/skills/runtime-context.mjs +24 -21
- package/dist/skills/skill.d.ts +3 -3
- package/dist/skills/skill.js +5 -5
- package/dist/skills/skill.mjs +4 -4
- package/dist/tools/core/call-ai/call-ai.tool.js +2 -2
- package/dist/tools/core/call-ai/call-ai.tool.mjs +2 -2
- package/dist/tools/core/web-search/web-search.tool.js +1 -1
- package/dist/tools/core/web-search/web-search.tool.mjs +1 -1
- package/dist/tools/tool.d.ts +2 -2
- package/dist/tools/tool.js +1 -1
- package/dist/tools/tool.mjs +1 -1
- package/docs/README.md +1 -1
- package/docs/agent.md +10 -10
- package/docs/authentication.md +15 -114
- package/docs/authorization.md +18 -18
- package/docs/automations.md +30 -28
- package/docs/chats.md +14 -14
- package/docs/configuration.md +14 -15
- package/docs/error-reporting.md +6 -6
- package/docs/guardrails.md +1 -1
- package/docs/integration-guide.md +12 -12
- package/docs/loops.md +2 -2
- package/docs/mcp-servers.md +15 -15
- package/docs/skills.md +1 -1
- package/docs/tools.md +2 -2
- package/docs/usage.md +5 -5
- package/docs/users.md +18 -91
- package/examples/automations/create-automation.ts +4 -4
- package/examples/automations/create-event-automation.ts +5 -5
- package/examples/automations/list-automation-runs.ts +7 -7
- package/examples/automations/list-automations.ts +4 -4
- package/examples/automations/preview-automation-runs.ts +1 -1
- package/examples/automations/receive-automation-event.ts +1 -1
- package/examples/automations/revoke-automation-event-token.ts +6 -6
- package/examples/automations/run-automation-now.ts +4 -4
- package/examples/automations/run-automation-worker.ts +1 -1
- package/examples/automations/update-automation.ts +6 -6
- package/examples/chats/delete-chat.ts +6 -6
- package/examples/chats/get-chat-by-id.ts +6 -6
- package/examples/chats/list-autonomous-chats.ts +4 -4
- package/examples/chats/list-chats.ts +4 -4
- package/examples/chats/search-chats.ts +5 -5
- package/examples/errors/error-reporting.ts +6 -6
- package/examples/loops/custom-loop.ts +5 -5
- package/examples/mcps/create-mcp.ts +4 -4
- package/examples/mcps/decide-mcp.ts +7 -7
- package/examples/mcps/delete-mcp.ts +6 -6
- package/examples/mcps/get-mcp-by-id.ts +4 -4
- package/examples/mcps/internal-mcp-admin.ts +8 -8
- package/examples/mcps/internal-mcp.ts +5 -5
- package/examples/mcps/list-all-mcps.ts +4 -4
- package/examples/mcps/list-user-mcps.ts +4 -4
- package/examples/mcps/update-mcp.ts +4 -4
- package/examples/mcps/verify-mcp.ts +4 -4
- package/examples/run-agent/interrupt-agent.ts +5 -5
- package/examples/run-agent/run-agent-autonomous.ts +5 -5
- package/examples/run-agent/run-agent-multi-tenant.ts +10 -11
- package/examples/run-agent/run-agent-strict-mode.ts +5 -5
- package/examples/run-agent/run-agent-with-confirmation.ts +6 -6
- package/examples/run-agent/run-agent-with-fallback-model.ts +5 -5
- package/examples/run-agent/run-agent-with-fetch-url.ts +5 -5
- package/examples/run-agent/run-agent-with-guards.ts +5 -5
- package/examples/run-agent/run-agent-with-hooks.ts +5 -5
- package/examples/run-agent/run-agent-with-identity.ts +5 -5
- package/examples/run-agent/run-agent-with-model.ts +5 -5
- package/examples/run-agent/run-agent-with-slack.ts +5 -5
- package/examples/run-agent/run-agent-with-tools.ts +5 -5
- package/examples/run-agent/run-agent-with-usage-limit-stop.ts +5 -5
- package/examples/run-agent/run-agent-with-usage-limit.ts +5 -5
- package/examples/tools/basic-tool.ts +1 -1
- package/examples/tools/web-search-tool.ts +1 -1
- package/examples/usage/get-chat-usage.ts +4 -4
- package/examples/usage/get-message-usage.ts +4 -4
- package/examples/usage/get-usage-stats-by-range.ts +4 -4
- package/examples/usage/get-usage-stats.ts +4 -4
- package/examples/users/set-default-model.ts +12 -21
- package/package.json +7 -22
- package/dist/common/base/base.app.d.ts +0 -12
- package/dist/common/base/base.app.js +0 -57
- package/dist/common/base/base.app.mjs +0 -33
- package/dist/common/base/base.entity.d.ts +0 -38
- package/dist/common/base/base.entity.js +0 -100
- package/dist/common/base/base.entity.mjs +0 -76
- package/dist/common/base/base.use-case.d.ts +0 -11
- package/dist/common/base/base.use-case.js +0 -30
- package/dist/common/base/base.use-case.mjs +0 -6
- package/dist/common/base/current-session.d.ts +0 -129
- package/dist/common/base/current-session.js +0 -123
- package/dist/common/base/current-session.mjs +0 -98
- package/dist/common/base/current-user.d.ts +0 -16
- package/dist/common/base/current-user.js +0 -85
- package/dist/common/base/current-user.mjs +0 -61
- package/dist/common/base/index.d.ts +0 -3
- package/dist/common/base/index.js +0 -26
- package/dist/common/base/index.mjs +0 -3
- package/dist/common/base/share.d.ts +0 -12
- package/dist/common/base/share.js +0 -45
- package/dist/common/base/share.mjs +0 -20
- package/dist/common/base/utils/index.d.ts +0 -2
- package/dist/common/base/utils/index.js +0 -24
- package/dist/common/base/utils/index.mjs +0 -2
- package/dist/common/base/utils/is-plain-object.d.ts +0 -1
- package/dist/common/base/utils/is-plain-object.js +0 -32
- package/dist/common/base/utils/is-plain-object.mjs +0 -8
- package/dist/common/base/utils/to-patch.d.ts +0 -9
- package/dist/common/base/utils/to-patch.js +0 -46
- package/dist/common/base/utils/to-patch.mjs +0 -21
- package/dist/common/error/error-reporter.d.ts +0 -11
- package/dist/common/error/error-reporter.mjs +0 -11
- package/dist/common/error/http-error.d.ts +0 -11
- package/dist/common/error/http-error.js +0 -37
- package/dist/common/error/http-error.mjs +0 -13
- package/dist/common/error/index.d.ts +0 -3
- package/dist/common/error/index.js +0 -26
- package/dist/common/error/index.mjs +0 -3
- package/dist/common/error/reportError.d.ts +0 -2
- package/dist/common/error/reportError.js +0 -61
- package/dist/common/error/reportError.mjs +0 -37
- package/dist/common/error/sentry-client.d.ts +0 -10
- package/dist/common/error/sentry-client.js +0 -82
- package/dist/common/error/sentry-client.mjs +0 -57
- package/dist/common/index.d.ts +0 -6
- package/dist/common/index.js +0 -37
- package/dist/common/index.mjs +0 -9
- package/dist/common/logger/index.d.ts +0 -1
- package/dist/common/logger/index.mjs +0 -1
- package/dist/common/logger/pino.d.ts +0 -12
- package/dist/common/logger/pino.js +0 -79
- package/dist/common/logger/pino.mjs +0 -44
- package/dist/common/repositories/index.d.ts +0 -3
- package/dist/common/repositories/index.js +0 -26
- package/dist/common/repositories/index.mjs +0 -3
- package/dist/common/repositories/mongo-db.client.d.ts +0 -11
- package/dist/common/repositories/mongo-db.client.js +0 -83
- package/dist/common/repositories/mongo-db.client.mjs +0 -60
- package/dist/common/repositories/mongo-db.repository.d.ts +0 -130
- package/dist/common/repositories/mongo-db.repository.js +0 -357
- package/dist/common/repositories/mongo-db.repository.mjs +0 -332
- package/dist/common/repositories/scope.d.ts +0 -19
- package/dist/common/repositories/scope.js +0 -63
- package/dist/common/repositories/scope.mjs +0 -39
- package/dist/common/utils/config-context.d.ts +0 -3
- package/dist/common/utils/config-context.js +0 -33
- package/dist/common/utils/config-context.mjs +0 -8
- package/dist/common/utils/database-name.d.ts +0 -2
- package/dist/common/utils/database-name.js +0 -32
- package/dist/common/utils/database-name.mjs +0 -7
- package/dist/common/utils/secret-manager.d.ts +0 -17
- package/dist/common/utils/secret-manager.js +0 -124
- package/dist/common/utils/secret-manager.mjs +0 -89
- package/dist/db/indexes/refresh-tokens.d.ts +0 -2
- package/dist/db/indexes/refresh-tokens.js +0 -33
- package/dist/db/indexes/refresh-tokens.mjs +0 -9
- package/dist/db/indexes/revoked-tokens.d.ts +0 -2
- package/dist/db/indexes/revoked-tokens.js +0 -31
- package/dist/db/indexes/revoked-tokens.mjs +0 -7
- package/dist/services/authentication/entities/index.d.ts +0 -2
- package/dist/services/authentication/entities/index.js +0 -24
- package/dist/services/authentication/entities/index.mjs +0 -2
- package/dist/services/authentication/entities/refresh-token.entity.d.ts +0 -25
- package/dist/services/authentication/entities/refresh-token.entity.js +0 -75
- package/dist/services/authentication/entities/refresh-token.entity.mjs +0 -51
- package/dist/services/authentication/entities/revoked-token.entity.d.ts +0 -17
- package/dist/services/authentication/entities/revoked-token.entity.js +0 -67
- package/dist/services/authentication/entities/revoked-token.entity.mjs +0 -43
- package/dist/services/authentication/helpers/auth-config.d.ts +0 -9
- package/dist/services/authentication/helpers/auth-config.js +0 -36
- package/dist/services/authentication/helpers/auth-config.mjs +0 -12
- package/dist/services/authentication/helpers/session-tokens.d.ts +0 -16
- package/dist/services/authentication/helpers/session-tokens.js +0 -60
- package/dist/services/authentication/helpers/session-tokens.mjs +0 -35
- package/dist/services/authentication/helpers/tokens.d.ts +0 -43
- package/dist/services/authentication/helpers/tokens.js +0 -113
- package/dist/services/authentication/helpers/tokens.mjs +0 -71
- package/dist/services/authentication/index.d.ts +0 -5
- package/dist/services/authentication/index.js +0 -47
- package/dist/services/authentication/index.mjs +0 -13
- package/dist/services/authentication/module.d.ts +0 -16
- package/dist/services/authentication/module.js +0 -81
- package/dist/services/authentication/module.mjs +0 -50
- package/dist/services/authentication/repositories/index.d.ts +0 -2
- package/dist/services/authentication/repositories/index.js +0 -24
- package/dist/services/authentication/repositories/index.mjs +0 -2
- package/dist/services/authentication/repositories/refresh-token.repository.d.ts +0 -10
- package/dist/services/authentication/repositories/refresh-token.repository.js +0 -60
- package/dist/services/authentication/repositories/refresh-token.repository.mjs +0 -36
- package/dist/services/authentication/repositories/revoked-token.repository.d.ts +0 -7
- package/dist/services/authentication/repositories/revoked-token.repository.js +0 -44
- package/dist/services/authentication/repositories/revoked-token.repository.mjs +0 -20
- package/dist/services/authentication/use-cases/claim-refresh-token.use-case.d.ts +0 -12
- package/dist/services/authentication/use-cases/claim-refresh-token.use-case.js +0 -40
- package/dist/services/authentication/use-cases/claim-refresh-token.use-case.mjs +0 -16
- package/dist/services/authentication/use-cases/create-refresh-token.use-case.d.ts +0 -11
- package/dist/services/authentication/use-cases/create-refresh-token.use-case.js +0 -43
- package/dist/services/authentication/use-cases/create-refresh-token.use-case.mjs +0 -19
- package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.d.ts +0 -11
- package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.js +0 -40
- package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.mjs +0 -16
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +0 -13
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.js +0 -42
- package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +0 -18
- package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.d.ts +0 -18
- package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.js +0 -49
- package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.mjs +0 -25
- package/dist/services/authentication/use-cases/issue-session.use-case.d.ts +0 -13
- package/dist/services/authentication/use-cases/issue-session.use-case.js +0 -48
- package/dist/services/authentication/use-cases/issue-session.use-case.mjs +0 -24
- package/dist/services/authentication/use-cases/login.use-case.d.ts +0 -20
- package/dist/services/authentication/use-cases/login.use-case.js +0 -54
- package/dist/services/authentication/use-cases/login.use-case.mjs +0 -30
- package/dist/services/authentication/use-cases/logout.use-case.d.ts +0 -14
- package/dist/services/authentication/use-cases/logout.use-case.js +0 -48
- package/dist/services/authentication/use-cases/logout.use-case.mjs +0 -24
- package/dist/services/authentication/use-cases/refresh.use-case.d.ts +0 -23
- package/dist/services/authentication/use-cases/refresh.use-case.js +0 -84
- package/dist/services/authentication/use-cases/refresh.use-case.mjs +0 -60
- package/dist/services/authentication/use-cases/reset-password.use-case.d.ts +0 -15
- package/dist/services/authentication/use-cases/reset-password.use-case.js +0 -61
- package/dist/services/authentication/use-cases/reset-password.use-case.mjs +0 -37
- package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.d.ts +0 -11
- package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.js +0 -40
- package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.mjs +0 -16
- package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +0 -12
- package/dist/services/authentication/use-cases/revoke-token.use-case.js +0 -52
- package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +0 -28
- package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.d.ts +0 -13
- package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.js +0 -40
- package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.mjs +0 -16
- package/dist/services/users/entities/index.d.ts +0 -1
- package/dist/services/users/entities/index.js +0 -22
- package/dist/services/users/entities/index.mjs +0 -1
- package/dist/services/users/entities/user-acquisition.d.ts +0 -12
- package/dist/services/users/entities/user-acquisition.js +0 -42
- package/dist/services/users/entities/user-acquisition.mjs +0 -18
- package/dist/services/users/entities/user-country.d.ts +0 -11
- package/dist/services/users/entities/user-country.js +0 -44
- package/dist/services/users/entities/user-country.mjs +0 -20
- package/dist/services/users/entities/user-currency.d.ts +0 -13
- package/dist/services/users/entities/user-currency.js +0 -44
- package/dist/services/users/entities/user-currency.mjs +0 -20
- package/dist/services/users/entities/user-default-model.d.ts +0 -11
- package/dist/services/users/entities/user-default-model.js +0 -42
- package/dist/services/users/entities/user-default-model.mjs +0 -18
- package/dist/services/users/entities/user-email.value-object.d.ts +0 -6
- package/dist/services/users/entities/user-email.value-object.js +0 -43
- package/dist/services/users/entities/user-email.value-object.mjs +0 -19
- package/dist/services/users/entities/user-language.d.ts +0 -11
- package/dist/services/users/entities/user-language.js +0 -44
- package/dist/services/users/entities/user-language.mjs +0 -20
- package/dist/services/users/entities/user-marketing.d.ts +0 -9
- package/dist/services/users/entities/user-marketing.js +0 -40
- package/dist/services/users/entities/user-marketing.mjs +0 -16
- package/dist/services/users/entities/user-notification-preferences.d.ts +0 -11
- package/dist/services/users/entities/user-notification-preferences.js +0 -41
- package/dist/services/users/entities/user-notification-preferences.mjs +0 -17
- package/dist/services/users/entities/user-password.value-object.d.ts +0 -8
- package/dist/services/users/entities/user-password.value-object.js +0 -69
- package/dist/services/users/entities/user-password.value-object.mjs +0 -35
- package/dist/services/users/entities/user-permissions.d.ts +0 -21
- package/dist/services/users/entities/user-permissions.js +0 -59
- package/dist/services/users/entities/user-permissions.mjs +0 -35
- package/dist/services/users/entities/user-preferences.d.ts +0 -28
- package/dist/services/users/entities/user-preferences.js +0 -74
- package/dist/services/users/entities/user-preferences.mjs +0 -50
- package/dist/services/users/entities/user-report-preferences.d.ts +0 -16
- package/dist/services/users/entities/user-report-preferences.js +0 -56
- package/dist/services/users/entities/user-report-preferences.mjs +0 -32
- package/dist/services/users/entities/user-report-schedule.d.ts +0 -11
- package/dist/services/users/entities/user-report-schedule.js +0 -41
- package/dist/services/users/entities/user-report-schedule.mjs +0 -17
- package/dist/services/users/entities/user-timezone.d.ts +0 -11
- package/dist/services/users/entities/user-timezone.js +0 -44
- package/dist/services/users/entities/user-timezone.mjs +0 -20
- package/dist/services/users/entities/user.entity.d.ts +0 -42
- package/dist/services/users/entities/user.entity.js +0 -117
- package/dist/services/users/entities/user.entity.mjs +0 -92
- package/dist/services/users/index.d.ts +0 -3
- package/dist/services/users/index.js +0 -26
- package/dist/services/users/index.mjs +0 -3
- package/dist/services/users/module.d.ts +0 -12
- package/dist/services/users/module.js +0 -67
- package/dist/services/users/module.mjs +0 -38
- package/dist/services/users/repositories/index.d.ts +0 -1
- package/dist/services/users/repositories/index.js +0 -22
- package/dist/services/users/repositories/index.mjs +0 -1
- package/dist/services/users/repositories/user.repository.d.ts +0 -18
- package/dist/services/users/repositories/user.repository.js +0 -88
- package/dist/services/users/repositories/user.repository.mjs +0 -64
- package/dist/services/users/use-cases/change-password.use-case.d.ts +0 -15
- package/dist/services/users/use-cases/change-password.use-case.js +0 -52
- package/dist/services/users/use-cases/change-password.use-case.mjs +0 -28
- package/dist/services/users/use-cases/create-user.use-case.d.ts +0 -12
- package/dist/services/users/use-cases/create-user.use-case.js +0 -49
- package/dist/services/users/use-cases/create-user.use-case.mjs +0 -25
- package/dist/services/users/use-cases/delete-user.use-case.d.ts +0 -16
- package/dist/services/users/use-cases/delete-user.use-case.js +0 -48
- package/dist/services/users/use-cases/delete-user.use-case.mjs +0 -24
- package/dist/services/users/use-cases/get-user-by-id.use-case.d.ts +0 -12
- package/dist/services/users/use-cases/get-user-by-id.use-case.js +0 -43
- package/dist/services/users/use-cases/get-user-by-id.use-case.mjs +0 -19
- package/dist/services/users/use-cases/list-users-by-props.use-case.d.ts +0 -17
- package/dist/services/users/use-cases/list-users-by-props.use-case.js +0 -42
- package/dist/services/users/use-cases/list-users-by-props.use-case.mjs +0 -18
- package/dist/services/users/use-cases/update-user.use-case.d.ts +0 -13
- package/dist/services/users/use-cases/update-user.use-case.js +0 -53
- package/dist/services/users/use-cases/update-user.use-case.mjs +0 -29
- package/dist/services/users/utils/default-model.d.ts +0 -6
- package/dist/services/users/utils/default-model.js +0 -38
- package/dist/services/users/utils/default-model.mjs +0 -14
- package/examples/authentication/login.ts +0 -22
- package/examples/users/create-user.ts +0 -25
- package/examples/users/delete-user.ts +0 -42
- package/examples/users/get-user-by-id.ts +0 -21
- package/examples/users/list-users.ts +0 -22
- package/examples/users/update-user.ts +0 -25
|
@@ -1,357 +0,0 @@
|
|
|
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
|
-
VersionConflictError: () => VersionConflictError
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(mongo_db_repository_exports);
|
|
25
|
-
var import_mongodb = require("mongodb");
|
|
26
|
-
var import_error = require("../error/index.js");
|
|
27
|
-
var import_mongo_db = require("./mongo-db.client");
|
|
28
|
-
const DEFAULT_LIMIT = 10;
|
|
29
|
-
const PROTECTED_FIELDS = ["__v", "ownerId", "sharedWith", "createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy", "archivedAt", "archivedBy"];
|
|
30
|
-
const IMMUTABLE_FIELDS = ["_id", "__v", "createdAt", "createdBy"];
|
|
31
|
-
class VersionConflictError extends Error {
|
|
32
|
-
code = "VERSION_CONFLICT";
|
|
33
|
-
statusCode = 409;
|
|
34
|
-
constructor(message = "[Mongo Repository] The document was modified by someone else, reload and try again") {
|
|
35
|
-
super(message);
|
|
36
|
-
this.name = "VersionConflictError";
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
class MongoRepository {
|
|
40
|
-
database;
|
|
41
|
-
collection;
|
|
42
|
-
envvar;
|
|
43
|
-
_where = { deletedAt: null, archivedAt: null };
|
|
44
|
-
scoped;
|
|
45
|
-
ownerField;
|
|
46
|
-
protectedFields;
|
|
47
|
-
report = (error) => (0, import_error.reportError)(error, { source: "mongo", collection: this.collection });
|
|
48
|
-
constructor(props) {
|
|
49
|
-
const { database, collection, envvar, scoped = false, ownerField = "ownerId", protectedFields = [] } = props || {};
|
|
50
|
-
if (!database) throw new Error("[Mongo Repository] Database name is required");
|
|
51
|
-
if (!collection) throw new Error("[Mongo Repository] Collection name is required");
|
|
52
|
-
this.envvar = envvar;
|
|
53
|
-
this.database = database;
|
|
54
|
-
this.collection = collection;
|
|
55
|
-
this.scoped = scoped;
|
|
56
|
-
this.ownerField = ownerField;
|
|
57
|
-
this.protectedFields = [...PROTECTED_FIELDS, ...protectedFields];
|
|
58
|
-
}
|
|
59
|
-
async db() {
|
|
60
|
-
const client = (0, import_mongo_db.getMongoDBClient)(this.envvar);
|
|
61
|
-
if (!client) throw new Error("[Mongo Repository] Database client not found");
|
|
62
|
-
return client.db(typeof this.database === "function" ? this.database() : this.database);
|
|
63
|
-
}
|
|
64
|
-
assertScope(scope) {
|
|
65
|
-
if (!scope && this.scoped) throw new Error(`[Mongo Repository] Scope is required in ${this.collection}`);
|
|
66
|
-
}
|
|
67
|
-
actorId(scope) {
|
|
68
|
-
if (!scope || scope.kind === "system") return void 0;
|
|
69
|
-
const userId = this.parseId(scope.userId);
|
|
70
|
-
if (!userId) throw new Error("[Mongo Repository] Invalid user id in scope");
|
|
71
|
-
return userId;
|
|
72
|
-
}
|
|
73
|
-
withScope(filter, scope) {
|
|
74
|
-
this.assertScope(scope);
|
|
75
|
-
if (!scope || scope.trusted) return filter;
|
|
76
|
-
return { $and: [filter, { [this.ownerField]: this.actorId(scope) }] };
|
|
77
|
-
}
|
|
78
|
-
stampCreate(payload, scope) {
|
|
79
|
-
this.assertScope(scope);
|
|
80
|
-
if (!scope) return { ...payload };
|
|
81
|
-
const actor = this.actorId(scope);
|
|
82
|
-
return {
|
|
83
|
-
...this.withoutProtected(payload, scope),
|
|
84
|
-
...scope.trusted || this.ownerField === "_id" ? {} : { [this.ownerField]: actor },
|
|
85
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
86
|
-
...actor ? { createdBy: actor } : {}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
withoutProtected(payload, scope) {
|
|
90
|
-
if (!scope || scope.trusted) return payload;
|
|
91
|
-
const kept = Object.fromEntries(Object.entries(payload).filter(([key]) => !this.protectedFields.includes(key)));
|
|
92
|
-
return this.protectedFields.filter((path) => path.includes(".")).reduce((result, path) => this.withoutPath(result, path.split(".")), kept);
|
|
93
|
-
}
|
|
94
|
-
withoutPath(node, path) {
|
|
95
|
-
const [head, ...rest] = path;
|
|
96
|
-
if (!(head in node)) return node;
|
|
97
|
-
if (!rest.length) {
|
|
98
|
-
const { [head]: removed, ...others2 } = node;
|
|
99
|
-
return others2;
|
|
100
|
-
}
|
|
101
|
-
const child = node[head];
|
|
102
|
-
if (!child || typeof child !== "object" || Array.isArray(child) || child instanceof Date || child instanceof import_mongodb.ObjectId) return node;
|
|
103
|
-
const cleaned = this.withoutPath(child, rest);
|
|
104
|
-
if (Object.keys(cleaned).length) return { ...node, [head]: cleaned };
|
|
105
|
-
const { [head]: dropped, ...others } = node;
|
|
106
|
-
return others;
|
|
107
|
-
}
|
|
108
|
-
parseId(id) {
|
|
109
|
-
return typeof id === "string" && import_mongodb.ObjectId.isValid(id) ? new import_mongodb.ObjectId(id) : void 0;
|
|
110
|
-
}
|
|
111
|
-
cleanInput(value) {
|
|
112
|
-
return value?.replace(/[{}[\]()\/\\]/g, "");
|
|
113
|
-
}
|
|
114
|
-
clampLimit(limit) {
|
|
115
|
-
const n = Number(limit);
|
|
116
|
-
return !Number.isFinite(n) || n <= 0 ? DEFAULT_LIMIT : n;
|
|
117
|
-
}
|
|
118
|
-
async findOne({ where, select, options, scope }) {
|
|
119
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
120
|
-
try {
|
|
121
|
-
const db = await this.db();
|
|
122
|
-
const collection = db.collection(this.collection);
|
|
123
|
-
const result = await collection.findOne(
|
|
124
|
-
filter,
|
|
125
|
-
{
|
|
126
|
-
...select ? { projection: select } : {},
|
|
127
|
-
...options
|
|
128
|
-
}
|
|
129
|
-
);
|
|
130
|
-
return result;
|
|
131
|
-
} catch (error) {
|
|
132
|
-
await this.report(error);
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
async findMany(params) {
|
|
137
|
-
const _limit = this.clampLimit(params.options?.limit);
|
|
138
|
-
return this.query(params, _limit, _limit);
|
|
139
|
-
}
|
|
140
|
-
async findManyPaginated(params) {
|
|
141
|
-
const _limit = this.clampLimit(params.options?.limit);
|
|
142
|
-
const results = await this.query(params, _limit, _limit + 1);
|
|
143
|
-
return { items: results.slice(0, _limit), hasMore: results.length > _limit };
|
|
144
|
-
}
|
|
145
|
-
async query({ where, select, options, scope }, pageSize, fetchSize) {
|
|
146
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
147
|
-
try {
|
|
148
|
-
const db = await this.db();
|
|
149
|
-
const collection = db.collection(this.collection);
|
|
150
|
-
const { page = 1 } = options || {};
|
|
151
|
-
const _skip = +page > 0 ? (+page - 1) * pageSize : 0;
|
|
152
|
-
const result = await collection.find(filter, { projection: select }).sort(options?.sortBy || { _id: -1 }).skip(_skip).limit(fetchSize).toArray();
|
|
153
|
-
return result;
|
|
154
|
-
} catch (error) {
|
|
155
|
-
await this.report(error);
|
|
156
|
-
throw error;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
async findAll({ where, select, options, scope }) {
|
|
160
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
161
|
-
try {
|
|
162
|
-
const db = await this.db();
|
|
163
|
-
const collection = db.collection(this.collection);
|
|
164
|
-
const cursor = collection.find(filter, { projection: select });
|
|
165
|
-
const result = await (options?.sortBy ? cursor.sort(options.sortBy) : cursor).toArray();
|
|
166
|
-
return result;
|
|
167
|
-
} catch (error) {
|
|
168
|
-
await this.report(error);
|
|
169
|
-
throw error;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
async createOne({ payload, scope }) {
|
|
173
|
-
if (!payload || Object.keys(payload).length === 0) throw new Error("[Mongo Repository] Payload is required for createOne operation");
|
|
174
|
-
const document = this.stampCreate(payload, scope);
|
|
175
|
-
try {
|
|
176
|
-
const db = await this.db();
|
|
177
|
-
const collection = db.collection(this.collection);
|
|
178
|
-
const { insertedId } = await collection.insertOne({ ...document, __v: 1 }, { ignoreUndefined: true });
|
|
179
|
-
return { ...document, _id: insertedId, __v: 1 };
|
|
180
|
-
} catch (error) {
|
|
181
|
-
await this.report(error);
|
|
182
|
-
throw error;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
async createMany({ payload, scope }) {
|
|
186
|
-
const documents = payload.map((item) => this.stampCreate(item, scope));
|
|
187
|
-
try {
|
|
188
|
-
const db = await this.db();
|
|
189
|
-
const collection = db.collection(this.collection);
|
|
190
|
-
const { insertedIds } = await collection.insertMany(documents.map((document) => ({ ...document, __v: 1 })), { ignoreUndefined: true });
|
|
191
|
-
return insertedIds;
|
|
192
|
-
} catch (error) {
|
|
193
|
-
await this.report(error);
|
|
194
|
-
throw error;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
async patchOne({ where, set, unset, expectedVersion, scope }) {
|
|
198
|
-
return this.applyPatch({ where, set, unset, expectedVersion, scope });
|
|
199
|
-
}
|
|
200
|
-
async archiveByPatch(params) {
|
|
201
|
-
const actor = this.actorId(params.scope);
|
|
202
|
-
return this.applyPatch(params, { archivedAt: /* @__PURE__ */ new Date(), ...actor ? { archivedBy: actor } : {} });
|
|
203
|
-
}
|
|
204
|
-
async applyPatch({ where, set, unset, expectedVersion, scope }, stamps = {}) {
|
|
205
|
-
if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for patchOne operation");
|
|
206
|
-
const actor = this.actorId(scope);
|
|
207
|
-
const toSet = {
|
|
208
|
-
...this.withoutProtectedPaths(set ?? {}, scope),
|
|
209
|
-
...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {},
|
|
210
|
-
...stamps
|
|
211
|
-
};
|
|
212
|
-
const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
|
|
213
|
-
return this.modifyOne(where, {
|
|
214
|
-
$set: toSet,
|
|
215
|
-
...Object.keys(toUnset).length ? { $unset: toUnset } : {}
|
|
216
|
-
}, scope, expectedVersion);
|
|
217
|
-
}
|
|
218
|
-
async claimOne({ where, set, scope }) {
|
|
219
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
220
|
-
try {
|
|
221
|
-
const db = await this.db();
|
|
222
|
-
const collection = db.collection(this.collection);
|
|
223
|
-
const result = await collection.findOneAndUpdate(
|
|
224
|
-
filter,
|
|
225
|
-
{ $set: this.withoutProtectedPaths(set ?? {}, scope) },
|
|
226
|
-
{ returnDocument: "before", ignoreUndefined: true }
|
|
227
|
-
);
|
|
228
|
-
return result;
|
|
229
|
-
} catch (error) {
|
|
230
|
-
await this.report(error);
|
|
231
|
-
throw error;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
withoutProtectedPaths(fields, scope) {
|
|
235
|
-
const guarded = scope && !scope.trusted;
|
|
236
|
-
const isProtected = (key) => this.protectedFields.some((field) => key === field || key.startsWith(`${field}.`) || field.startsWith(`${key}.`));
|
|
237
|
-
return Object.fromEntries(Object.entries(fields).filter(([key]) => !IMMUTABLE_FIELDS.includes(key) && !(guarded && isProtected(key))));
|
|
238
|
-
}
|
|
239
|
-
async softDelete({ where, payload, unset, scope }) {
|
|
240
|
-
if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for softDelete operation");
|
|
241
|
-
const actor = this.actorId(scope);
|
|
242
|
-
const extra = this.withoutProtected(payload ?? {}, scope);
|
|
243
|
-
const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
|
|
244
|
-
return this.modifyOne(where, {
|
|
245
|
-
$set: { ...extra, deletedAt: /* @__PURE__ */ new Date(), ...actor ? { deletedBy: actor } : {} },
|
|
246
|
-
...Object.keys(toUnset).length ? { $unset: toUnset } : {}
|
|
247
|
-
}, scope);
|
|
248
|
-
}
|
|
249
|
-
async modifyOne(where, update, scope, expectedVersion) {
|
|
250
|
-
const checkVersion = typeof expectedVersion === "number";
|
|
251
|
-
const filter = this.withScope({ ...where, ...checkVersion ? { __v: expectedVersion } : {}, ...this._where }, scope);
|
|
252
|
-
try {
|
|
253
|
-
const db = await this.db();
|
|
254
|
-
const collection = db.collection(this.collection);
|
|
255
|
-
const result = await collection.findOneAndUpdate(
|
|
256
|
-
filter,
|
|
257
|
-
{ $inc: { __v: 1 }, ...update },
|
|
258
|
-
{ returnDocument: "after", ignoreUndefined: true }
|
|
259
|
-
);
|
|
260
|
-
if (!result && checkVersion) {
|
|
261
|
-
const exists = await collection.findOne(this.withScope({ ...where, ...this._where }, scope), { projection: { _id: 1 } });
|
|
262
|
-
if (exists) throw new VersionConflictError();
|
|
263
|
-
}
|
|
264
|
-
return result;
|
|
265
|
-
} catch (error) {
|
|
266
|
-
if (!(error instanceof VersionConflictError)) await this.report(error);
|
|
267
|
-
throw error;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
async updateMany({ where, payload, scope }) {
|
|
271
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
272
|
-
const actor = this.actorId(scope);
|
|
273
|
-
const toSet = {
|
|
274
|
-
...this.withoutProtected(payload ?? {}, scope),
|
|
275
|
-
...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {}
|
|
276
|
-
};
|
|
277
|
-
try {
|
|
278
|
-
const db = await this.db();
|
|
279
|
-
const collection = db.collection(this.collection);
|
|
280
|
-
const result = await collection.updateMany(
|
|
281
|
-
filter,
|
|
282
|
-
{ $set: toSet }
|
|
283
|
-
);
|
|
284
|
-
const countUpdated = result.modifiedCount;
|
|
285
|
-
return countUpdated;
|
|
286
|
-
} catch (error) {
|
|
287
|
-
await this.report(error);
|
|
288
|
-
throw error;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async deleteOne({ where, scope }) {
|
|
292
|
-
const filter = this.withScope({ ...where }, scope);
|
|
293
|
-
try {
|
|
294
|
-
const db = await this.db();
|
|
295
|
-
const collection = db.collection(this.collection);
|
|
296
|
-
const { deletedCount } = await collection.deleteOne(filter);
|
|
297
|
-
return deletedCount;
|
|
298
|
-
} catch (error) {
|
|
299
|
-
await this.report(error);
|
|
300
|
-
throw error;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
async deleteMany({ where, scope }) {
|
|
304
|
-
const filter = this.withScope({ ...where }, scope);
|
|
305
|
-
try {
|
|
306
|
-
const db = await this.db();
|
|
307
|
-
const collection = db.collection(this.collection);
|
|
308
|
-
const { deletedCount } = await collection.deleteMany(filter);
|
|
309
|
-
return deletedCount;
|
|
310
|
-
} catch (error) {
|
|
311
|
-
await this.report(error);
|
|
312
|
-
throw error;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
async count({ where, options, scope }) {
|
|
316
|
-
const filter = this.withScope({ ...where, ...options?.includeDeleted ? {} : this._where }, scope);
|
|
317
|
-
try {
|
|
318
|
-
const db = await this.db();
|
|
319
|
-
const collection = db.collection(this.collection);
|
|
320
|
-
const result = await collection.countDocuments(filter);
|
|
321
|
-
return result;
|
|
322
|
-
} catch (error) {
|
|
323
|
-
await this.report(error);
|
|
324
|
-
throw error;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
async aggregate(pipeline, scope) {
|
|
328
|
-
const scopeFilter = this.withScope({}, scope);
|
|
329
|
-
const scopedPipeline = Object.keys(scopeFilter).length ? [{ $match: scopeFilter }, ...pipeline] : pipeline;
|
|
330
|
-
try {
|
|
331
|
-
const db = await this.db();
|
|
332
|
-
const collection = db.collection(this.collection);
|
|
333
|
-
const result = await collection.aggregate(scopedPipeline).toArray();
|
|
334
|
-
return result;
|
|
335
|
-
} catch (error) {
|
|
336
|
-
await this.report(error);
|
|
337
|
-
throw error;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
async distinct(field, where, scope) {
|
|
341
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
342
|
-
try {
|
|
343
|
-
const db = await this.db();
|
|
344
|
-
const collection = db.collection(this.collection);
|
|
345
|
-
const result = await collection.distinct(field, filter);
|
|
346
|
-
return result;
|
|
347
|
-
} catch (error) {
|
|
348
|
-
await this.report(error);
|
|
349
|
-
throw error;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
354
|
-
0 && (module.exports = {
|
|
355
|
-
MongoRepository,
|
|
356
|
-
VersionConflictError
|
|
357
|
-
});
|
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
import { ObjectId } from "mongodb";
|
|
2
|
-
import { reportError } from "../error/index.js";
|
|
3
|
-
import { getMongoDBClient } from "./mongo-db.client";
|
|
4
|
-
const DEFAULT_LIMIT = 10;
|
|
5
|
-
const PROTECTED_FIELDS = ["__v", "ownerId", "sharedWith", "createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy", "archivedAt", "archivedBy"];
|
|
6
|
-
const IMMUTABLE_FIELDS = ["_id", "__v", "createdAt", "createdBy"];
|
|
7
|
-
class VersionConflictError extends Error {
|
|
8
|
-
code = "VERSION_CONFLICT";
|
|
9
|
-
statusCode = 409;
|
|
10
|
-
constructor(message = "[Mongo Repository] The document was modified by someone else, reload and try again") {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = "VersionConflictError";
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
class MongoRepository {
|
|
16
|
-
database;
|
|
17
|
-
collection;
|
|
18
|
-
envvar;
|
|
19
|
-
_where = { deletedAt: null, archivedAt: null };
|
|
20
|
-
scoped;
|
|
21
|
-
ownerField;
|
|
22
|
-
protectedFields;
|
|
23
|
-
report = (error) => reportError(error, { source: "mongo", collection: this.collection });
|
|
24
|
-
constructor(props) {
|
|
25
|
-
const { database, collection, envvar, scoped = false, ownerField = "ownerId", protectedFields = [] } = props || {};
|
|
26
|
-
if (!database) throw new Error("[Mongo Repository] Database name is required");
|
|
27
|
-
if (!collection) throw new Error("[Mongo Repository] Collection name is required");
|
|
28
|
-
this.envvar = envvar;
|
|
29
|
-
this.database = database;
|
|
30
|
-
this.collection = collection;
|
|
31
|
-
this.scoped = scoped;
|
|
32
|
-
this.ownerField = ownerField;
|
|
33
|
-
this.protectedFields = [...PROTECTED_FIELDS, ...protectedFields];
|
|
34
|
-
}
|
|
35
|
-
async db() {
|
|
36
|
-
const client = getMongoDBClient(this.envvar);
|
|
37
|
-
if (!client) throw new Error("[Mongo Repository] Database client not found");
|
|
38
|
-
return client.db(typeof this.database === "function" ? this.database() : this.database);
|
|
39
|
-
}
|
|
40
|
-
assertScope(scope) {
|
|
41
|
-
if (!scope && this.scoped) throw new Error(`[Mongo Repository] Scope is required in ${this.collection}`);
|
|
42
|
-
}
|
|
43
|
-
actorId(scope) {
|
|
44
|
-
if (!scope || scope.kind === "system") return void 0;
|
|
45
|
-
const userId = this.parseId(scope.userId);
|
|
46
|
-
if (!userId) throw new Error("[Mongo Repository] Invalid user id in scope");
|
|
47
|
-
return userId;
|
|
48
|
-
}
|
|
49
|
-
withScope(filter, scope) {
|
|
50
|
-
this.assertScope(scope);
|
|
51
|
-
if (!scope || scope.trusted) return filter;
|
|
52
|
-
return { $and: [filter, { [this.ownerField]: this.actorId(scope) }] };
|
|
53
|
-
}
|
|
54
|
-
stampCreate(payload, scope) {
|
|
55
|
-
this.assertScope(scope);
|
|
56
|
-
if (!scope) return { ...payload };
|
|
57
|
-
const actor = this.actorId(scope);
|
|
58
|
-
return {
|
|
59
|
-
...this.withoutProtected(payload, scope),
|
|
60
|
-
...scope.trusted || this.ownerField === "_id" ? {} : { [this.ownerField]: actor },
|
|
61
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
62
|
-
...actor ? { createdBy: actor } : {}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
withoutProtected(payload, scope) {
|
|
66
|
-
if (!scope || scope.trusted) return payload;
|
|
67
|
-
const kept = Object.fromEntries(Object.entries(payload).filter(([key]) => !this.protectedFields.includes(key)));
|
|
68
|
-
return this.protectedFields.filter((path) => path.includes(".")).reduce((result, path) => this.withoutPath(result, path.split(".")), kept);
|
|
69
|
-
}
|
|
70
|
-
withoutPath(node, path) {
|
|
71
|
-
const [head, ...rest] = path;
|
|
72
|
-
if (!(head in node)) return node;
|
|
73
|
-
if (!rest.length) {
|
|
74
|
-
const { [head]: removed, ...others2 } = node;
|
|
75
|
-
return others2;
|
|
76
|
-
}
|
|
77
|
-
const child = node[head];
|
|
78
|
-
if (!child || typeof child !== "object" || Array.isArray(child) || child instanceof Date || child instanceof ObjectId) return node;
|
|
79
|
-
const cleaned = this.withoutPath(child, rest);
|
|
80
|
-
if (Object.keys(cleaned).length) return { ...node, [head]: cleaned };
|
|
81
|
-
const { [head]: dropped, ...others } = node;
|
|
82
|
-
return others;
|
|
83
|
-
}
|
|
84
|
-
parseId(id) {
|
|
85
|
-
return typeof id === "string" && ObjectId.isValid(id) ? new ObjectId(id) : void 0;
|
|
86
|
-
}
|
|
87
|
-
cleanInput(value) {
|
|
88
|
-
return value?.replace(/[{}[\]()\/\\]/g, "");
|
|
89
|
-
}
|
|
90
|
-
clampLimit(limit) {
|
|
91
|
-
const n = Number(limit);
|
|
92
|
-
return !Number.isFinite(n) || n <= 0 ? DEFAULT_LIMIT : n;
|
|
93
|
-
}
|
|
94
|
-
async findOne({ where, select, options, scope }) {
|
|
95
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
96
|
-
try {
|
|
97
|
-
const db = await this.db();
|
|
98
|
-
const collection = db.collection(this.collection);
|
|
99
|
-
const result = await collection.findOne(
|
|
100
|
-
filter,
|
|
101
|
-
{
|
|
102
|
-
...select ? { projection: select } : {},
|
|
103
|
-
...options
|
|
104
|
-
}
|
|
105
|
-
);
|
|
106
|
-
return result;
|
|
107
|
-
} catch (error) {
|
|
108
|
-
await this.report(error);
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
async findMany(params) {
|
|
113
|
-
const _limit = this.clampLimit(params.options?.limit);
|
|
114
|
-
return this.query(params, _limit, _limit);
|
|
115
|
-
}
|
|
116
|
-
async findManyPaginated(params) {
|
|
117
|
-
const _limit = this.clampLimit(params.options?.limit);
|
|
118
|
-
const results = await this.query(params, _limit, _limit + 1);
|
|
119
|
-
return { items: results.slice(0, _limit), hasMore: results.length > _limit };
|
|
120
|
-
}
|
|
121
|
-
async query({ where, select, options, scope }, pageSize, fetchSize) {
|
|
122
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
123
|
-
try {
|
|
124
|
-
const db = await this.db();
|
|
125
|
-
const collection = db.collection(this.collection);
|
|
126
|
-
const { page = 1 } = options || {};
|
|
127
|
-
const _skip = +page > 0 ? (+page - 1) * pageSize : 0;
|
|
128
|
-
const result = await collection.find(filter, { projection: select }).sort(options?.sortBy || { _id: -1 }).skip(_skip).limit(fetchSize).toArray();
|
|
129
|
-
return result;
|
|
130
|
-
} catch (error) {
|
|
131
|
-
await this.report(error);
|
|
132
|
-
throw error;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
async findAll({ where, select, options, scope }) {
|
|
136
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
137
|
-
try {
|
|
138
|
-
const db = await this.db();
|
|
139
|
-
const collection = db.collection(this.collection);
|
|
140
|
-
const cursor = collection.find(filter, { projection: select });
|
|
141
|
-
const result = await (options?.sortBy ? cursor.sort(options.sortBy) : cursor).toArray();
|
|
142
|
-
return result;
|
|
143
|
-
} catch (error) {
|
|
144
|
-
await this.report(error);
|
|
145
|
-
throw error;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
async createOne({ payload, scope }) {
|
|
149
|
-
if (!payload || Object.keys(payload).length === 0) throw new Error("[Mongo Repository] Payload is required for createOne operation");
|
|
150
|
-
const document = this.stampCreate(payload, scope);
|
|
151
|
-
try {
|
|
152
|
-
const db = await this.db();
|
|
153
|
-
const collection = db.collection(this.collection);
|
|
154
|
-
const { insertedId } = await collection.insertOne({ ...document, __v: 1 }, { ignoreUndefined: true });
|
|
155
|
-
return { ...document, _id: insertedId, __v: 1 };
|
|
156
|
-
} catch (error) {
|
|
157
|
-
await this.report(error);
|
|
158
|
-
throw error;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
async createMany({ payload, scope }) {
|
|
162
|
-
const documents = payload.map((item) => this.stampCreate(item, scope));
|
|
163
|
-
try {
|
|
164
|
-
const db = await this.db();
|
|
165
|
-
const collection = db.collection(this.collection);
|
|
166
|
-
const { insertedIds } = await collection.insertMany(documents.map((document) => ({ ...document, __v: 1 })), { ignoreUndefined: true });
|
|
167
|
-
return insertedIds;
|
|
168
|
-
} catch (error) {
|
|
169
|
-
await this.report(error);
|
|
170
|
-
throw error;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
async patchOne({ where, set, unset, expectedVersion, scope }) {
|
|
174
|
-
return this.applyPatch({ where, set, unset, expectedVersion, scope });
|
|
175
|
-
}
|
|
176
|
-
async archiveByPatch(params) {
|
|
177
|
-
const actor = this.actorId(params.scope);
|
|
178
|
-
return this.applyPatch(params, { archivedAt: /* @__PURE__ */ new Date(), ...actor ? { archivedBy: actor } : {} });
|
|
179
|
-
}
|
|
180
|
-
async applyPatch({ where, set, unset, expectedVersion, scope }, stamps = {}) {
|
|
181
|
-
if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for patchOne operation");
|
|
182
|
-
const actor = this.actorId(scope);
|
|
183
|
-
const toSet = {
|
|
184
|
-
...this.withoutProtectedPaths(set ?? {}, scope),
|
|
185
|
-
...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {},
|
|
186
|
-
...stamps
|
|
187
|
-
};
|
|
188
|
-
const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
|
|
189
|
-
return this.modifyOne(where, {
|
|
190
|
-
$set: toSet,
|
|
191
|
-
...Object.keys(toUnset).length ? { $unset: toUnset } : {}
|
|
192
|
-
}, scope, expectedVersion);
|
|
193
|
-
}
|
|
194
|
-
async claimOne({ where, set, scope }) {
|
|
195
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
196
|
-
try {
|
|
197
|
-
const db = await this.db();
|
|
198
|
-
const collection = db.collection(this.collection);
|
|
199
|
-
const result = await collection.findOneAndUpdate(
|
|
200
|
-
filter,
|
|
201
|
-
{ $set: this.withoutProtectedPaths(set ?? {}, scope) },
|
|
202
|
-
{ returnDocument: "before", ignoreUndefined: true }
|
|
203
|
-
);
|
|
204
|
-
return result;
|
|
205
|
-
} catch (error) {
|
|
206
|
-
await this.report(error);
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
withoutProtectedPaths(fields, scope) {
|
|
211
|
-
const guarded = scope && !scope.trusted;
|
|
212
|
-
const isProtected = (key) => this.protectedFields.some((field) => key === field || key.startsWith(`${field}.`) || field.startsWith(`${key}.`));
|
|
213
|
-
return Object.fromEntries(Object.entries(fields).filter(([key]) => !IMMUTABLE_FIELDS.includes(key) && !(guarded && isProtected(key))));
|
|
214
|
-
}
|
|
215
|
-
async softDelete({ where, payload, unset, scope }) {
|
|
216
|
-
if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for softDelete operation");
|
|
217
|
-
const actor = this.actorId(scope);
|
|
218
|
-
const extra = this.withoutProtected(payload ?? {}, scope);
|
|
219
|
-
const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
|
|
220
|
-
return this.modifyOne(where, {
|
|
221
|
-
$set: { ...extra, deletedAt: /* @__PURE__ */ new Date(), ...actor ? { deletedBy: actor } : {} },
|
|
222
|
-
...Object.keys(toUnset).length ? { $unset: toUnset } : {}
|
|
223
|
-
}, scope);
|
|
224
|
-
}
|
|
225
|
-
async modifyOne(where, update, scope, expectedVersion) {
|
|
226
|
-
const checkVersion = typeof expectedVersion === "number";
|
|
227
|
-
const filter = this.withScope({ ...where, ...checkVersion ? { __v: expectedVersion } : {}, ...this._where }, scope);
|
|
228
|
-
try {
|
|
229
|
-
const db = await this.db();
|
|
230
|
-
const collection = db.collection(this.collection);
|
|
231
|
-
const result = await collection.findOneAndUpdate(
|
|
232
|
-
filter,
|
|
233
|
-
{ $inc: { __v: 1 }, ...update },
|
|
234
|
-
{ returnDocument: "after", ignoreUndefined: true }
|
|
235
|
-
);
|
|
236
|
-
if (!result && checkVersion) {
|
|
237
|
-
const exists = await collection.findOne(this.withScope({ ...where, ...this._where }, scope), { projection: { _id: 1 } });
|
|
238
|
-
if (exists) throw new VersionConflictError();
|
|
239
|
-
}
|
|
240
|
-
return result;
|
|
241
|
-
} catch (error) {
|
|
242
|
-
if (!(error instanceof VersionConflictError)) await this.report(error);
|
|
243
|
-
throw error;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
async updateMany({ where, payload, scope }) {
|
|
247
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
248
|
-
const actor = this.actorId(scope);
|
|
249
|
-
const toSet = {
|
|
250
|
-
...this.withoutProtected(payload ?? {}, scope),
|
|
251
|
-
...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {}
|
|
252
|
-
};
|
|
253
|
-
try {
|
|
254
|
-
const db = await this.db();
|
|
255
|
-
const collection = db.collection(this.collection);
|
|
256
|
-
const result = await collection.updateMany(
|
|
257
|
-
filter,
|
|
258
|
-
{ $set: toSet }
|
|
259
|
-
);
|
|
260
|
-
const countUpdated = result.modifiedCount;
|
|
261
|
-
return countUpdated;
|
|
262
|
-
} catch (error) {
|
|
263
|
-
await this.report(error);
|
|
264
|
-
throw error;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
async deleteOne({ where, scope }) {
|
|
268
|
-
const filter = this.withScope({ ...where }, scope);
|
|
269
|
-
try {
|
|
270
|
-
const db = await this.db();
|
|
271
|
-
const collection = db.collection(this.collection);
|
|
272
|
-
const { deletedCount } = await collection.deleteOne(filter);
|
|
273
|
-
return deletedCount;
|
|
274
|
-
} catch (error) {
|
|
275
|
-
await this.report(error);
|
|
276
|
-
throw error;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
async deleteMany({ where, scope }) {
|
|
280
|
-
const filter = this.withScope({ ...where }, scope);
|
|
281
|
-
try {
|
|
282
|
-
const db = await this.db();
|
|
283
|
-
const collection = db.collection(this.collection);
|
|
284
|
-
const { deletedCount } = await collection.deleteMany(filter);
|
|
285
|
-
return deletedCount;
|
|
286
|
-
} catch (error) {
|
|
287
|
-
await this.report(error);
|
|
288
|
-
throw error;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async count({ where, options, scope }) {
|
|
292
|
-
const filter = this.withScope({ ...where, ...options?.includeDeleted ? {} : this._where }, scope);
|
|
293
|
-
try {
|
|
294
|
-
const db = await this.db();
|
|
295
|
-
const collection = db.collection(this.collection);
|
|
296
|
-
const result = await collection.countDocuments(filter);
|
|
297
|
-
return result;
|
|
298
|
-
} catch (error) {
|
|
299
|
-
await this.report(error);
|
|
300
|
-
throw error;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
async aggregate(pipeline, scope) {
|
|
304
|
-
const scopeFilter = this.withScope({}, scope);
|
|
305
|
-
const scopedPipeline = Object.keys(scopeFilter).length ? [{ $match: scopeFilter }, ...pipeline] : pipeline;
|
|
306
|
-
try {
|
|
307
|
-
const db = await this.db();
|
|
308
|
-
const collection = db.collection(this.collection);
|
|
309
|
-
const result = await collection.aggregate(scopedPipeline).toArray();
|
|
310
|
-
return result;
|
|
311
|
-
} catch (error) {
|
|
312
|
-
await this.report(error);
|
|
313
|
-
throw error;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
async distinct(field, where, scope) {
|
|
317
|
-
const filter = this.withScope({ ...where, ...this._where }, scope);
|
|
318
|
-
try {
|
|
319
|
-
const db = await this.db();
|
|
320
|
-
const collection = db.collection(this.collection);
|
|
321
|
-
const result = await collection.distinct(field, filter);
|
|
322
|
-
return result;
|
|
323
|
-
} catch (error) {
|
|
324
|
-
await this.report(error);
|
|
325
|
-
throw error;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
export {
|
|
330
|
-
MongoRepository,
|
|
331
|
-
VersionConflictError
|
|
332
|
-
};
|