@vandenberghinc/volt 1.1.26 → 1.1.28
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/{blacklist.d.ts → backend/src/blacklist.d.ts} +5 -3
- package/backend/dist/cjs/{blacklist.js → backend/src/blacklist.js} +8 -5
- package/backend/dist/cjs/{cli.js → backend/src/cli.js} +29 -47
- package/backend/dist/cjs/backend/src/database/collection.d.ts +1543 -0
- package/backend/dist/cjs/backend/src/database/collection.js +3042 -0
- package/backend/dist/cjs/backend/src/database/database.d.ts +66 -0
- package/backend/dist/cjs/{database → backend/src/database}/database.js +48 -43
- 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.js +443 -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 +75 -0
- package/backend/dist/cjs/{logger.js → backend/src/database/flatten.js} +18 -7
- package/backend/dist/cjs/backend/src/database/flatten_test.js +175 -0
- package/backend/dist/cjs/backend/src/database/quota/quota.d.ts +461 -0
- package/backend/dist/cjs/backend/src/database/quota/quota.js +1014 -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 +293 -0
- package/backend/dist/cjs/backend/src/database/quota/safe_int.js +573 -0
- package/backend/dist/{esm → cjs/backend/src}/endpoint.d.ts +69 -46
- package/backend/dist/cjs/{endpoint.js → backend/src/endpoint.js} +87 -101
- 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/{esm/utils.d.ts → cjs/backend/src/errors/internal_external.d.ts} +14 -22
- package/backend/dist/cjs/backend/src/errors/internal_external.js +85 -0
- package/backend/dist/cjs/backend/src/errors/invalid_usage_error.d.ts +38 -0
- package/backend/dist/cjs/{mutex.js → backend/src/errors/invalid_usage_error.js} +20 -37
- package/backend/dist/cjs/backend/src/errors/system_error.d.ts +230 -0
- package/backend/dist/cjs/backend/src/errors/system_error.js +393 -0
- package/backend/dist/cjs/backend/src/events.d.ts +54 -0
- package/backend/dist/cjs/backend/src/events.js +15 -0
- package/backend/dist/cjs/{frontend.js → backend/src/frontend.js} +1 -1
- package/backend/dist/cjs/{image_endpoint.d.ts → backend/src/image_endpoint.d.ts} +16 -1
- package/backend/dist/cjs/{image_endpoint.js → backend/src/image_endpoint.js} +3 -5
- 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 +64 -0
- package/backend/dist/cjs/{meta.js → backend/src/meta.js} +9 -12
- package/backend/dist/cjs/backend/src/payments/paddle.d.ts +326 -0
- package/backend/dist/cjs/{payments → backend/src/payments}/paddle.js +377 -327
- 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/mail/mail.d.ts +248 -0
- package/backend/dist/cjs/backend/src/plugins/mail/mail.js +379 -0
- package/backend/dist/{esm → cjs/backend/src}/plugins/mail/ui.d.ts +23 -0
- package/backend/dist/cjs/backend/src/plugins/pdf.d.ts +1 -0
- package/backend/dist/cjs/backend/src/rate_limit.d.ts +145 -0
- package/backend/dist/cjs/backend/src/rate_limit.js +549 -0
- package/backend/dist/cjs/{route.d.ts → backend/src/route.d.ts} +3 -10
- package/backend/dist/cjs/{route.js → backend/src/route.js} +23 -21
- package/backend/dist/cjs/backend/src/server.d.ts +485 -0
- package/backend/dist/cjs/{server.js → backend/src/server.js} +688 -873
- package/backend/dist/cjs/backend/src/splash_screen.d.ts +80 -0
- package/backend/dist/cjs/{splash_screen.js → backend/src/splash_screen.js} +24 -3
- package/backend/dist/cjs/backend/src/status.d.ts +74 -0
- package/backend/dist/cjs/{status.js → backend/src/status.js} +64 -64
- package/backend/dist/cjs/backend/src/stream.d.ts +376 -0
- package/backend/dist/cjs/{stream.js → backend/src/stream.js} +299 -276
- package/backend/dist/cjs/backend/src/users.d.ts +807 -0
- package/backend/dist/cjs/backend/src/users.js +1971 -0
- package/backend/dist/cjs/backend/src/utils.d.ts +16 -0
- package/backend/dist/cjs/{utils.js → backend/src/utils.js} +14 -77
- package/backend/dist/{esm → cjs/backend/src}/view.d.ts +33 -11
- package/backend/dist/cjs/backend/src/view.js +508 -0
- package/backend/dist/{esm → cjs/backend/src}/volt.d.ts +10 -1
- package/backend/dist/cjs/{volt.js → backend/src/volt.js} +8 -5
- 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/esm/{blacklist.d.ts → backend/src/blacklist.d.ts} +5 -3
- package/backend/dist/esm/{blacklist.js → backend/src/blacklist.js} +9 -6
- package/backend/dist/esm/{cli.js → backend/src/cli.js} +43 -60
- package/backend/dist/esm/backend/src/database/collection.d.ts +1543 -0
- package/backend/dist/esm/backend/src/database/collection.js +3510 -0
- package/backend/dist/esm/backend/src/database/database.d.ts +66 -0
- package/backend/dist/esm/{database → backend/src/database}/database.js +62 -103
- 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 +405 -0
- package/backend/dist/esm/backend/src/database/flatten.d.ts +75 -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/quota.d.ts +461 -0
- package/backend/dist/esm/backend/src/database/quota/quota.js +1118 -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 +293 -0
- package/backend/dist/esm/backend/src/database/quota/safe_int.js +602 -0
- package/backend/dist/{cjs → esm/backend/src}/endpoint.d.ts +69 -46
- package/backend/dist/esm/{endpoint.js → backend/src/endpoint.js} +136 -127
- 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/{cjs/utils.d.ts → esm/backend/src/errors/internal_external.d.ts} +14 -22
- package/backend/dist/esm/backend/src/errors/internal_external.js +70 -0
- package/backend/dist/esm/backend/src/errors/invalid_usage_error.d.ts +38 -0
- package/backend/dist/esm/backend/src/errors/invalid_usage_error.js +30 -0
- package/backend/dist/esm/backend/src/errors/system_error.d.ts +230 -0
- package/backend/dist/esm/backend/src/errors/system_error.js +402 -0
- package/backend/dist/esm/backend/src/events.d.ts +54 -0
- package/backend/dist/esm/backend/src/events.js +5 -0
- package/backend/dist/esm/{frontend.js → backend/src/frontend.js} +1 -1
- package/backend/dist/esm/{image_endpoint.d.ts → backend/src/image_endpoint.d.ts} +16 -1
- package/backend/dist/esm/{image_endpoint.js → backend/src/image_endpoint.js} +16 -20
- 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 +64 -0
- package/backend/dist/esm/{meta.js → backend/src/meta.js} +15 -54
- package/backend/dist/esm/backend/src/payments/paddle.d.ts +326 -0
- package/backend/dist/esm/{payments → backend/src/payments}/paddle.js +417 -452
- 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/mail/mail.d.ts +248 -0
- package/backend/dist/esm/backend/src/plugins/mail/mail.js +389 -0
- package/backend/dist/{cjs → esm/backend/src}/plugins/mail/ui.d.ts +23 -0
- package/backend/dist/esm/{plugins → backend/src/plugins}/mail/ui.js +3 -6
- package/backend/dist/esm/backend/src/plugins/pdf.d.ts +1 -0
- package/backend/dist/esm/{plugins → backend/src/plugins}/pdf.js +3 -3
- package/backend/dist/esm/backend/src/rate_limit.d.ts +145 -0
- package/backend/dist/esm/backend/src/rate_limit.js +667 -0
- package/backend/dist/esm/{route.d.ts → backend/src/route.d.ts} +3 -10
- package/backend/dist/esm/{route.js → backend/src/route.js} +26 -21
- package/backend/dist/esm/backend/src/server.d.ts +485 -0
- package/backend/dist/esm/{server.js → backend/src/server.js} +891 -1441
- package/backend/dist/esm/backend/src/splash_screen.d.ts +80 -0
- package/backend/dist/esm/{splash_screen.js → backend/src/splash_screen.js} +42 -55
- package/backend/dist/esm/backend/src/status.d.ts +74 -0
- package/backend/dist/esm/backend/src/status.js +199 -0
- package/backend/dist/esm/backend/src/stream.d.ts +376 -0
- package/backend/dist/esm/{stream.js → backend/src/stream.js} +327 -292
- package/backend/dist/esm/backend/src/users.d.ts +809 -0
- package/backend/dist/esm/backend/src/users.js +2140 -0
- package/backend/dist/esm/backend/src/utils.d.ts +16 -0
- package/backend/dist/esm/{utils.js → backend/src/utils.js} +20 -81
- package/backend/dist/{cjs → esm/backend/src}/view.d.ts +33 -11
- package/backend/dist/esm/{view.js → backend/src/view.js} +266 -86
- package/backend/dist/{cjs → esm/backend/src}/volt.d.ts +10 -1
- package/backend/dist/esm/{volt.js → backend/src/volt.js} +7 -4
- 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 +1543 -0
- package/frontend/dist/backend/src/database/collection.js +3510 -0
- package/frontend/dist/backend/src/database/database.d.ts +66 -0
- package/frontend/dist/backend/src/database/database.js +196 -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 +75 -0
- package/frontend/dist/backend/src/database/flatten.js +22 -0
- package/frontend/dist/backend/src/endpoint.d.ts +204 -0
- package/frontend/dist/backend/src/endpoint.js +570 -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 +38 -0
- package/frontend/dist/backend/src/errors/internal_external.js +70 -0
- package/frontend/dist/backend/src/errors/invalid_usage_error.d.ts +38 -0
- package/frontend/dist/backend/src/errors/invalid_usage_error.js +30 -0
- package/frontend/dist/backend/src/errors/system_error.d.ts +230 -0
- package/frontend/dist/backend/src/errors/system_error.js +402 -0
- package/frontend/dist/backend/src/events.d.ts +54 -0
- package/frontend/dist/backend/src/events.js +5 -0
- package/frontend/dist/backend/src/frontend.d.ts +11 -0
- package/frontend/dist/backend/src/frontend.js +12 -0
- package/frontend/dist/backend/src/image_endpoint.d.ts +39 -0
- package/frontend/dist/backend/src/image_endpoint.js +202 -0
- package/frontend/dist/backend/src/meta.d.ts +64 -0
- package/frontend/dist/backend/src/meta.js +110 -0
- package/frontend/dist/backend/src/payments/paddle.d.ts +326 -0
- package/frontend/dist/backend/src/payments/paddle.js +2256 -0
- package/frontend/dist/backend/src/plugins/mail/mail.d.ts +248 -0
- package/frontend/dist/backend/src/plugins/mail/mail.js +389 -0
- package/{backend/dist/esm/plugins/mail.d.ts → frontend/dist/backend/src/plugins/mail/ui.d.ts} +23 -0
- package/{backend/dist/esm/plugins/mail.js → frontend/dist/backend/src/plugins/mail/ui.js} +3 -6
- package/frontend/dist/backend/src/rate_limit.d.ts +145 -0
- package/frontend/dist/backend/src/rate_limit.js +673 -0
- package/frontend/dist/backend/src/route.d.ts +35 -0
- package/frontend/dist/backend/src/route.js +212 -0
- package/frontend/dist/backend/src/server.d.ts +485 -0
- package/frontend/dist/backend/src/server.js +2670 -0
- package/frontend/dist/backend/src/splash_screen.d.ts +80 -0
- package/frontend/dist/backend/src/splash_screen.js +135 -0
- package/frontend/dist/backend/src/status.d.ts +74 -0
- package/frontend/dist/backend/src/status.js +199 -0
- package/frontend/dist/backend/src/stream.d.ts +376 -0
- package/frontend/dist/backend/src/stream.js +1007 -0
- package/frontend/dist/backend/src/users.d.ts +807 -0
- package/frontend/dist/backend/src/users.js +2118 -0
- package/frontend/dist/backend/src/utils.d.ts +16 -0
- package/frontend/dist/backend/src/utils.js +241 -0
- package/frontend/dist/backend/src/view.d.ts +162 -0
- package/frontend/dist/backend/src/view.js +720 -0
- package/frontend/dist/frontend/src/elements/base.d.ts +4414 -0
- package/frontend/dist/{elements → frontend/src/elements}/base.js +3624 -260
- package/frontend/dist/frontend/src/elements/module.d.ts +95 -0
- package/frontend/dist/{elements → frontend/src/elements}/module.js +53 -52
- 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/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/{modules → frontend/src/modules}/color.js +2 -2
- 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 +74 -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/{modules → frontend/src/modules}/meta.js +9 -7
- package/frontend/dist/{modules → frontend/src/modules}/paddle.d.ts +37 -134
- package/frontend/dist/{modules → frontend/src/modules}/paddle.js +620 -568
- 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/{modules → frontend/src/modules}/statics.js +15 -18
- package/frontend/dist/frontend/src/modules/support.d.ts +30 -0
- package/frontend/dist/frontend/src/modules/support.js +53 -0
- package/frontend/dist/{modules → frontend/src/modules}/theme.d.ts +67 -0
- package/frontend/dist/{modules → frontend/src/modules}/theme.js +68 -38
- 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 +268 -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/{types → frontend/src/types}/gradient.js +14 -18
- package/frontend/dist/frontend/src/ui/border_button.d.ts +94 -0
- package/frontend/dist/{ui → frontend/src/ui}/border_button.js +7 -13
- package/frontend/dist/frontend/src/ui/button.d.ts +28 -0
- package/frontend/dist/{ui → frontend/src/ui}/button.js +21 -12
- package/frontend/dist/frontend/src/ui/canvas.d.ts +138 -0
- package/frontend/dist/{ui → frontend/src/ui}/canvas.js +88 -55
- package/frontend/dist/frontend/src/ui/checkbox.d.ts +74 -0
- package/frontend/dist/{ui → frontend/src/ui}/checkbox.js +80 -41
- package/frontend/dist/{ui → frontend/src/ui}/code.d.ts +73 -6
- package/frontend/dist/{ui → frontend/src/ui}/code.js +55 -52
- package/frontend/dist/{ui → frontend/src/ui}/context_menu.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/context_menu.js +12 -17
- package/frontend/dist/{ui → frontend/src/ui}/css.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/css.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/divider.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/divider.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/dropdown.d.ts +57 -2
- package/frontend/dist/{ui → frontend/src/ui}/dropdown.js +87 -94
- package/frontend/dist/{ui → frontend/src/ui}/for_each.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/for_each.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/form.d.ts +6 -2
- package/frontend/dist/{ui → frontend/src/ui}/form.js +10 -7
- package/frontend/dist/frontend/src/ui/frame_modes.d.ts +37 -0
- package/frontend/dist/{ui → frontend/src/ui}/frame_modes.js +16 -22
- package/frontend/dist/{ui → frontend/src/ui}/google_map.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/google_map.js +4 -4
- package/frontend/dist/{ui → frontend/src/ui}/gradient.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/gradient.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/image.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/image.js +5 -5
- package/frontend/dist/frontend/src/ui/input.d.ts +392 -0
- package/frontend/dist/{ui → frontend/src/ui}/input.js +346 -360
- package/frontend/dist/{ui → frontend/src/ui}/link.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/link.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/list.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/list.js +12 -6
- package/frontend/dist/frontend/src/ui/loader_button.d.ts +80 -0
- package/frontend/dist/{ui → frontend/src/ui}/loader_button.js +35 -47
- package/frontend/dist/frontend/src/ui/loaders.d.ts +57 -0
- package/frontend/dist/{ui → frontend/src/ui}/loaders.js +11 -11
- package/frontend/dist/{ui → frontend/src/ui}/popup.d.ts +11 -6
- package/frontend/dist/{ui → frontend/src/ui}/popup.js +32 -18
- package/frontend/dist/frontend/src/ui/pseudo.d.ts +44 -0
- package/frontend/dist/{ui → frontend/src/ui}/pseudo.js +84 -8
- package/frontend/dist/{ui → frontend/src/ui}/scroller.d.ts +14 -2
- package/frontend/dist/{ui → frontend/src/ui}/scroller.js +37 -43
- package/frontend/dist/{ui → frontend/src/ui}/slider.d.ts +5 -1
- package/frontend/dist/{ui → frontend/src/ui}/slider.js +4 -4
- package/frontend/dist/{ui → frontend/src/ui}/spacer.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/spacer.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/span.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/span.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/stack.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/stack.js +3 -9
- package/frontend/dist/frontend/src/ui/steps.d.ts +131 -0
- package/frontend/dist/{ui → frontend/src/ui}/steps.js +30 -45
- package/frontend/dist/{ui → frontend/src/ui}/style.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/style.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/switch.d.ts +5 -1
- package/frontend/dist/{ui → frontend/src/ui}/switch.js +4 -4
- package/frontend/dist/{ui → frontend/src/ui}/table.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/table.js +6 -6
- package/frontend/dist/{ui → frontend/src/ui}/tabs.d.ts +45 -3
- package/frontend/dist/{ui → frontend/src/ui}/tabs.js +65 -40
- package/frontend/dist/{ui → frontend/src/ui}/text.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/text.js +3 -3
- package/frontend/dist/frontend/src/ui/title.d.ts +91 -0
- package/frontend/dist/frontend/src/ui/title.js +272 -0
- package/frontend/dist/{ui → frontend/src/ui}/view.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/view.js +3 -3
- package/frontend/dist/{volt.d.ts → frontend/src/volt.d.ts} +3 -0
- package/frontend/dist/{volt.js → frontend/src/volt.js} +4 -0
- package/frontend/tools/bundle_d_ts.js +71 -0
- package/frontend/tools/convert_to_jsdoc_input.txt +9452 -0
- package/frontend/tools/convert_to_jsdoc_output.txt +7626 -0
- package/frontend/tools/convert_to_jsdoc_tmp.js +345 -0
- package/package.json +11 -12
- package/backend/dist/cjs/database/collection.d.ts +0 -160
- package/backend/dist/cjs/database/collection.js +0 -842
- package/backend/dist/cjs/database/database.d.ts +0 -121
- package/backend/dist/cjs/database/document.d.ts +0 -131
- package/backend/dist/cjs/database/document.js +0 -224
- package/backend/dist/cjs/database.d.ts +0 -502
- package/backend/dist/cjs/database.js +0 -2248
- package/backend/dist/cjs/logger.d.ts +0 -3
- package/backend/dist/cjs/meta.d.ts +0 -50
- package/backend/dist/cjs/mutex.d.ts +0 -24
- package/backend/dist/cjs/payments/paddle.d.ts +0 -160
- package/backend/dist/cjs/plugins/browser.d.ts +0 -36
- package/backend/dist/cjs/plugins/browser.js +0 -198
- package/backend/dist/cjs/plugins/css.d.ts +0 -11
- package/backend/dist/cjs/plugins/css.js +0 -80
- package/backend/dist/cjs/plugins/mail.d.ts +0 -277
- package/backend/dist/cjs/plugins/mail.js +0 -1370
- package/backend/dist/cjs/plugins/ts/compiler.d.ts +0 -139
- package/backend/dist/cjs/plugins/ts/compiler.js +0 -750
- package/backend/dist/cjs/plugins/ts/preprocessing.d.ts +0 -14
- package/backend/dist/cjs/plugins/ts/preprocessing.js +0 -440
- package/backend/dist/cjs/rate_limit.d.ts +0 -63
- package/backend/dist/cjs/rate_limit.js +0 -348
- package/backend/dist/cjs/request.deprc.d.ts +0 -48
- package/backend/dist/cjs/request.deprc.js +0 -572
- package/backend/dist/cjs/response.deprc.d.ts +0 -55
- package/backend/dist/cjs/response.deprc.js +0 -275
- package/backend/dist/cjs/server.d.ts +0 -342
- package/backend/dist/cjs/splash_screen.d.ts +0 -35
- package/backend/dist/cjs/status.d.ts +0 -61
- package/backend/dist/cjs/stream.d.ts +0 -79
- package/backend/dist/cjs/users.d.ts +0 -111
- package/backend/dist/cjs/users.js +0 -1817
- package/backend/dist/cjs/view.js +0 -352
- package/backend/dist/cjs/vinc.dev.d.ts +0 -3
- package/backend/dist/cjs/vinc.dev.js +0 -7
- package/backend/dist/css/adyen.css +0 -92
- package/backend/dist/css/volt.css +0 -70
- package/backend/dist/esm/database/collection.d.ts +0 -160
- package/backend/dist/esm/database/collection.js +0 -1328
- package/backend/dist/esm/database/database.d.ts +0 -121
- package/backend/dist/esm/database/document.d.ts +0 -131
- package/backend/dist/esm/database/document.js +0 -247
- package/backend/dist/esm/database.d.ts +0 -502
- package/backend/dist/esm/database.js +0 -2423
- package/backend/dist/esm/file_watcher.js +0 -329
- package/backend/dist/esm/logger.d.ts +0 -3
- package/backend/dist/esm/logger.js +0 -11
- package/backend/dist/esm/meta.d.ts +0 -50
- package/backend/dist/esm/mutex.d.ts +0 -24
- package/backend/dist/esm/mutex.js +0 -48
- package/backend/dist/esm/payments/paddle.d.ts +0 -160
- package/backend/dist/esm/plugins/browser.d.ts +0 -36
- package/backend/dist/esm/plugins/browser.js +0 -176
- package/backend/dist/esm/plugins/css.d.ts +0 -11
- package/backend/dist/esm/plugins/css.js +0 -90
- package/backend/dist/esm/plugins/ts/compiler.d.ts +0 -139
- package/backend/dist/esm/plugins/ts/compiler.js +0 -1194
- package/backend/dist/esm/plugins/ts/preprocessing.d.ts +0 -14
- package/backend/dist/esm/plugins/ts/preprocessing.js +0 -726
- package/backend/dist/esm/rate_limit.d.ts +0 -63
- package/backend/dist/esm/rate_limit.js +0 -417
- package/backend/dist/esm/request.deprc.d.ts +0 -48
- package/backend/dist/esm/request.deprc.js +0 -572
- package/backend/dist/esm/response.deprc.d.ts +0 -55
- package/backend/dist/esm/response.deprc.js +0 -275
- package/backend/dist/esm/server.d.ts +0 -342
- package/backend/dist/esm/splash_screen.d.ts +0 -35
- package/backend/dist/esm/status.d.ts +0 -61
- package/backend/dist/esm/status.js +0 -197
- package/backend/dist/esm/stream.d.ts +0 -79
- package/backend/dist/esm/users.d.ts +0 -111
- package/backend/dist/esm/users.js +0 -1935
- package/backend/dist/esm/vinc.dev.d.ts +0 -3
- package/backend/dist/esm/vinc.dev.js +0 -7
- package/frontend/dist/elements/base.d.ts +0 -9889
- package/frontend/dist/elements/module.d.ts +0 -30
- package/frontend/dist/modules/array.d.ts +0 -94
- package/frontend/dist/modules/array.js +0 -634
- package/frontend/dist/modules/auth.d.ts +0 -46
- package/frontend/dist/modules/auth.js +0 -139
- package/frontend/dist/modules/colors.d.ts +0 -1
- package/frontend/dist/modules/colors.js +0 -417
- package/frontend/dist/modules/compression.d.ts +0 -6
- package/frontend/dist/modules/compression.js +0 -999
- package/frontend/dist/modules/cookies.d.ts +0 -18
- package/frontend/dist/modules/cookies.js +0 -167
- package/frontend/dist/modules/date.d.ts +0 -142
- package/frontend/dist/modules/date.js +0 -493
- package/frontend/dist/modules/events.d.ts +0 -8
- package/frontend/dist/modules/events.js +0 -91
- package/frontend/dist/modules/google.d.ts +0 -11
- package/frontend/dist/modules/google.js +0 -54
- package/frontend/dist/modules/meta.d.ts +0 -10
- package/frontend/dist/modules/mutex.d.ts +0 -7
- package/frontend/dist/modules/mutex.js +0 -51
- package/frontend/dist/modules/number.d.ts +0 -16
- package/frontend/dist/modules/number.js +0 -23
- package/frontend/dist/modules/object.d.ts +0 -52
- package/frontend/dist/modules/object.js +0 -383
- package/frontend/dist/modules/scheme.d.ts +0 -227
- package/frontend/dist/modules/scheme.js +0 -531
- package/frontend/dist/modules/settings.d.ts +0 -3
- package/frontend/dist/modules/settings.js +0 -4
- package/frontend/dist/modules/statics.d.ts +0 -5
- package/frontend/dist/modules/string.d.ts +0 -124
- package/frontend/dist/modules/string.js +0 -745
- package/frontend/dist/modules/support.d.ts +0 -19
- package/frontend/dist/modules/support.js +0 -103
- package/frontend/dist/modules/themes.d.ts +0 -8
- package/frontend/dist/modules/themes.js +0 -18
- package/frontend/dist/modules/user.d.ts +0 -59
- package/frontend/dist/modules/user.js +0 -280
- package/frontend/dist/modules/utils.d.ts +0 -87
- package/frontend/dist/modules/utils.js +0 -923
- package/frontend/dist/types/gradient.d.ts +0 -12
- package/frontend/dist/ui/border_button.d.ts +0 -152
- package/frontend/dist/ui/button.d.ts +0 -21
- package/frontend/dist/ui/canvas.d.ts +0 -56
- package/frontend/dist/ui/checkbox.d.ts +0 -52
- package/frontend/dist/ui/frame_modes.d.ts +0 -25
- package/frontend/dist/ui/input.d.ts +0 -241
- package/frontend/dist/ui/loader_button.d.ts +0 -93
- package/frontend/dist/ui/loaders.d.ts +0 -57
- package/frontend/dist/ui/pseudo.d.ts +0 -16
- package/frontend/dist/ui/steps.d.ts +0 -59
- package/frontend/dist/ui/title.d.ts +0 -21
- package/frontend/dist/ui/title.js +0 -121
- package/frontend/examples/dashboard/dashboard.ts +0 -776
- /package/backend/dist/cjs/{cli.d.ts → backend/src/cli.d.ts} +0 -0
- /package/backend/dist/cjs/{file_watcher.d.ts → backend/src/database/document.d.ts} +0 -0
- /package/backend/dist/cjs/{file_watcher.js → backend/src/database/document.js} +0 -0
- /package/backend/dist/cjs/{plugins/pdf.d.ts → backend/src/database/filters/strict_filter_test.d.ts} +0 -0
- /package/backend/dist/{esm/file_watcher.d.ts → cjs/backend/src/database/filters/strict_filter_test_v0.d.ts} +0 -0
- /package/backend/dist/{esm/plugins/pdf.d.ts → cjs/backend/src/database/flatten_test.d.ts} +0 -0
- /package/backend/dist/cjs/{frontend.d.ts → backend/src/frontend.d.ts} +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/communication.d.ts +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/communication.js +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/mail/ui.js +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/pdf.js +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/thread_monitor.d.ts +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/thread_monitor.js +0 -0
- /package/backend/dist/cjs/{vinc.d.ts → backend/src/vinc.d.ts} +0 -0
- /package/backend/dist/cjs/{vinc.js → backend/src/vinc.js} +0 -0
- /package/backend/dist/esm/{cli.d.ts → backend/src/cli.d.ts} +0 -0
- /package/backend/dist/esm/{frontend.d.ts → backend/src/frontend.d.ts} +0 -0
- /package/backend/dist/esm/{plugins → backend/src/plugins}/communication.d.ts +0 -0
- /package/backend/dist/esm/{plugins → backend/src/plugins}/communication.js +0 -0
- /package/backend/dist/esm/{plugins → backend/src/plugins}/thread_monitor.d.ts +0 -0
- /package/backend/dist/esm/{plugins → backend/src/plugins}/thread_monitor.js +0 -0
- /package/backend/dist/esm/{vinc.d.ts → backend/src/vinc.d.ts} +0 -0
- /package/backend/dist/esm/{vinc.js → backend/src/vinc.js} +0 -0
- /package/frontend/dist/{elements → frontend/src/elements}/register_element.d.ts +0 -0
- /package/frontend/dist/{elements → frontend/src/elements}/register_element.js +0 -0
- /package/frontend/dist/{modules → frontend/src/modules}/color.d.ts +0 -0
- /package/frontend/dist/{ui → frontend/src/ui}/ui.d.ts +0 -0
- /package/frontend/dist/{ui → frontend/src/ui}/ui.js +0 -0
|
@@ -1,1328 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Daan van den Bergh
|
|
3
|
-
* @copyright © 2022 - 2025 Daan van den Bergh.
|
|
4
|
-
*/
|
|
5
|
-
// External imports.
|
|
6
|
-
import { deserialize, serialize } from "bson";
|
|
7
|
-
// Imports.
|
|
8
|
-
import { logger } from "../logger.js";
|
|
9
|
-
import { Document } from "./document.js";
|
|
10
|
-
/** Debug */
|
|
11
|
-
const { log } = logger;
|
|
12
|
-
// ---------------------------------------------------------
|
|
13
|
-
/**
|
|
14
|
-
* A wrapper class for the MongoDB collection.
|
|
15
|
-
*
|
|
16
|
-
* @note Any document type is suported, including primitives, arrays and objects.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* const col1 = server.db.collection("col1");
|
|
20
|
-
* const col2 = server.db.collection({
|
|
21
|
-
* name: "col2",
|
|
22
|
-
* indexes: ["uid", "name"],
|
|
23
|
-
* ttl: 1000 * 60 * 60 * 24, // 1 day
|
|
24
|
-
* });
|
|
25
|
-
*/
|
|
26
|
-
export class Collection {
|
|
27
|
-
// Static attributes.
|
|
28
|
-
static chunk_size = 1024 * 1024 * 4; // 4MB chunks, lower is better for frequent updates.
|
|
29
|
-
static constructor_scheme = {
|
|
30
|
-
name: "string",
|
|
31
|
-
ttl: { type: "number", default: null }, // ttl in msec
|
|
32
|
-
indexes: {
|
|
33
|
-
type: "array",
|
|
34
|
-
default: [],
|
|
35
|
-
value_scheme: {
|
|
36
|
-
type: ["string", "object"],
|
|
37
|
-
scheme: {
|
|
38
|
-
key: { type: "string", required: (data) => data.key == null && data.keys == null },
|
|
39
|
-
keys: {
|
|
40
|
-
type: ["array"],
|
|
41
|
-
required: (data) => data.key == null && data.keys == null, value_scheme: "string",
|
|
42
|
-
postprocess: (keys) => typeof keys === "string" ? [keys] : keys,
|
|
43
|
-
},
|
|
44
|
-
options: { type: "object", required: false },
|
|
45
|
-
forced: { type: "boolean", default: false },
|
|
46
|
-
},
|
|
47
|
-
postprocess: (info) => {
|
|
48
|
-
if (typeof info === "string")
|
|
49
|
-
return { keys: [info] };
|
|
50
|
-
return info;
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
/** Collection name */
|
|
56
|
-
name;
|
|
57
|
-
/** Time to live in msec for all documents. */
|
|
58
|
-
ttl;
|
|
59
|
-
ttl_enabled;
|
|
60
|
-
/** The column. */
|
|
61
|
-
_col;
|
|
62
|
-
/**
|
|
63
|
-
* The Database parent class, used to initialize the column on demand.
|
|
64
|
-
* So the user can define collections at root level before the database is initialized. */
|
|
65
|
-
db;
|
|
66
|
-
/** Is initialized. */
|
|
67
|
-
initialized = false;
|
|
68
|
-
/** The temporary indexes passed to the constructor for the init method. */
|
|
69
|
-
_init_indexes;
|
|
70
|
-
/** Constructor. */
|
|
71
|
-
constructor(opts) {
|
|
72
|
-
// Attributes.
|
|
73
|
-
this.name = opts.name;
|
|
74
|
-
this._col = opts.col;
|
|
75
|
-
this.ttl = opts.ttl;
|
|
76
|
-
this.ttl_enabled = typeof opts.ttl === "number";
|
|
77
|
-
this.db = opts.db;
|
|
78
|
-
this._init_indexes = opts.indexes;
|
|
79
|
-
}
|
|
80
|
-
/** Initialize. */
|
|
81
|
-
async init() {
|
|
82
|
-
if (this.initialized === false) {
|
|
83
|
-
// Create column.
|
|
84
|
-
if (this._col == null) {
|
|
85
|
-
// Start connection in dev mode.
|
|
86
|
-
if (!this.db.server.production) {
|
|
87
|
-
await this.db.ensure_connection();
|
|
88
|
-
}
|
|
89
|
-
// Not connected.
|
|
90
|
-
if (!this.db.connected || !this.db._db) {
|
|
91
|
-
throw new Error(`Database is not connected.`);
|
|
92
|
-
}
|
|
93
|
-
// Check if t
|
|
94
|
-
// he collection exists
|
|
95
|
-
if (this.db._listed_cols == null) {
|
|
96
|
-
this.db._listed_cols = await this.db._db.listCollections().toArray();
|
|
97
|
-
}
|
|
98
|
-
if (!this.db._listed_cols.find(x => x.name === this.name)) {
|
|
99
|
-
log(0, `Creating collection "${this.name}".`);
|
|
100
|
-
await this.db._db.createCollection(this.name);
|
|
101
|
-
}
|
|
102
|
-
// Create collection.
|
|
103
|
-
this._col = this.db._db.collection(this.name);
|
|
104
|
-
}
|
|
105
|
-
// Assign as initialized when the column is created.
|
|
106
|
-
// Also since next used methods are checking for this attribute.
|
|
107
|
-
this.initialized = true;
|
|
108
|
-
// Create ttl index.
|
|
109
|
-
if (this.ttl_enabled) {
|
|
110
|
-
await this._setup_ttl();
|
|
111
|
-
}
|
|
112
|
-
// Create indexes.
|
|
113
|
-
if (this._init_indexes?.length) {
|
|
114
|
-
for (const item of this._init_indexes) {
|
|
115
|
-
await this.create_index(item);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
await this.create_index({ key: "_path", options: { unique: false } });
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return this;
|
|
123
|
-
}
|
|
124
|
-
assert_init() {
|
|
125
|
-
if (this._col == null) {
|
|
126
|
-
throw new Error(`Collection "${this.name}" is not initialized.`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/** Setup the ttl configuration. */
|
|
130
|
-
async _setup_ttl() {
|
|
131
|
-
if (!this.initialized) {
|
|
132
|
-
await this.init();
|
|
133
|
-
}
|
|
134
|
-
this.assert_init();
|
|
135
|
-
if (this.ttl == null) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const desired_seconds = Math.floor(this.ttl / 1000);
|
|
139
|
-
// 1) Get all indexes
|
|
140
|
-
const indexes = await this._col.indexes(); // [{ key: { _ttl_timestamp: 1 }, expireAfterSeconds: 3600 }, …]
|
|
141
|
-
// 2) Find the TTL index
|
|
142
|
-
const ttl_index = indexes.find(ix => ix.key._ttl_timestamp === 1 ||
|
|
143
|
-
(ix.key instanceof Array && ix.key[0] === '_ttl_timestamp'));
|
|
144
|
-
// 3a) Doesn’t exist → create it
|
|
145
|
-
if (!ttl_index) {
|
|
146
|
-
await this._col.createIndex({ _ttl_timestamp: 1 }, { expireAfterSeconds: desired_seconds });
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
// 3b) Exists but wrong TTL → drop & recreate
|
|
150
|
-
if (ttl_index.expireAfterSeconds !== desired_seconds) {
|
|
151
|
-
if (!ttl_index.name) {
|
|
152
|
-
// nothing to drop
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
await this._col.dropIndex(ttl_index.name);
|
|
156
|
-
await this._col.createIndex({ _ttl_timestamp: 1 }, { expireAfterSeconds: desired_seconds });
|
|
157
|
-
}
|
|
158
|
-
// 3c) Exists and correct → nothing to do
|
|
159
|
-
}
|
|
160
|
-
_process_doc(doc) {
|
|
161
|
-
if (doc == null) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
else if (doc._content != null) {
|
|
165
|
-
return doc._content;
|
|
166
|
-
}
|
|
167
|
-
return doc;
|
|
168
|
-
}
|
|
169
|
-
// Chunked methods.
|
|
170
|
-
async _load_chunked(path, find_opts) {
|
|
171
|
-
if (!this.initialized) {
|
|
172
|
-
await this.init();
|
|
173
|
-
}
|
|
174
|
-
this.assert_init();
|
|
175
|
-
let query = typeof path === "string" ?
|
|
176
|
-
{ _path: path, chunk: { $gte: 0 } } :
|
|
177
|
-
{ ...path, chunk: { $gte: 0 } };
|
|
178
|
-
const chunks_cursor = this._col.find(query, find_opts).sort({ chunk: 1 });
|
|
179
|
-
const chunks = await chunks_cursor.toArray();
|
|
180
|
-
if (chunks.length === 0) {
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
const buffer = Buffer.concat(chunks.map(chunk => chunk.data.buffer));
|
|
184
|
-
return deserialize(buffer);
|
|
185
|
-
}
|
|
186
|
-
async _save_chunked(path, content) {
|
|
187
|
-
if (!this.initialized) {
|
|
188
|
-
await this.init();
|
|
189
|
-
}
|
|
190
|
-
this.assert_init();
|
|
191
|
-
// Serialize.
|
|
192
|
-
const buffer = serialize(content);
|
|
193
|
-
const new_chunk_count = Math.ceil(buffer.length / Collection.chunk_size);
|
|
194
|
-
// Retrieve the old chunk count
|
|
195
|
-
const ref_query = typeof path === "string" ?
|
|
196
|
-
{ _path: path, chunk: -1 } :
|
|
197
|
-
{ ...path, chunk: -1 };
|
|
198
|
-
const object_ref = await this._col.findOne(ref_query);
|
|
199
|
-
const old_chunk_count = object_ref ? object_ref.chunks : 0;
|
|
200
|
-
// Update chunks.
|
|
201
|
-
const bulk_ops = [];
|
|
202
|
-
for (let i = 0; i < buffer.length; i += Collection.chunk_size) {
|
|
203
|
-
let query, update;
|
|
204
|
-
if (typeof path === "string") {
|
|
205
|
-
query = {
|
|
206
|
-
_path: path,
|
|
207
|
-
chunk: i / Collection.chunk_size,
|
|
208
|
-
};
|
|
209
|
-
update = {
|
|
210
|
-
chunk: i / Collection.chunk_size,
|
|
211
|
-
data: buffer.slice(i, i + Collection.chunk_size)
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
query = {
|
|
216
|
-
...path,
|
|
217
|
-
chunk: i / Collection.chunk_size,
|
|
218
|
-
};
|
|
219
|
-
update = {
|
|
220
|
-
chunk: i / Collection.chunk_size,
|
|
221
|
-
data: buffer.slice(i, i + Collection.chunk_size)
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
const full_update = {
|
|
225
|
-
$set: update,
|
|
226
|
-
};
|
|
227
|
-
if (this.ttl_enabled) {
|
|
228
|
-
full_update["$setOnInsert"] = { _ttl_timestamp: new Date() };
|
|
229
|
-
}
|
|
230
|
-
bulk_ops.push({
|
|
231
|
-
updateOne: {
|
|
232
|
-
filter: query,
|
|
233
|
-
update: full_update,
|
|
234
|
-
upsert: true
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
// Update reference.
|
|
239
|
-
const full_update = {
|
|
240
|
-
$set: {
|
|
241
|
-
chunk: -1,
|
|
242
|
-
chunks: new_chunk_count,
|
|
243
|
-
},
|
|
244
|
-
};
|
|
245
|
-
if (this.ttl_enabled) {
|
|
246
|
-
full_update["$setOnInsert"] = { _ttl_timestamp: new Date() };
|
|
247
|
-
}
|
|
248
|
-
bulk_ops.push({
|
|
249
|
-
updateOne: {
|
|
250
|
-
filter: ref_query,
|
|
251
|
-
update: full_update,
|
|
252
|
-
upsert: true
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
// Write.
|
|
256
|
-
await this._col.bulkWrite(bulk_ops, { ordered: true });
|
|
257
|
-
// Delete any excess chunks if the new chunk count is less than the old chunk count
|
|
258
|
-
if (new_chunk_count < old_chunk_count) {
|
|
259
|
-
ref_query.chunk = { $gte: new_chunk_count };
|
|
260
|
-
await this._col.deleteMany(ref_query);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
// Get the raw and initialized mongo collection.
|
|
264
|
-
async col() {
|
|
265
|
-
await this.init();
|
|
266
|
-
return this._col;
|
|
267
|
-
}
|
|
268
|
-
/** Create a reference. */
|
|
269
|
-
ref(query, opts) {
|
|
270
|
-
return new Document.Ref(query, opts ? { ...opts, col: this } : { col: this });
|
|
271
|
-
}
|
|
272
|
-
reference(query, opts) {
|
|
273
|
-
return new Document.Ref(query, opts ? { ...opts, col: this } : { col: this });
|
|
274
|
-
}
|
|
275
|
-
/** Has index. */
|
|
276
|
-
async has_index(index) {
|
|
277
|
-
if (!this.initialized) {
|
|
278
|
-
await this.init();
|
|
279
|
-
}
|
|
280
|
-
this.assert_init();
|
|
281
|
-
return (await this._col.listIndexes().toArray()).some(x => x.name === index);
|
|
282
|
-
}
|
|
283
|
-
/* @docs:
|
|
284
|
-
@title: Create index
|
|
285
|
-
@description: Creates indexes on collections.
|
|
286
|
-
@return:
|
|
287
|
-
Returns the document that was found or `null` when no document is found.
|
|
288
|
-
@parameter:
|
|
289
|
-
@name: keys
|
|
290
|
-
@desc: The `keys` argument for the orignal mongodb `createIndex()` function.
|
|
291
|
-
@parameter:
|
|
292
|
-
@name: options
|
|
293
|
-
@desc: The `options` argument for the orignal mongodb `createIndex()` function.
|
|
294
|
-
@parameter:
|
|
295
|
-
@name: commitQuorum
|
|
296
|
-
@desc: The `commitQuorum` argument for the orignal mongodb `createIndex()` function.
|
|
297
|
-
*/
|
|
298
|
-
async create_index(opts) {
|
|
299
|
-
if (!this.initialized) {
|
|
300
|
-
await this.init();
|
|
301
|
-
}
|
|
302
|
-
this.assert_init();
|
|
303
|
-
let key, keys;
|
|
304
|
-
let options;
|
|
305
|
-
let forced = false;
|
|
306
|
-
if (typeof opts === "string") {
|
|
307
|
-
key = opts;
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
({
|
|
311
|
-
key,
|
|
312
|
-
keys,
|
|
313
|
-
options,
|
|
314
|
-
forced = false
|
|
315
|
-
} = opts);
|
|
316
|
-
}
|
|
317
|
-
// Create keys objs per input type.
|
|
318
|
-
let keys_obj = {};
|
|
319
|
-
if (key) {
|
|
320
|
-
keys_obj = {};
|
|
321
|
-
keys_obj[key] = 1;
|
|
322
|
-
}
|
|
323
|
-
else if (Array.isArray(keys) && keys.length > 0) {
|
|
324
|
-
keys_obj = {};
|
|
325
|
-
for (const key of keys) {
|
|
326
|
-
keys_obj[key] = 1;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
throw new Error("Define one of the following parameters: [key, keys].");
|
|
331
|
-
}
|
|
332
|
-
// Drop index.
|
|
333
|
-
if (forced) {
|
|
334
|
-
try {
|
|
335
|
-
await this._col.dropIndex(options?.name ??
|
|
336
|
-
Object.entries(keys_obj)
|
|
337
|
-
.map(([key, value]) => `${key}_${value}`)
|
|
338
|
-
.join('_'));
|
|
339
|
-
}
|
|
340
|
-
catch (err) {
|
|
341
|
-
if (err.codeName !== 'IndexNotFound') {
|
|
342
|
-
throw err;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
// Create index.
|
|
347
|
-
// @ts-ignore
|
|
348
|
-
return await this._col.createIndex(keys_obj, options || {});
|
|
349
|
-
}
|
|
350
|
-
/* @docs:
|
|
351
|
-
* @title: Find
|
|
352
|
-
* @description: Find a document by a query.
|
|
353
|
-
* @return:
|
|
354
|
-
* Returns the document that was found or `null` when no document is found.
|
|
355
|
-
* @parameter:
|
|
356
|
-
* @name: query
|
|
357
|
-
* @desc: The query options.
|
|
358
|
-
* @type: object
|
|
359
|
-
*/
|
|
360
|
-
async find(query) {
|
|
361
|
-
if (!this.initialized) {
|
|
362
|
-
await this.init();
|
|
363
|
-
}
|
|
364
|
-
this.assert_init();
|
|
365
|
-
try {
|
|
366
|
-
return this._process_doc(await this._col.findOne(query));
|
|
367
|
-
}
|
|
368
|
-
catch (error) {
|
|
369
|
-
console.error(error);
|
|
370
|
-
throw new Error('Encountered an error while finding the document.');
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
async find_many(query) {
|
|
374
|
-
if (!this.initialized) {
|
|
375
|
-
await this.init();
|
|
376
|
-
}
|
|
377
|
-
this.assert_init();
|
|
378
|
-
try {
|
|
379
|
-
const list = await this._col.find(query).toArray();
|
|
380
|
-
return list.map(i => this._process_doc(i));
|
|
381
|
-
}
|
|
382
|
-
catch (error) {
|
|
383
|
-
console.error(error);
|
|
384
|
-
throw new Error('Encountered an error while finding the document.');
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
/* @docs:
|
|
388
|
-
* @title: Exists
|
|
389
|
-
* @description: Check if a document exists.
|
|
390
|
-
* @parameter:
|
|
391
|
-
* @name: path
|
|
392
|
-
* @description: The database path to the document.
|
|
393
|
-
* @type: string
|
|
394
|
-
*/
|
|
395
|
-
async exists(path) {
|
|
396
|
-
if (!this.initialized) {
|
|
397
|
-
await this.init();
|
|
398
|
-
}
|
|
399
|
-
this.assert_init();
|
|
400
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
401
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
402
|
-
}
|
|
403
|
-
try {
|
|
404
|
-
const doc = await this._col.findOne(typeof path === "object" ? path : { _path: path }, { projection: { _id: 1 } });
|
|
405
|
-
return doc != null;
|
|
406
|
-
}
|
|
407
|
-
catch (error) {
|
|
408
|
-
console.error(error);
|
|
409
|
-
throw new Error('Encountered an error while checking if the document exists.');
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
/* @docs:
|
|
413
|
-
* @title: Load
|
|
414
|
-
* @description: Load data by path.
|
|
415
|
-
* @return:
|
|
416
|
-
* Returns the loaded document.
|
|
417
|
-
*
|
|
418
|
-
* Returns the `def` parameter when the data does not exist, keep in mind that when parameter `def` is an object it could be a reference to a defined variable.
|
|
419
|
-
* @parameter:
|
|
420
|
-
* @name: path
|
|
421
|
-
* @description: The database path to the document.
|
|
422
|
-
* @type: string
|
|
423
|
-
* @parameter:
|
|
424
|
-
* @name: opts
|
|
425
|
-
* @desc: Additional options.
|
|
426
|
-
* @type: null, object
|
|
427
|
-
* @attribute:
|
|
428
|
-
* @name: default
|
|
429
|
-
* @description:
|
|
430
|
-
* The default data to be returned when the data does not exist.
|
|
431
|
-
*
|
|
432
|
-
* When the type of attribute `default` is `object` then the keys that do not exist in the loaded object, but do exist in the default object will be inserted into the loaded object.
|
|
433
|
-
* @type: null, object
|
|
434
|
-
* @attribute:
|
|
435
|
-
* @name: chunked
|
|
436
|
-
* @description: Load a chunked document.
|
|
437
|
-
* @type: null, object
|
|
438
|
-
* @attribute:
|
|
439
|
-
* @name: attributes
|
|
440
|
-
* @description: The attributes to load.
|
|
441
|
-
* @type: null, string[]
|
|
442
|
-
*/
|
|
443
|
-
async load(path, opts = null) {
|
|
444
|
-
if (!this.initialized) {
|
|
445
|
-
await this.init();
|
|
446
|
-
}
|
|
447
|
-
this.assert_init();
|
|
448
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
449
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
450
|
-
}
|
|
451
|
-
if (opts && opts.projection && opts.chunked) {
|
|
452
|
-
throw new Error("The `projection` and `chunked` options cannot be used together.");
|
|
453
|
-
}
|
|
454
|
-
try {
|
|
455
|
-
// Get attributes.
|
|
456
|
-
let find_opts;
|
|
457
|
-
if (opts) {
|
|
458
|
-
if (opts.projection) {
|
|
459
|
-
find_opts = { projection: opts.projection };
|
|
460
|
-
}
|
|
461
|
-
else if (opts.attributes) {
|
|
462
|
-
find_opts = { projection: {
|
|
463
|
-
_id: 1,
|
|
464
|
-
_path: 1,
|
|
465
|
-
_uid: 1,
|
|
466
|
-
} };
|
|
467
|
-
opts.attributes.forEach((i) => {
|
|
468
|
-
if (find_opts?.projection) {
|
|
469
|
-
find_opts.projection[i] = 1;
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
// Load doc.
|
|
475
|
-
let doc;
|
|
476
|
-
if (opts != null && opts.chunked === true) {
|
|
477
|
-
doc = await this._load_chunked(path, find_opts);
|
|
478
|
-
}
|
|
479
|
-
else {
|
|
480
|
-
// Load.
|
|
481
|
-
doc = await this._col.findOne(typeof path === "object" ? path : { _path: path }, find_opts);
|
|
482
|
-
}
|
|
483
|
-
// Process doc.
|
|
484
|
-
doc = this._process_doc(doc);
|
|
485
|
-
// Handle default.
|
|
486
|
-
if (doc == null) {
|
|
487
|
-
if (opts != null && opts.default !== undefined) {
|
|
488
|
-
return opts.default;
|
|
489
|
-
}
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
// Insert default keys.
|
|
493
|
-
else if (opts != null && typeof opts.default === "object" && opts.default != null && Array.isArray(opts.default) === false) {
|
|
494
|
-
const set_defaults = (obj, defaults) => {
|
|
495
|
-
Object.keys(defaults).forEach((key) => {
|
|
496
|
-
if (obj[key] === undefined) {
|
|
497
|
-
obj[key] = defaults[key];
|
|
498
|
-
}
|
|
499
|
-
else if (typeof obj[key] === "object" && !Array.isArray(obj[key]) && obj[key] != null &&
|
|
500
|
-
typeof defaults[key] === "object" && !Array.isArray(defaults[key]) && defaults[key] != null) {
|
|
501
|
-
set_defaults(obj[key], defaults[key]);
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
};
|
|
505
|
-
set_defaults(doc, opts.default);
|
|
506
|
-
}
|
|
507
|
-
// Response.
|
|
508
|
-
return doc;
|
|
509
|
-
}
|
|
510
|
-
catch (error) {
|
|
511
|
-
console.error(error);
|
|
512
|
-
throw new Error('Encountered an error while loading the document.');
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
/* @docs:
|
|
516
|
-
* @title: Save
|
|
517
|
-
* @description: Save data by path. When the document already exists this function only updates the specified content attributes.
|
|
518
|
-
* @return:
|
|
519
|
-
* Returns the updated document.
|
|
520
|
-
* @parameter:
|
|
521
|
-
* @name: path
|
|
522
|
-
* @description: The database path to the document.
|
|
523
|
-
* @type: string
|
|
524
|
-
* @parameter:
|
|
525
|
-
* @name: data
|
|
526
|
-
* @description: The data to save.
|
|
527
|
-
* @type: null, boolean, number, string, array, object
|
|
528
|
-
* @parameter:
|
|
529
|
-
* @name: opts
|
|
530
|
-
* @desc: Additional options.
|
|
531
|
-
* @type: null, object
|
|
532
|
-
* @attribute:
|
|
533
|
-
* @name: chunked
|
|
534
|
-
* @description: Chunk the document into multiple documents, therefore documents larger than 16MB are supported.
|
|
535
|
-
* @warning: Currently this option is only supported for types `object` and `array`.
|
|
536
|
-
* @default: false
|
|
537
|
-
* @type: boolean
|
|
538
|
-
* @attribute:
|
|
539
|
-
* @name: bulk
|
|
540
|
-
* @description: Get a bulk operation object, so several operations can be executed in bulk.
|
|
541
|
-
* @default: false
|
|
542
|
-
* @type: boolean
|
|
543
|
-
* @attribute:
|
|
544
|
-
* @name: set
|
|
545
|
-
* @description: By default the $set attribute is used for the content, with `opts.set` disabled you can create your own instructions. The `content` attribute must reflect this.
|
|
546
|
-
* @warning: This does not work in combination with `opts.chunked`.
|
|
547
|
-
* @default: true
|
|
548
|
-
* @type: boolean
|
|
549
|
-
*/
|
|
550
|
-
async save(path, content, opts = null) {
|
|
551
|
-
if (!this.initialized) {
|
|
552
|
-
await this.init();
|
|
553
|
-
}
|
|
554
|
-
this.assert_init();
|
|
555
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
556
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
557
|
-
}
|
|
558
|
-
try {
|
|
559
|
-
// Vars.
|
|
560
|
-
let doc, set;
|
|
561
|
-
// Create set.
|
|
562
|
-
if (typeof content === "object" && Array.isArray(content) == false && content != null) {
|
|
563
|
-
delete content._id;
|
|
564
|
-
delete content._path;
|
|
565
|
-
delete content._uid;
|
|
566
|
-
delete content._ttl_timestamp;
|
|
567
|
-
set = content;
|
|
568
|
-
}
|
|
569
|
-
else {
|
|
570
|
-
set = { _content: content };
|
|
571
|
-
}
|
|
572
|
-
// Save chunked.
|
|
573
|
-
if (opts != null && opts.chunked === true) {
|
|
574
|
-
await this._save_chunked(path, set);
|
|
575
|
-
}
|
|
576
|
-
// Save as single doc.
|
|
577
|
-
else {
|
|
578
|
-
// Apply $set rules.
|
|
579
|
-
if (opts == null || (opts.set !== false)) {
|
|
580
|
-
set = { $set: set };
|
|
581
|
-
}
|
|
582
|
-
// Apply TTL.
|
|
583
|
-
if (this.ttl_enabled) {
|
|
584
|
-
if (set["$setOnInsert"] === undefined) {
|
|
585
|
-
set["$setOnInsert"] = {};
|
|
586
|
-
set["$setOnInsert"]._ttl_timestamp = new Date();
|
|
587
|
-
}
|
|
588
|
-
else if (set["$setOnInsert"] != null && typeof set["$setOnInsert"] === "object") {
|
|
589
|
-
set["$setOnInsert"]._ttl_timestamp = new Date();
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
throw new Error(`Undefined behaviour: Unable to assign the $setOnInsert data for ttl control.`);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
// Bulk operation.
|
|
596
|
-
if (opts != null && opts.bulk) {
|
|
597
|
-
return {
|
|
598
|
-
updateOne: {
|
|
599
|
-
filter: typeof path === "object" ? path : { _path: path },
|
|
600
|
-
update: set,
|
|
601
|
-
upsert: true,
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
// Normal operation.
|
|
606
|
-
else {
|
|
607
|
-
await this._col.updateOne(typeof path === "object" ? path : { _path: path }, set, { upsert: true });
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
// Response.
|
|
611
|
-
return content;
|
|
612
|
-
}
|
|
613
|
-
catch (error) {
|
|
614
|
-
console.error(error);
|
|
615
|
-
throw new Error('Encountered an error while updating the document.');
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
/** Update many. */
|
|
619
|
-
async update_many(...args) {
|
|
620
|
-
if (!this.initialized) {
|
|
621
|
-
await this.init();
|
|
622
|
-
}
|
|
623
|
-
this.assert_init();
|
|
624
|
-
return this._col.updateMany(...args);
|
|
625
|
-
}
|
|
626
|
-
// List.
|
|
627
|
-
/* @docs:
|
|
628
|
-
* @title: List
|
|
629
|
-
* @description: List all child documents of directory path.
|
|
630
|
-
* @parameter:
|
|
631
|
-
* @name: path
|
|
632
|
-
* @description: The database directory path.
|
|
633
|
-
* @type: string
|
|
634
|
-
* @parameter:
|
|
635
|
-
* @name: options
|
|
636
|
-
* @description: List options.
|
|
637
|
-
* @type: object
|
|
638
|
-
* @attribute:
|
|
639
|
-
* @name: process
|
|
640
|
-
* @description: Process the document. By default saved non object data will be stored under `_content`. Processing checks this attribute and uses that content instead when it is detected.
|
|
641
|
-
* @type: boolean
|
|
642
|
-
* @default: true
|
|
643
|
-
* @attribute:
|
|
644
|
-
* @name: projection
|
|
645
|
-
* @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
646
|
-
* @type: object
|
|
647
|
-
* @default: undefined
|
|
648
|
-
*/
|
|
649
|
-
async list(path, options = {}) {
|
|
650
|
-
if (!this.initialized) {
|
|
651
|
-
await this.init();
|
|
652
|
-
}
|
|
653
|
-
this.assert_init();
|
|
654
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
655
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
656
|
-
}
|
|
657
|
-
if (typeof path === "string") {
|
|
658
|
-
while (path.length > 0 && path.charAt(path.length - 1) === "/") {
|
|
659
|
-
path = path.substr(0, path.length - 1);
|
|
660
|
-
}
|
|
661
|
-
if (path.length == 0) {
|
|
662
|
-
throw Error("Invalid path.");
|
|
663
|
-
}
|
|
664
|
-
path = { _path: { $regex: `^${path}/` } };
|
|
665
|
-
}
|
|
666
|
-
else if (path._path) {
|
|
667
|
-
let _path = path._path;
|
|
668
|
-
while (_path.length > 0 && _path.charAt(_path.length - 1) === "/") {
|
|
669
|
-
_path = _path.substr(0, _path.length - 1);
|
|
670
|
-
}
|
|
671
|
-
if (_path.length == 0) {
|
|
672
|
-
throw Error("Invalid path.");
|
|
673
|
-
}
|
|
674
|
-
path._path = { $regex: `^${_path}/` };
|
|
675
|
-
}
|
|
676
|
-
try {
|
|
677
|
-
const docs = await this._col.find(path, { projection: options.projection }).toArray();
|
|
678
|
-
if (options.process === false) {
|
|
679
|
-
return docs;
|
|
680
|
-
}
|
|
681
|
-
return docs.map((doc) => this._process_doc(doc));
|
|
682
|
-
}
|
|
683
|
-
catch (error) {
|
|
684
|
-
console.error(error);
|
|
685
|
-
throw new Error('Encountered an error while listing all documents.');
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
/* @docs:
|
|
689
|
-
* @title: List Query
|
|
690
|
-
* @description: List all documents of the collection based on a query.
|
|
691
|
-
* @parameter:
|
|
692
|
-
* @name: query
|
|
693
|
-
* @desc: The query options.
|
|
694
|
-
* @type: object
|
|
695
|
-
* @parameter:
|
|
696
|
-
* @name: options
|
|
697
|
-
* @description: List options.
|
|
698
|
-
* @type: object
|
|
699
|
-
* @attribute:
|
|
700
|
-
* @name: process
|
|
701
|
-
* @description: Process the document. By default saved non object data will be stored under `_content`. Processing checks this attribute and uses that content instead when it is detected.
|
|
702
|
-
* @type: boolean
|
|
703
|
-
* @default: true
|
|
704
|
-
* @attribute:
|
|
705
|
-
* @name: projection
|
|
706
|
-
* @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
707
|
-
* @type: object
|
|
708
|
-
* @default: undefined
|
|
709
|
-
*/
|
|
710
|
-
async list_query(query = {}, options = {}) {
|
|
711
|
-
if (!this.initialized) {
|
|
712
|
-
await this.init();
|
|
713
|
-
}
|
|
714
|
-
this.assert_init();
|
|
715
|
-
try {
|
|
716
|
-
const docs = await this._col.find(query, { projection: options.projection }).toArray();
|
|
717
|
-
if (options.process === false) {
|
|
718
|
-
return docs;
|
|
719
|
-
}
|
|
720
|
-
return docs.map((doc) => this._process_doc(doc)); // list as array since the user might have used a path object width different attributes so dict is not reliable.
|
|
721
|
-
}
|
|
722
|
-
catch (error) {
|
|
723
|
-
console.error(error);
|
|
724
|
-
throw new Error('Encountered an error while listing all documents.');
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
/* @docs:
|
|
728
|
-
* @title: List All
|
|
729
|
-
* @description: List all documents of the collection, optionally per uid.
|
|
730
|
-
* @parameter:
|
|
731
|
-
* @name: query
|
|
732
|
-
* @ignore: true
|
|
733
|
-
* @parameter:
|
|
734
|
-
* @name: options
|
|
735
|
-
* @description: List options.
|
|
736
|
-
* @type: object
|
|
737
|
-
* @attribute:
|
|
738
|
-
* @name: process
|
|
739
|
-
* @description: Process the document. By default saved non object data will be stored under `_content`. Processing checks this attribute and uses that content instead when it is detected.
|
|
740
|
-
* @type: boolean
|
|
741
|
-
* @default: true
|
|
742
|
-
* @attribute:
|
|
743
|
-
* @name: projection
|
|
744
|
-
* @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
745
|
-
* @type: object
|
|
746
|
-
* @default: undefined
|
|
747
|
-
*/
|
|
748
|
-
async list_all(query = {}, options = {}) {
|
|
749
|
-
if (!this.initialized) {
|
|
750
|
-
await this.init();
|
|
751
|
-
}
|
|
752
|
-
this.assert_init();
|
|
753
|
-
let docs;
|
|
754
|
-
docs = await this._col.find(query, { projection: options.projection }).toArray();
|
|
755
|
-
if (options.process === false) {
|
|
756
|
-
return docs;
|
|
757
|
-
}
|
|
758
|
-
return docs.map((doc) => this._process_doc(doc)); // list as array since the user might have used a path object width different attributes so dict is not reliable.
|
|
759
|
-
}
|
|
760
|
-
/* @docs:
|
|
761
|
-
* @title: Delete
|
|
762
|
-
* @description: Delete a document of the collection by path.
|
|
763
|
-
* @parameter:
|
|
764
|
-
* @name: path
|
|
765
|
-
* @description: The database path to the document.
|
|
766
|
-
* @type: string
|
|
767
|
-
* @parameter:
|
|
768
|
-
* @name: opts
|
|
769
|
-
* @desc: Additional options.
|
|
770
|
-
* @type: null, object
|
|
771
|
-
* @attribute:
|
|
772
|
-
* @name: chunked
|
|
773
|
-
* @description: Delete a chunked document.
|
|
774
|
-
* @default: false
|
|
775
|
-
* @type: boolean
|
|
776
|
-
* @attribute:
|
|
777
|
-
* @name: bulk
|
|
778
|
-
* @description: Get a bulk operation object, so several operations can be executed in bulk.
|
|
779
|
-
* @default: false
|
|
780
|
-
* @type: boolean
|
|
781
|
-
*/
|
|
782
|
-
async delete(path, opts) {
|
|
783
|
-
if (!this.initialized) {
|
|
784
|
-
await this.init();
|
|
785
|
-
}
|
|
786
|
-
this.assert_init();
|
|
787
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
788
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
789
|
-
}
|
|
790
|
-
try {
|
|
791
|
-
if (opts != null && opts.chunked === true) {
|
|
792
|
-
if (opts.bulk) {
|
|
793
|
-
return { deleteMany: { filter: typeof path === "object" ? path : { _path: path } } };
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
await this._col.deleteMany(typeof path === "object" ? path : { _path: path });
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
else {
|
|
800
|
-
if (opts != null && opts.bulk) {
|
|
801
|
-
return { deleteOne: { filter: typeof path === "object" ? path : { _path: path } } };
|
|
802
|
-
}
|
|
803
|
-
else {
|
|
804
|
-
await this._col.deleteOne(typeof path === "object" ? path : { _path: path });
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
catch (error) {
|
|
809
|
-
console.error(error);
|
|
810
|
-
throw new Error('Encountered an error while deleting.');
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
/* @docs:
|
|
814
|
-
* @title: Delete Query
|
|
815
|
-
* @description: Delete a document of the collection by query.
|
|
816
|
-
* @parameter:
|
|
817
|
-
* @name: query
|
|
818
|
-
* @description: The query object.
|
|
819
|
-
* @type: object
|
|
820
|
-
*/
|
|
821
|
-
async delete_query(query = {}) {
|
|
822
|
-
if (!this.initialized) {
|
|
823
|
-
await this.init();
|
|
824
|
-
}
|
|
825
|
-
this.assert_init();
|
|
826
|
-
if (typeof query !== "object" || query == null || Object.keys(query).length === 0) {
|
|
827
|
-
throw Error(`Parameter "query" has an invalid type "${typeof query}", the valid type is "object".`);
|
|
828
|
-
}
|
|
829
|
-
if (Object.keys(query).length === 0) {
|
|
830
|
-
throw Error(`Parameter "query" is an empty object.`);
|
|
831
|
-
}
|
|
832
|
-
await this._col.deleteMany(query);
|
|
833
|
-
}
|
|
834
|
-
// Delete all.
|
|
835
|
-
async delete_all(path) {
|
|
836
|
-
if (!this.initialized) {
|
|
837
|
-
await this.init();
|
|
838
|
-
}
|
|
839
|
-
this.assert_init();
|
|
840
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
841
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
842
|
-
}
|
|
843
|
-
try {
|
|
844
|
-
await this._col.deleteMany(typeof path === "object" ? path : { _path: path });
|
|
845
|
-
}
|
|
846
|
-
catch (error) {
|
|
847
|
-
console.error(error);
|
|
848
|
-
throw new Error('Encountered an error while deleting.');
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
async delete_many(query) {
|
|
852
|
-
if (!this.initialized) {
|
|
853
|
-
await this.init();
|
|
854
|
-
}
|
|
855
|
-
this.assert_init();
|
|
856
|
-
try {
|
|
857
|
-
await this._col.deleteMany(query);
|
|
858
|
-
}
|
|
859
|
-
catch (error) {
|
|
860
|
-
console.error(error);
|
|
861
|
-
throw new Error('Encountered an error while deleting.');
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
/* @docs:
|
|
865
|
-
* @title: Delete Collection
|
|
866
|
-
* @description: Delete all documents of from the collection.
|
|
867
|
-
*/
|
|
868
|
-
async delete_collection() {
|
|
869
|
-
if (!this.initialized) {
|
|
870
|
-
await this.init();
|
|
871
|
-
}
|
|
872
|
-
this.assert_init();
|
|
873
|
-
await this._col.deleteMany();
|
|
874
|
-
await this._col.drop();
|
|
875
|
-
}
|
|
876
|
-
/* @docs:
|
|
877
|
-
// * @title: Clean document
|
|
878
|
-
// * @description: Clean a document from all default system attributes.
|
|
879
|
-
// */
|
|
880
|
-
clean(doc) {
|
|
881
|
-
if (doc == null) {
|
|
882
|
-
return doc;
|
|
883
|
-
}
|
|
884
|
-
if (typeof doc === "object") {
|
|
885
|
-
delete doc._id;
|
|
886
|
-
delete doc._path;
|
|
887
|
-
if (this.ttl_enabled) {
|
|
888
|
-
delete doc._ttl_timestamp;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
return doc;
|
|
892
|
-
}
|
|
893
|
-
/** Write bulk operations. */
|
|
894
|
-
async bulk_operations(operations = []) {
|
|
895
|
-
if (!this.initialized) {
|
|
896
|
-
await this.init();
|
|
897
|
-
}
|
|
898
|
-
this.assert_init();
|
|
899
|
-
return await this._col.bulkWrite(operations, { ordered: true });
|
|
900
|
-
}
|
|
901
|
-
async aggregate(pipeline, opts) {
|
|
902
|
-
if (!this.initialized) {
|
|
903
|
-
await this.init();
|
|
904
|
-
}
|
|
905
|
-
this.assert_init();
|
|
906
|
-
const out = this._col.aggregate(pipeline);
|
|
907
|
-
if (opts?.cursor) {
|
|
908
|
-
return out;
|
|
909
|
-
}
|
|
910
|
-
const arr = await out.toArray();
|
|
911
|
-
if (opts?.clean === true) {
|
|
912
|
-
return arr.map((doc) => this.clean(doc)).filter((x) => x != null);
|
|
913
|
-
}
|
|
914
|
-
return arr;
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
// ---------------------------------------------------------
|
|
918
|
-
// UID based collection.
|
|
919
|
-
// @warning: The "path" param must always be allowed to be an object or string, also for the UIDCollection class.
|
|
920
|
-
// @warning: THE DATABASE COLLECTION SHOULD ALSO ACCEPT OBJECTS FOR PATHS.
|
|
921
|
-
/* @docs:
|
|
922
|
-
@nav: Backend
|
|
923
|
-
@chapter: Database
|
|
924
|
-
@title: UID Collection
|
|
925
|
-
@desc: The UID based database collection class.
|
|
926
|
-
@note: The document attribute `_uid` is a reserved index attribute for the user id of the document.
|
|
927
|
-
@note: The document attribute `_path` is a reserved index attribute for the path of the document.
|
|
928
|
-
@attribute:
|
|
929
|
-
@name: col
|
|
930
|
-
@desc: The native mongodb collection.
|
|
931
|
-
*/
|
|
932
|
-
// export class UIDCollection {
|
|
933
|
-
// private _col: Collection;
|
|
934
|
-
// col: MongoCollection;
|
|
935
|
-
// constructor(
|
|
936
|
-
// name: string,
|
|
937
|
-
// collection: MongoCollection,
|
|
938
|
-
// indexes: IndexOptions[] = [],
|
|
939
|
-
// ttl: number | null = null,
|
|
940
|
-
// ) {
|
|
941
|
-
// this._col = new Collection(name, collection, ttl, indexes, true);
|
|
942
|
-
// this.col = this._col.col;
|
|
943
|
-
// }
|
|
944
|
-
// /* @docs:
|
|
945
|
-
// @title: Create index
|
|
946
|
-
// @description: Creates indexes on collections.
|
|
947
|
-
// @return:
|
|
948
|
-
// Returns the document that was found or `null` when no document is found.
|
|
949
|
-
// @parameter:
|
|
950
|
-
// @name: keys
|
|
951
|
-
// @desc: The `keys` argument for the orignal mongodb `createIndex()` function.
|
|
952
|
-
// @parameter:
|
|
953
|
-
// @name: options
|
|
954
|
-
// @desc: The `options` argument for the orignal mongodb `createIndex()` function.
|
|
955
|
-
// @parameter:
|
|
956
|
-
// @name: commitQuorum
|
|
957
|
-
// @desc: The `commitQuorum` argument for the orignal mongodb `createIndex()` function.
|
|
958
|
-
// */
|
|
959
|
-
// async create_index(args: IndexOptions): Promise<string> {
|
|
960
|
-
// return this._col.create_index(args);
|
|
961
|
-
// }
|
|
962
|
-
// /* @docs:
|
|
963
|
-
// * @title: Find
|
|
964
|
-
// * @description: Find a document by a query.
|
|
965
|
-
// * @return:
|
|
966
|
-
// * Returns the document that was found or `null` when no document is found.
|
|
967
|
-
// * @parameter:
|
|
968
|
-
// * @name: uid
|
|
969
|
-
// * @cached: Users:uid:param
|
|
970
|
-
// * @required: false
|
|
971
|
-
// * @parameter:
|
|
972
|
-
// * @name: query
|
|
973
|
-
// * @desc: The query options.
|
|
974
|
-
// * @type: object
|
|
975
|
-
// */
|
|
976
|
-
// async find(uid: string | null = null, query: Record<string, any> = {}): Promise<any> {
|
|
977
|
-
// if (uid != null) {
|
|
978
|
-
// query._uid = uid;
|
|
979
|
-
// }
|
|
980
|
-
// return await this._col.find(query);
|
|
981
|
-
// }
|
|
982
|
-
// /* @docs:
|
|
983
|
-
// * @title: Exists
|
|
984
|
-
// * @description: Check if a document exists.
|
|
985
|
-
// * @parameter:
|
|
986
|
-
// * @name: uid
|
|
987
|
-
// * @cached: Users:uid:param
|
|
988
|
-
// * @parameter:
|
|
989
|
-
// * @name: path
|
|
990
|
-
// * @description: The database path to the document.
|
|
991
|
-
// * @type: string, object
|
|
992
|
-
// */
|
|
993
|
-
// async exists(uid: string, path: Query): Promise<boolean> {
|
|
994
|
-
// if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
995
|
-
// throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
996
|
-
// }
|
|
997
|
-
// if (typeof uid !== "string") {
|
|
998
|
-
// throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
999
|
-
// }
|
|
1000
|
-
// if (typeof path === "object") {
|
|
1001
|
-
// return await this._col.exists({...path, _uid: uid});
|
|
1002
|
-
// } else {
|
|
1003
|
-
// return await this._col.exists({_path: path, _uid: uid});
|
|
1004
|
-
// }
|
|
1005
|
-
// }
|
|
1006
|
-
// /* @docs:
|
|
1007
|
-
// * @title: Load
|
|
1008
|
-
// * @description: Load data by user id and path.
|
|
1009
|
-
// * @return:
|
|
1010
|
-
// * Returns the loaded document.
|
|
1011
|
-
// *
|
|
1012
|
-
// * Returns the `def` parameter when the data does not exist, keep in mind that when parameter `def` is an object it could be a reference to a defined variable.
|
|
1013
|
-
// * @parameter:
|
|
1014
|
-
// * @name: uid
|
|
1015
|
-
// * @cached: Users:uid:param
|
|
1016
|
-
// * @parameter:
|
|
1017
|
-
// * @name: path
|
|
1018
|
-
// * @description: The database path to the document.
|
|
1019
|
-
// * @type: string, object
|
|
1020
|
-
// * @parameter:
|
|
1021
|
-
// * @name: opts
|
|
1022
|
-
// * @desc: Additional options.
|
|
1023
|
-
// * @type: null, object
|
|
1024
|
-
// * @attribute:
|
|
1025
|
-
// * @name: default
|
|
1026
|
-
// * @description:
|
|
1027
|
-
// * The default data to be returned when the data does not exist.
|
|
1028
|
-
// *
|
|
1029
|
-
// * When the type of attribute `default` is `object` then the keys that do not exist in the loaded object, but do exist in the default object will be inserted into the loaded object.
|
|
1030
|
-
// * @type: null, object
|
|
1031
|
-
// */
|
|
1032
|
-
// async load(
|
|
1033
|
-
// uid: string,
|
|
1034
|
-
// path: Query,
|
|
1035
|
-
// opts: {
|
|
1036
|
-
// default?: any,
|
|
1037
|
-
// chunked?: boolean,
|
|
1038
|
-
// attributes?: string[],
|
|
1039
|
-
// projection?: Record<string, any>
|
|
1040
|
-
// } | null = null
|
|
1041
|
-
// ): Promise<any> {
|
|
1042
|
-
// if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
1043
|
-
// throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
1044
|
-
// }
|
|
1045
|
-
// if (typeof uid !== "string") {
|
|
1046
|
-
// throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
1047
|
-
// }
|
|
1048
|
-
// if (typeof path === "object") {
|
|
1049
|
-
// return await this._col.load({...path, _uid: uid}, opts);
|
|
1050
|
-
// } else {
|
|
1051
|
-
// return await this._col.load({_path: path, _uid: uid}, opts);
|
|
1052
|
-
// }
|
|
1053
|
-
// }
|
|
1054
|
-
// /* @docs:
|
|
1055
|
-
// * @title: Save
|
|
1056
|
-
// * @description: Save data by user id and path. When the document already exists this function only updates the specified content attributes.
|
|
1057
|
-
// * @return:
|
|
1058
|
-
// * Returns the updated document.
|
|
1059
|
-
// * @parameter:
|
|
1060
|
-
// * @name: uid
|
|
1061
|
-
// * @cached: Users:uid:param
|
|
1062
|
-
// * @parameter:
|
|
1063
|
-
// * @name: path
|
|
1064
|
-
// * @description: The database path to the document.
|
|
1065
|
-
// * @type: string, object
|
|
1066
|
-
// * @parameter:
|
|
1067
|
-
// * @name: data
|
|
1068
|
-
// * @description: The data to save.
|
|
1069
|
-
// * @type: null, boolean, number, string, array, object
|
|
1070
|
-
// * @parameter:
|
|
1071
|
-
// * @name: opts
|
|
1072
|
-
// * @desc: Additional options.
|
|
1073
|
-
// * @type: null, object
|
|
1074
|
-
// * @attribute:
|
|
1075
|
-
// * @name: chunked
|
|
1076
|
-
// * @description: Chunk the document into multiple documents, therefore documents larger than 16MB are supported.
|
|
1077
|
-
// * @warning: Currently this option is only supported for types `object` and `array`.
|
|
1078
|
-
// * @default: false
|
|
1079
|
-
// * @type: boolean
|
|
1080
|
-
// * @attribute:
|
|
1081
|
-
// * @name: bulk
|
|
1082
|
-
// * @description: Get a bulk operation object, so several operations can be executed in bulk.
|
|
1083
|
-
// * @default: false
|
|
1084
|
-
// * @type: boolean
|
|
1085
|
-
// * @attribute:
|
|
1086
|
-
// * @name: set
|
|
1087
|
-
// * @description: By default the $set attribute is used for the content, with `opts.set` disabled you can create your own instructions. The `content` attribute must reflect this.
|
|
1088
|
-
// * @warning: This does not work in combination with `opts.chunked`.
|
|
1089
|
-
// * @default: true
|
|
1090
|
-
// * @type: boolean
|
|
1091
|
-
// */
|
|
1092
|
-
// async save(
|
|
1093
|
-
// uid: string,
|
|
1094
|
-
// path: Query,
|
|
1095
|
-
// content: any,
|
|
1096
|
-
// opts: {
|
|
1097
|
-
// chunked?: boolean,
|
|
1098
|
-
// bulk?: boolean,
|
|
1099
|
-
// set?: boolean
|
|
1100
|
-
// } | null = null
|
|
1101
|
-
// ): Promise<any> {
|
|
1102
|
-
// if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
1103
|
-
// throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
1104
|
-
// }
|
|
1105
|
-
// if (typeof uid !== "string") {
|
|
1106
|
-
// throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
1107
|
-
// }
|
|
1108
|
-
// if (typeof path === "object") {
|
|
1109
|
-
// return await this._col.save({...path, _uid: uid}, content, opts);
|
|
1110
|
-
// } else {
|
|
1111
|
-
// return await this._col.save({_path: path, _uid: uid}, content, opts);
|
|
1112
|
-
// }
|
|
1113
|
-
// }
|
|
1114
|
-
// /** Update many. */
|
|
1115
|
-
// async update_many(...args: Parameters<typeof this.col.updateMany>): Promise<any> {
|
|
1116
|
-
// return this.col.updateMany(...args);
|
|
1117
|
-
// }
|
|
1118
|
-
// /* @docs:
|
|
1119
|
-
// * @title: List
|
|
1120
|
-
// * @description: List all child documents of directory path.
|
|
1121
|
-
// * @parameter:
|
|
1122
|
-
// * @name: uid
|
|
1123
|
-
// * @cached: Users:uid:param
|
|
1124
|
-
// * @parameter:
|
|
1125
|
-
// * @name: path
|
|
1126
|
-
// * @description: The database directory path.
|
|
1127
|
-
// * @type: string, object
|
|
1128
|
-
// * @parameter:
|
|
1129
|
-
// * @name: options
|
|
1130
|
-
// * @description: List options.
|
|
1131
|
-
// * @type: object
|
|
1132
|
-
// * @attribute:
|
|
1133
|
-
// * @name: process
|
|
1134
|
-
// * @description: Process the document. By default saved non object data will be stored under `_content`. Processing checks this attribute and uses that content instead when it is detected.
|
|
1135
|
-
// * @type: boolean
|
|
1136
|
-
// * @default: true
|
|
1137
|
-
// * @attribute:
|
|
1138
|
-
// * @name: projection
|
|
1139
|
-
// * @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
1140
|
-
// * @type: object
|
|
1141
|
-
// * @default: undefined
|
|
1142
|
-
// */
|
|
1143
|
-
// async list(
|
|
1144
|
-
// uid: string,
|
|
1145
|
-
// path: Query,
|
|
1146
|
-
// options: {
|
|
1147
|
-
// process?: boolean,
|
|
1148
|
-
// projection?: Record<string, any>
|
|
1149
|
-
// } = {}
|
|
1150
|
-
// ): Promise<any[]> {
|
|
1151
|
-
// if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
1152
|
-
// throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
1153
|
-
// }
|
|
1154
|
-
// if (typeof uid !== "string") {
|
|
1155
|
-
// throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
1156
|
-
// }
|
|
1157
|
-
// if (typeof path === "object") {
|
|
1158
|
-
// return await this._col.list({...path, _uid: uid}, options)
|
|
1159
|
-
// } else {
|
|
1160
|
-
// return await this._col.list({_path: path, _uid: uid}, options)
|
|
1161
|
-
// }
|
|
1162
|
-
// }
|
|
1163
|
-
// /* @docs:
|
|
1164
|
-
// * @title: List Query
|
|
1165
|
-
// * @description: List all documents of the collection based on a query.
|
|
1166
|
-
// * @parameter:
|
|
1167
|
-
// * @name: query
|
|
1168
|
-
// * @desc: The query options.
|
|
1169
|
-
// * @type: object
|
|
1170
|
-
// * @parameter:
|
|
1171
|
-
// * @name: options
|
|
1172
|
-
// * @description: List options.
|
|
1173
|
-
// * @type: object
|
|
1174
|
-
// * @attribute:
|
|
1175
|
-
// * @name: process
|
|
1176
|
-
// * @description: Process the document. By default saved non object data will be stored under `_content`. Processing checks this attribute and uses that content instead when it is detected.
|
|
1177
|
-
// * @type: boolean
|
|
1178
|
-
// * @default: true
|
|
1179
|
-
// * @attribute:
|
|
1180
|
-
// * @name: projection
|
|
1181
|
-
// * @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
1182
|
-
// * @type: object
|
|
1183
|
-
// * @default: undefined
|
|
1184
|
-
// */
|
|
1185
|
-
// async list_query(
|
|
1186
|
-
// query: Record<string, any> = {},
|
|
1187
|
-
// options: {
|
|
1188
|
-
// process?: boolean,
|
|
1189
|
-
// projection?: Record<string, any>
|
|
1190
|
-
// } = {}
|
|
1191
|
-
// ): Promise<any[]> {
|
|
1192
|
-
// return await this._col.list_query(query, options);
|
|
1193
|
-
// }
|
|
1194
|
-
// /* @docs:
|
|
1195
|
-
// * @title: List All
|
|
1196
|
-
// * @description: List all documents of the collection, optionally per uid.
|
|
1197
|
-
// * @parameter:
|
|
1198
|
-
// * @name: uid
|
|
1199
|
-
// * @cached: Users:uid:param
|
|
1200
|
-
// * @parameter:
|
|
1201
|
-
// * @name: options
|
|
1202
|
-
// * @description: List options.
|
|
1203
|
-
// * @type: object
|
|
1204
|
-
// * @attribute:
|
|
1205
|
-
// * @name: process
|
|
1206
|
-
// * @description: Process the document. By default saved non object data will be stored under `_content`. Processing checks this attribute and uses that content instead when it is detected.
|
|
1207
|
-
// * @type: boolean
|
|
1208
|
-
// * @default: true
|
|
1209
|
-
// * @attribute:
|
|
1210
|
-
// * @name: projection
|
|
1211
|
-
// * @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
1212
|
-
// * @type: object
|
|
1213
|
-
// * @default: undefined
|
|
1214
|
-
// */
|
|
1215
|
-
// async list_all(
|
|
1216
|
-
// uid: string | null = null,
|
|
1217
|
-
// options: {
|
|
1218
|
-
// process?: boolean,
|
|
1219
|
-
// projection?: Record<string, any>
|
|
1220
|
-
// } = {}
|
|
1221
|
-
// ): Promise<any[]> {
|
|
1222
|
-
// if (uid == null) {
|
|
1223
|
-
// return await this._col.list_all({}, options)
|
|
1224
|
-
// } else {
|
|
1225
|
-
// return await this._col.list_all({_uid: uid}, options);
|
|
1226
|
-
// }
|
|
1227
|
-
// }
|
|
1228
|
-
// /* @docs:
|
|
1229
|
-
// * @title: Delete
|
|
1230
|
-
// * @description: Delete a document of the collection by uid and path.
|
|
1231
|
-
// * @parameter:
|
|
1232
|
-
// * @name: uid
|
|
1233
|
-
// * @cached: Users:uid:param
|
|
1234
|
-
// * @parameter:
|
|
1235
|
-
// * @name: path
|
|
1236
|
-
// * @description: The database path to the document.
|
|
1237
|
-
// * @type: string, object
|
|
1238
|
-
// * @parameter:
|
|
1239
|
-
// * @name: opts
|
|
1240
|
-
// * @desc: Additional options.
|
|
1241
|
-
// * @type: null, object
|
|
1242
|
-
// * @attribute:
|
|
1243
|
-
// * @name: chunked
|
|
1244
|
-
// * @description: Delete a chunked document.
|
|
1245
|
-
// * @default: false
|
|
1246
|
-
// * @type: boolean
|
|
1247
|
-
// * @attribute:
|
|
1248
|
-
// * @name: bulk
|
|
1249
|
-
// * @description: Get a bulk operation object, so several operations can be executed in bulk.
|
|
1250
|
-
// * @default: false
|
|
1251
|
-
// * @type: boolean
|
|
1252
|
-
// */
|
|
1253
|
-
// async delete(
|
|
1254
|
-
// uid: string,
|
|
1255
|
-
// path: Query,
|
|
1256
|
-
// opts?: {
|
|
1257
|
-
// chunked?: boolean,
|
|
1258
|
-
// bulk?: boolean
|
|
1259
|
-
// }
|
|
1260
|
-
// ): Promise<any> {
|
|
1261
|
-
// if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
1262
|
-
// throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
1263
|
-
// }
|
|
1264
|
-
// if (typeof uid !== "string") {
|
|
1265
|
-
// throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
1266
|
-
// }
|
|
1267
|
-
// if (typeof path === "object") {
|
|
1268
|
-
// return await this._col.delete({...path, _uid: uid}, opts)
|
|
1269
|
-
// } else {
|
|
1270
|
-
// return await this._col.delete({_path: path, _uid: uid}, opts)
|
|
1271
|
-
// }
|
|
1272
|
-
// }
|
|
1273
|
-
// /* @docs:
|
|
1274
|
-
// * @title: Delete Query
|
|
1275
|
-
// * @description: Delete a document of the collection by query.
|
|
1276
|
-
// * @parameter:
|
|
1277
|
-
// * @name: query
|
|
1278
|
-
// * @description: The query object.
|
|
1279
|
-
// * @type: object
|
|
1280
|
-
// */
|
|
1281
|
-
// async delete_query(query: Record<string, any>): Promise<any> {
|
|
1282
|
-
// if (typeof query !== "object" || query == null || Object.keys(query).length === 0) {
|
|
1283
|
-
// throw Error(`Parameter "query" has an invalid type "${typeof query}", the valid type is "object".`);
|
|
1284
|
-
// }
|
|
1285
|
-
// if (Object.keys(query).length === 0) {
|
|
1286
|
-
// throw Error(`Parameter "query" is an empty object.`);
|
|
1287
|
-
// }
|
|
1288
|
-
// return await this._col.delete_query(query)
|
|
1289
|
-
// }
|
|
1290
|
-
// // Delete all.
|
|
1291
|
-
// async delete_all(
|
|
1292
|
-
// uid: string,
|
|
1293
|
-
// path: Query | null = null
|
|
1294
|
-
// ): Promise<void> {
|
|
1295
|
-
// if (typeof uid !== "string") {
|
|
1296
|
-
// throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
1297
|
-
// }
|
|
1298
|
-
// if (path == null) {
|
|
1299
|
-
// return await this._col.delete_all({_uid: uid})
|
|
1300
|
-
// }
|
|
1301
|
-
// else if (typeof path === "object") {
|
|
1302
|
-
// return await this._col.delete_all({...path, _uid: uid})
|
|
1303
|
-
// } else {
|
|
1304
|
-
// return await this._col.delete_all({_path: path, _uid: uid})
|
|
1305
|
-
// }
|
|
1306
|
-
// }
|
|
1307
|
-
// async delete_many(query: Record<string, any>): Promise<void> {
|
|
1308
|
-
// return await this._col.delete_many(query)
|
|
1309
|
-
// }
|
|
1310
|
-
// /* @docs:
|
|
1311
|
-
// * @title: Delete Collection
|
|
1312
|
-
// * @description: Delete all documents of from the collection.
|
|
1313
|
-
// */
|
|
1314
|
-
// async delete_collection(): Promise<void> {
|
|
1315
|
-
// await this._col.delete_collection()
|
|
1316
|
-
// }
|
|
1317
|
-
// /* @docs:
|
|
1318
|
-
// * @title: Clean document
|
|
1319
|
-
// * @description: Clean a document from all default system attributes.
|
|
1320
|
-
// */
|
|
1321
|
-
// clean<T>(doc: T): T | null {
|
|
1322
|
-
// return this._col.clean(doc);
|
|
1323
|
-
// }
|
|
1324
|
-
// /** Write bulk operations. */
|
|
1325
|
-
// async bulk_operations(operations: any[] = []): Promise<any> {
|
|
1326
|
-
// return await this.col.bulkWrite(operations, {ordered: true});
|
|
1327
|
-
// }
|
|
1328
|
-
// }
|