@vandenberghinc/volt 1.2.6 → 1.2.7
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/backend/dist/cjs/backend/src/blacklist.d.ts +12 -0
- package/backend/dist/cjs/backend/src/blacklist.js +78 -0
- package/backend/dist/cjs/backend/src/cli.d.ts +2 -0
- package/backend/dist/cjs/backend/src/cli.js +198 -0
- package/backend/dist/cjs/backend/src/database/collection.d.ts +1765 -0
- package/backend/dist/cjs/backend/src/database/collection.js +3301 -0
- package/backend/dist/cjs/backend/src/database/database.d.ts +92 -0
- package/backend/dist/cjs/backend/src/database/database.js +170 -0
- package/backend/dist/cjs/backend/src/database/document.d.ts +1 -0
- package/backend/dist/cjs/backend/src/database/document.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/filters.d.ts +6 -0
- package/backend/dist/cjs/backend/src/database/filters/filters.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter.d.ts +223 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.d.ts +1 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.js +443 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.d.ts +1 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.d.ts +50 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.d.ts +76 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.d.ts +75 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.d.ts +219 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.d.ts +165 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.d.ts +5 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.js +355 -0
- package/backend/dist/cjs/backend/src/database/flatten.d.ts +78 -0
- package/backend/dist/cjs/backend/src/database/flatten.js +53 -0
- package/backend/dist/cjs/backend/src/database/flatten_test.d.ts +1 -0
- package/backend/dist/cjs/backend/src/database/flatten_test.js +175 -0
- package/backend/dist/cjs/backend/src/database/quota/quoata_v2.d.ts +533 -0
- package/backend/dist/cjs/backend/src/database/quota/quoata_v2.js +1046 -0
- package/backend/dist/cjs/backend/src/database/quota/quota.d.ts +551 -0
- package/backend/dist/cjs/backend/src/database/quota/quota.js +1108 -0
- package/backend/dist/cjs/backend/src/database/quota/quota_v1.d.ts +534 -0
- package/backend/dist/cjs/backend/src/database/quota/quota_v1.js +1087 -0
- package/backend/dist/cjs/backend/src/database/quota/safe_int.d.ts +412 -0
- package/backend/dist/cjs/backend/src/database/quota/safe_int.js +745 -0
- package/backend/dist/cjs/backend/src/endpoint.d.ts +346 -0
- package/backend/dist/cjs/backend/src/endpoint.js +468 -0
- package/backend/dist/cjs/backend/src/errors/index.d.ts +7 -0
- package/backend/dist/cjs/backend/src/errors/index.js +25 -0
- package/backend/dist/cjs/backend/src/errors/internal_external.d.ts +52 -0
- package/backend/dist/cjs/backend/src/errors/internal_external.js +95 -0
- package/backend/dist/cjs/backend/src/errors/invalid_usage_error.d.ts +41 -0
- package/backend/dist/cjs/backend/src/errors/invalid_usage_error.js +47 -0
- package/backend/dist/cjs/backend/src/errors/system_error.d.ts +261 -0
- package/backend/dist/cjs/backend/src/errors/system_error.js +436 -0
- package/backend/dist/cjs/backend/src/events.d.ts +97 -0
- package/backend/dist/cjs/backend/src/events.js +15 -0
- package/backend/dist/cjs/backend/src/frontend.d.ts +13 -0
- package/backend/dist/cjs/backend/src/frontend.js +56 -0
- package/backend/dist/cjs/backend/src/image_endpoint.d.ts +44 -0
- package/backend/dist/cjs/backend/src/image_endpoint.js +185 -0
- package/backend/dist/cjs/backend/src/index.d.ts +23 -0
- package/backend/dist/cjs/backend/src/index.js +70 -0
- package/backend/dist/cjs/backend/src/logger.d.ts +5 -0
- package/backend/dist/cjs/backend/src/logger.js +15 -0
- package/backend/dist/cjs/backend/src/meta.d.ts +112 -0
- package/backend/dist/cjs/backend/src/meta.js +181 -0
- package/backend/dist/cjs/backend/src/payments/paddle.d.ts +329 -0
- package/backend/dist/cjs/backend/src/payments/paddle.js +1996 -0
- package/backend/dist/cjs/backend/src/payments/stripe/checkout.d.ts +113 -0
- package/backend/dist/cjs/backend/src/payments/stripe/checkout.js +295 -0
- package/backend/dist/cjs/backend/src/payments/stripe/customers.d.ts +17 -0
- package/backend/dist/cjs/backend/src/payments/stripe/customers.js +164 -0
- package/backend/dist/cjs/backend/src/payments/stripe/error.d.ts +74 -0
- package/backend/dist/cjs/backend/src/payments/stripe/error.js +64 -0
- package/backend/dist/cjs/backend/src/payments/stripe/events.d.ts +155 -0
- package/backend/dist/cjs/backend/src/payments/stripe/events.js +15 -0
- package/backend/dist/cjs/backend/src/payments/stripe/meters.d.ts +105 -0
- package/backend/dist/cjs/backend/src/payments/stripe/meters.js +230 -0
- package/backend/dist/cjs/backend/src/payments/stripe/payment_methods.d.ts +58 -0
- package/backend/dist/cjs/backend/src/payments/stripe/payment_methods.js +109 -0
- package/backend/dist/cjs/backend/src/payments/stripe/products.d.ts +519 -0
- package/backend/dist/cjs/backend/src/payments/stripe/products.js +650 -0
- package/backend/dist/cjs/backend/src/payments/stripe/stripe.d.ts +215 -0
- package/backend/dist/cjs/backend/src/payments/stripe/stripe.js +468 -0
- package/backend/dist/cjs/backend/src/payments/stripe/subscriptions.d.ts +172 -0
- package/backend/dist/cjs/backend/src/payments/stripe/subscriptions.js +557 -0
- package/backend/dist/cjs/backend/src/payments/stripe/utils.d.ts +63 -0
- package/backend/dist/cjs/backend/src/payments/stripe/utils.js +118 -0
- package/backend/dist/cjs/backend/src/payments/stripe/webhooks.d.ts +105 -0
- package/backend/dist/cjs/backend/src/payments/stripe/webhooks.js +627 -0
- package/backend/dist/cjs/backend/src/plugins/browser.d.ts +1 -0
- package/backend/dist/cjs/backend/src/plugins/browser.js +15 -0
- package/backend/dist/cjs/backend/src/plugins/communication.d.ts +70 -0
- package/backend/dist/cjs/backend/src/plugins/communication.js +196 -0
- package/backend/dist/cjs/backend/src/plugins/mail/mail.d.ts +255 -0
- package/backend/dist/cjs/backend/src/plugins/mail/mail.js +381 -0
- package/backend/dist/cjs/backend/src/plugins/mail/ui.d.ts +297 -0
- package/backend/dist/cjs/backend/src/plugins/mail/ui.js +1370 -0
- package/backend/dist/cjs/backend/src/plugins/pdf.d.ts +1 -0
- package/backend/dist/cjs/backend/src/plugins/pdf.js +1456 -0
- package/backend/dist/cjs/backend/src/plugins/thread_monitor.d.ts +18 -0
- package/backend/dist/cjs/backend/src/plugins/thread_monitor.js +116 -0
- package/backend/dist/cjs/backend/src/rate_limit.d.ts +148 -0
- package/backend/dist/cjs/backend/src/rate_limit.js +543 -0
- package/backend/dist/cjs/backend/src/route.d.ts +39 -0
- package/backend/dist/cjs/backend/src/route.js +172 -0
- package/backend/dist/cjs/backend/src/server.d.ts +502 -0
- package/backend/dist/cjs/backend/src/server.js +1710 -0
- package/backend/dist/cjs/backend/src/server.old.d.ts +594 -0
- package/backend/dist/cjs/backend/src/server.old.js +2058 -0
- package/backend/dist/cjs/backend/src/splash_screen.d.ts +93 -0
- package/backend/dist/cjs/backend/src/splash_screen.js +119 -0
- package/backend/dist/cjs/backend/src/status.d.ts +89 -0
- package/backend/dist/cjs/backend/src/status.js +211 -0
- package/backend/dist/cjs/backend/src/stream.d.ts +494 -0
- package/backend/dist/cjs/backend/src/stream.js +1370 -0
- package/backend/dist/cjs/backend/src/users.d.ts +926 -0
- package/backend/dist/cjs/backend/src/users.js +2223 -0
- package/backend/dist/cjs/backend/src/utils.d.ts +22 -0
- package/backend/dist/cjs/backend/src/utils.js +626 -0
- package/backend/dist/cjs/backend/src/view.d.ts +115 -0
- package/backend/dist/cjs/backend/src/view.js +519 -0
- package/backend/dist/cjs/backend/src/vinc.d.ts +6 -0
- package/backend/dist/cjs/backend/src/vinc.js +40 -0
- package/backend/dist/cjs/backend/src/volt.d.ts +24 -0
- package/backend/dist/cjs/backend/src/volt.js +72 -0
- package/backend/dist/cjs/frontend/src/modules/request.d.ts +70 -0
- package/backend/dist/cjs/frontend/src/modules/request.js +99 -0
- package/backend/dist/cjs/package.json +1 -0
- package/backend/dist/esm/backend/src/blacklist.d.ts +12 -0
- package/backend/dist/esm/backend/src/blacklist.js +52 -0
- package/backend/dist/esm/backend/src/cli.d.ts +2 -0
- package/backend/dist/esm/backend/src/cli.js +211 -0
- package/backend/dist/esm/backend/src/database/collection.d.ts +1765 -0
- package/backend/dist/esm/backend/src/database/collection.js +3779 -0
- package/backend/dist/esm/backend/src/database/database.d.ts +92 -0
- package/backend/dist/esm/backend/src/database/database.js +214 -0
- package/backend/dist/esm/backend/src/database/document.d.ts +1 -0
- package/backend/dist/esm/backend/src/database/document.js +558 -0
- package/backend/dist/esm/backend/src/database/filters/filters.d.ts +6 -0
- package/backend/dist/esm/backend/src/database/filters/filters.js +1 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter.d.ts +223 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter.js +3 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test.d.ts +1 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test.js +505 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.d.ts +1 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.js +712 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.d.ts +50 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.js +5 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.d.ts +76 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.js +44 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.d.ts +75 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.js +5 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.d.ts +219 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.js +1 -0
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter.d.ts +165 -0
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter.js +5 -0
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.d.ts +5 -0
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.js +415 -0
- package/backend/dist/esm/backend/src/database/flatten.d.ts +78 -0
- package/backend/dist/esm/backend/src/database/flatten.js +22 -0
- package/backend/dist/esm/backend/src/database/flatten_test.d.ts +1 -0
- package/backend/dist/esm/backend/src/database/flatten_test.js +174 -0
- package/backend/dist/esm/backend/src/database/quota/quoata_v2.d.ts +533 -0
- package/backend/dist/esm/backend/src/database/quota/quoata_v2.js +1155 -0
- package/backend/dist/esm/backend/src/database/quota/quota.d.ts +551 -0
- package/backend/dist/esm/backend/src/database/quota/quota.js +1219 -0
- package/backend/dist/esm/backend/src/database/quota/quota_v1.d.ts +534 -0
- package/backend/dist/esm/backend/src/database/quota/quota_v1.js +1242 -0
- package/backend/dist/esm/backend/src/database/quota/safe_int.d.ts +412 -0
- package/backend/dist/esm/backend/src/database/quota/safe_int.js +810 -0
- package/backend/dist/esm/backend/src/endpoint.d.ts +346 -0
- package/backend/dist/esm/backend/src/endpoint.js +479 -0
- package/backend/dist/esm/backend/src/errors/index.d.ts +7 -0
- package/backend/dist/esm/backend/src/errors/index.js +7 -0
- package/backend/dist/esm/backend/src/errors/internal_external.d.ts +52 -0
- package/backend/dist/esm/backend/src/errors/internal_external.js +86 -0
- package/backend/dist/esm/backend/src/errors/invalid_usage_error.d.ts +41 -0
- package/backend/dist/esm/backend/src/errors/invalid_usage_error.js +33 -0
- package/backend/dist/esm/backend/src/errors/system_error.d.ts +261 -0
- package/backend/dist/esm/backend/src/errors/system_error.js +444 -0
- package/backend/dist/esm/backend/src/events.d.ts +97 -0
- package/backend/dist/esm/backend/src/events.js +5 -0
- package/backend/dist/esm/backend/src/frontend.d.ts +13 -0
- package/backend/dist/esm/backend/src/frontend.js +23 -0
- package/backend/dist/esm/backend/src/image_endpoint.d.ts +44 -0
- package/backend/dist/esm/backend/src/image_endpoint.js +196 -0
- package/backend/dist/esm/backend/src/index.d.ts +23 -0
- package/backend/dist/esm/backend/src/index.js +26 -0
- package/backend/dist/esm/backend/src/logger.d.ts +5 -0
- package/backend/dist/esm/backend/src/logger.js +8 -0
- package/backend/dist/esm/backend/src/meta.d.ts +112 -0
- package/backend/dist/esm/backend/src/meta.js +152 -0
- package/backend/dist/esm/backend/src/payments/paddle.d.ts +329 -0
- package/backend/dist/esm/backend/src/payments/paddle.js +2276 -0
- package/backend/dist/esm/backend/src/payments/stripe/checkout.d.ts +113 -0
- package/backend/dist/esm/backend/src/payments/stripe/checkout.js +356 -0
- package/backend/dist/esm/backend/src/payments/stripe/customers.d.ts +17 -0
- package/backend/dist/esm/backend/src/payments/stripe/customers.js +193 -0
- package/backend/dist/esm/backend/src/payments/stripe/error.d.ts +74 -0
- package/backend/dist/esm/backend/src/payments/stripe/error.js +51 -0
- package/backend/dist/esm/backend/src/payments/stripe/events.d.ts +155 -0
- package/backend/dist/esm/backend/src/payments/stripe/events.js +5 -0
- package/backend/dist/esm/backend/src/payments/stripe/meters.d.ts +105 -0
- package/backend/dist/esm/backend/src/payments/stripe/meters.js +318 -0
- package/backend/dist/esm/backend/src/payments/stripe/payment_methods.d.ts +58 -0
- package/backend/dist/esm/backend/src/payments/stripe/payment_methods.js +135 -0
- package/backend/dist/esm/backend/src/payments/stripe/products.d.ts +519 -0
- package/backend/dist/esm/backend/src/payments/stripe/products.js +896 -0
- package/backend/dist/esm/backend/src/payments/stripe/stripe.d.ts +215 -0
- package/backend/dist/esm/backend/src/payments/stripe/stripe.js +464 -0
- package/backend/dist/esm/backend/src/payments/stripe/subscriptions.d.ts +172 -0
- package/backend/dist/esm/backend/src/payments/stripe/subscriptions.js +754 -0
- package/backend/dist/esm/backend/src/payments/stripe/utils.d.ts +63 -0
- package/backend/dist/esm/backend/src/payments/stripe/utils.js +131 -0
- package/backend/dist/esm/backend/src/payments/stripe/webhooks.d.ts +105 -0
- package/backend/dist/esm/backend/src/payments/stripe/webhooks.js +752 -0
- package/backend/dist/esm/backend/src/plugins/browser.d.ts +1 -0
- package/backend/dist/esm/backend/src/plugins/browser.js +170 -0
- package/backend/dist/esm/backend/src/plugins/communication.d.ts +70 -0
- package/backend/dist/esm/backend/src/plugins/communication.js +169 -0
- package/backend/dist/esm/backend/src/plugins/mail/mail.d.ts +255 -0
- package/backend/dist/esm/backend/src/plugins/mail/mail.js +396 -0
- package/backend/dist/esm/backend/src/plugins/mail/ui.d.ts +297 -0
- package/backend/dist/esm/backend/src/plugins/mail/ui.js +1400 -0
- package/backend/dist/esm/backend/src/plugins/pdf.d.ts +1 -0
- package/backend/dist/esm/backend/src/plugins/pdf.js +1694 -0
- package/backend/dist/esm/backend/src/plugins/thread_monitor.d.ts +18 -0
- package/backend/dist/esm/backend/src/plugins/thread_monitor.js +120 -0
- package/backend/dist/esm/backend/src/rate_limit.d.ts +148 -0
- package/backend/dist/esm/backend/src/rate_limit.js +667 -0
- package/backend/dist/esm/backend/src/route.d.ts +39 -0
- package/backend/dist/esm/backend/src/route.js +222 -0
- package/backend/dist/esm/backend/src/server.d.ts +502 -0
- package/backend/dist/esm/backend/src/server.js +2031 -0
- package/backend/dist/esm/backend/src/server.old.d.ts +594 -0
- package/backend/dist/esm/backend/src/server.old.js +2630 -0
- package/backend/dist/esm/backend/src/splash_screen.d.ts +93 -0
- package/backend/dist/esm/backend/src/splash_screen.js +156 -0
- package/backend/dist/esm/backend/src/status.d.ts +89 -0
- package/backend/dist/esm/backend/src/status.js +213 -0
- package/backend/dist/esm/backend/src/stream.d.ts +494 -0
- package/backend/dist/esm/backend/src/stream.js +1611 -0
- package/backend/dist/esm/backend/src/users.d.ts +926 -0
- package/backend/dist/esm/backend/src/users.js +2423 -0
- package/backend/dist/esm/backend/src/utils.d.ts +22 -0
- package/backend/dist/esm/backend/src/utils.js +463 -0
- package/backend/dist/esm/backend/src/view.d.ts +115 -0
- package/backend/dist/esm/backend/src/view.js +584 -0
- package/backend/dist/esm/backend/src/vinc.d.ts +6 -0
- package/backend/dist/esm/backend/src/vinc.js +6 -0
- package/backend/dist/esm/backend/src/volt.d.ts +24 -0
- package/backend/dist/esm/backend/src/volt.js +27 -0
- package/backend/dist/esm/frontend/src/modules/request.d.ts +70 -0
- package/backend/dist/esm/frontend/src/modules/request.js +117 -0
- package/frontend/dist/backend/src/database/collection.d.ts +1765 -0
- package/frontend/dist/backend/src/database/collection.js +3779 -0
- package/frontend/dist/backend/src/database/database.d.ts +92 -0
- package/frontend/dist/backend/src/database/database.js +214 -0
- package/frontend/dist/backend/src/database/filters/filters.d.ts +6 -0
- package/frontend/dist/backend/src/database/filters/filters.js +1 -0
- package/frontend/dist/backend/src/database/filters/strict_filter.d.ts +223 -0
- package/frontend/dist/backend/src/database/filters/strict_filter.js +3 -0
- package/frontend/dist/backend/src/database/filters/strict_update_filter.d.ts +165 -0
- package/frontend/dist/backend/src/database/filters/strict_update_filter.js +5 -0
- package/frontend/dist/backend/src/database/flatten.d.ts +78 -0
- package/frontend/dist/backend/src/database/flatten.js +22 -0
- package/frontend/dist/backend/src/endpoint.d.ts +346 -0
- package/frontend/dist/backend/src/endpoint.js +479 -0
- package/frontend/dist/backend/src/errors/index.d.ts +7 -0
- package/frontend/dist/backend/src/errors/index.js +7 -0
- package/frontend/dist/backend/src/errors/internal_external.d.ts +52 -0
- package/frontend/dist/backend/src/errors/internal_external.js +86 -0
- package/frontend/dist/backend/src/errors/invalid_usage_error.d.ts +41 -0
- package/frontend/dist/backend/src/errors/invalid_usage_error.js +33 -0
- package/frontend/dist/backend/src/errors/system_error.d.ts +261 -0
- package/frontend/dist/backend/src/errors/system_error.js +444 -0
- package/frontend/dist/backend/src/events.d.ts +97 -0
- package/frontend/dist/backend/src/events.js +5 -0
- package/frontend/dist/backend/src/frontend.d.ts +13 -0
- package/frontend/dist/backend/src/frontend.js +23 -0
- package/frontend/dist/backend/src/image_endpoint.d.ts +44 -0
- package/frontend/dist/backend/src/image_endpoint.js +196 -0
- package/frontend/dist/backend/src/meta.d.ts +112 -0
- package/frontend/dist/backend/src/meta.js +152 -0
- package/frontend/dist/backend/src/payments/paddle.d.ts +329 -0
- package/frontend/dist/backend/src/payments/paddle.js +2276 -0
- package/frontend/dist/backend/src/payments/stripe/checkout.d.ts +113 -0
- package/frontend/dist/backend/src/payments/stripe/checkout.js +356 -0
- package/frontend/dist/backend/src/payments/stripe/customers.d.ts +17 -0
- package/frontend/dist/backend/src/payments/stripe/customers.js +193 -0
- package/frontend/dist/backend/src/payments/stripe/error.d.ts +74 -0
- package/frontend/dist/backend/src/payments/stripe/error.js +51 -0
- package/frontend/dist/backend/src/payments/stripe/events.d.ts +155 -0
- package/frontend/dist/backend/src/payments/stripe/events.js +5 -0
- package/frontend/dist/backend/src/payments/stripe/meters.d.ts +105 -0
- package/frontend/dist/backend/src/payments/stripe/meters.js +318 -0
- package/frontend/dist/backend/src/payments/stripe/payment_methods.d.ts +58 -0
- package/frontend/dist/backend/src/payments/stripe/payment_methods.js +135 -0
- package/frontend/dist/backend/src/payments/stripe/products.d.ts +519 -0
- package/frontend/dist/backend/src/payments/stripe/products.js +896 -0
- package/frontend/dist/backend/src/payments/stripe/stripe.d.ts +215 -0
- package/frontend/dist/backend/src/payments/stripe/stripe.js +464 -0
- package/frontend/dist/backend/src/payments/stripe/subscriptions.d.ts +172 -0
- package/frontend/dist/backend/src/payments/stripe/subscriptions.js +754 -0
- package/frontend/dist/backend/src/payments/stripe/utils.d.ts +63 -0
- package/frontend/dist/backend/src/payments/stripe/utils.js +131 -0
- package/frontend/dist/backend/src/payments/stripe/webhooks.d.ts +105 -0
- package/frontend/dist/backend/src/payments/stripe/webhooks.js +752 -0
- package/frontend/dist/backend/src/plugins/mail/mail.d.ts +255 -0
- package/frontend/dist/backend/src/plugins/mail/mail.js +396 -0
- package/frontend/dist/backend/src/plugins/mail/ui.d.ts +297 -0
- package/frontend/dist/backend/src/plugins/mail/ui.js +1400 -0
- package/frontend/dist/backend/src/rate_limit.d.ts +148 -0
- package/frontend/dist/backend/src/rate_limit.js +667 -0
- package/frontend/dist/backend/src/route.d.ts +39 -0
- package/frontend/dist/backend/src/route.js +222 -0
- package/frontend/dist/backend/src/server.d.ts +502 -0
- package/frontend/dist/backend/src/server.js +2031 -0
- package/frontend/dist/backend/src/splash_screen.d.ts +93 -0
- package/frontend/dist/backend/src/splash_screen.js +156 -0
- package/frontend/dist/backend/src/status.d.ts +89 -0
- package/frontend/dist/backend/src/status.js +213 -0
- package/frontend/dist/backend/src/stream.d.ts +494 -0
- package/frontend/dist/backend/src/stream.js +1611 -0
- package/frontend/dist/backend/src/users.d.ts +926 -0
- package/frontend/dist/backend/src/users.js +2423 -0
- package/frontend/dist/backend/src/utils.d.ts +22 -0
- package/frontend/dist/backend/src/utils.js +463 -0
- package/frontend/dist/backend/src/view.d.ts +115 -0
- package/frontend/dist/backend/src/view.js +584 -0
- package/frontend/dist/frontend/src/css/adyen.css +92 -0
- package/frontend/dist/frontend/src/css/volt.css +75 -0
- package/frontend/dist/frontend/src/elements/base.d.ts +3743 -0
- package/frontend/dist/frontend/src/elements/base.js +12151 -0
- package/frontend/dist/frontend/src/elements/module.d.ts +95 -0
- package/frontend/dist/frontend/src/elements/module.js +216 -0
- package/frontend/dist/frontend/src/elements/register_element.d.ts +3 -0
- package/frontend/dist/frontend/src/elements/register_element.js +22 -0
- package/frontend/dist/frontend/src/elements/resize_query_manager.d.ts +0 -0
- package/frontend/dist/frontend/src/elements/resize_query_manager.js +150 -0
- package/frontend/dist/frontend/src/elements/types.d.ts +52 -0
- package/frontend/dist/frontend/src/elements/types.js +5 -0
- package/frontend/dist/frontend/src/index.d.ts +21 -0
- package/frontend/dist/frontend/src/index.js +29 -0
- package/frontend/dist/frontend/src/modules/attachment.d.ts +126 -0
- package/frontend/dist/frontend/src/modules/attachment.js +306 -0
- package/frontend/dist/frontend/src/modules/auth.d.ts +44 -0
- package/frontend/dist/frontend/src/modules/auth.js +80 -0
- package/frontend/dist/frontend/src/modules/color.d.ts +160 -0
- package/frontend/dist/frontend/src/modules/color.js +316 -0
- package/frontend/dist/frontend/src/modules/compression.d.ts +39 -0
- package/frontend/dist/frontend/src/modules/compression.js +102 -0
- package/frontend/dist/frontend/src/modules/cookies.d.ts +44 -0
- package/frontend/dist/frontend/src/modules/cookies.js +143 -0
- package/frontend/dist/frontend/src/modules/events.d.ts +31 -0
- package/frontend/dist/frontend/src/modules/events.js +79 -0
- package/frontend/dist/frontend/src/modules/google.d.ts +23 -0
- package/frontend/dist/frontend/src/modules/google.js +52 -0
- package/frontend/dist/frontend/src/modules/meta.d.ts +14 -0
- package/frontend/dist/frontend/src/modules/meta.js +48 -0
- package/frontend/dist/frontend/src/modules/paddle.d.ts +1207 -0
- package/frontend/dist/frontend/src/modules/paddle.js +2594 -0
- package/frontend/dist/frontend/src/modules/request.d.ts +70 -0
- package/frontend/dist/frontend/src/modules/request.js +117 -0
- package/frontend/dist/frontend/src/modules/settings.d.ts +3 -0
- package/frontend/dist/frontend/src/modules/settings.js +5 -0
- package/frontend/dist/frontend/src/modules/statics.d.ts +21 -0
- package/frontend/dist/frontend/src/modules/statics.js +43 -0
- package/frontend/dist/frontend/src/modules/stripe/cart.d.ts +112 -0
- package/frontend/dist/frontend/src/modules/stripe/cart.js +321 -0
- package/frontend/dist/frontend/src/modules/stripe/checkout.d.ts +7 -0
- package/frontend/dist/frontend/src/modules/stripe/checkout.js +37 -0
- package/frontend/dist/frontend/src/modules/stripe/index.m.d.ts +6 -0
- package/frontend/dist/frontend/src/modules/stripe/index.m.js +6 -0
- package/frontend/dist/frontend/src/modules/stripe/payments.d.ts +58 -0
- package/frontend/dist/frontend/src/modules/stripe/payments.js +92 -0
- package/frontend/dist/frontend/src/modules/support.d.ts +30 -0
- package/frontend/dist/frontend/src/modules/support.js +53 -0
- package/frontend/dist/frontend/src/modules/theme.d.ts +133 -0
- package/frontend/dist/frontend/src/modules/theme.js +406 -0
- package/frontend/dist/frontend/src/modules/themes.d.ts +12 -0
- package/frontend/dist/frontend/src/modules/themes.js +22 -0
- package/frontend/dist/frontend/src/modules/user.d.ts +164 -0
- package/frontend/dist/frontend/src/modules/user.js +270 -0
- package/frontend/dist/frontend/src/modules/utils.d.ts +176 -0
- package/frontend/dist/frontend/src/modules/utils.js +569 -0
- package/frontend/dist/frontend/src/types/gradient.d.ts +29 -0
- package/frontend/dist/frontend/src/types/gradient.js +79 -0
- package/frontend/dist/frontend/src/ui/border_button.d.ts +94 -0
- package/frontend/dist/frontend/src/ui/border_button.js +228 -0
- package/frontend/dist/frontend/src/ui/button.d.ts +241 -0
- package/frontend/dist/frontend/src/ui/button.js +682 -0
- package/frontend/dist/frontend/src/ui/canvas.d.ts +138 -0
- package/frontend/dist/frontend/src/ui/canvas.js +444 -0
- package/frontend/dist/frontend/src/ui/checkbox.d.ts +74 -0
- package/frontend/dist/frontend/src/ui/checkbox.js +321 -0
- package/frontend/dist/frontend/src/ui/code.d.ts +235 -0
- package/frontend/dist/frontend/src/ui/code.js +1007 -0
- package/frontend/dist/frontend/src/ui/context_menu.d.ts +36 -0
- package/frontend/dist/frontend/src/ui/context_menu.js +205 -0
- package/frontend/dist/frontend/src/ui/css.d.ts +16 -0
- package/frontend/dist/frontend/src/ui/css.js +48 -0
- package/frontend/dist/frontend/src/ui/divider.d.ts +15 -0
- package/frontend/dist/frontend/src/ui/divider.js +78 -0
- package/frontend/dist/frontend/src/ui/dropdown.d.ts +176 -0
- package/frontend/dist/frontend/src/ui/dropdown.js +481 -0
- package/frontend/dist/frontend/src/ui/for_each.d.ts +37 -0
- package/frontend/dist/frontend/src/ui/for_each.js +92 -0
- package/frontend/dist/frontend/src/ui/form.d.ts +34 -0
- package/frontend/dist/frontend/src/ui/form.js +233 -0
- package/frontend/dist/frontend/src/ui/frame_modes.d.ts +37 -0
- package/frontend/dist/frontend/src/ui/frame_modes.js +108 -0
- package/frontend/dist/frontend/src/ui/google_map.d.ts +24 -0
- package/frontend/dist/frontend/src/ui/google_map.js +106 -0
- package/frontend/dist/frontend/src/ui/gradient.d.ts +25 -0
- package/frontend/dist/frontend/src/ui/gradient.js +131 -0
- package/frontend/dist/frontend/src/ui/image.d.ts +111 -0
- package/frontend/dist/frontend/src/ui/image.js +576 -0
- package/frontend/dist/frontend/src/ui/input.d.ts +392 -0
- package/frontend/dist/frontend/src/ui/input.js +1201 -0
- package/frontend/dist/frontend/src/ui/link.d.ts +25 -0
- package/frontend/dist/frontend/src/ui/link.js +140 -0
- package/frontend/dist/frontend/src/ui/list.d.ts +37 -0
- package/frontend/dist/frontend/src/ui/list.js +170 -0
- package/frontend/dist/frontend/src/ui/loader_button.d.ts +80 -0
- package/frontend/dist/frontend/src/ui/loader_button.js +193 -0
- package/frontend/dist/frontend/src/ui/loaders.d.ts +57 -0
- package/frontend/dist/frontend/src/ui/loaders.js +157 -0
- package/frontend/dist/frontend/src/ui/popup.d.ts +94 -0
- package/frontend/dist/frontend/src/ui/popup.js +510 -0
- package/frontend/dist/frontend/src/ui/pseudo.d.ts +44 -0
- package/frontend/dist/frontend/src/ui/pseudo.js +154 -0
- package/frontend/dist/frontend/src/ui/scroller.d.ts +105 -0
- package/frontend/dist/frontend/src/ui/scroller.js +1253 -0
- package/frontend/dist/frontend/src/ui/slider.d.ts +45 -0
- package/frontend/dist/frontend/src/ui/slider.js +217 -0
- package/frontend/dist/frontend/src/ui/spacer.d.ts +15 -0
- package/frontend/dist/frontend/src/ui/spacer.js +78 -0
- package/frontend/dist/frontend/src/ui/span.d.ts +15 -0
- package/frontend/dist/frontend/src/ui/span.js +73 -0
- package/frontend/dist/frontend/src/ui/stack.d.ts +66 -0
- package/frontend/dist/frontend/src/ui/stack.js +335 -0
- package/frontend/dist/frontend/src/ui/steps.d.ts +131 -0
- package/frontend/dist/frontend/src/ui/steps.js +308 -0
- package/frontend/dist/frontend/src/ui/style.d.ts +17 -0
- package/frontend/dist/frontend/src/ui/style.js +73 -0
- package/frontend/dist/frontend/src/ui/switch.d.ts +69 -0
- package/frontend/dist/frontend/src/ui/switch.js +357 -0
- package/frontend/dist/frontend/src/ui/table.d.ts +100 -0
- package/frontend/dist/frontend/src/ui/table.js +405 -0
- package/frontend/dist/frontend/src/ui/tabs.d.ts +111 -0
- package/frontend/dist/frontend/src/ui/tabs.js +424 -0
- package/frontend/dist/frontend/src/ui/text.d.ts +15 -0
- package/frontend/dist/frontend/src/ui/text.js +83 -0
- package/frontend/dist/frontend/src/ui/title.d.ts +91 -0
- package/frontend/dist/frontend/src/ui/title.js +272 -0
- package/frontend/dist/frontend/src/ui/ui.d.ts +35 -0
- package/frontend/dist/frontend/src/ui/ui.js +38 -0
- package/frontend/dist/frontend/src/ui/view.d.ts +15 -0
- package/frontend/dist/frontend/src/ui/view.js +88 -0
- package/frontend/dist/frontend/src/volt.d.ts +20 -0
- package/frontend/dist/frontend/src/volt.js +27 -0
- package/package.json +7 -2
|
@@ -0,0 +1,1765 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Daan van den Bergh
|
|
3
|
+
* @copyright © 2022 - 2025 Daan van den Bergh.
|
|
4
|
+
*/
|
|
5
|
+
import { WithId } from 'mongodb';
|
|
6
|
+
import * as mongodb from 'mongodb';
|
|
7
|
+
import type { Database } from "./database.js";
|
|
8
|
+
import { StrictFilter, StrictUpdateFilter } from "./filters/filters.js";
|
|
9
|
+
import { FlattenToDotNotation } from "./flatten.js";
|
|
10
|
+
/**
|
|
11
|
+
* A wrapper class for the MongoDB collection.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const col1 = server.db.collection("col1");
|
|
15
|
+
* const col2 = server.db.collection({
|
|
16
|
+
* name: "col2",
|
|
17
|
+
* indexes: ["uid", "name"],
|
|
18
|
+
* ttl: 1000 * 60 * 60 * 24, // 1 day
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* @nav Database
|
|
22
|
+
* @docs
|
|
23
|
+
*/
|
|
24
|
+
export declare class Collection<Data extends mongodb.Document = mongodb.Document> {
|
|
25
|
+
/** Collection name */
|
|
26
|
+
name: string;
|
|
27
|
+
/** The mongo collection. */
|
|
28
|
+
_col?: mongodb.Collection<Data>;
|
|
29
|
+
/**
|
|
30
|
+
* The Database parent class, used to initialize the collection on demand.
|
|
31
|
+
* So the user can define collections at root level before the database is initialized.
|
|
32
|
+
*/
|
|
33
|
+
db: Database;
|
|
34
|
+
/** Is initialized. */
|
|
35
|
+
initialized: boolean;
|
|
36
|
+
/** Whether this collection instance is transaction-based. */
|
|
37
|
+
is_transaction: boolean;
|
|
38
|
+
/** Whether this transaction has been finalized (committed or aborted). */
|
|
39
|
+
is_finalized_transaction: boolean;
|
|
40
|
+
/** Time to live in msec for all documents. */
|
|
41
|
+
readonly ttl?: number;
|
|
42
|
+
/** Is ttl behaviour enabled? */
|
|
43
|
+
readonly ttl_enabled: boolean;
|
|
44
|
+
/** Enable sliding ttl (refreshes ttl on update), or static ttl (sets ttl on insert) */
|
|
45
|
+
readonly sliding_ttl: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The temporary indexes passed to the constructor for the init method.
|
|
48
|
+
* @note This is not private so it can be updated by {@link QuotaManager}.
|
|
49
|
+
*/
|
|
50
|
+
_init_indexes?: (string | Collection.IndexOpts)[];
|
|
51
|
+
/** The MongoDB client session for transaction support. */
|
|
52
|
+
protected _session?: mongodb.ClientSession;
|
|
53
|
+
/**
|
|
54
|
+
* The record type version for the database.
|
|
55
|
+
* See {@link Collection.Opts.record_version} for more info.
|
|
56
|
+
*
|
|
57
|
+
* Ensure its always defined so we always set the version to `1`,
|
|
58
|
+
* in case the user decides later that it would need the transform version
|
|
59
|
+
* for older documents. Otherwise they would not have the old `1` version.
|
|
60
|
+
*/
|
|
61
|
+
readonly record_version: number;
|
|
62
|
+
/**
|
|
63
|
+
* The function to transform an older document version to the current version.
|
|
64
|
+
* See {@link Collection.Opts.on_transform_version} for more info.
|
|
65
|
+
*/
|
|
66
|
+
readonly on_transform_version?: Collection.OnTransformVersion<Data>;
|
|
67
|
+
/**
|
|
68
|
+
* Save fully transformed documents again to prevent unneeded future transformations.
|
|
69
|
+
* See {@link Collection.Opts.persist_transformed_on_load} for more info.
|
|
70
|
+
*/
|
|
71
|
+
readonly persist_transformed_on_load: boolean | "replace";
|
|
72
|
+
/**
|
|
73
|
+
* The function to call when a document is loaded (also when a default value is used).
|
|
74
|
+
* See {@link Collection.Opts.on_load} for more info.
|
|
75
|
+
*/
|
|
76
|
+
readonly on_load_cb?: Collection.OnLoad<Data>;
|
|
77
|
+
/**
|
|
78
|
+
* Constructs a new Collection instance.
|
|
79
|
+
*
|
|
80
|
+
* @param opts The constructor options for the collection.
|
|
81
|
+
*
|
|
82
|
+
* @throws An error when attempting to initialize a transaction-based collection without initializing the derived collection first.
|
|
83
|
+
*
|
|
84
|
+
* @docs
|
|
85
|
+
*/
|
|
86
|
+
constructor(opts: Collection.Opts<Data> | TransactionCollection.Opts<Data>);
|
|
87
|
+
/**
|
|
88
|
+
* Initialize a database query from path or object.
|
|
89
|
+
* @throws An error if the input type is incorrect, and optionally if the query is empty.
|
|
90
|
+
*/
|
|
91
|
+
private _init_query;
|
|
92
|
+
/**
|
|
93
|
+
* Setup the ttl configuration.
|
|
94
|
+
*
|
|
95
|
+
* @note When transaction mode is enabled, the session option will not be used.
|
|
96
|
+
*/
|
|
97
|
+
private _setup_ttl;
|
|
98
|
+
/**
|
|
99
|
+
* Apply the ttl timestamp to a database operation (update doc or pipeline).
|
|
100
|
+
* Do not upsert if the user explicitly sets `upsert: false` in the operation.
|
|
101
|
+
*/
|
|
102
|
+
private _apply_ttl_to_operation;
|
|
103
|
+
/**
|
|
104
|
+
* Injects `__record_version` into an update **only on insert paths**.
|
|
105
|
+
*
|
|
106
|
+
* Rules:
|
|
107
|
+
* - **Pipeline updates** (`update: Document[]`): no-op here (MongoDB has no `$setOnInsert` in pipelines).
|
|
108
|
+
* If you rely on upsert+pipeline, set `__record_version` explicitly in your pipeline.
|
|
109
|
+
* - **Replacement doc** (no operators):
|
|
110
|
+
* - When `upsert === true`, set `__record_version` **only if missing**.
|
|
111
|
+
* - When `upsert !== true`, do nothing (don’t mask older stored versions).
|
|
112
|
+
* - **Operator doc**:
|
|
113
|
+
* - Respect any user-provided `__record_version` in `$set` or `$setOnInsert`.
|
|
114
|
+
* - When `upsert === true` and the user didn’t provide a value, set it via `$setOnInsert`.
|
|
115
|
+
*
|
|
116
|
+
* Rationale:
|
|
117
|
+
* This avoids bumping `__record_version` during normal updates (which would mask older versions)
|
|
118
|
+
* while still stamping newly inserted documents.
|
|
119
|
+
*/
|
|
120
|
+
private _apply_record_version_to_operation;
|
|
121
|
+
/**
|
|
122
|
+
* Decide if an error is worth a bounded retry.
|
|
123
|
+
* Prefers label-based detection and adds well-known transient/network surfaces.
|
|
124
|
+
*
|
|
125
|
+
* @param unknown_err The thrown error.
|
|
126
|
+
* @returns True for retryable/transient errors; false otherwise.
|
|
127
|
+
*/
|
|
128
|
+
private _should_retry_error;
|
|
129
|
+
/**
|
|
130
|
+
* Execute an async function with bounded, exponential backoff retries for retryable errors.
|
|
131
|
+
*
|
|
132
|
+
* - attempts: 1 ⇒ no retry (single execution).
|
|
133
|
+
* - Uses small bounded jitter to smooth load (see Collection.Retry).
|
|
134
|
+
*
|
|
135
|
+
* @param fn The async operation to execute.
|
|
136
|
+
* @param retry Number of attempts (1 = no retries) or {@link Collection.Retry.Opts}.
|
|
137
|
+
* @returns The function result when successful.
|
|
138
|
+
* @throws The last error if not retryable or retries exhausted.
|
|
139
|
+
*/
|
|
140
|
+
private _with_retry;
|
|
141
|
+
/**
|
|
142
|
+
* Ensure `__record_version` is properly included for projections so version
|
|
143
|
+
* transformation can determine the original version reliably.
|
|
144
|
+
*
|
|
145
|
+
* @param projection The user-specified projection (if any).
|
|
146
|
+
* @returns A projection with `__record_version` enforced where needed.
|
|
147
|
+
*/
|
|
148
|
+
private _ensure_version_in_projection;
|
|
149
|
+
/**
|
|
150
|
+
* Determine whether a projection should be considered partial.
|
|
151
|
+
* @param projection The user-specified projection (if any).
|
|
152
|
+
* @returns True when a non-empty projection was provided.
|
|
153
|
+
*/
|
|
154
|
+
private _is_partial_projection;
|
|
155
|
+
/**
|
|
156
|
+
* Check whether the given update is operator-style (or a pipeline).
|
|
157
|
+
* - Aggregation pipeline: Array → valid.
|
|
158
|
+
* - Operator update: at least one top-level key starts with '$' → valid.
|
|
159
|
+
* - Plain object without '$' keys → NOT valid for updateOne/findOneAndUpdate.
|
|
160
|
+
*/
|
|
161
|
+
private _is_operator_update_or_pipeline;
|
|
162
|
+
private _index_key_signature;
|
|
163
|
+
private _keys_equal;
|
|
164
|
+
private _normalize_index_opts;
|
|
165
|
+
/**
|
|
166
|
+
* Drop all indexes that are NOT part of this._init_indexes, excluding _id_ (and TTL index if enabled).
|
|
167
|
+
*
|
|
168
|
+
* @note We match by key pattern rather than name because names can differ.
|
|
169
|
+
*/
|
|
170
|
+
private _drop_non_init_indexes;
|
|
171
|
+
/**
|
|
172
|
+
* Creates indexes on collections.
|
|
173
|
+
*
|
|
174
|
+
* @note When transaction mode is enabled, the session option will not be used.
|
|
175
|
+
*
|
|
176
|
+
* @param opts The index create options.
|
|
177
|
+
*/
|
|
178
|
+
private _create_index;
|
|
179
|
+
/**
|
|
180
|
+
* Initialize the collection, creating indexes and setting up TTL if needed.
|
|
181
|
+
* @returns The initialized collection instance.
|
|
182
|
+
*
|
|
183
|
+
* @docs
|
|
184
|
+
*/
|
|
185
|
+
init(): Promise<this>;
|
|
186
|
+
/**
|
|
187
|
+
* Assert that the collection is initialized and has a valid MongoDB collection.
|
|
188
|
+
* @throws {Error} Throws if the collection is not initialized or _col is null
|
|
189
|
+
* @returns An initialized collection type assertion
|
|
190
|
+
*
|
|
191
|
+
* @docs
|
|
192
|
+
*/
|
|
193
|
+
assert_init(): asserts this is {
|
|
194
|
+
_col: mongodb.Collection<Data>;
|
|
195
|
+
initialized: true;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Assert that if this is a transaction, it has not been finalized.
|
|
199
|
+
* @throws Error if this is a finalized transaction.
|
|
200
|
+
*
|
|
201
|
+
* @docs
|
|
202
|
+
*/
|
|
203
|
+
assert_not_finalized(): void;
|
|
204
|
+
/**
|
|
205
|
+
* Assert that this collection is not transaction based.
|
|
206
|
+
*
|
|
207
|
+
* @docs
|
|
208
|
+
*/
|
|
209
|
+
assert_not_transaction_based(): void;
|
|
210
|
+
/**
|
|
211
|
+
* Get operation options with session if this is a transaction.
|
|
212
|
+
* @returns Options object with session if applicable.
|
|
213
|
+
*
|
|
214
|
+
* @docs
|
|
215
|
+
*/
|
|
216
|
+
get_operation_options<T extends Record<string, any> = {}>(opts?: T): T & {
|
|
217
|
+
session?: mongodb.ClientSession;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Get the raw and initialized MongoDB collection.
|
|
221
|
+
* @returns The MongoDB collection instance.
|
|
222
|
+
*
|
|
223
|
+
* @docs
|
|
224
|
+
*/
|
|
225
|
+
col(): Promise<mongodb.Collection<Data>>;
|
|
226
|
+
/**
|
|
227
|
+
* Check if an index exists.
|
|
228
|
+
* @note Not supported for transaction based collections.
|
|
229
|
+
* @param index The name of the index to check.
|
|
230
|
+
* @returns True if the index exists, false otherwise.
|
|
231
|
+
*
|
|
232
|
+
* @docs
|
|
233
|
+
*/
|
|
234
|
+
has_index(index: string): Promise<boolean>;
|
|
235
|
+
/**
|
|
236
|
+
* Standalone helper: merge `source` into `target` for missing keys only.
|
|
237
|
+
* Clones assigned nested objects/arrays/dates once (when `clone` is true).
|
|
238
|
+
*
|
|
239
|
+
* @throws An error if the max depth recursion depth has been exceeded.
|
|
240
|
+
*
|
|
241
|
+
* @docs
|
|
242
|
+
*/
|
|
243
|
+
static insert_defaults(target: Record<string, any>, source: Record<string, any>, opts?: {
|
|
244
|
+
depth?: number;
|
|
245
|
+
max_depth?: number;
|
|
246
|
+
clone?: boolean;
|
|
247
|
+
}): void;
|
|
248
|
+
/**
|
|
249
|
+
* Flatten a nested object to a flat `key.subkey` like object, suitable for {@link set} and {@link save} $inc operations.
|
|
250
|
+
* @param obj The object to flatten.
|
|
251
|
+
* @param prefix The prefix to use for the keys, used for recursive calls, new keys will be formatted as `{prefix}.key`.
|
|
252
|
+
* @returns A flat object with keys in the format `key.subkey`.
|
|
253
|
+
* @example
|
|
254
|
+
* const nested = { a: { b: 1, c: { d: 2 } }, e: 3 };
|
|
255
|
+
* const flat = flatten(nested);
|
|
256
|
+
* // flat = { 'a.b': 1, 'a.c.d': 2, 'e': 3 }
|
|
257
|
+
*
|
|
258
|
+
* @docs
|
|
259
|
+
*/
|
|
260
|
+
flatten<T extends Record<string, any>>(obj: T, prefix?: string): FlattenToDotNotation<T>;
|
|
261
|
+
flatten<T extends Record<string, any>, const Prefix extends string>(obj: T, prefix: Prefix): FlattenToDotNotation<T, Prefix>;
|
|
262
|
+
/**
|
|
263
|
+
* Execute `on_transform_version` and `on_load_cb` on a loaded document.
|
|
264
|
+
* Ensures `__record_version` is set when {@link record_version} is defined.
|
|
265
|
+
*
|
|
266
|
+
* @note This is done automatically during load operations.
|
|
267
|
+
*
|
|
268
|
+
* @param data The loaded document.
|
|
269
|
+
* @param opts Additional options.
|
|
270
|
+
*
|
|
271
|
+
* @returns The transformed document.
|
|
272
|
+
*
|
|
273
|
+
* @throws {Collection.OnTransformError} When an error occurs during the {@link Collection.Opts.on_transform_version} callback.
|
|
274
|
+
* @throws {Collection.OnLoadError} When an error occurs during the {@link Collection.Opts.on_load} callback.
|
|
275
|
+
*
|
|
276
|
+
* @docs
|
|
277
|
+
*/
|
|
278
|
+
apply_on_load<Projection extends Collection.Projection | undefined>(data: any, opts: {
|
|
279
|
+
/**
|
|
280
|
+
* The projection option for the load operation
|
|
281
|
+
* Assign to `undefined` when no projection was defined.
|
|
282
|
+
*/
|
|
283
|
+
projection: Projection;
|
|
284
|
+
/**
|
|
285
|
+
* The permission to persist the document after making
|
|
286
|
+
* the necessary `on_transform_version` transformations.
|
|
287
|
+
*/
|
|
288
|
+
persist: boolean;
|
|
289
|
+
/**
|
|
290
|
+
* Await the persist operation.
|
|
291
|
+
* Note that errors encountered during the save operation are silently ignored.
|
|
292
|
+
*/
|
|
293
|
+
await_persist: boolean;
|
|
294
|
+
}): Promise<any>;
|
|
295
|
+
/**
|
|
296
|
+
* Count documents accurately using MongoDB's `countDocuments`.
|
|
297
|
+
*
|
|
298
|
+
* @param query An optional filter to count matching documents. When omitted, counts all documents.
|
|
299
|
+
* @param opts Additional options, see {@link Collection.CountOpts}.
|
|
300
|
+
*
|
|
301
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
302
|
+
*
|
|
303
|
+
* @returns
|
|
304
|
+
* - A number representing the accurate count when successful.
|
|
305
|
+
* - A {@link Collection.CountError} when `opts.throw === false` and an error occurs.
|
|
306
|
+
*
|
|
307
|
+
* @throws {Collection.CountError} When `throw !== false` and the count fails.
|
|
308
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
309
|
+
*
|
|
310
|
+
* @docs
|
|
311
|
+
*/
|
|
312
|
+
count<Throw extends Collection.CountOpts.Throw = undefined>(query?: Collection.Query<Data>, opts?: Collection.CountOpts<Throw>): Promise<Collection.CountResult<Throw>>;
|
|
313
|
+
/**
|
|
314
|
+
* Return a fast, approximate count of the entire collection using
|
|
315
|
+
* MongoDB's `estimatedDocumentCount`. This method does **not** accept
|
|
316
|
+
* a filter and may be off under heavy churn.
|
|
317
|
+
*
|
|
318
|
+
* @param opts Additional options, see {@link Collection.CountOpts}.
|
|
319
|
+
*
|
|
320
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
321
|
+
*
|
|
322
|
+
* @returns
|
|
323
|
+
* - A number representing the estimated total number of documents when successful.
|
|
324
|
+
* - A {@link Collection.CountError} when `opts.throw === false` and an error occurs.
|
|
325
|
+
*
|
|
326
|
+
* @throws {Collection.CountError} When `throw !== false` and the count fails.
|
|
327
|
+
* @throws {InvalidUsageError} (always) When the collection was not used properly.
|
|
328
|
+
*
|
|
329
|
+
* @docs
|
|
330
|
+
*/
|
|
331
|
+
count_estimated<Throw extends Collection.CountOpts.Throw = undefined>(opts?: Collection.CountOpts<Throw>): Promise<Collection.CountResult<Throw>>;
|
|
332
|
+
/**
|
|
333
|
+
* List all documents for a specific query.
|
|
334
|
+
*
|
|
335
|
+
* @param query The database directory path.
|
|
336
|
+
* @param opts The list options, see {@link Collection.ListOpts}.
|
|
337
|
+
* @param allow_empty_query When `true`, allows an empty query (i.e. `{}`) to be passed, which would otherwise throw an error.
|
|
338
|
+
*
|
|
339
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
340
|
+
* @note The {@link Collection.Opts.on_load} and {@link Collection.Opts.on_transform_version} callbacks
|
|
341
|
+
* are not executed when `opts.cursor === true`.
|
|
342
|
+
* @note When `opts.callback` is a function (and `opts.cursor !== true`), this method streams documents and
|
|
343
|
+
* invokes the callback for each processed document, then returns `undefined` on success.
|
|
344
|
+
* This mode is memory-friendly and avoids accumulating the entire result set.
|
|
345
|
+
*
|
|
346
|
+
* @returns
|
|
347
|
+
* - An error if `opts.throw === false` and a {@link Collection.ListError} has occurred.
|
|
348
|
+
* - The find cursor when `opts.cursor === true`.
|
|
349
|
+
* - When `opts.callback && !opts.cursor` is provided, `undefined` on success.
|
|
350
|
+
* - When `opts.page_info === true && !opts.cursor && !opts.callback`, returns {@link Collection.ListedPage}.
|
|
351
|
+
* - Otherwise, an array of documents matching the path.
|
|
352
|
+
*
|
|
353
|
+
* @throws {Collection.ListError} When `throw !== false` if an error occurred during the operation, in which case {@link Collection.ListError.cause} is defined.
|
|
354
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
355
|
+
*
|
|
356
|
+
* @docs
|
|
357
|
+
*/
|
|
358
|
+
list<Projection extends Collection.ListOpts.Projection = undefined, Throw extends Collection.ListOpts.Throw = undefined, Cursor extends Collection.ListOpts.Cursor = undefined, Callback extends Collection.ListOpts.Callback<Data, Projection> = undefined, PageInfo extends Collection.ListOpts.PageInfo = undefined>(query: Collection.Query<Data>, opts?: Collection.ListOpts<Data, Projection, Throw, Cursor, Callback, PageInfo>, allow_empty_query?: boolean): Promise<Collection.ListResult<Data, Projection, Throw, Cursor, Callback, PageInfo>>;
|
|
359
|
+
/**
|
|
360
|
+
* List all documents of the collection.
|
|
361
|
+
*
|
|
362
|
+
* @param opts The list options, see {@link Collection.ListOpts}.
|
|
363
|
+
*
|
|
364
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
365
|
+
* @note The {@link Collection.Opts.on_load} and {@link Collection.Opts.on_transform_version} callbacks
|
|
366
|
+
* are not executed when `opts.cursor === true`.
|
|
367
|
+
* @note When `opts.callback` is a function (and `opts.cursor !== true`), this method streams documents and
|
|
368
|
+
* invokes the callback for each processed document, then returns `undefined` on success.
|
|
369
|
+
*
|
|
370
|
+
* @returns
|
|
371
|
+
* - Array of all documents in the collection.
|
|
372
|
+
* - The find cursor when `opts.cursor === true`.
|
|
373
|
+
* - `undefined` when `opts.callback && !opts.cursor`.
|
|
374
|
+
* - An error if `opts.throw === false` and a {@link Collection.ListError} has occurred.
|
|
375
|
+
*
|
|
376
|
+
* @throws {Collection.ListError} When `throw !== false` if an error occurred during the operation, in which case {@link Collection.ListError.cause} is defined.
|
|
377
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
378
|
+
*
|
|
379
|
+
* @docs
|
|
380
|
+
*/
|
|
381
|
+
list_all<Projection extends Collection.ListOpts.Projection = undefined, Throw extends Collection.ListOpts.Throw = undefined, Cursor extends Collection.ListOpts.Cursor = undefined, Callback extends Collection.ListOpts.Callback<Data, Projection> = undefined, PageInfo extends Collection.ListOpts.PageInfo = undefined>(opts?: Collection.ListOpts<Data, Projection, Throw, Cursor, Callback, PageInfo>): Promise<Collection.ListResult<Data, Projection, Throw, Cursor, Callback, PageInfo>>;
|
|
382
|
+
/**
|
|
383
|
+
* Check if a document exists by only loading the document's id.
|
|
384
|
+
*
|
|
385
|
+
* @param query The database path to the document.
|
|
386
|
+
* @param opts The exists options, see {@link Collection.ExistsOpts}.
|
|
387
|
+
*
|
|
388
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
389
|
+
* @note This method does not execute the {@link Collection.Opts.on_load}
|
|
390
|
+
* and {@link Collection.Opts.on_transform_version} callbacks.
|
|
391
|
+
*
|
|
392
|
+
* @returns
|
|
393
|
+
* - An error if `opts.throw === false` and a {@link Collection.ExistsError} has occurred.
|
|
394
|
+
* - True if the document exists, false otherwise.
|
|
395
|
+
*
|
|
396
|
+
* @throws {Collection.ExistsError} When `throw !== false` if an error occurred during the operation, in which case {@link Collection.ExistsError.cause} is defined.
|
|
397
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
398
|
+
*
|
|
399
|
+
* @docs
|
|
400
|
+
*/
|
|
401
|
+
exists<Throw extends Collection.ExistsOpts.Throw = undefined>(query: Collection.Query<Data>, opts?: Collection.ExistsOpts<Throw>): Promise<Collection.ExistsResult<Throw>>;
|
|
402
|
+
/**
|
|
403
|
+
* Load a single document by query.
|
|
404
|
+
*
|
|
405
|
+
* Applies an optional projection and, if a `default` is provided, inserts any
|
|
406
|
+
* missing keys from the default into the loaded document (values are deep-cloned).
|
|
407
|
+
*
|
|
408
|
+
* @note The `default` value is deep-cloned if it is returned or inserted.
|
|
409
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
410
|
+
*
|
|
411
|
+
* @param query The database query.
|
|
412
|
+
* @param opts Additional load options {@link Collection.LoadOpts}.
|
|
413
|
+
*
|
|
414
|
+
* @returns
|
|
415
|
+
* - When `opts.throw === false`:
|
|
416
|
+
* - If found: the loaded (projected) document.
|
|
417
|
+
* - If not found and `opts.default` is provided: the deep-cloned default data.
|
|
418
|
+
* - If not found and no default: a {@link Collection.NotFoundError}.
|
|
419
|
+
* - On load failure: a {@link Collection.LoadError}.
|
|
420
|
+
* - When `opts.throw !== false` (default):
|
|
421
|
+
* - If found: the loaded (projected) document.
|
|
422
|
+
* - If not found and `opts.default` is provided: the deep-cloned default data.
|
|
423
|
+
* - If not found and no default: a {@link Collection.NotFoundError} is **thrown**.
|
|
424
|
+
* - On load failure: a {@link Collection.LoadError} is **thrown**.
|
|
425
|
+
*
|
|
426
|
+
* @throws {Collection.LoadError} Only when `opts.throw !== false` and the load fails.
|
|
427
|
+
* @throws {Collection.NotFoundError} When the document is not found and `opts.throw !== false && opts.default == null`.
|
|
428
|
+
* @throws {InvalidUsageError} When the provided arguments are invalid or if the collection was not used properly.
|
|
429
|
+
*
|
|
430
|
+
* @docs
|
|
431
|
+
*/
|
|
432
|
+
load<Default extends Collection.LoadOpts.Default<Data> = undefined, Projection extends Collection.LoadOpts.Projection = undefined, Throw extends Collection.LoadOpts.Throw = undefined>(query: Collection.Query<Data>, opts?: Collection.LoadOpts<Data, Default, Projection, Throw>): Promise<Collection.LoadResult<Data, Default, Projection, Throw>>;
|
|
433
|
+
/**
|
|
434
|
+
* Save data with predefined `$set` behaviour.
|
|
435
|
+
* When the document already exists this function only updates the specified content attributes.
|
|
436
|
+
* When a document does not exist it will automatically be created, unless `opts.upsert !== false`.
|
|
437
|
+
*
|
|
438
|
+
* @param query The database query / path to the document.
|
|
439
|
+
* @param content The data to save.
|
|
440
|
+
* @param opts Additional options, see {@link Collection.SetOpts}.
|
|
441
|
+
*
|
|
442
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
443
|
+
* @note The `opts.upsert` option defaults to `true`.
|
|
444
|
+
* @note `set()` does not deep-merge nested objects.
|
|
445
|
+
* With `flatten: false`, nested objects are written as whole objects—so their keys are replaced
|
|
446
|
+
* by exactly what you provide (missing nested keys can be overwritten/removed).
|
|
447
|
+
* With `flatten: true`, nested objects are flattened into dot notation, allowing you to update specific nested keys without affecting siblings.
|
|
448
|
+
*
|
|
449
|
+
* @returns
|
|
450
|
+
* - When `opts.bulk === true`: an unexecuted bulk operation.
|
|
451
|
+
* - When `opts.return === true`: the **updated** document; or a {@link Collection.SaveError} when `throw:false` and a write failure occurs.
|
|
452
|
+
* - Otherwise: `undefined` on success; or a {@link Collection.SaveError} when `throw:false` and a write failure occurs.
|
|
453
|
+
*
|
|
454
|
+
* @throws {Collection.SaveError} Only when `opts.throw !== false` and the write fails.
|
|
455
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
456
|
+
*
|
|
457
|
+
* @docs
|
|
458
|
+
*/
|
|
459
|
+
set<Bulk extends Collection.SetOpts.Bulk = undefined, Return extends Collection.SetOpts.Return = undefined, Throw extends Collection.SetOpts.Throw = undefined, Upsert extends Collection.SetOpts.Upsert = undefined>(query: Collection.Query<Data>, content: Partial<Data> | Partial<FlattenToDotNotation<Data>>, opts?: Collection.SetOpts<Bulk, Return, Throw, Upsert>): Promise<Collection.SetResult<Data, Bulk, Return, Throw>>;
|
|
460
|
+
/**
|
|
461
|
+
* Save a single document without performing any default `$set` or `$inc` like operations.
|
|
462
|
+
* When a document does not exist it will automatically be created unless `opts.upsert === false`.
|
|
463
|
+
*
|
|
464
|
+
* @param query The database query / path to the document.
|
|
465
|
+
* @param operation The MongoDB update document or pipeline (e.g. `{ $set: { key: value } }`).
|
|
466
|
+
* @param opts Additional options, see {@link Collection.SaveOpts}.
|
|
467
|
+
*
|
|
468
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
469
|
+
* @note The `opts.upsert` option defaults to `true`.
|
|
470
|
+
* @note Replacement documents are not allowed here. An update operator
|
|
471
|
+
* document (e.g. `$set`, `$inc`) or an aggregation pipeline is required.
|
|
472
|
+
* To replace a document use {@link replace}.
|
|
473
|
+
*
|
|
474
|
+
* @note This writes the value you pass in—it does not deep-merge nested objects.
|
|
475
|
+
* If you save a nested object, any nested keys you leave out may be overwritten/removed.
|
|
476
|
+
* Use `set()` in combination with `flatten: true` to perform deep merges on nested objects without worrying about this behavior.
|
|
477
|
+
*
|
|
478
|
+
* @returns
|
|
479
|
+
* - When `opts.bulk === true`: an unexecuted bulk operation.
|
|
480
|
+
* - When `opts.return === true`: the **updated** document; or a {@link Collection.SaveError} when `throw:false` and a write failure occurs.
|
|
481
|
+
* - Otherwise: {@link mongodb.UpdateResult} on success; or a {@link Collection.SaveError} when `throw:false` and a write failure occurs.
|
|
482
|
+
*
|
|
483
|
+
* @throws {Collection.SaveError} Only when `opts.throw !== false` and the write fails.
|
|
484
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
485
|
+
*
|
|
486
|
+
* @docs
|
|
487
|
+
*/
|
|
488
|
+
save<Bulk extends Collection.SaveOpts.Bulk = undefined, Return extends Collection.SaveOpts.Return = undefined, Throw extends Collection.SaveOpts.Throw = undefined, Upsert extends Collection.SaveOpts.Upsert = undefined>(query: Collection.Query<Data>, operation: StrictUpdateFilter<Data> | mongodb.Document[], // @todo add strict pipeline type.
|
|
489
|
+
opts?: Collection.SaveOpts<Bulk, Return, Throw, Upsert>): Promise<Collection.SaveResult<Data, Bulk, Return, Throw>>;
|
|
490
|
+
/**
|
|
491
|
+
* Save multiple documents without performing any default `$set` or `$inc` operations.
|
|
492
|
+
* Uses MongoDB `updateMany` (unlike {@link save}, which uses `updateOne`).
|
|
493
|
+
*
|
|
494
|
+
* @param query The database query / path to the documents.
|
|
495
|
+
* @param operation The MongoDB update document or pipeline (e.g. `{ $set: { ... } }`).
|
|
496
|
+
* @param opts Additional options, see {@link Collection.SaveManyOpts}.
|
|
497
|
+
*
|
|
498
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
499
|
+
* @note The `opts.upsert` option defaults to `false` (unlike {@link save}, which defaults to `true`).
|
|
500
|
+
* @note When `opts.return` is truthy, this performs a **follow-up** {@link list} with the same `query`
|
|
501
|
+
* to return the (post-update) documents. This is **less efficient** than `save(..., { return: true })`
|
|
502
|
+
* because it requires an additional list query after the write.
|
|
503
|
+
* @note If the follow-up `list()` fails:
|
|
504
|
+
* - with `opts.throw !== false`, it will throw a {@link Collection.ListError};
|
|
505
|
+
* - with `opts.throw === false`, it will return a {@link Collection.ListError}.
|
|
506
|
+
*
|
|
507
|
+
* @returns
|
|
508
|
+
* - When `opts.bulk === true`: an unexecuted bulk operation (`{ updateMany: ... }`).
|
|
509
|
+
* - When `opts.return` is falsy: {@link mongodb.UpdateResult} on success; or a {@link Collection.SaveError} when `throw:false`.
|
|
510
|
+
* - When `opts.return` is truthy: the matched/updated docs (via `list()`); or
|
|
511
|
+
* - a {@link Collection.SaveError} when the write fails and `throw:false`, or
|
|
512
|
+
* - a {@link Collection.ListError} when the follow-up read fails and `throw:false`.
|
|
513
|
+
*
|
|
514
|
+
* @throws {Collection.SaveError} Only when `opts.throw !== false` and the write fails.
|
|
515
|
+
* @throws {Collection.ListError} Only when `opts.throw !== false` and the follow-up list fails.
|
|
516
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or the collection was misused.
|
|
517
|
+
*
|
|
518
|
+
* @docs
|
|
519
|
+
*/
|
|
520
|
+
save_many<Bulk extends boolean | undefined = undefined, Return extends boolean | Collection.SaveManyReturnOpts | undefined = undefined, Throw extends boolean | undefined = undefined, Upsert extends boolean | undefined = undefined>(query: Collection.Query<Data>, operation: StrictUpdateFilter<Data> | mongodb.Document[], opts?: Collection.SaveManyOpts<Bulk, Return, Throw, Upsert>): Promise<Collection.SaveManyResult<Data, Bulk, Return, Throw>>;
|
|
521
|
+
/**
|
|
522
|
+
* Build an aggregation replacement pipeline that preserves _id on matches and
|
|
523
|
+
* applies versioning/TTL consistently with non-pipeline paths.
|
|
524
|
+
*
|
|
525
|
+
* - On matches: preserve stored `__record_version` and (for static TTL) stored `__ttl_timestamp`.
|
|
526
|
+
* - On upserts:
|
|
527
|
+
* - `__record_version`: respect user value if provided, else stamp `this.record_version`.
|
|
528
|
+
* - `__ttl_timestamp`:
|
|
529
|
+
* • sliding TTL → always set to "now"
|
|
530
|
+
* • static TTL → respect user value if provided, else set to "now"
|
|
531
|
+
*
|
|
532
|
+
* @param base_replacement A shallow clone of the user replacement. For replace_many, pass without `_id`.
|
|
533
|
+
* @param upsert Whether the write is an upsert.
|
|
534
|
+
* @param apply_ttl Whether TTL logic should be applied (`this.ttl_enabled && opts?.apply_ttl !== false`).
|
|
535
|
+
* @returns A MongoDB aggregation pipeline that performs the replacement.
|
|
536
|
+
*/
|
|
537
|
+
private _build_replace_pipeline;
|
|
538
|
+
/**
|
|
539
|
+
* Replace a single document.
|
|
540
|
+
* Accepts a replacement document only (no update operators/pipelines).
|
|
541
|
+
*
|
|
542
|
+
* Internally uses an aggregation pipeline to emulate a full replacement while preserving `_id`
|
|
543
|
+
* for matched documents and applying record-version/TTL semantics consistently.
|
|
544
|
+
*
|
|
545
|
+
* @param query The match filter.
|
|
546
|
+
* @param replacement The replacement document, no `$` operators.
|
|
547
|
+
* @param opts Options, see {@link Collection.ReplaceOpts}.
|
|
548
|
+
*
|
|
549
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
550
|
+
* @note The `opts.upsert` option defaults to `true`.
|
|
551
|
+
* @note TTL semantics:
|
|
552
|
+
* - When `opts.apply_ttl === false` (or TTL is disabled), the existing TTL is preserved for matched docs.
|
|
553
|
+
* - With sliding TTL, `__ttl_timestamp` is refreshed on every write.
|
|
554
|
+
* - With static TTL, matched docs keep their original TTL; upserts receive a fresh timestamp.
|
|
555
|
+
*
|
|
556
|
+
* @warning Updating the document id `_id` will cause undefined behaviour on matches. On matched documents,
|
|
557
|
+
* a user-supplied `_id` is ignored and the existing `_id` is preserved. On true upserts, a
|
|
558
|
+
* user-supplied `_id` is allowed and will be used by the server.
|
|
559
|
+
*
|
|
560
|
+
* @returns
|
|
561
|
+
* - When `opts.bulk === true`: an unexecuted bulk operation.
|
|
562
|
+
* - When `opts.return === true`: the **updated** document; or a {@link Collection.SaveError} when `throw:false` and a write failure occurs.
|
|
563
|
+
* - Otherwise: {@link mongodb.UpdateResult} on success; or a {@link Collection.SaveError} when `throw:false` and a write failure occurs.
|
|
564
|
+
*
|
|
565
|
+
* @throws {Collection.SaveError} Only when `opts.throw !== false` and the write fails.
|
|
566
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
567
|
+
*
|
|
568
|
+
* @docs
|
|
569
|
+
*/
|
|
570
|
+
replace<Bulk extends boolean | undefined = undefined, Return extends boolean | undefined = undefined, Throw extends boolean | undefined = undefined, Upsert extends boolean | undefined = undefined>(query: Collection.Query<Data>, replacement: Data, opts?: Collection.ReplaceOpts<Bulk, Return, Throw, Upsert>): Promise<Collection.ReplaceResult<Data, Bulk, Return, Throw>>;
|
|
571
|
+
/**
|
|
572
|
+
* Replace multiple documents matched by `query`.
|
|
573
|
+
* Accepts a **replacement document only** (no update operators or pipelines).
|
|
574
|
+
*
|
|
575
|
+
* Internally uses an aggregation pipeline to emulate a full replacement while preserving `_id`
|
|
576
|
+
* for matched documents and applying record-version/TTL semantics consistently.
|
|
577
|
+
*
|
|
578
|
+
* @param query The match filter.
|
|
579
|
+
* @param replacement The replacement document, no `$` operators.
|
|
580
|
+
* @param opts Options, see {@link Collection.ReplaceManyOpts}.
|
|
581
|
+
*
|
|
582
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
583
|
+
* @note The `opts.upsert` option defaults to `false` (unlike {@link replace}, which defaults to `true`).
|
|
584
|
+
* @note When `opts.return` is truthy, this performs a **follow-up** {@link list} with the same `query`
|
|
585
|
+
* to return the (post-update) documents. This is **less efficient** than `replace(..., { return: true })`
|
|
586
|
+
* because it requires an additional list query after the write.
|
|
587
|
+
* @note TTL semantics:
|
|
588
|
+
* - When `opts.apply_ttl === false` (or TTL is disabled), the existing TTL is preserved for matched docs.
|
|
589
|
+
* - With sliding TTL, `__ttl_timestamp` is refreshed on every write.
|
|
590
|
+
* - With static TTL, matched docs keep their original TTL; upserts receive a fresh timestamp.
|
|
591
|
+
*
|
|
592
|
+
* @warning The `_id` field is handled with special care:
|
|
593
|
+
* - Any `_id` present in the `replacement` is **ignored/stripped** for `replace_many`.
|
|
594
|
+
* This prevents attempts to change immutable ids across multiple documents.
|
|
595
|
+
* - For matched documents, the existing `_id` is always preserved.
|
|
596
|
+
* - For true upserts (`opts.upsert === true` when no match occurs), the server will
|
|
597
|
+
* generate a new `_id`. If you need to upsert with a caller-chosen `_id`, use
|
|
598
|
+
* {@link replace} (single-document) instead.
|
|
599
|
+
*
|
|
600
|
+
* @returns
|
|
601
|
+
* - When `opts.bulk === true`: an unexecuted bulk operation (`{ updateMany: ... }`).
|
|
602
|
+
* - When `opts.return` is falsy: {@link mongodb.UpdateResult} on success; or a
|
|
603
|
+
* {@link Collection.SaveError} when `throw:false` and a write failure occurs.
|
|
604
|
+
* - When `opts.return` is truthy: the matched/updated docs (via a follow-up {@link list});
|
|
605
|
+
* or a {@link Collection.SaveError} / {@link Collection.ListError} when `throw:false`.
|
|
606
|
+
*
|
|
607
|
+
* @throws {Collection.SaveError} Only when `opts.throw !== false` and the write fails.
|
|
608
|
+
* @throws {Collection.ListError} Only when `opts.throw !== false` and the follow-up list fails.
|
|
609
|
+
* @throws {InvalidUsageError} (always) When arguments are invalid or the collection was misused.
|
|
610
|
+
*
|
|
611
|
+
* @docs
|
|
612
|
+
*/
|
|
613
|
+
replace_many<Bulk extends boolean | undefined = undefined, Return extends boolean | Collection.SaveManyReturnOpts | undefined = undefined, Throw extends boolean | undefined = undefined, Upsert extends boolean | undefined = undefined>(query: Collection.Query<Data>, replacement: Data, opts?: Collection.ReplaceManyOpts<Bulk, Return, Throw, Upsert>): Promise<Collection.ReplaceManyResult<Data, Bulk, Return, Throw>>;
|
|
614
|
+
/**
|
|
615
|
+
* Delete a document of the collection.
|
|
616
|
+
*
|
|
617
|
+
* @param query The database query to the document.
|
|
618
|
+
* @param opts Additional options, see {@link Collection.DeleteOpts}.
|
|
619
|
+
*
|
|
620
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
621
|
+
*
|
|
622
|
+
* @returns
|
|
623
|
+
* - An unexecuted bulk operation object if `bulk === true`.
|
|
624
|
+
* - A {@link Collection.DeleteError} when occurred and `opts.throw === false`.
|
|
625
|
+
* - A {@link mongodb.DeleteResult}.
|
|
626
|
+
*
|
|
627
|
+
* @throws {Collection.DeleteError} When `opts.throw !== false` and if the deletion was not acknowledged, this does not check against the deleted document count.
|
|
628
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
629
|
+
*
|
|
630
|
+
* @docs
|
|
631
|
+
*/
|
|
632
|
+
delete<Bulk extends boolean | undefined = undefined, Throw extends boolean | undefined = undefined>(query: Collection.Query<Data>, opts?: Collection.DeleteOpts<Bulk, Throw>): Promise<Collection.DeleteResult<Data, Bulk, Throw>>;
|
|
633
|
+
/**
|
|
634
|
+
* Delete multiple documents matching the query.
|
|
635
|
+
*
|
|
636
|
+
* @param query The database query to the document(s).
|
|
637
|
+
* @param opts Additional options, see {@link Collection.DeleteOpts}.
|
|
638
|
+
* @param allow_empty_query When `true`, allows an empty query (i.e. `{}`) to be passed, which would otherwise throw an error.
|
|
639
|
+
*
|
|
640
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
641
|
+
*
|
|
642
|
+
* @returns
|
|
643
|
+
* - An unexecuted bulk operation object if `bulk === true`.
|
|
644
|
+
* - A {@link Collection.DeleteError} when occurred and `opts.throw == false`.
|
|
645
|
+
* - A {@link mongodb.DeleteResult}.
|
|
646
|
+
*
|
|
647
|
+
* @throws {Collection.DeleteError} When `opts.throw !== false` and if the deletion was not acknowledged, this does not check against the deleted document count.
|
|
648
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
649
|
+
*
|
|
650
|
+
* @docs
|
|
651
|
+
*/
|
|
652
|
+
delete_many<Bulk extends boolean | undefined = undefined, Throw extends boolean | undefined = undefined>(query: Collection.Query<Data>, opts?: Collection.DeleteOpts<Bulk, Throw>, allow_empty_query?: boolean): Promise<Collection.DeleteResult<Data, Bulk, Throw>>;
|
|
653
|
+
/**
|
|
654
|
+
* Delete all documents in the collection.
|
|
655
|
+
*
|
|
656
|
+
* @param opts Additional options, see {@link Collection.DeleteOpts}.
|
|
657
|
+
*
|
|
658
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
659
|
+
*
|
|
660
|
+
* @returns
|
|
661
|
+
* - An unexecuted bulk operation object if `bulk === true`.
|
|
662
|
+
* - A {@link Collection.DeleteError} when occurred and `opts.throw == false`.
|
|
663
|
+
* - A {@link mongodb.DeleteResult}.
|
|
664
|
+
*
|
|
665
|
+
* @throws {Collection.DeleteError} When `opts.throw !== false` and if the deletion was not acknowledged, this does not check against the deleted document count.
|
|
666
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
667
|
+
*
|
|
668
|
+
* @docs
|
|
669
|
+
*/
|
|
670
|
+
delete_all<Bulk extends boolean | undefined = undefined, Throw extends boolean | undefined = undefined>(opts?: Collection.DeleteOpts<Bulk, Throw>): Promise<Collection.DeleteResult<Data, Bulk, Throw>>;
|
|
671
|
+
/**
|
|
672
|
+
* Delete all documents from the collection and drop the collection.
|
|
673
|
+
*
|
|
674
|
+
* @note This function is not supported for transaction based collections.
|
|
675
|
+
*
|
|
676
|
+
* @param opts Additional options, see {@link Collection.DeleteOpts}.
|
|
677
|
+
*
|
|
678
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
679
|
+
*
|
|
680
|
+
* @returns
|
|
681
|
+
* - A {@link Collection.DeleteError} when occurred and `opts.throw === false`.
|
|
682
|
+
* - Undefined upon success.
|
|
683
|
+
*
|
|
684
|
+
* @throws {Collection.DeleteError} When `opts.throw !== false` and if the deletion was not acknowledged, this does not check against the deleted document count.
|
|
685
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
686
|
+
*
|
|
687
|
+
* @docs
|
|
688
|
+
*/
|
|
689
|
+
delete_collection<Throw extends boolean | undefined = undefined>(opts?: Collection.DeleteCollectionOpts<Throw>): Promise<Collection.DeleteCollectionResult<Throw>>;
|
|
690
|
+
/**
|
|
691
|
+
* Execute bulk write operations.
|
|
692
|
+
*
|
|
693
|
+
* @param operations Array of bulk write operations.
|
|
694
|
+
* @param opts Additional options, see {@link Collection.BulkOpts}
|
|
695
|
+
*
|
|
696
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
697
|
+
*
|
|
698
|
+
* @returns
|
|
699
|
+
* - A {@link Collection.BulkError} if occurred and `opts.throw === false`.
|
|
700
|
+
* - A {@link mongodb.BulkWriteResult}.
|
|
701
|
+
*
|
|
702
|
+
* @throws {Collection.BulkError} When `opts.throw !== false` and if the bulk operation failed, this does not check against the bulk write result (this may change in the future).
|
|
703
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
704
|
+
*
|
|
705
|
+
* @docs
|
|
706
|
+
*/
|
|
707
|
+
bulk_operations<Throw extends boolean | undefined = undefined>(operations: mongodb.AnyBulkWriteOperation<Data>[], opts?: Collection.BulkOpts<Throw>): Promise<Collection.BulkResult<Throw>>;
|
|
708
|
+
/**
|
|
709
|
+
* Execute an aggregation pipeline.
|
|
710
|
+
*
|
|
711
|
+
* @param pipeline MongoDB aggregation pipeline stages.
|
|
712
|
+
* @param opts Aggregation options, see {@link Collection.AggregateOpts}
|
|
713
|
+
*
|
|
714
|
+
* @note The `opts.throw` option defaults to `true`.
|
|
715
|
+
* @note This method does not execute the {@link Collection.Opts.on_load}
|
|
716
|
+
* and {@link Collection.Opts.on_transform_version} callbacks.
|
|
717
|
+
*
|
|
718
|
+
* @returns
|
|
719
|
+
* - A {@link Collection.AggregateError} if occurred and `opts.throw === false`.
|
|
720
|
+
* - An {@link mongodb.AggregationCursor} if `opts.cursor === true`.
|
|
721
|
+
* - An array of document results.
|
|
722
|
+
*
|
|
723
|
+
* @throws {Collection.AggregateError} When `opts.throw !== false` and if the aggregate operation failed, this does not check against the aggregate result (this may change in the future).
|
|
724
|
+
* @throws {InvalidUsageError} (always) When the provided argument(s) are invalid or if the collection was not used properly.
|
|
725
|
+
*
|
|
726
|
+
* @docs
|
|
727
|
+
*/
|
|
728
|
+
aggregate<T extends Partial<Data> = Data, Throw extends boolean | undefined = undefined, Cursor extends boolean | undefined = undefined>(pipeline: mongodb.Document[], // @todo add strict pipeline type.
|
|
729
|
+
opts?: Collection.AggregateOpts<Throw, Cursor>): Promise<Collection.AggregateResult<T, Throw, Cursor>>;
|
|
730
|
+
/**
|
|
731
|
+
* Clean a document from all default system attributes.
|
|
732
|
+
* @param doc The document to clean.
|
|
733
|
+
* @returns The cleaned document without system attributes.
|
|
734
|
+
*
|
|
735
|
+
* @docs
|
|
736
|
+
*/
|
|
737
|
+
clean<T extends Partial<Data> = Data>(doc: T): Omit<T, "_id" | "_path" | "__ttl_timestamp" | "__record_version">;
|
|
738
|
+
/**
|
|
739
|
+
* Start a new transaction by creating a TransactionCollection instance.
|
|
740
|
+
* @returns A new TransactionCollection instance with transaction capabilities.
|
|
741
|
+
*
|
|
742
|
+
* @docs
|
|
743
|
+
*/
|
|
744
|
+
start_transaction(): Promise<TransactionCollection<Data>>;
|
|
745
|
+
/** Prepare a _path based regex operation. @deprecated */
|
|
746
|
+
private prepare_path_regex_filter;
|
|
747
|
+
}
|
|
748
|
+
/** Nested types for the {@link Collection} class. */
|
|
749
|
+
export declare namespace Collection {
|
|
750
|
+
/**
|
|
751
|
+
* The constructor options for {@link Collection}.
|
|
752
|
+
*
|
|
753
|
+
* @docs
|
|
754
|
+
*/
|
|
755
|
+
interface Opts<Data extends mongodb.Document = mongodb.Document> {
|
|
756
|
+
/** The name of the collection. */
|
|
757
|
+
name: string;
|
|
758
|
+
/** The MongoDB collection instance. */
|
|
759
|
+
col?: mongodb.Collection<Data>;
|
|
760
|
+
/** The time to live for every record in the collection. */
|
|
761
|
+
ttl?: number | {
|
|
762
|
+
/** The time to live value in milliseconds. */
|
|
763
|
+
milliseconds: number;
|
|
764
|
+
/**
|
|
765
|
+
* Enable sliding ttl (refreshes ttl on update), or static ttl (sets ttl on insert)
|
|
766
|
+
* Defaults to `true`.
|
|
767
|
+
*/
|
|
768
|
+
sliding?: boolean;
|
|
769
|
+
};
|
|
770
|
+
/** The indexes to create / validate upon initialization. */
|
|
771
|
+
indexes?: (string | Collection.IndexOpts)[];
|
|
772
|
+
/** Construct the collection in transaction mode. */
|
|
773
|
+
transaction_based?: false;
|
|
774
|
+
/** The {@link Database} instance. */
|
|
775
|
+
db: Database;
|
|
776
|
+
/**
|
|
777
|
+
* The record type version for the database.
|
|
778
|
+
* Defaults to `1` when not defined.
|
|
779
|
+
* When not `1`, {@link on_transform_version} must be defined.
|
|
780
|
+
*/
|
|
781
|
+
record_version?: number;
|
|
782
|
+
/**
|
|
783
|
+
* The function to transform an older document version to the current version.
|
|
784
|
+
*
|
|
785
|
+
* Only allowed when {@link record_version} is defined.
|
|
786
|
+
*
|
|
787
|
+
* Executed before {@link on_load}.
|
|
788
|
+
*
|
|
789
|
+
* Any errors produced inside this callback will be wrapped in the `cause` of a {@link OnTransformError},
|
|
790
|
+
* However, this error is often wrapped inside the `cause` of the operation specific error such as {@link LoadError}.
|
|
791
|
+
*
|
|
792
|
+
* @note This callback is executed when a document is loaded anywhere inside the {@link Collection} class.
|
|
793
|
+
* Except for the special cases mentioned in the warnings sections.
|
|
794
|
+
*
|
|
795
|
+
* @warning This callback is not executed:
|
|
796
|
+
* - When a `Cursor` is returned in for instance {@link Collection.list} or {@link Collection.aggregate}.
|
|
797
|
+
* - Inside the {@link Collection.aggregate} method.
|
|
798
|
+
*/
|
|
799
|
+
on_transform_version?: OnTransformVersion<Data>;
|
|
800
|
+
/**
|
|
801
|
+
* If true, after a successful on_transform_version (and only when we loaded a full doc,
|
|
802
|
+
* not a projection), the transformed document is persisted once so future reads don't
|
|
803
|
+
* need to transform again.
|
|
804
|
+
* If `replace`, the existing document is replaced with the transformed document.
|
|
805
|
+
* Defaults to `true`.
|
|
806
|
+
*/
|
|
807
|
+
persist_transformed_on_load?: boolean | "replace";
|
|
808
|
+
/**
|
|
809
|
+
* The function to call when a document is loaded, also when a default value is used.
|
|
810
|
+
*
|
|
811
|
+
* Executed after {@link on_transform_version}.
|
|
812
|
+
*
|
|
813
|
+
* Any errors produced inside this callback will be wrapped in the `cause` of a {@link OnLoadError},
|
|
814
|
+
* However, this error is often wrapped inside the `cause` of the operation specific error such as {@link LoadError}.
|
|
815
|
+
*
|
|
816
|
+
* @note This callback is executed when a document is loaded anywhere inside the {@link Collection} class.
|
|
817
|
+
* Except for the special cases mentioned in the warnings sections.
|
|
818
|
+
*
|
|
819
|
+
* @warning This callback is not executed:
|
|
820
|
+
* - When a `Cursor` is returned in for instance {@link Collection.list} or {@link Collection.aggregate}.
|
|
821
|
+
* - Inside the {@link Collection.aggregate} method.
|
|
822
|
+
*/
|
|
823
|
+
on_load?: OnLoad<Data>;
|
|
824
|
+
derived_collection?: never;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* The type for the {@link Opts.on_transform_version} and {@link Collection.on_transform_version} callback.
|
|
828
|
+
* @note The input `data` may be an older document shape that does not match {@link Data}.
|
|
829
|
+
*
|
|
830
|
+
* @docs
|
|
831
|
+
*/
|
|
832
|
+
type OnTransformVersion<Data extends mongodb.Document> = <Projection extends Collection.LoadOpts.Projection>(data: Record<string, any>, opts: {
|
|
833
|
+
from_version: undefined | number;
|
|
834
|
+
to_version: number;
|
|
835
|
+
projection: Projection;
|
|
836
|
+
is_partial: Projection extends undefined ? false : true;
|
|
837
|
+
}) => WithProjection<Projection, Data> | Promise<WithProjection<Projection, Data>>;
|
|
838
|
+
/**
|
|
839
|
+
* The type for the {@link Opts.on_load} and {@link Collection.on_load_cb} callback
|
|
840
|
+
*
|
|
841
|
+
* @docs
|
|
842
|
+
*/
|
|
843
|
+
type OnLoad<Data extends mongodb.Document> = <Projection extends Collection.LoadOpts.Projection>(data: WithProjection<Projection, Data>, opts: {
|
|
844
|
+
projection: Projection;
|
|
845
|
+
is_partial: Projection extends undefined ? false : true;
|
|
846
|
+
}) => WithProjection<Projection, Data> | Promise<WithProjection<Projection, Data>>;
|
|
847
|
+
/**
|
|
848
|
+
* Index options for {@link Collection.create_index}.
|
|
849
|
+
*
|
|
850
|
+
* @docs
|
|
851
|
+
*/
|
|
852
|
+
type IndexOpts = {
|
|
853
|
+
/**
|
|
854
|
+
* Creates a unique index.
|
|
855
|
+
* When used with multiple fields, the combination of values must be unique.
|
|
856
|
+
* @warning An error will be thrown both when `unique` and `options.unique` are booleans with different values.
|
|
857
|
+
*/
|
|
858
|
+
unique?: boolean;
|
|
859
|
+
/** Creates a sparse index, so documents without the indexed field don’t bloat the index. */
|
|
860
|
+
sparse?: boolean;
|
|
861
|
+
/** When forced is enabled, the potentially existing index will be dropped and recreated later. */
|
|
862
|
+
forced?: boolean;
|
|
863
|
+
/** The options from {@link mongodb.CreateIndexesOptions} */
|
|
864
|
+
options?: {
|
|
865
|
+
name?: string;
|
|
866
|
+
expireAfterSeconds?: number;
|
|
867
|
+
partialFilterExpression?: mongodb.Document;
|
|
868
|
+
collation?: mongodb.CollationOptions;
|
|
869
|
+
};
|
|
870
|
+
} & ({
|
|
871
|
+
key: string;
|
|
872
|
+
keys?: never;
|
|
873
|
+
} | {
|
|
874
|
+
key?: never;
|
|
875
|
+
keys: string[] | Record<string, number>;
|
|
876
|
+
});
|
|
877
|
+
/**
|
|
878
|
+
* Query type for querying documents.
|
|
879
|
+
* @note Keep this as a simple alias for now in case we want to build in a
|
|
880
|
+
* `QueryByStrict<Data, Strict extends boolean>` like type to support strict and non strict.
|
|
881
|
+
*/
|
|
882
|
+
type Query<Data extends mongodb.Document> = StrictFilter<Data>;
|
|
883
|
+
/** Mini module for managing retry attempts. */
|
|
884
|
+
namespace Retry {
|
|
885
|
+
/**
|
|
886
|
+
* Retry options for database operations such as {@link Collection.save}.
|
|
887
|
+
*
|
|
888
|
+
* The operation is only retried for retryable errors.
|
|
889
|
+
*/
|
|
890
|
+
interface Opts {
|
|
891
|
+
/**
|
|
892
|
+
* The number of retry attempts, `1` means no retry but a single operation.
|
|
893
|
+
* Minimum value is `1` maximum is `100`,
|
|
894
|
+
* this value is automatically capped if exceeded.
|
|
895
|
+
*/
|
|
896
|
+
attempts: number;
|
|
897
|
+
/**
|
|
898
|
+
* The initial delay before the first retry attempt (in milliseconds).
|
|
899
|
+
* Defaults to `100`.
|
|
900
|
+
*/
|
|
901
|
+
initial_delay?: number;
|
|
902
|
+
/**
|
|
903
|
+
* The maximum delay between retry attempts (in milliseconds).
|
|
904
|
+
* Defaults to `1000`.
|
|
905
|
+
*/
|
|
906
|
+
max_delay?: number;
|
|
907
|
+
/**
|
|
908
|
+
* A backoff factor to apply to the delay between attempts.
|
|
909
|
+
* Defaults to `2`.
|
|
910
|
+
*/
|
|
911
|
+
backoff_factor?: number;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* The normalized retry options interface.
|
|
915
|
+
*/
|
|
916
|
+
interface Normalized extends Required<Opts> {
|
|
917
|
+
/** Jitter ratio in `[0, 1]` to randomize backoff. */
|
|
918
|
+
jitter_ratio: number;
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Get the number of attempts from a a retry type
|
|
922
|
+
* @returns 1 when undefined, or the specified number of attempts,
|
|
923
|
+
* with a minimum of 1 and maximum of 100.
|
|
924
|
+
*/
|
|
925
|
+
function get_attempts(retry: undefined | number | Opts): number;
|
|
926
|
+
/**
|
|
927
|
+
* Normalize retry options into a bounded, concrete shape.
|
|
928
|
+
*
|
|
929
|
+
* @param retry A retry attempts number or {@link Collection.Retry.Opts}.
|
|
930
|
+
* @returns A normalized retry configuration.
|
|
931
|
+
*/
|
|
932
|
+
function normalize(retry?: number | Opts): Normalized;
|
|
933
|
+
/**
|
|
934
|
+
* Compute a single backoff delay using exponential growth with bounded jitter.
|
|
935
|
+
*
|
|
936
|
+
* @param attempt_index Zero-based retry index (0 = first retry).
|
|
937
|
+
* @param initial_delay Initial delay for the *first* retry.
|
|
938
|
+
* @param backoff_factor Exponential factor.
|
|
939
|
+
* @param max_delay Maximum delay cap.
|
|
940
|
+
* @param jitter_ratio Additive jitter ratio in `[0, 1]`.
|
|
941
|
+
* @returns Milliseconds to wait before the next retry.
|
|
942
|
+
*/
|
|
943
|
+
function compute_backoff_delay(attempt_index: number, params: Normalized): number;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Wrap a (return) type as an error or as the return type based on a `Throw` generic.
|
|
947
|
+
* Generic `Throw` defaults to `true`, so `undefined` counts as `true`.
|
|
948
|
+
*
|
|
949
|
+
* @returns
|
|
950
|
+
* 1. When `Throw` is `true | undefined`, the returned type will be `NoThrowType`.
|
|
951
|
+
* 2. When `Throw` is `false` the returned type will be `NoThrowType | PossibleErrors`.
|
|
952
|
+
*
|
|
953
|
+
* @template Throw The throw generic, defaults to `true` if `undefined`.
|
|
954
|
+
* @template PossibleErrors The errors that are returned if `Throw` is `false`.
|
|
955
|
+
* @template NoThrowType The type when `Throw` is `false`.
|
|
956
|
+
*
|
|
957
|
+
* @docs
|
|
958
|
+
*/
|
|
959
|
+
type WithThrow<Throw extends boolean | undefined, PossibleErrors extends Error, NoThrowType> = Throw extends true | undefined ? NoThrowType : NoThrowType | PossibleErrors;
|
|
960
|
+
/**
|
|
961
|
+
* Options for {@link Collection.count} and {@link Collection.count_estimated}.
|
|
962
|
+
*
|
|
963
|
+
* @docs
|
|
964
|
+
*/
|
|
965
|
+
interface CountOpts<Throw extends CountOpts.Throw = undefined> {
|
|
966
|
+
/**
|
|
967
|
+
* When false, the operation will **not throw** on count-related failures.
|
|
968
|
+
* Instead, it will return a {@link Collection.CountError}.
|
|
969
|
+
* Defaults to `true`.
|
|
970
|
+
*/
|
|
971
|
+
throw?: Throw;
|
|
972
|
+
/**
|
|
973
|
+
* Optional bounded retry attempts for retryable errors (e.g., transient/network).
|
|
974
|
+
* Retries use exponential backoff. Defaults to `1` (no retry).
|
|
975
|
+
* For specific control use {@link Collection.Retry.Opts}.
|
|
976
|
+
*/
|
|
977
|
+
retry?: number | Collection.Retry.Opts;
|
|
978
|
+
/** Per-operation timeout in milliseconds, mapped to `maxTimeMS`. */
|
|
979
|
+
timeout?: number;
|
|
980
|
+
}
|
|
981
|
+
/** The nested types for {@link CountOpts}. */
|
|
982
|
+
namespace CountOpts {
|
|
983
|
+
/** The default value for the `Throw` template of {@link CountOpts}. */
|
|
984
|
+
type Throw = boolean | undefined;
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* The return type of {@link Collection.count} and {@link Collection.count_estimated}.
|
|
988
|
+
* @note `Error` is also a returned type since other errors might be thrown as well.
|
|
989
|
+
*
|
|
990
|
+
* @docs
|
|
991
|
+
*/
|
|
992
|
+
type CountResult<Throw extends CountOpts.Throw = undefined> = WithThrow<Throw, Collection.CountError | Error, number>;
|
|
993
|
+
/**
|
|
994
|
+
* The options for {@link Collection.list} and alike
|
|
995
|
+
*
|
|
996
|
+
* @docs
|
|
997
|
+
*/
|
|
998
|
+
interface ListOpts<Data extends ListOpts.Data = ListOpts.Data, Projection extends ListOpts.Projection = undefined, Throw extends ListOpts.Throw = undefined, Cursor extends ListOpts.Cursor = undefined, Callback extends Collection.ListOpts.Callback<Data, Projection> = undefined, PageInfo extends ListOpts.PageInfo = undefined> {
|
|
999
|
+
/**
|
|
1000
|
+
* The attributes to include (1) or exclude (0) from the document.
|
|
1001
|
+
* Mixing inclusion and exclusion patterns is not allowed, following mongodb rules.
|
|
1002
|
+
* @throws An error if inclusion and exclusion patterns are mixed.
|
|
1003
|
+
*/
|
|
1004
|
+
projection?: Projection;
|
|
1005
|
+
/**
|
|
1006
|
+
* Maximum number of documents to return (non-negative integer).
|
|
1007
|
+
* If omitted, all matching documents are streamed and returned.
|
|
1008
|
+
* Pagination is always enabled; only the batch size is configurable.
|
|
1009
|
+
*/
|
|
1010
|
+
limit?: number;
|
|
1011
|
+
/**
|
|
1012
|
+
* When false, the operation will **not throw** on list-related failures.
|
|
1013
|
+
* Instead, it will return a {@link Collection.ListError}.
|
|
1014
|
+
* Defaults to `true`.
|
|
1015
|
+
*/
|
|
1016
|
+
throw?: Throw;
|
|
1017
|
+
/**
|
|
1018
|
+
* Optional bounded retry attempts for retryable errors (e.g., transient/network).
|
|
1019
|
+
* Retries use exponential backoff. Defaults to `1` (no retry).
|
|
1020
|
+
* For specific control use {@link Retry.Opts}.
|
|
1021
|
+
*/
|
|
1022
|
+
retry?: number | Retry.Opts;
|
|
1023
|
+
/** Per-operation timeout in milliseconds, mapped to `maxTimeoutMS`. */
|
|
1024
|
+
timeout?: number;
|
|
1025
|
+
/** Set to sort the documents coming back from the query. Array of indexes, `[['a', 1]]` etc. */
|
|
1026
|
+
sort?: mongodb.Sort;
|
|
1027
|
+
/** Set to skip N documents ahead in your query (non-negative integer). */
|
|
1028
|
+
skip?: number;
|
|
1029
|
+
/**
|
|
1030
|
+
* Options for cursor-based pagination/streaming beyond any single-round-trip limit.
|
|
1031
|
+
* By default pagination is enabled.
|
|
1032
|
+
*/
|
|
1033
|
+
pagination?: {
|
|
1034
|
+
/**
|
|
1035
|
+
* The pagination batch size, must be a number
|
|
1036
|
+
* between `1` and `10000`, defaults to `1000`.
|
|
1037
|
+
*/
|
|
1038
|
+
batch_size?: number;
|
|
1039
|
+
};
|
|
1040
|
+
/**
|
|
1041
|
+
* Whether to return the find cursor or an array of found documents.
|
|
1042
|
+
* If `true` the find cursor is returned.
|
|
1043
|
+
* If `false | undefined` an array of documents is returned.
|
|
1044
|
+
* Defaults to `false`.
|
|
1045
|
+
*/
|
|
1046
|
+
cursor?: Callback extends undefined ? PageInfo extends undefined ? Cursor : never : never;
|
|
1047
|
+
/**
|
|
1048
|
+
* A per-document callback to process each document **as it streams in**.
|
|
1049
|
+
*
|
|
1050
|
+
* When defined (and `cursor !== true`), {@link Collection.list} will:
|
|
1051
|
+
* - Iterate the cursor, apply {@link Collection.Opts.on_transform_version} and {@link Collection.Opts.on_load},
|
|
1052
|
+
* then invoke this callback for **each** processed document,
|
|
1053
|
+
* - Respect `limit`, `skip`, `sort`, and `pagination.batch_size`,
|
|
1054
|
+
* - **Not** accumulate results in memory,
|
|
1055
|
+
* - Return `undefined` on success.
|
|
1056
|
+
*
|
|
1057
|
+
* @warning Mutually exclusive with `cursor:true` and `page_info:true`.
|
|
1058
|
+
*/
|
|
1059
|
+
callback?: Cursor extends false | undefined ? PageInfo extends undefined ? Callback : never : never;
|
|
1060
|
+
/** If true (and not returning a cursor), then the returned result is wrapped in a {@link ListedPage}. */
|
|
1061
|
+
page_info?: Cursor extends false | undefined ? Callback extends undefined ? PageInfo : never : never;
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* A per-document streaming callback for {@link Collection.list}.
|
|
1065
|
+
*
|
|
1066
|
+
* @docs
|
|
1067
|
+
*/
|
|
1068
|
+
type ListCallback<Data extends ListOpts.Data = ListOpts.Data, Projection extends ListOpts.Projection = undefined> = (
|
|
1069
|
+
/**
|
|
1070
|
+
* A single document from the result set.
|
|
1071
|
+
* Type: {@link WithProjection} of the collection's {@link Data} with {@link WithId}.
|
|
1072
|
+
*/
|
|
1073
|
+
doc: WithProjection<Projection, WithId<Data>>) => void | Promise<void>;
|
|
1074
|
+
/**
|
|
1075
|
+
* Nested types for the {@link ListOpts}
|
|
1076
|
+
*/
|
|
1077
|
+
namespace ListOpts {
|
|
1078
|
+
/** The default value for the `Data` template of {@link ListOpts} */
|
|
1079
|
+
type Data = mongodb.Document;
|
|
1080
|
+
/** The default value for the `Projection` template of {@link ListOpts} */
|
|
1081
|
+
type Projection = Collection.Projection | undefined;
|
|
1082
|
+
/** The default value for the `Throw` template of {@link ListOpts} */
|
|
1083
|
+
type Throw = boolean | undefined;
|
|
1084
|
+
/** The default value for the `Cursor` template of {@link ListOpts} */
|
|
1085
|
+
type Cursor = boolean | undefined;
|
|
1086
|
+
/** The default value for the `Callback` template of {@link ListOpts} */
|
|
1087
|
+
type Callback<D extends Data, P extends Projection> = ListCallback<D, P> | undefined;
|
|
1088
|
+
/** The default value for the `PageInfo` template of {@link ListOpts} */
|
|
1089
|
+
type PageInfo = boolean | undefined;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* The returned page information.
|
|
1093
|
+
*
|
|
1094
|
+
* @docs
|
|
1095
|
+
*/
|
|
1096
|
+
interface ListedPage<T> {
|
|
1097
|
+
/** The returned documents. */
|
|
1098
|
+
items: T[];
|
|
1099
|
+
/** Still has more documents. */
|
|
1100
|
+
has_more: boolean;
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* The return type of {@link Collection.list} and alike
|
|
1104
|
+
* @note `Error` is also a returned type since some other errors might be thrown as well.
|
|
1105
|
+
* @docs
|
|
1106
|
+
*/
|
|
1107
|
+
type ListResult<Data extends ListOpts.Data = ListOpts.Data, Projection extends ListOpts.Projection = undefined, Throw extends ListOpts.Throw = undefined, Cursor extends ListOpts.Cursor = undefined, Callback extends ListOpts.Callback<Data, Projection> = undefined, PageInfo extends ListOpts.PageInfo = undefined> = WithThrow<Throw, Collection.ListError | Error, (Cursor extends true ? mongodb.FindCursor<WithProjection<Projection, WithId<Data>>> : Callback extends ListCallback<Data, Projection> ? undefined : PageInfo extends true ? ListedPage<WithProjection<Projection, WithId<Data>>> : WithProjection<Projection, WithId<Data>>[])>;
|
|
1108
|
+
/**
|
|
1109
|
+
* The options for {@link Collection.exist}
|
|
1110
|
+
*
|
|
1111
|
+
* @docs
|
|
1112
|
+
*/
|
|
1113
|
+
interface ExistsOpts<Throw extends ExistsOpts.Throw = undefined> {
|
|
1114
|
+
/**
|
|
1115
|
+
* When false, the operation will **not throw** on exist-related failures.
|
|
1116
|
+
* Instead, it will return a {@link Collection.ExistsError}.
|
|
1117
|
+
* Defaults to `true`.
|
|
1118
|
+
*/
|
|
1119
|
+
throw?: Throw;
|
|
1120
|
+
/**
|
|
1121
|
+
* Optional bounded retry attempts for retryable errors (e.g., transient/network).
|
|
1122
|
+
* Retries use exponential backoff. Defaults to `1` (no retry).
|
|
1123
|
+
* For specific control use {@link Retry.Opts}.
|
|
1124
|
+
*/
|
|
1125
|
+
retry?: number | Retry.Opts;
|
|
1126
|
+
/** Per-operation timeout in milliseconds, mapped to `maxTimeoutMS`. */
|
|
1127
|
+
timeout?: number;
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Nested types for the {@link ExistsOpts}
|
|
1131
|
+
*/
|
|
1132
|
+
namespace ExistsOpts {
|
|
1133
|
+
/** The default value for the `Throw` template of {@link ExistsOpts} */
|
|
1134
|
+
type Throw = boolean | undefined;
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* The return type of {@link Collection.exists} and alike
|
|
1138
|
+
* @note `Error` is also a returned type since some other errors might be thrown as well.
|
|
1139
|
+
*
|
|
1140
|
+
* @docs
|
|
1141
|
+
*/
|
|
1142
|
+
type ExistsResult<Throw extends ExistsOpts.Throw = undefined> = WithThrow<Throw, ExistsError | Error, boolean>;
|
|
1143
|
+
/**
|
|
1144
|
+
* The options for {@link Collection.load}
|
|
1145
|
+
*
|
|
1146
|
+
* @docs
|
|
1147
|
+
*/
|
|
1148
|
+
interface LoadOpts<Data extends LoadOpts.Data = LoadOpts.Data, Default extends LoadOpts.Default<Data> = undefined, Projection extends LoadOpts.Projection = undefined, Throw extends LoadOpts.Throw = undefined> {
|
|
1149
|
+
/**
|
|
1150
|
+
* The default data to be returned when the data does not exist.
|
|
1151
|
+
*
|
|
1152
|
+
* Keys that do not exist in the loaded object, but do exist in the default object
|
|
1153
|
+
* will automatically be inserted upon loading.
|
|
1154
|
+
*
|
|
1155
|
+
* The object will automatically be deep-cloned if used as default or for insertion.
|
|
1156
|
+
*
|
|
1157
|
+
* @note This does not save the default data when the document does not exist, its merely used for the returned value.
|
|
1158
|
+
*/
|
|
1159
|
+
default?: Default;
|
|
1160
|
+
/**
|
|
1161
|
+
* The attributes to include (1) or exclude (0) from the document.
|
|
1162
|
+
* Mixing inclusion and exclusion patterns is not allowed, following mongodb rules.
|
|
1163
|
+
* @throws An error if inclusion and exclusion patterns are mixed.
|
|
1164
|
+
*/
|
|
1165
|
+
projection?: Projection;
|
|
1166
|
+
/**
|
|
1167
|
+
* When false, the operation will **not throw** on load-related failures.
|
|
1168
|
+
* Instead, it will return a {@link Collection.LoadError}.
|
|
1169
|
+
* Defaults to `true`.
|
|
1170
|
+
*/
|
|
1171
|
+
throw?: Throw;
|
|
1172
|
+
/**
|
|
1173
|
+
* Optional bounded retry attempts for retryable errors (e.g., transient/network).
|
|
1174
|
+
* Retries use exponential backoff. Defaults to `1` (no retry).
|
|
1175
|
+
* For specific control use {@link Retry.Opts}.
|
|
1176
|
+
*/
|
|
1177
|
+
retry?: number | Retry.Opts;
|
|
1178
|
+
/** Per-operation timeout in milliseconds, mapped to `maxTimeoutMS`. */
|
|
1179
|
+
timeout?: number;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Nested types for the {@link LoadOpts} interface.
|
|
1183
|
+
*/
|
|
1184
|
+
namespace LoadOpts {
|
|
1185
|
+
/** The default value for the `Data` template of {@link LoadOpts} */
|
|
1186
|
+
type Data = mongodb.Document;
|
|
1187
|
+
/** The default value for the `Default` template of {@link LoadOpts} */
|
|
1188
|
+
type Default<Data extends mongodb.Document> = Data | (() => Data) | undefined;
|
|
1189
|
+
/** The default value for the `Projection` template of {@link LoadOpts} */
|
|
1190
|
+
type Projection = Collection.Projection | undefined;
|
|
1191
|
+
/** The default value for the `Throw` template of {@link LoadOpts} */
|
|
1192
|
+
type Throw = boolean | undefined;
|
|
1193
|
+
}
|
|
1194
|
+
/** Helper type to return type unpack the default value type. */
|
|
1195
|
+
type UnpackedDefault<Data extends LoadOpts.Data, Default extends LoadOpts.Default<Data>> = Default extends () => infer R ? R : Default;
|
|
1196
|
+
/**
|
|
1197
|
+
* The return type of {@link Collection.load}
|
|
1198
|
+
* @note `Error` is also a returned type since some other errors might be thrown as well.
|
|
1199
|
+
*
|
|
1200
|
+
* @docs
|
|
1201
|
+
*/
|
|
1202
|
+
type LoadResult<Data extends LoadOpts.Data = LoadOpts.Data, Default extends LoadOpts.Default<Data> = undefined, Projection extends LoadOpts.Projection = undefined, Throw extends LoadOpts.Throw = undefined> = Default extends undefined ? WithThrow<Throw, Collection.NotFoundError | Collection.LoadError | Error, WithProjection<Projection, WithId<Data>>> : WithThrow<Throw, Collection.LoadError | Error, WithProjection<Projection, WithId<Data>> | WithId<UnpackedDefault<Data, Default>>>;
|
|
1203
|
+
/**
|
|
1204
|
+
* Options for the save operation.
|
|
1205
|
+
*
|
|
1206
|
+
* @property bulk If `true`, returns an unexecuted bulk operation object.
|
|
1207
|
+
* @property return If `true` (and not bulk), return the **updated** document.
|
|
1208
|
+
* @property throw When `false`, the operation will **not throw** on write-related failures.
|
|
1209
|
+
* Instead, it will return a {@link Collection.SaveError}.
|
|
1210
|
+
* Defaults to `true`.
|
|
1211
|
+
* @property upsert When true/undefined, the document will be created if it does not exist (default: true).
|
|
1212
|
+
* When `false`, no upsert is performed.
|
|
1213
|
+
* @property retry Optional bounded retry attempts for retryable errors (e.g., transient/network).
|
|
1214
|
+
* Retries use exponential backoff. Defaults to `1` (no retry).
|
|
1215
|
+
* For specific control use {@link Retry.Opts}.
|
|
1216
|
+
* @property timeout Per-operation timeout in milliseconds, mapped to `maxTimeoutMS`.
|
|
1217
|
+
* @property apply_ttl If `false` the TTL index will not be applied to the operation.
|
|
1218
|
+
* This behaviour only takes effect if the collection has TTL settings enabled.
|
|
1219
|
+
* Defaults to `true`.
|
|
1220
|
+
*
|
|
1221
|
+
* @docs
|
|
1222
|
+
*/
|
|
1223
|
+
type SaveOpts<Bulk extends SaveOpts.Bulk = undefined, Return extends SaveOpts.Return = undefined, Throw extends SaveOpts.Throw = undefined, Upsert extends SaveOpts.Upsert = undefined> = Bulk extends true ? {
|
|
1224
|
+
bulk: Bulk;
|
|
1225
|
+
return?: never;
|
|
1226
|
+
throw?: never;
|
|
1227
|
+
upsert?: Upsert;
|
|
1228
|
+
retry?: never;
|
|
1229
|
+
timeout?: never;
|
|
1230
|
+
apply_ttl?: never;
|
|
1231
|
+
} : Return extends true ? Upsert extends false ? {
|
|
1232
|
+
bulk?: false;
|
|
1233
|
+
return: Return;
|
|
1234
|
+
throw?: Throw;
|
|
1235
|
+
upsert: Upsert;
|
|
1236
|
+
retry?: number | Retry.Opts;
|
|
1237
|
+
timeout?: number;
|
|
1238
|
+
apply_ttl?: boolean;
|
|
1239
|
+
} : {
|
|
1240
|
+
bulk?: false;
|
|
1241
|
+
return: Return;
|
|
1242
|
+
throw?: Throw;
|
|
1243
|
+
upsert?: Upsert;
|
|
1244
|
+
retry?: number | Retry.Opts;
|
|
1245
|
+
timeout?: number;
|
|
1246
|
+
apply_ttl?: boolean;
|
|
1247
|
+
} : {
|
|
1248
|
+
bulk?: false;
|
|
1249
|
+
return?: false;
|
|
1250
|
+
throw?: Throw;
|
|
1251
|
+
upsert?: Upsert;
|
|
1252
|
+
retry?: number | Retry.Opts;
|
|
1253
|
+
timeout?: number;
|
|
1254
|
+
apply_ttl?: boolean;
|
|
1255
|
+
};
|
|
1256
|
+
/** Nested types for the {@link LoadOpts} interface. */
|
|
1257
|
+
namespace SaveOpts {
|
|
1258
|
+
/** The default value for the `Data` template of {@link SaveOpts} */
|
|
1259
|
+
type Data = mongodb.Document;
|
|
1260
|
+
/** The default value for the `Bulk` template of {@link SaveOpts} */
|
|
1261
|
+
type Bulk = boolean | undefined;
|
|
1262
|
+
/** The default value for the `Return` template of {@link SaveOpts} */
|
|
1263
|
+
type Return = boolean | undefined;
|
|
1264
|
+
/** The default value for the `Throw` template of {@link SaveOpts} */
|
|
1265
|
+
type Throw = boolean | undefined;
|
|
1266
|
+
/** The default value for the `Upsert` template of {@link SaveOpts} */
|
|
1267
|
+
type Upsert = boolean | undefined;
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* The return type of {@link Collection.save}.
|
|
1271
|
+
* @note `Error` is also a returned type since some other errors might be thrown as well.
|
|
1272
|
+
*
|
|
1273
|
+
* @docs
|
|
1274
|
+
*/
|
|
1275
|
+
type SaveResult<Data extends SaveOpts.Data = SaveOpts.Data, Bulk extends SaveOpts.Bulk = undefined, Return extends SaveOpts.Return = undefined, Throw extends SaveOpts.Throw = undefined> = Bulk extends true ? mongodb.AnyBulkWriteOperation<Data> : Return extends true ? WithThrow<Throw, Collection.SaveError | Error, WithId<Data>> : WithThrow<Throw, Collection.SaveError | Error, mongodb.UpdateResult<Data>>;
|
|
1276
|
+
/**
|
|
1277
|
+
* The options (third arg) for {@link Collection.set}
|
|
1278
|
+
*
|
|
1279
|
+
* @docs
|
|
1280
|
+
*/
|
|
1281
|
+
type SetOpts<Bulk extends SetOpts.Bulk = undefined, Return extends SetOpts.Return = undefined, Throw extends SetOpts.Throw = undefined, Upsert extends SetOpts.Upsert = undefined> = SaveOpts<Bulk, Return, Throw, Upsert> & {
|
|
1282
|
+
/** If true, the operation will flatten the input data to a dot nested notation. */
|
|
1283
|
+
flatten?: boolean;
|
|
1284
|
+
};
|
|
1285
|
+
/** Nested types for the {@link SetOpts} interface. */
|
|
1286
|
+
namespace SetOpts {
|
|
1287
|
+
/** The default value for the `Data` template of {@link SetOpts} */
|
|
1288
|
+
type Data = mongodb.Document;
|
|
1289
|
+
/** The default value for the `Bulk` template of {@link SetOpts} */
|
|
1290
|
+
type Bulk = boolean | undefined;
|
|
1291
|
+
/** The default value for the `Return` template of {@link SetOpts} */
|
|
1292
|
+
type Return = boolean | undefined;
|
|
1293
|
+
/** The default value for the `Throw` template of {@link SetOpts} */
|
|
1294
|
+
type Throw = boolean | undefined;
|
|
1295
|
+
/** The default value for the `Upsert` template of {@link SetOpts} */
|
|
1296
|
+
type Upsert = boolean | undefined;
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* The return type of {@link Collection.set}.
|
|
1300
|
+
*
|
|
1301
|
+
* @docs
|
|
1302
|
+
*/
|
|
1303
|
+
type SetResult<Data extends mongodb.Document = mongodb.Document, Bulk extends SetOpts.Bulk = undefined, Return extends SetOpts.Return = undefined, Throw extends SetOpts.Throw = undefined> = SaveResult<Data, Bulk, Return, Throw>;
|
|
1304
|
+
/**
|
|
1305
|
+
* The additional return options for {@link SaveManyOpts.return}
|
|
1306
|
+
*
|
|
1307
|
+
* @docs
|
|
1308
|
+
*/
|
|
1309
|
+
type SaveManyReturnOpts = Omit<ListOpts, "throw" | "retry" | "timeout" | "cursor" | "page_info" | "callback">;
|
|
1310
|
+
/**
|
|
1311
|
+
* Options for the {@link Collection.save_many} operation.
|
|
1312
|
+
* @docs
|
|
1313
|
+
*/
|
|
1314
|
+
interface SaveManyOpts<Bulk extends boolean | undefined = undefined, Return extends boolean | undefined | SaveManyReturnOpts = undefined, Throw extends boolean | undefined = undefined, Upsert extends boolean | undefined = undefined> {
|
|
1315
|
+
/** If true, returns an unexecuted bulk operation object (`{ updateMany: ... }`). */
|
|
1316
|
+
bulk?: Bulk extends true ? Bulk : never;
|
|
1317
|
+
/**
|
|
1318
|
+
* When truthy, return the matched/updated documents by running a follow-up {@link list} with the same `query`.
|
|
1319
|
+
* You can pass `true` (no extra options), or an options object to control the follow-up read.
|
|
1320
|
+
* @warning This is **less efficient** than {@link save} with `return:true`,
|
|
1321
|
+
* because it requires an additional read after the write.
|
|
1322
|
+
*/
|
|
1323
|
+
return?: Bulk extends true ? never : (Return);
|
|
1324
|
+
/**
|
|
1325
|
+
* When false, the operation will **not throw** on write-related failures.
|
|
1326
|
+
* Instead it will return a {@link Collection.SaveError}. Defaults to `true`.
|
|
1327
|
+
*/
|
|
1328
|
+
throw?: Bulk extends true ? never : (Throw);
|
|
1329
|
+
/**
|
|
1330
|
+
* When true, perform an upsert if no documents match the filter.
|
|
1331
|
+
* Defaults to `false` (unlike {@link save}, which defaults to `true`).
|
|
1332
|
+
*/
|
|
1333
|
+
upsert?: Bulk extends true ? never : (Upsert);
|
|
1334
|
+
/**
|
|
1335
|
+
* Optional bounded retry attempts for retryable errors (e.g., transient/network) on the **write** operation.
|
|
1336
|
+
* Retries use exponential backoff. Defaults to `1` (no retry).
|
|
1337
|
+
* For specific control use {@link Retry.Opts}.
|
|
1338
|
+
*/
|
|
1339
|
+
retry?: Bulk extends true ? never : (number | Retry.Opts);
|
|
1340
|
+
/** Per-operation timeout in milliseconds for the **write** call, mapped to `maxTimeMS`. */
|
|
1341
|
+
timeout?: Bulk extends true ? never : (number);
|
|
1342
|
+
/**
|
|
1343
|
+
* If `false` the TTL index will not be applied to the operation.
|
|
1344
|
+
* This behaviour only takes effect if the collection has TTL settings enabled.
|
|
1345
|
+
* Defaults to `true`.
|
|
1346
|
+
*/
|
|
1347
|
+
apply_ttl?: boolean;
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* The return type of {@link Collection.save_many}.
|
|
1351
|
+
* @docs
|
|
1352
|
+
*/
|
|
1353
|
+
type SaveManyResult<Data extends mongodb.Document = mongodb.Document, Bulk extends boolean | undefined = undefined, Return extends boolean | SaveManyReturnOpts | undefined = undefined, Throw extends boolean | undefined = undefined> = Bulk extends true ? mongodb.AnyBulkWriteOperation<Data> : (Return extends false | undefined ? WithThrow<Throw, Collection.SaveError | Error, mongodb.UpdateResult<Data>> : WithThrow<Throw, Collection.SaveError | Collection.ListError | Error, WithProjection<ExtractProjection<Return>, WithId<Data>>[]>);
|
|
1354
|
+
/**
|
|
1355
|
+
* The options (third arg) for {@link Collection.replace}
|
|
1356
|
+
* @docs
|
|
1357
|
+
*/
|
|
1358
|
+
type ReplaceOpts<Bulk extends boolean | undefined = undefined, Return extends boolean | undefined = undefined, Throw extends boolean | undefined = undefined, Upsert extends boolean | undefined = undefined> = SaveOpts<Bulk, Return, Throw, Upsert>;
|
|
1359
|
+
/**
|
|
1360
|
+
* The return type of {@link Collection.replace}.
|
|
1361
|
+
* @docs
|
|
1362
|
+
*/
|
|
1363
|
+
type ReplaceResult<Data extends mongodb.Document = mongodb.Document, Bulk extends boolean | undefined = undefined, Return extends boolean | undefined = undefined, Throw extends boolean | undefined = undefined> = SaveResult<Data, Bulk, Return, Throw>;
|
|
1364
|
+
/**
|
|
1365
|
+
* The options for {@link Collection.replace_many}
|
|
1366
|
+
* @docs
|
|
1367
|
+
*/
|
|
1368
|
+
type ReplaceManyOpts<Bulk extends boolean | undefined = undefined, Return extends boolean | undefined | SaveManyReturnOpts = undefined, Throw extends boolean | undefined = undefined, Upsert extends boolean | undefined = undefined> = SaveManyOpts<Bulk, Return, Throw, Upsert>;
|
|
1369
|
+
/**
|
|
1370
|
+
* The return type of {@link Collection.replace_many}
|
|
1371
|
+
* @docs
|
|
1372
|
+
*/
|
|
1373
|
+
type ReplaceManyResult<Data extends mongodb.Document = mongodb.Document, Bulk extends boolean | undefined = undefined, Return extends boolean | SaveManyReturnOpts | undefined = undefined, Throw extends boolean | undefined = undefined> = SaveManyResult<Data, Bulk, Return, Throw>;
|
|
1374
|
+
/**
|
|
1375
|
+
* The options for {@link Collection.delete}
|
|
1376
|
+
* @docs
|
|
1377
|
+
*/
|
|
1378
|
+
interface DeleteOpts<Bulk extends boolean | undefined = undefined, Throw extends boolean | undefined = undefined> {
|
|
1379
|
+
/** If true, the operation will return a non executed bulk operation object. */
|
|
1380
|
+
bulk?: Bulk;
|
|
1381
|
+
/**
|
|
1382
|
+
* Optional bounded retry attempts for retryable errors (e.g., transient/network).
|
|
1383
|
+
* Retries use exponential backoff. Defaults to `1` (no retry).
|
|
1384
|
+
* For specific control use {@link Retry.Opts}.
|
|
1385
|
+
*/
|
|
1386
|
+
retry?: number | Retry.Opts;
|
|
1387
|
+
/**
|
|
1388
|
+
* When false, the operation will **not throw** on delete-related failures.
|
|
1389
|
+
* Instead, it will return a {@link Collection.DeleteError}.
|
|
1390
|
+
* Defaults to `true`.
|
|
1391
|
+
*/
|
|
1392
|
+
throw?: Throw;
|
|
1393
|
+
/** Per-operation timeout in milliseconds, mapped to `maxTimeoutMS`. */
|
|
1394
|
+
timeout?: number;
|
|
1395
|
+
}
|
|
1396
|
+
/**
|
|
1397
|
+
* The return type of {@link Collection.delete}
|
|
1398
|
+
* @docs
|
|
1399
|
+
*/
|
|
1400
|
+
type DeleteResult<Data extends mongodb.Document = mongodb.Document, Bulk extends boolean | undefined = undefined, Throw extends boolean | undefined = undefined> = Bulk extends true ? mongodb.AnyBulkWriteOperation<Data> : WithThrow<Throw, DeleteError | Error, mongodb.DeleteResult>;
|
|
1401
|
+
/**
|
|
1402
|
+
* The options for {@link Collection.delete_collection}
|
|
1403
|
+
* @docs
|
|
1404
|
+
*/
|
|
1405
|
+
type DeleteCollectionOpts<Throw extends boolean | undefined = undefined> = Pick<DeleteOpts<false, Throw>, "retry" | "throw" | "timeout">;
|
|
1406
|
+
/**
|
|
1407
|
+
* The return type of {@link Collection.delete_collection}
|
|
1408
|
+
* @docs
|
|
1409
|
+
*/
|
|
1410
|
+
type DeleteCollectionResult<Throw extends boolean | undefined = undefined> = WithThrow<Throw, DeleteError | Error, undefined>;
|
|
1411
|
+
/**
|
|
1412
|
+
* The options for {@link Collection.bulk_operations}
|
|
1413
|
+
* @docs
|
|
1414
|
+
*/
|
|
1415
|
+
interface BulkOpts<Throw extends boolean | undefined = undefined> {
|
|
1416
|
+
/**
|
|
1417
|
+
* Optional bounded retry attempts for retryable errors (e.g., transient/network).
|
|
1418
|
+
* Retries use exponential backoff. Defaults to `1` (no retry).
|
|
1419
|
+
* For specific control use {@link Retry.Opts}.
|
|
1420
|
+
*/
|
|
1421
|
+
retry?: number | Collection.Retry.Opts;
|
|
1422
|
+
/**
|
|
1423
|
+
* When false, the operation will **not throw** on bulk-related failures.
|
|
1424
|
+
* Instead, it will return a {@link Collection.BulkError}.
|
|
1425
|
+
* Defaults to `true`.
|
|
1426
|
+
*/
|
|
1427
|
+
throw?: Throw;
|
|
1428
|
+
/** Per-operation timeout in milliseconds, mapped to `maxTimeoutMS`. */
|
|
1429
|
+
timeout?: number;
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* The return type of {@link Collection.bulk_operations}
|
|
1433
|
+
* @docs
|
|
1434
|
+
*/
|
|
1435
|
+
type BulkResult<Throw extends boolean | undefined = undefined> = WithThrow<Throw, BulkError | Error, mongodb.BulkWriteResult>;
|
|
1436
|
+
/**
|
|
1437
|
+
* The options for {@link Collection.aggregate}
|
|
1438
|
+
* @docs
|
|
1439
|
+
*/
|
|
1440
|
+
interface AggregateOpts<Throw extends boolean | undefined = undefined, Cursor extends boolean | undefined = undefined> {
|
|
1441
|
+
/**
|
|
1442
|
+
* Optional bounded retry attempts for retryable errors (e.g., transient/network).
|
|
1443
|
+
* Retries use exponential backoff. Defaults to `1` (no retry).
|
|
1444
|
+
* For specific control use {@link Retry.Opts}.
|
|
1445
|
+
*/
|
|
1446
|
+
retry?: number | Collection.Retry.Opts;
|
|
1447
|
+
/**
|
|
1448
|
+
* When false, the operation will **not throw** on aggregation-related failures.
|
|
1449
|
+
* Instead, it will return a {@link Collection.AggregateError}.
|
|
1450
|
+
* Defaults to `true`.
|
|
1451
|
+
*/
|
|
1452
|
+
throw?: Throw;
|
|
1453
|
+
/**
|
|
1454
|
+
* Whether to return the find cursor or an array of documents.
|
|
1455
|
+
* If `true` the aggregation cursor is returned.
|
|
1456
|
+
* If `false | undefined` an array of documents is returned.
|
|
1457
|
+
* Defaults to `false`.
|
|
1458
|
+
*/
|
|
1459
|
+
cursor?: Cursor;
|
|
1460
|
+
/** Per-operation timeout in milliseconds, mapped to `maxTimeoutMS`. */
|
|
1461
|
+
timeout?: number;
|
|
1462
|
+
}
|
|
1463
|
+
/**
|
|
1464
|
+
* The return type of {@link Collection.aggregate}
|
|
1465
|
+
* @docs
|
|
1466
|
+
*/
|
|
1467
|
+
type AggregateResult<Data extends mongodb.Document = mongodb.Document, Throw extends boolean | undefined = undefined, Cursor extends boolean | undefined = undefined> = WithThrow<Throw, AggregateError | Error, (Cursor extends true ? mongodb.AggregationCursor<Data> : Data[])>;
|
|
1468
|
+
/**
|
|
1469
|
+
* The base error for {@link NotFoundError}, {@link DeleteError} etc.
|
|
1470
|
+
*/
|
|
1471
|
+
class OperationError extends Error implements OperationError.Opts {
|
|
1472
|
+
/** The error message. */
|
|
1473
|
+
message: string;
|
|
1474
|
+
query: Record<string, any> | Record<string, any>[];
|
|
1475
|
+
reason?: string;
|
|
1476
|
+
/** An optional error that caused this error. */
|
|
1477
|
+
cause?: unknown;
|
|
1478
|
+
/** Construct a not found error. */
|
|
1479
|
+
constructor(opts: OperationError.Opts);
|
|
1480
|
+
}
|
|
1481
|
+
/** The nested types for {@link BaseError} */
|
|
1482
|
+
namespace OperationError {
|
|
1483
|
+
/** The constructor options for {@link BaseError} */
|
|
1484
|
+
interface Opts {
|
|
1485
|
+
/** The new error message. */
|
|
1486
|
+
message: string;
|
|
1487
|
+
/**
|
|
1488
|
+
* The document query.
|
|
1489
|
+
* May be an empty query, for instance when deleting all
|
|
1490
|
+
* documents in the collection, or for other reasons.
|
|
1491
|
+
*/
|
|
1492
|
+
query: Record<string, any> | Record<string, any>[];
|
|
1493
|
+
/**
|
|
1494
|
+
* The reason code for the invalid usage error, e.g. `bad_ttl`
|
|
1495
|
+
* or `invalid_filter`.
|
|
1496
|
+
*
|
|
1497
|
+
* Could be used to detect specific issues with the request,
|
|
1498
|
+
*/
|
|
1499
|
+
reason?: string;
|
|
1500
|
+
/** An optional error that caused this error. */
|
|
1501
|
+
cause?: unknown;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* Error thrown when a document is not found.
|
|
1506
|
+
* This error extends the {@link OperationError} which in turn extends the default {@link Error} class.
|
|
1507
|
+
* @docs
|
|
1508
|
+
*/
|
|
1509
|
+
class NotFoundError extends OperationError {
|
|
1510
|
+
/**
|
|
1511
|
+
* Constructor method.
|
|
1512
|
+
* @param opts The error options, see {@link OperationError.Opts}.
|
|
1513
|
+
*/
|
|
1514
|
+
constructor(opts: OperationError.Opts);
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Error thrown when a {@link Collection.Opts.on_transform_version} callback fails.
|
|
1518
|
+
* This error extends the {@link OperationError} which in turn extends the default {@link Error} class.
|
|
1519
|
+
* @docs
|
|
1520
|
+
*/
|
|
1521
|
+
class OnTransformError extends OperationError {
|
|
1522
|
+
/**
|
|
1523
|
+
* Constructor method.
|
|
1524
|
+
* @param opts The error options, see {@link OperationError.Opts}.
|
|
1525
|
+
*/
|
|
1526
|
+
constructor(opts: OperationError.Opts);
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Error thrown when a {@link Collection.Opts.on_load} callback fails.
|
|
1530
|
+
* This error extends the {@link OperationError} which in turn extends the default {@link Error} class.
|
|
1531
|
+
* @docs
|
|
1532
|
+
*/
|
|
1533
|
+
class OnLoadError extends OperationError {
|
|
1534
|
+
/**
|
|
1535
|
+
* Constructor method.
|
|
1536
|
+
* @param opts The error options, see {@link OperationError.Opts}.
|
|
1537
|
+
*/
|
|
1538
|
+
constructor(opts: OperationError.Opts);
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Error thrown when a count operation fails.
|
|
1542
|
+
* This error extends {@link OperationError} which in turn extends the default {@link Error} class.
|
|
1543
|
+
* @docs
|
|
1544
|
+
*/
|
|
1545
|
+
class CountError extends OperationError {
|
|
1546
|
+
/**
|
|
1547
|
+
* Construct a {@link CountError}.
|
|
1548
|
+
* @param opts The error options, see {@link OperationError.Opts}.
|
|
1549
|
+
*/
|
|
1550
|
+
constructor(opts: OperationError.Opts);
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Error thrown when a list operation fails.
|
|
1554
|
+
* This error extends the {@link OperationError} which in turn extends the default {@link Error} class.
|
|
1555
|
+
* @docs
|
|
1556
|
+
*/
|
|
1557
|
+
class ListError extends OperationError {
|
|
1558
|
+
/**
|
|
1559
|
+
* Constructor method.
|
|
1560
|
+
* @param opts The error options, see {@link OperationError.Opts}.
|
|
1561
|
+
*/
|
|
1562
|
+
constructor(opts: OperationError.Opts);
|
|
1563
|
+
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Error thrown when a load operation fails.
|
|
1566
|
+
* This error extends the {@link OperationError} which in turn extends the default {@link Error} class.
|
|
1567
|
+
* @docs
|
|
1568
|
+
*/
|
|
1569
|
+
class ExistsError extends OperationError {
|
|
1570
|
+
/**
|
|
1571
|
+
* Constructor method.
|
|
1572
|
+
* @param opts The error options, see {@link OperationError.Opts}.
|
|
1573
|
+
*/
|
|
1574
|
+
constructor(opts: OperationError.Opts);
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Error thrown when a load operation fails.
|
|
1578
|
+
* This error extends the {@link OperationError} which in turn extends the default {@link Error} class.
|
|
1579
|
+
* @docs
|
|
1580
|
+
*/
|
|
1581
|
+
class LoadError extends OperationError {
|
|
1582
|
+
/**
|
|
1583
|
+
* Constructor method.
|
|
1584
|
+
* @param opts The error options, see {@link OperationError.Opts}.
|
|
1585
|
+
*/
|
|
1586
|
+
constructor(opts: OperationError.Opts);
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Error thrown when a save operation fails.
|
|
1590
|
+
* This error extends the {@link OperationError} which in turn extends the default {@link Error} class.
|
|
1591
|
+
* @docs
|
|
1592
|
+
*/
|
|
1593
|
+
class SaveError extends OperationError {
|
|
1594
|
+
/**
|
|
1595
|
+
* Constructor method.
|
|
1596
|
+
* @param opts The error options, see {@link OperationError.Opts}.
|
|
1597
|
+
*/
|
|
1598
|
+
constructor(opts: OperationError.Opts);
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Error thrown when a delete operation fails.
|
|
1602
|
+
* This error extends the {@link OperationError} which in turn extends the default {@link Error} class.
|
|
1603
|
+
* @docs
|
|
1604
|
+
*/
|
|
1605
|
+
class DeleteError extends OperationError {
|
|
1606
|
+
/**
|
|
1607
|
+
* Constructor method.
|
|
1608
|
+
* @param opts The error options, see {@link OperationError.Opts}.
|
|
1609
|
+
*/
|
|
1610
|
+
constructor(opts: OperationError.Opts);
|
|
1611
|
+
}
|
|
1612
|
+
/**
|
|
1613
|
+
* Error thrown when a bulk operation fails.
|
|
1614
|
+
* This error extends the {@link OperationError} which in turn extends the default {@link Error} class.
|
|
1615
|
+
* @docs
|
|
1616
|
+
*/
|
|
1617
|
+
class BulkError extends OperationError {
|
|
1618
|
+
/**
|
|
1619
|
+
* Constructor method.
|
|
1620
|
+
* @param opts The error options, see {@link OperationError.Opts}.
|
|
1621
|
+
*/
|
|
1622
|
+
constructor(opts: OperationError.Opts);
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* Error thrown when an aggregate operation fails.
|
|
1626
|
+
* This error extends the {@link OperationError} which in turn extends the default {@link Error} class.
|
|
1627
|
+
* @docs
|
|
1628
|
+
*/
|
|
1629
|
+
class AggregateError extends OperationError {
|
|
1630
|
+
/**
|
|
1631
|
+
* Constructor method.
|
|
1632
|
+
* @param opts The error options, see {@link OperationError.Opts}.
|
|
1633
|
+
*/
|
|
1634
|
+
constructor(opts: OperationError.Opts);
|
|
1635
|
+
}
|
|
1636
|
+
/**
|
|
1637
|
+
* The attributes to include (1) or exclude (0) from the loaded document in a database query.
|
|
1638
|
+
* Mixing inclusion and exclusion patterns is not allowed, following mongodb rules.
|
|
1639
|
+
*/
|
|
1640
|
+
type Projection = readonly string[] | Record<string, number | boolean>;
|
|
1641
|
+
/** The nested types for the {@link Projection} type. */
|
|
1642
|
+
namespace Projection {
|
|
1643
|
+
/**
|
|
1644
|
+
* Convert a projection query into a MongoDB-compatible format.
|
|
1645
|
+
* @throws An error if both inclusion (1) and exclusion (0) patterns are found,
|
|
1646
|
+
* since this is not allowed by mongodb.
|
|
1647
|
+
*/
|
|
1648
|
+
function init(projection: Projection): Record<string, number | boolean>;
|
|
1649
|
+
type IncludeKeys<P> = P extends readonly (infer K)[] ? Extract<K, string> : P extends Record<string, 0 | 1 | boolean> ? {
|
|
1650
|
+
[K in keyof P]: P[K] extends 1 | true ? (K & string) : never;
|
|
1651
|
+
}[keyof P] : never;
|
|
1652
|
+
type ExcludeKeys<P> = P extends Record<string, 0 | 1 | boolean> ? {
|
|
1653
|
+
[K in keyof P]: P[K] extends 0 | false ? (K & string) : never;
|
|
1654
|
+
}[keyof P] : never;
|
|
1655
|
+
/**
|
|
1656
|
+
* Determines which keys from `Data` are included after applying projection `P`.
|
|
1657
|
+
*
|
|
1658
|
+
* - Empty `[]` or `{}` → all keys (no projection)
|
|
1659
|
+
* - Array `["field1", ...]` → specified fields + "_id"
|
|
1660
|
+
* - Inclusion `{field1: 1}` → specified fields + "_id" (unless `{_id: 0}`)
|
|
1661
|
+
* - Exclusion `{field1: 0}` → all keys except excluded ones
|
|
1662
|
+
*/
|
|
1663
|
+
type IncludedKeysFor<Data extends mongodb.Document, P> = P extends readonly [] ? keyof WithId<Data> : P extends readonly any[] ? ("_id" | (IncludeKeys<P> & keyof WithId<Data>)) : ([
|
|
1664
|
+
keyof P
|
|
1665
|
+
] extends [never] ? keyof WithId<Data> : P extends Record<string, 0 | 1 | boolean> ? (IncludeKeys<P> extends never ? Exclude<keyof WithId<Data>, ExcludeKeys<P>> : ((IncludeKeys<P> & keyof WithId<Data>) | (P extends {
|
|
1666
|
+
_id: 0 | false;
|
|
1667
|
+
} ? never : "_id"))) : keyof WithId<Data>);
|
|
1668
|
+
}
|
|
1669
|
+
/**
|
|
1670
|
+
* Projected document.
|
|
1671
|
+
* The projected fields are included as is, and the non included fields
|
|
1672
|
+
* are included as optional, since {@link LoadOpts.default} may add them.
|
|
1673
|
+
* @docs
|
|
1674
|
+
*/
|
|
1675
|
+
type Projected<Projection extends Collection.Projection, Data extends mongodb.Document> = Projection extends readonly [] ? WithId<Data> : [
|
|
1676
|
+
keyof Projection
|
|
1677
|
+
] extends [never] ? WithId<Data> : Partial<Omit<WithId<Data>, Projection.IncludedKeysFor<Data, Projection>>> & Pick<WithId<Data>, Extract<Projection.IncludedKeysFor<Data, Projection>, keyof WithId<Data>>>;
|
|
1678
|
+
/**
|
|
1679
|
+
* Wrap a (return) type as a projected document or as a document type based on a `Projection` generic.
|
|
1680
|
+
* Generic `Projection` defaults to `undefined`, so `undefined` returns a non projected document.
|
|
1681
|
+
*
|
|
1682
|
+
* @returns
|
|
1683
|
+
* 1. When `Projection` is `Collection.Projection`, the returned type will be `ProjectedDocument<Data, Projection>`.
|
|
1684
|
+
* 2. When `Projection` is `undefined` the returned type will be `Data`.
|
|
1685
|
+
*
|
|
1686
|
+
* @template Projection The throw generic, defaults to `undefined`.
|
|
1687
|
+
* @template Data The document data type.
|
|
1688
|
+
*
|
|
1689
|
+
* @docs
|
|
1690
|
+
*/
|
|
1691
|
+
type WithProjection<Projection extends Collection.Projection | undefined, Data extends mongodb.Document> = Projection extends Collection.Projection ? Projected<Projection, Data> : Data;
|
|
1692
|
+
/** Extract the projection field from a type. */
|
|
1693
|
+
type ExtractProjection<R> = R extends {
|
|
1694
|
+
projection?: infer P extends undefined | Collection.Projection;
|
|
1695
|
+
} ? P : undefined;
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* TransactionCollection extends Collection with transaction-specific methods.
|
|
1699
|
+
* This class provides commit and abort functionality for MongoDB transactions.
|
|
1700
|
+
* @warning The transaction collection should only be initialized via {@link Collection.start_transaction}.
|
|
1701
|
+
*
|
|
1702
|
+
* @nav Database
|
|
1703
|
+
* @docs
|
|
1704
|
+
*/
|
|
1705
|
+
export declare class TransactionCollection<Data extends mongodb.Document = mongodb.Document> extends Collection<Data> {
|
|
1706
|
+
/**
|
|
1707
|
+
* Commit the current transaction.
|
|
1708
|
+
* Implements retry logic for transient errors and unknown commit results.
|
|
1709
|
+
* @throws {InvalidUsageError} If there is no active session or if the transaction has already been finalized.
|
|
1710
|
+
* @throws {Error} If the commit fails after retries or encounters a non-retryable error.
|
|
1711
|
+
*
|
|
1712
|
+
* @docs
|
|
1713
|
+
*/
|
|
1714
|
+
commit(): Promise<void>;
|
|
1715
|
+
/**
|
|
1716
|
+
* Abort the current transaction.
|
|
1717
|
+
* Implements retry logic for transient errors.
|
|
1718
|
+
* @throws {InvalidUsageError} If there is no active session or if the transaction has already been finalized.
|
|
1719
|
+
* @throws {Error} If the abort fails after retries or encounters a non-retryable error.
|
|
1720
|
+
*
|
|
1721
|
+
* @docs
|
|
1722
|
+
*/
|
|
1723
|
+
abort(): Promise<void>;
|
|
1724
|
+
/**
|
|
1725
|
+
* Cleanup method for proper resource management
|
|
1726
|
+
* Can be called manually or via async disposal
|
|
1727
|
+
*
|
|
1728
|
+
* @warning This method aborts the transaction if it is still active.
|
|
1729
|
+
* @docs
|
|
1730
|
+
*/
|
|
1731
|
+
cleanup(): Promise<void>;
|
|
1732
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
1733
|
+
/**
|
|
1734
|
+
* Check if the transaction is still active (not finalized).
|
|
1735
|
+
* @returns True if the transaction is active, false otherwise.
|
|
1736
|
+
* @docs
|
|
1737
|
+
*/
|
|
1738
|
+
is_active(): boolean;
|
|
1739
|
+
}
|
|
1740
|
+
/** Nested types for the {@link TransactionCollection} class. */
|
|
1741
|
+
export declare namespace TransactionCollection {
|
|
1742
|
+
/**
|
|
1743
|
+
* The constructor options for a transaction based {@link Collection}.
|
|
1744
|
+
* @docs
|
|
1745
|
+
*/
|
|
1746
|
+
interface Opts<Data extends mongodb.Document = mongodb.Document> {
|
|
1747
|
+
/** Construct the collection in transaction mode. */
|
|
1748
|
+
transaction_based: true;
|
|
1749
|
+
/**
|
|
1750
|
+
* The derived collection
|
|
1751
|
+
* @warning Ensure this collection is initialized by {@link init},
|
|
1752
|
+
* or an error will be thrown when attempting to construct
|
|
1753
|
+
* a transaction based collection instance.
|
|
1754
|
+
*/
|
|
1755
|
+
derived_collection: (Omit<Collection<Data>, "_col" | "initialized"> & {
|
|
1756
|
+
initialized: true;
|
|
1757
|
+
_col: mongodb.Collection<Data>;
|
|
1758
|
+
});
|
|
1759
|
+
name?: never;
|
|
1760
|
+
col?: never;
|
|
1761
|
+
ttl?: never;
|
|
1762
|
+
indexes?: never;
|
|
1763
|
+
db?: never;
|
|
1764
|
+
}
|
|
1765
|
+
}
|