@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,2248 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var stdin_exports = {};
|
|
19
|
-
__export(stdin_exports, {
|
|
20
|
-
Collection: () => Collection,
|
|
21
|
-
Database: () => Database,
|
|
22
|
-
DocumentRef: () => DocumentRef,
|
|
23
|
-
UIDCollection: () => UIDCollection,
|
|
24
|
-
UIDDocument: () => UIDDocument
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(stdin_exports);
|
|
27
|
-
var import_child_process = require("child_process");
|
|
28
|
-
var import_bson = require("bson");
|
|
29
|
-
var import_mongodb = require("mongodb");
|
|
30
|
-
var import_logger = require("./logger.js");
|
|
31
|
-
var import_status = require("./status.js");
|
|
32
|
-
var import_vinc = require("./vinc.js");
|
|
33
|
-
var import_utils = require("./utils.js");
|
|
34
|
-
const { log, debug } = import_logger.logger.loggers();
|
|
35
|
-
class Collection {
|
|
36
|
-
// Static attributes.
|
|
37
|
-
static chunk_size = 1024 * 1024 * 4;
|
|
38
|
-
// 4MB chunks, lower is better for frequent updates.
|
|
39
|
-
static constructor_scheme = {
|
|
40
|
-
name: "string",
|
|
41
|
-
uid_based: "boolean",
|
|
42
|
-
ttl: { type: "number", default: null },
|
|
43
|
-
// ttl in msec
|
|
44
|
-
indexes: {
|
|
45
|
-
type: "array",
|
|
46
|
-
default: [],
|
|
47
|
-
value_scheme: {
|
|
48
|
-
type: ["string", "object"],
|
|
49
|
-
scheme: {
|
|
50
|
-
key: { type: "string", required: (data) => data.key == null && data.keys == null },
|
|
51
|
-
keys: {
|
|
52
|
-
type: ["array"],
|
|
53
|
-
required: (data) => data.key == null && data.keys == null,
|
|
54
|
-
value_scheme: "string",
|
|
55
|
-
postprocess: (keys) => typeof keys === "string" ? [keys] : keys
|
|
56
|
-
},
|
|
57
|
-
options: { type: "object", required: false },
|
|
58
|
-
commit_quorom: { type: "object", required: false },
|
|
59
|
-
forced: { type: "boolean", default: false }
|
|
60
|
-
},
|
|
61
|
-
postprocess: (info) => {
|
|
62
|
-
if (typeof info === "string")
|
|
63
|
-
return { keys: [info] };
|
|
64
|
-
return info;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
// Instance attributes
|
|
70
|
-
col;
|
|
71
|
-
name;
|
|
72
|
-
uid_based;
|
|
73
|
-
ttl;
|
|
74
|
-
// ttl in msec
|
|
75
|
-
ttl_enabled;
|
|
76
|
-
constructor(name, collection, ttl = null, indexes = [], uid_based = false) {
|
|
77
|
-
({ indexes, ttl } = import_vinc.vlib.Scheme.verify({
|
|
78
|
-
object: {
|
|
79
|
-
name,
|
|
80
|
-
indexes,
|
|
81
|
-
ttl,
|
|
82
|
-
uid_based
|
|
83
|
-
},
|
|
84
|
-
check_unknown: true,
|
|
85
|
-
scheme: Collection.constructor_scheme
|
|
86
|
-
}));
|
|
87
|
-
this.name = name;
|
|
88
|
-
this.col = collection;
|
|
89
|
-
this.uid_based = uid_based;
|
|
90
|
-
this.ttl = ttl;
|
|
91
|
-
this.ttl_enabled = typeof ttl === "number";
|
|
92
|
-
if (uid_based) {
|
|
93
|
-
this.col.createIndex({ _path: 1, _uid: 1 });
|
|
94
|
-
} else {
|
|
95
|
-
this.col.createIndex({ _path: 1 });
|
|
96
|
-
}
|
|
97
|
-
if (this.ttl_enabled) {
|
|
98
|
-
this.col.dropIndex("_ttl_timestamp_1").catch((err) => {
|
|
99
|
-
if (err.codeName !== "IndexNotFound" && err.codeName !== "NamespaceNotFound") {
|
|
100
|
-
err.stack = new Error(err.message).stack;
|
|
101
|
-
throw err;
|
|
102
|
-
}
|
|
103
|
-
}).then(() => {
|
|
104
|
-
this.col.createIndex({ _ttl_timestamp: 1 }, { expireAfterSeconds: parseInt(String(this.ttl / 1e3)) });
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
if (Array.isArray(indexes) && indexes.length > 0) {
|
|
108
|
-
for (let item of indexes) {
|
|
109
|
-
this.create_index(item);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// Handle file response.
|
|
114
|
-
_process_doc(doc) {
|
|
115
|
-
if (doc == null) {
|
|
116
|
-
return null;
|
|
117
|
-
} else if (doc._content != null) {
|
|
118
|
-
return doc._content;
|
|
119
|
-
}
|
|
120
|
-
return doc;
|
|
121
|
-
}
|
|
122
|
-
// Chunked methods.
|
|
123
|
-
async _load_chunked(path, find_opts) {
|
|
124
|
-
let query = typeof path === "string" ? { _path: path, chunk: { $gte: 0 } } : { ...path, chunk: { $gte: 0 } };
|
|
125
|
-
const chunks_cursor = this.col.find(query, find_opts).sort({ chunk: 1 });
|
|
126
|
-
const chunks = await chunks_cursor.toArray();
|
|
127
|
-
if (chunks.length === 0) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
const buffer = Buffer.concat(chunks.map((chunk) => chunk.data.buffer));
|
|
131
|
-
return (0, import_bson.deserialize)(buffer);
|
|
132
|
-
}
|
|
133
|
-
async _save_chunked(path, content) {
|
|
134
|
-
const buffer = (0, import_bson.serialize)(content);
|
|
135
|
-
const new_chunk_count = Math.ceil(buffer.length / Collection.chunk_size);
|
|
136
|
-
const ref_query = typeof path === "string" ? { _path: path, chunk: -1 } : { ...path, chunk: -1 };
|
|
137
|
-
const object_ref = await this.col.findOne(ref_query);
|
|
138
|
-
const old_chunk_count = object_ref ? object_ref.chunks : 0;
|
|
139
|
-
const bulk_ops = [];
|
|
140
|
-
for (let i = 0; i < buffer.length; i += Collection.chunk_size) {
|
|
141
|
-
let query, update;
|
|
142
|
-
if (typeof path === "string") {
|
|
143
|
-
query = {
|
|
144
|
-
_path: path,
|
|
145
|
-
chunk: i / Collection.chunk_size
|
|
146
|
-
};
|
|
147
|
-
update = {
|
|
148
|
-
chunk: i / Collection.chunk_size,
|
|
149
|
-
data: buffer.slice(i, i + Collection.chunk_size)
|
|
150
|
-
};
|
|
151
|
-
} else {
|
|
152
|
-
query = {
|
|
153
|
-
...path,
|
|
154
|
-
chunk: i / Collection.chunk_size
|
|
155
|
-
};
|
|
156
|
-
update = {
|
|
157
|
-
chunk: i / Collection.chunk_size,
|
|
158
|
-
data: buffer.slice(i, i + Collection.chunk_size)
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
const full_update2 = {
|
|
162
|
-
$set: update
|
|
163
|
-
};
|
|
164
|
-
if (this.ttl_enabled) {
|
|
165
|
-
full_update2["$setOnInsert"] = { _ttl_timestamp: /* @__PURE__ */ new Date() };
|
|
166
|
-
}
|
|
167
|
-
bulk_ops.push({
|
|
168
|
-
updateOne: {
|
|
169
|
-
filter: query,
|
|
170
|
-
update: full_update2,
|
|
171
|
-
upsert: true
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
const full_update = {
|
|
176
|
-
$set: {
|
|
177
|
-
chunk: -1,
|
|
178
|
-
chunks: new_chunk_count
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
if (this.ttl_enabled) {
|
|
182
|
-
full_update["$setOnInsert"] = { _ttl_timestamp: /* @__PURE__ */ new Date() };
|
|
183
|
-
}
|
|
184
|
-
bulk_ops.push({
|
|
185
|
-
updateOne: {
|
|
186
|
-
filter: ref_query,
|
|
187
|
-
update: full_update,
|
|
188
|
-
upsert: true
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
await this.col.bulkWrite(bulk_ops, { ordered: true });
|
|
192
|
-
if (new_chunk_count < old_chunk_count) {
|
|
193
|
-
ref_query.chunk = { $gte: new_chunk_count };
|
|
194
|
-
await this.col.deleteMany(ref_query);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
/* @docs:
|
|
198
|
-
@title: Create index
|
|
199
|
-
@description: Creates indexes on collections.
|
|
200
|
-
@return:
|
|
201
|
-
Returns the document that was found or `null` when no document is found.
|
|
202
|
-
@parameter:
|
|
203
|
-
@name: keys
|
|
204
|
-
@desc: The `keys` argument for the orignal mongodb `createIndex()` function.
|
|
205
|
-
@parameter:
|
|
206
|
-
@name: options
|
|
207
|
-
@desc: The `options` argument for the orignal mongodb `createIndex()` function.
|
|
208
|
-
@parameter:
|
|
209
|
-
@name: commitQuorum
|
|
210
|
-
@desc: The `commitQuorum` argument for the orignal mongodb `createIndex()` function.
|
|
211
|
-
*/
|
|
212
|
-
async create_index({
|
|
213
|
-
key = void 0,
|
|
214
|
-
keys = void 0,
|
|
215
|
-
// following the IndexOptions "key" or "keys" must be defined in typescript but not in raw js.
|
|
216
|
-
options = void 0,
|
|
217
|
-
commit_quorum = void 0,
|
|
218
|
-
forced = false
|
|
219
|
-
}) {
|
|
220
|
-
let keys_obj = {};
|
|
221
|
-
if (key) {
|
|
222
|
-
keys_obj = {};
|
|
223
|
-
keys_obj[key] = 1;
|
|
224
|
-
} else if (Array.isArray(keys) && keys.length > 0) {
|
|
225
|
-
keys_obj = {};
|
|
226
|
-
for (const key2 of keys) {
|
|
227
|
-
keys_obj[key2] = 1;
|
|
228
|
-
}
|
|
229
|
-
} else {
|
|
230
|
-
throw new Error("Define one of the following parameters: [key, keys].");
|
|
231
|
-
}
|
|
232
|
-
if (forced) {
|
|
233
|
-
try {
|
|
234
|
-
await this.col.dropIndex(options?.name ?? Object.entries(keys_obj).map(([key2, value]) => `${key2}_${value}`).join("_"));
|
|
235
|
-
} catch (err) {
|
|
236
|
-
if (err.codeName !== "IndexNotFound") {
|
|
237
|
-
throw err;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return await this.col.createIndex(keys_obj, options || {}, commit_quorum);
|
|
242
|
-
}
|
|
243
|
-
/* @docs:
|
|
244
|
-
* @title: Find
|
|
245
|
-
* @description: Find a document by a query.
|
|
246
|
-
* @return:
|
|
247
|
-
* Returns the document that was found or `null` when no document is found.
|
|
248
|
-
* @parameter:
|
|
249
|
-
* @name: query
|
|
250
|
-
* @desc: The query options.
|
|
251
|
-
* @type: object
|
|
252
|
-
*/
|
|
253
|
-
async find(query) {
|
|
254
|
-
try {
|
|
255
|
-
return this._process_doc(await this.col.findOne(query));
|
|
256
|
-
} catch (error) {
|
|
257
|
-
console.error(error);
|
|
258
|
-
throw new Error("Encountered an error while finding the document.");
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
/* @docs:
|
|
262
|
-
* @title: Exists
|
|
263
|
-
* @description: Check if a document exists.
|
|
264
|
-
* @parameter:
|
|
265
|
-
* @name: path
|
|
266
|
-
* @description: The database path to the document.
|
|
267
|
-
* @type: string
|
|
268
|
-
*/
|
|
269
|
-
async exists(path) {
|
|
270
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
271
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
272
|
-
}
|
|
273
|
-
try {
|
|
274
|
-
const doc = await this.col.findOne(typeof path === "object" ? path : { _path: path }, { projection: { _id: 1 } });
|
|
275
|
-
return doc != null;
|
|
276
|
-
} catch (error) {
|
|
277
|
-
console.error(error);
|
|
278
|
-
throw new Error("Encountered an error while checking if the document exists.");
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
/* @docs:
|
|
282
|
-
* @title: Load
|
|
283
|
-
* @description: Load data by path.
|
|
284
|
-
* @return:
|
|
285
|
-
* Returns the loaded document.
|
|
286
|
-
*
|
|
287
|
-
* 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.
|
|
288
|
-
* @parameter:
|
|
289
|
-
* @name: path
|
|
290
|
-
* @description: The database path to the document.
|
|
291
|
-
* @type: string
|
|
292
|
-
* @parameter:
|
|
293
|
-
* @name: opts
|
|
294
|
-
* @desc: Additional options.
|
|
295
|
-
* @type: null, object
|
|
296
|
-
* @attribute:
|
|
297
|
-
* @name: default
|
|
298
|
-
* @description:
|
|
299
|
-
* The default data to be returned when the data does not exist.
|
|
300
|
-
*
|
|
301
|
-
* 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.
|
|
302
|
-
* @type: null, object
|
|
303
|
-
* @attribute:
|
|
304
|
-
* @name: chunked
|
|
305
|
-
* @description: Load a chunked document.
|
|
306
|
-
* @type: null, object
|
|
307
|
-
* @attribute:
|
|
308
|
-
* @name: attributes
|
|
309
|
-
* @description: The attributes to load.
|
|
310
|
-
* @type: null, string[]
|
|
311
|
-
*/
|
|
312
|
-
async load(path, opts = null) {
|
|
313
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
314
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
315
|
-
}
|
|
316
|
-
if (opts && opts.projection && opts.chunked) {
|
|
317
|
-
throw new Error("The `projection` and `chunked` options cannot be used together.");
|
|
318
|
-
}
|
|
319
|
-
try {
|
|
320
|
-
let find_opts;
|
|
321
|
-
if (opts) {
|
|
322
|
-
if (opts.projection) {
|
|
323
|
-
find_opts = { projection: opts.projection };
|
|
324
|
-
} else if (opts.attributes) {
|
|
325
|
-
find_opts = { projection: {
|
|
326
|
-
_id: 1,
|
|
327
|
-
_path: 1,
|
|
328
|
-
_uid: 1
|
|
329
|
-
} };
|
|
330
|
-
opts.attributes.forEach((i) => {
|
|
331
|
-
if (find_opts?.projection) {
|
|
332
|
-
find_opts.projection[i] = 1;
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
let doc;
|
|
338
|
-
if (opts != null && opts.chunked === true) {
|
|
339
|
-
doc = await this._load_chunked(path, find_opts);
|
|
340
|
-
} else {
|
|
341
|
-
doc = await this.col.findOne(typeof path === "object" ? path : { _path: path }, find_opts);
|
|
342
|
-
this.clean(doc);
|
|
343
|
-
}
|
|
344
|
-
doc = this._process_doc(doc);
|
|
345
|
-
if (doc == null) {
|
|
346
|
-
if (opts != null && opts.default !== void 0) {
|
|
347
|
-
return opts.default;
|
|
348
|
-
}
|
|
349
|
-
return null;
|
|
350
|
-
} else if (opts != null && typeof opts.default === "object" && opts.default != null && Array.isArray(opts.default) === false) {
|
|
351
|
-
const set_defaults = (obj, defaults) => {
|
|
352
|
-
Object.keys(defaults).forEach((key) => {
|
|
353
|
-
if (obj[key] === void 0) {
|
|
354
|
-
obj[key] = defaults[key];
|
|
355
|
-
} else if (typeof obj[key] === "object" && !Array.isArray(obj[key]) && obj[key] != null && typeof defaults[key] === "object" && !Array.isArray(defaults[key]) && defaults[key] != null) {
|
|
356
|
-
set_defaults(obj[key], defaults[key]);
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
};
|
|
360
|
-
set_defaults(doc, opts.default);
|
|
361
|
-
}
|
|
362
|
-
return doc;
|
|
363
|
-
} catch (error) {
|
|
364
|
-
console.error(error);
|
|
365
|
-
throw new Error("Encountered an error while loading the document.");
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
/* @docs:
|
|
369
|
-
* @title: Save
|
|
370
|
-
* @description: Save data by path. When the document already exists this function only updates the specified content attributes.
|
|
371
|
-
* @return:
|
|
372
|
-
* Returns the updated document.
|
|
373
|
-
* @parameter:
|
|
374
|
-
* @name: path
|
|
375
|
-
* @description: The database path to the document.
|
|
376
|
-
* @type: string
|
|
377
|
-
* @parameter:
|
|
378
|
-
* @name: data
|
|
379
|
-
* @description: The data to save.
|
|
380
|
-
* @type: null, boolean, number, string, array, object
|
|
381
|
-
* @parameter:
|
|
382
|
-
* @name: opts
|
|
383
|
-
* @desc: Additional options.
|
|
384
|
-
* @type: null, object
|
|
385
|
-
* @attribute:
|
|
386
|
-
* @name: chunked
|
|
387
|
-
* @description: Chunk the document into multiple documents, therefore documents larger than 16MB are supported.
|
|
388
|
-
* @warning: Currently this option is only supported for types `object` and `array`.
|
|
389
|
-
* @default: false
|
|
390
|
-
* @type: boolean
|
|
391
|
-
* @attribute:
|
|
392
|
-
* @name: bulk
|
|
393
|
-
* @description: Get a bulk operation object, so several operations can be executed in bulk.
|
|
394
|
-
* @default: false
|
|
395
|
-
* @type: boolean
|
|
396
|
-
* @attribute:
|
|
397
|
-
* @name: set
|
|
398
|
-
* @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.
|
|
399
|
-
* @warning: This does not work in combination with `opts.chunked`.
|
|
400
|
-
* @default: true
|
|
401
|
-
* @type: boolean
|
|
402
|
-
*/
|
|
403
|
-
async save(path, content, opts = null) {
|
|
404
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
405
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
406
|
-
}
|
|
407
|
-
try {
|
|
408
|
-
let doc, set;
|
|
409
|
-
if (typeof content === "object" && Array.isArray(content) == false && content != null) {
|
|
410
|
-
delete content._id;
|
|
411
|
-
delete content._path;
|
|
412
|
-
delete content._uid;
|
|
413
|
-
delete content._ttl_timestamp;
|
|
414
|
-
set = content;
|
|
415
|
-
} else {
|
|
416
|
-
set = { _content: content };
|
|
417
|
-
}
|
|
418
|
-
if (opts != null && opts.chunked === true) {
|
|
419
|
-
await this._save_chunked(path, set);
|
|
420
|
-
} else {
|
|
421
|
-
if (opts == null || opts.set !== false) {
|
|
422
|
-
set = { $set: set };
|
|
423
|
-
}
|
|
424
|
-
if (this.ttl_enabled) {
|
|
425
|
-
if (set["$setOnInsert"] === void 0) {
|
|
426
|
-
set["$setOnInsert"] = {};
|
|
427
|
-
set["$setOnInsert"]._ttl_timestamp = /* @__PURE__ */ new Date();
|
|
428
|
-
} else if (set["$setOnInsert"] != null && typeof set["$setOnInsert"] === "object") {
|
|
429
|
-
set["$setOnInsert"]._ttl_timestamp = /* @__PURE__ */ new Date();
|
|
430
|
-
} else {
|
|
431
|
-
throw new Error(`Undefined behaviour: Unable to assign the $setOnInsert data for ttl control.`);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
if (opts != null && opts.bulk) {
|
|
435
|
-
return {
|
|
436
|
-
updateOne: {
|
|
437
|
-
filter: typeof path === "object" ? path : { _path: path },
|
|
438
|
-
update: set,
|
|
439
|
-
upsert: true
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
} else {
|
|
443
|
-
await this.col.updateOne(typeof path === "object" ? path : { _path: path }, set, { upsert: true });
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
return content;
|
|
447
|
-
} catch (error) {
|
|
448
|
-
console.error(error);
|
|
449
|
-
throw new Error("Encountered an error while updating the document.");
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
/** Update many. */
|
|
453
|
-
async update_many(...args) {
|
|
454
|
-
return this.col.updateMany(...args);
|
|
455
|
-
}
|
|
456
|
-
// List.
|
|
457
|
-
/* @docs:
|
|
458
|
-
* @title: List
|
|
459
|
-
* @description: List all child documents of directory path.
|
|
460
|
-
* @parameter:
|
|
461
|
-
* @name: path
|
|
462
|
-
* @description: The database directory path.
|
|
463
|
-
* @type: string
|
|
464
|
-
* @parameter:
|
|
465
|
-
* @name: options
|
|
466
|
-
* @description: List options.
|
|
467
|
-
* @type: object
|
|
468
|
-
* @attribute:
|
|
469
|
-
* @name: process
|
|
470
|
-
* @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.
|
|
471
|
-
* @type: boolean
|
|
472
|
-
* @default: true
|
|
473
|
-
* @attribute:
|
|
474
|
-
* @name: projection
|
|
475
|
-
* @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
476
|
-
* @type: object
|
|
477
|
-
* @default: undefined
|
|
478
|
-
*/
|
|
479
|
-
async list(path, options = {}) {
|
|
480
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
481
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
482
|
-
}
|
|
483
|
-
if (typeof path === "string") {
|
|
484
|
-
while (path.length > 0 && path.charAt(path.length - 1) === "/") {
|
|
485
|
-
path = path.substr(0, path.length - 1);
|
|
486
|
-
}
|
|
487
|
-
if (path.length == 0) {
|
|
488
|
-
throw Error("Invalid path.");
|
|
489
|
-
}
|
|
490
|
-
path = { _path: { $regex: `^${path}/` } };
|
|
491
|
-
} else if (path._path) {
|
|
492
|
-
let _path = path._path;
|
|
493
|
-
while (_path.length > 0 && _path.charAt(_path.length - 1) === "/") {
|
|
494
|
-
_path = _path.substr(0, _path.length - 1);
|
|
495
|
-
}
|
|
496
|
-
if (_path.length == 0) {
|
|
497
|
-
throw Error("Invalid path.");
|
|
498
|
-
}
|
|
499
|
-
path._path = { $regex: `^${_path}/` };
|
|
500
|
-
}
|
|
501
|
-
try {
|
|
502
|
-
const docs = await this.col.find(path, { projection: options.projection }).toArray();
|
|
503
|
-
if (options.process === false) {
|
|
504
|
-
return docs;
|
|
505
|
-
}
|
|
506
|
-
return docs.map((doc) => this._process_doc(doc));
|
|
507
|
-
} catch (error) {
|
|
508
|
-
console.error(error);
|
|
509
|
-
throw new Error("Encountered an error while listing all documents.");
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
/* @docs:
|
|
513
|
-
* @title: List Query
|
|
514
|
-
* @description: List all documents of the collection based on a query.
|
|
515
|
-
* @parameter:
|
|
516
|
-
* @name: query
|
|
517
|
-
* @desc: The query options.
|
|
518
|
-
* @type: object
|
|
519
|
-
* @parameter:
|
|
520
|
-
* @name: options
|
|
521
|
-
* @description: List options.
|
|
522
|
-
* @type: object
|
|
523
|
-
* @attribute:
|
|
524
|
-
* @name: process
|
|
525
|
-
* @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.
|
|
526
|
-
* @type: boolean
|
|
527
|
-
* @default: true
|
|
528
|
-
* @attribute:
|
|
529
|
-
* @name: projection
|
|
530
|
-
* @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
531
|
-
* @type: object
|
|
532
|
-
* @default: undefined
|
|
533
|
-
*/
|
|
534
|
-
async list_query(query = {}, options = {}) {
|
|
535
|
-
try {
|
|
536
|
-
const docs = await this.col.find(query, { projection: options.projection }).toArray();
|
|
537
|
-
if (options.process === false) {
|
|
538
|
-
return docs;
|
|
539
|
-
}
|
|
540
|
-
return docs.map((doc) => this._process_doc(doc));
|
|
541
|
-
} catch (error) {
|
|
542
|
-
console.error(error);
|
|
543
|
-
throw new Error("Encountered an error while listing all documents.");
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
/* @docs:
|
|
547
|
-
* @title: List All
|
|
548
|
-
* @description: List all documents of the collection, optionally per uid.
|
|
549
|
-
* @parameter:
|
|
550
|
-
* @name: query
|
|
551
|
-
* @ignore: true
|
|
552
|
-
* @parameter:
|
|
553
|
-
* @name: options
|
|
554
|
-
* @description: List options.
|
|
555
|
-
* @type: object
|
|
556
|
-
* @attribute:
|
|
557
|
-
* @name: process
|
|
558
|
-
* @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.
|
|
559
|
-
* @type: boolean
|
|
560
|
-
* @default: true
|
|
561
|
-
* @attribute:
|
|
562
|
-
* @name: projection
|
|
563
|
-
* @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
564
|
-
* @type: object
|
|
565
|
-
* @default: undefined
|
|
566
|
-
*/
|
|
567
|
-
async list_all(query = {}, options = {}) {
|
|
568
|
-
let docs;
|
|
569
|
-
if (this.uid_based) {
|
|
570
|
-
docs = await this.col.find(query, { projection: options.projection }).toArray();
|
|
571
|
-
} else {
|
|
572
|
-
docs = await this.col.find(query, { projection: options.projection }).toArray();
|
|
573
|
-
}
|
|
574
|
-
if (options.process === false) {
|
|
575
|
-
return docs;
|
|
576
|
-
}
|
|
577
|
-
return docs.map((doc) => this._process_doc(doc));
|
|
578
|
-
}
|
|
579
|
-
/* @docs:
|
|
580
|
-
* @title: Delete
|
|
581
|
-
* @description: Delete a document of the collection by path.
|
|
582
|
-
* @parameter:
|
|
583
|
-
* @name: path
|
|
584
|
-
* @description: The database path to the document.
|
|
585
|
-
* @type: string
|
|
586
|
-
* @parameter:
|
|
587
|
-
* @name: opts
|
|
588
|
-
* @desc: Additional options.
|
|
589
|
-
* @type: null, object
|
|
590
|
-
* @attribute:
|
|
591
|
-
* @name: chunked
|
|
592
|
-
* @description: Delete a chunked document.
|
|
593
|
-
* @default: false
|
|
594
|
-
* @type: boolean
|
|
595
|
-
* @attribute:
|
|
596
|
-
* @name: bulk
|
|
597
|
-
* @description: Get a bulk operation object, so several operations can be executed in bulk.
|
|
598
|
-
* @default: false
|
|
599
|
-
* @type: boolean
|
|
600
|
-
*/
|
|
601
|
-
async delete(path, opts) {
|
|
602
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
603
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
604
|
-
}
|
|
605
|
-
try {
|
|
606
|
-
if (opts != null && opts.chunked === true) {
|
|
607
|
-
if (opts.bulk) {
|
|
608
|
-
return { deleteMany: { filter: typeof path === "object" ? path : { _path: path } } };
|
|
609
|
-
} else {
|
|
610
|
-
await this.col.deleteMany(typeof path === "object" ? path : { _path: path });
|
|
611
|
-
}
|
|
612
|
-
} else {
|
|
613
|
-
if (opts != null && opts.bulk) {
|
|
614
|
-
return { deleteOne: { filter: typeof path === "object" ? path : { _path: path } } };
|
|
615
|
-
} else {
|
|
616
|
-
await this.col.deleteOne(typeof path === "object" ? path : { _path: path });
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
} catch (error) {
|
|
620
|
-
console.error(error);
|
|
621
|
-
throw new Error("Encountered an error while deleting.");
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
/* @docs:
|
|
625
|
-
* @title: Delete Query
|
|
626
|
-
* @description: Delete a document of the collection by query.
|
|
627
|
-
* @parameter:
|
|
628
|
-
* @name: query
|
|
629
|
-
* @description: The query object.
|
|
630
|
-
* @type: object
|
|
631
|
-
*/
|
|
632
|
-
async delete_query(query = {}) {
|
|
633
|
-
if (typeof query !== "object" || query == null || Object.keys(query).length === 0) {
|
|
634
|
-
throw Error(`Parameter "query" has an invalid type "${typeof query}", the valid type is "object".`);
|
|
635
|
-
}
|
|
636
|
-
if (Object.keys(query).length === 0) {
|
|
637
|
-
throw Error(`Parameter "query" is an empty object.`);
|
|
638
|
-
}
|
|
639
|
-
return await this.col.deleteMany(query);
|
|
640
|
-
}
|
|
641
|
-
// Delete all.
|
|
642
|
-
async delete_all(path) {
|
|
643
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
644
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
645
|
-
}
|
|
646
|
-
try {
|
|
647
|
-
await this.col.deleteMany(typeof path === "object" ? path : { _path: path });
|
|
648
|
-
} catch (error) {
|
|
649
|
-
console.error(error);
|
|
650
|
-
throw new Error("Encountered an error while deleting.");
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
async delete_many(query) {
|
|
654
|
-
try {
|
|
655
|
-
await this.col.deleteMany(query);
|
|
656
|
-
} catch (error) {
|
|
657
|
-
console.error(error);
|
|
658
|
-
throw new Error("Encountered an error while deleting.");
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
/* @docs:
|
|
662
|
-
* @title: Delete Collection
|
|
663
|
-
* @description: Delete all documents of from the collection.
|
|
664
|
-
*/
|
|
665
|
-
async delete_collection() {
|
|
666
|
-
await this.col.deleteMany();
|
|
667
|
-
await this.col.drop();
|
|
668
|
-
}
|
|
669
|
-
/* @docs:
|
|
670
|
-
* @title: Clean document
|
|
671
|
-
* @description: Clean a document from all default system attributes.
|
|
672
|
-
*/
|
|
673
|
-
clean(doc) {
|
|
674
|
-
if (doc == null) {
|
|
675
|
-
return doc;
|
|
676
|
-
}
|
|
677
|
-
if (typeof doc === "object") {
|
|
678
|
-
delete doc._id;
|
|
679
|
-
delete doc._path;
|
|
680
|
-
if (this.uid_based) {
|
|
681
|
-
delete doc._uid;
|
|
682
|
-
}
|
|
683
|
-
if (this.ttl_enabled) {
|
|
684
|
-
delete doc._ttl_timestamp;
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
return doc;
|
|
688
|
-
}
|
|
689
|
-
/** Write bulk operations. */
|
|
690
|
-
async bulk_operations(operations = []) {
|
|
691
|
-
return await this.col.bulkWrite(operations, { ordered: true });
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
class UIDCollection {
|
|
695
|
-
_col;
|
|
696
|
-
col;
|
|
697
|
-
constructor(name, collection, indexes = [], ttl = null) {
|
|
698
|
-
this._col = new Collection(name, collection, ttl, indexes, true);
|
|
699
|
-
this.col = this._col.col;
|
|
700
|
-
}
|
|
701
|
-
/* @docs:
|
|
702
|
-
@title: Create index
|
|
703
|
-
@description: Creates indexes on collections.
|
|
704
|
-
@return:
|
|
705
|
-
Returns the document that was found or `null` when no document is found.
|
|
706
|
-
@parameter:
|
|
707
|
-
@name: keys
|
|
708
|
-
@desc: The `keys` argument for the orignal mongodb `createIndex()` function.
|
|
709
|
-
@parameter:
|
|
710
|
-
@name: options
|
|
711
|
-
@desc: The `options` argument for the orignal mongodb `createIndex()` function.
|
|
712
|
-
@parameter:
|
|
713
|
-
@name: commitQuorum
|
|
714
|
-
@desc: The `commitQuorum` argument for the orignal mongodb `createIndex()` function.
|
|
715
|
-
*/
|
|
716
|
-
async create_index(args) {
|
|
717
|
-
return this._col.create_index(args);
|
|
718
|
-
}
|
|
719
|
-
/* @docs:
|
|
720
|
-
* @title: Find
|
|
721
|
-
* @description: Find a document by a query.
|
|
722
|
-
* @return:
|
|
723
|
-
* Returns the document that was found or `null` when no document is found.
|
|
724
|
-
* @parameter:
|
|
725
|
-
* @name: uid
|
|
726
|
-
* @cached: Users:uid:param
|
|
727
|
-
* @required: false
|
|
728
|
-
* @parameter:
|
|
729
|
-
* @name: query
|
|
730
|
-
* @desc: The query options.
|
|
731
|
-
* @type: object
|
|
732
|
-
*/
|
|
733
|
-
async find(uid = null, query = {}) {
|
|
734
|
-
if (uid != null) {
|
|
735
|
-
query._uid = uid;
|
|
736
|
-
}
|
|
737
|
-
return await this._col.find(query);
|
|
738
|
-
}
|
|
739
|
-
/* @docs:
|
|
740
|
-
* @title: Exists
|
|
741
|
-
* @description: Check if a document exists.
|
|
742
|
-
* @parameter:
|
|
743
|
-
* @name: uid
|
|
744
|
-
* @cached: Users:uid:param
|
|
745
|
-
* @parameter:
|
|
746
|
-
* @name: path
|
|
747
|
-
* @description: The database path to the document.
|
|
748
|
-
* @type: string, object
|
|
749
|
-
*/
|
|
750
|
-
async exists(uid, path) {
|
|
751
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
752
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
753
|
-
}
|
|
754
|
-
if (typeof uid !== "string") {
|
|
755
|
-
throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
756
|
-
}
|
|
757
|
-
if (typeof path === "object") {
|
|
758
|
-
return await this._col.exists({ ...path, _uid: uid });
|
|
759
|
-
} else {
|
|
760
|
-
return await this._col.exists({ _path: path, _uid: uid });
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
/* @docs:
|
|
764
|
-
* @title: Load
|
|
765
|
-
* @description: Load data by user id and path.
|
|
766
|
-
* @return:
|
|
767
|
-
* Returns the loaded document.
|
|
768
|
-
*
|
|
769
|
-
* 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.
|
|
770
|
-
* @parameter:
|
|
771
|
-
* @name: uid
|
|
772
|
-
* @cached: Users:uid:param
|
|
773
|
-
* @parameter:
|
|
774
|
-
* @name: path
|
|
775
|
-
* @description: The database path to the document.
|
|
776
|
-
* @type: string, object
|
|
777
|
-
* @parameter:
|
|
778
|
-
* @name: opts
|
|
779
|
-
* @desc: Additional options.
|
|
780
|
-
* @type: null, object
|
|
781
|
-
* @attribute:
|
|
782
|
-
* @name: default
|
|
783
|
-
* @description:
|
|
784
|
-
* The default data to be returned when the data does not exist.
|
|
785
|
-
*
|
|
786
|
-
* 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.
|
|
787
|
-
* @type: null, object
|
|
788
|
-
*/
|
|
789
|
-
async load(uid, path, opts = null) {
|
|
790
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
791
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
792
|
-
}
|
|
793
|
-
if (typeof uid !== "string") {
|
|
794
|
-
throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
795
|
-
}
|
|
796
|
-
if (typeof path === "object") {
|
|
797
|
-
return await this._col.load({ ...path, _uid: uid }, opts);
|
|
798
|
-
} else {
|
|
799
|
-
return await this._col.load({ _path: path, _uid: uid }, opts);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
/* @docs:
|
|
803
|
-
* @title: Save
|
|
804
|
-
* @description: Save data by user id and path. When the document already exists this function only updates the specified content attributes.
|
|
805
|
-
* @return:
|
|
806
|
-
* Returns the updated document.
|
|
807
|
-
* @parameter:
|
|
808
|
-
* @name: uid
|
|
809
|
-
* @cached: Users:uid:param
|
|
810
|
-
* @parameter:
|
|
811
|
-
* @name: path
|
|
812
|
-
* @description: The database path to the document.
|
|
813
|
-
* @type: string, object
|
|
814
|
-
* @parameter:
|
|
815
|
-
* @name: data
|
|
816
|
-
* @description: The data to save.
|
|
817
|
-
* @type: null, boolean, number, string, array, object
|
|
818
|
-
* @parameter:
|
|
819
|
-
* @name: opts
|
|
820
|
-
* @desc: Additional options.
|
|
821
|
-
* @type: null, object
|
|
822
|
-
* @attribute:
|
|
823
|
-
* @name: chunked
|
|
824
|
-
* @description: Chunk the document into multiple documents, therefore documents larger than 16MB are supported.
|
|
825
|
-
* @warning: Currently this option is only supported for types `object` and `array`.
|
|
826
|
-
* @default: false
|
|
827
|
-
* @type: boolean
|
|
828
|
-
* @attribute:
|
|
829
|
-
* @name: bulk
|
|
830
|
-
* @description: Get a bulk operation object, so several operations can be executed in bulk.
|
|
831
|
-
* @default: false
|
|
832
|
-
* @type: boolean
|
|
833
|
-
* @attribute:
|
|
834
|
-
* @name: set
|
|
835
|
-
* @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.
|
|
836
|
-
* @warning: This does not work in combination with `opts.chunked`.
|
|
837
|
-
* @default: true
|
|
838
|
-
* @type: boolean
|
|
839
|
-
*/
|
|
840
|
-
async save(uid, path, content, opts = null) {
|
|
841
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
842
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
843
|
-
}
|
|
844
|
-
if (typeof uid !== "string") {
|
|
845
|
-
throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
846
|
-
}
|
|
847
|
-
if (typeof path === "object") {
|
|
848
|
-
return await this._col.save({ ...path, _uid: uid }, content, opts);
|
|
849
|
-
} else {
|
|
850
|
-
return await this._col.save({ _path: path, _uid: uid }, content, opts);
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
/** Update many. */
|
|
854
|
-
async update_many(...args) {
|
|
855
|
-
return this.col.updateMany(...args);
|
|
856
|
-
}
|
|
857
|
-
/* @docs:
|
|
858
|
-
* @title: List
|
|
859
|
-
* @description: List all child documents of directory path.
|
|
860
|
-
* @parameter:
|
|
861
|
-
* @name: uid
|
|
862
|
-
* @cached: Users:uid:param
|
|
863
|
-
* @parameter:
|
|
864
|
-
* @name: path
|
|
865
|
-
* @description: The database directory path.
|
|
866
|
-
* @type: string, object
|
|
867
|
-
* @parameter:
|
|
868
|
-
* @name: options
|
|
869
|
-
* @description: List options.
|
|
870
|
-
* @type: object
|
|
871
|
-
* @attribute:
|
|
872
|
-
* @name: process
|
|
873
|
-
* @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.
|
|
874
|
-
* @type: boolean
|
|
875
|
-
* @default: true
|
|
876
|
-
* @attribute:
|
|
877
|
-
* @name: projection
|
|
878
|
-
* @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
879
|
-
* @type: object
|
|
880
|
-
* @default: undefined
|
|
881
|
-
*/
|
|
882
|
-
async list(uid, path, options = {}) {
|
|
883
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
884
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
885
|
-
}
|
|
886
|
-
if (typeof uid !== "string") {
|
|
887
|
-
throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
888
|
-
}
|
|
889
|
-
if (typeof path === "object") {
|
|
890
|
-
return await this._col.list({ ...path, _uid: uid }, options);
|
|
891
|
-
} else {
|
|
892
|
-
return await this._col.list({ _path: path, _uid: uid }, options);
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
/* @docs:
|
|
896
|
-
* @title: List Query
|
|
897
|
-
* @description: List all documents of the collection based on a query.
|
|
898
|
-
* @parameter:
|
|
899
|
-
* @name: query
|
|
900
|
-
* @desc: The query options.
|
|
901
|
-
* @type: object
|
|
902
|
-
* @parameter:
|
|
903
|
-
* @name: options
|
|
904
|
-
* @description: List options.
|
|
905
|
-
* @type: object
|
|
906
|
-
* @attribute:
|
|
907
|
-
* @name: process
|
|
908
|
-
* @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.
|
|
909
|
-
* @type: boolean
|
|
910
|
-
* @default: true
|
|
911
|
-
* @attribute:
|
|
912
|
-
* @name: projection
|
|
913
|
-
* @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
914
|
-
* @type: object
|
|
915
|
-
* @default: undefined
|
|
916
|
-
*/
|
|
917
|
-
async list_query(query = {}, options = {}) {
|
|
918
|
-
return await this._col.list_query(query, options);
|
|
919
|
-
}
|
|
920
|
-
/* @docs:
|
|
921
|
-
* @title: List All
|
|
922
|
-
* @description: List all documents of the collection, optionally per uid.
|
|
923
|
-
* @parameter:
|
|
924
|
-
* @name: uid
|
|
925
|
-
* @cached: Users:uid:param
|
|
926
|
-
* @parameter:
|
|
927
|
-
* @name: options
|
|
928
|
-
* @description: List options.
|
|
929
|
-
* @type: object
|
|
930
|
-
* @attribute:
|
|
931
|
-
* @name: process
|
|
932
|
-
* @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.
|
|
933
|
-
* @type: boolean
|
|
934
|
-
* @default: true
|
|
935
|
-
* @attribute:
|
|
936
|
-
* @name: projection
|
|
937
|
-
* @description: The data attributes to retrieve, when left undefined all attributes are retrieved.
|
|
938
|
-
* @type: object
|
|
939
|
-
* @default: undefined
|
|
940
|
-
*/
|
|
941
|
-
async list_all(uid = null, options = {}) {
|
|
942
|
-
if (uid == null) {
|
|
943
|
-
return await this._col.list_all({}, options);
|
|
944
|
-
} else {
|
|
945
|
-
return await this._col.list_all({ _uid: uid }, options);
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
/* @docs:
|
|
949
|
-
* @title: Delete
|
|
950
|
-
* @description: Delete a document of the collection by uid and path.
|
|
951
|
-
* @parameter:
|
|
952
|
-
* @name: uid
|
|
953
|
-
* @cached: Users:uid:param
|
|
954
|
-
* @parameter:
|
|
955
|
-
* @name: path
|
|
956
|
-
* @description: The database path to the document.
|
|
957
|
-
* @type: string, object
|
|
958
|
-
* @parameter:
|
|
959
|
-
* @name: opts
|
|
960
|
-
* @desc: Additional options.
|
|
961
|
-
* @type: null, object
|
|
962
|
-
* @attribute:
|
|
963
|
-
* @name: chunked
|
|
964
|
-
* @description: Delete a chunked document.
|
|
965
|
-
* @default: false
|
|
966
|
-
* @type: boolean
|
|
967
|
-
* @attribute:
|
|
968
|
-
* @name: bulk
|
|
969
|
-
* @description: Get a bulk operation object, so several operations can be executed in bulk.
|
|
970
|
-
* @default: false
|
|
971
|
-
* @type: boolean
|
|
972
|
-
*/
|
|
973
|
-
async delete(uid, path, opts) {
|
|
974
|
-
if (typeof path !== "string" && (typeof path !== "object" || path == null)) {
|
|
975
|
-
throw Error(`Parameter "path" has an invalid type "${typeof path}", the valid type is "string".`);
|
|
976
|
-
}
|
|
977
|
-
if (typeof uid !== "string") {
|
|
978
|
-
throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
979
|
-
}
|
|
980
|
-
if (typeof path === "object") {
|
|
981
|
-
return await this._col.delete({ ...path, _uid: uid }, opts);
|
|
982
|
-
} else {
|
|
983
|
-
return await this._col.delete({ _path: path, _uid: uid }, opts);
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
/* @docs:
|
|
987
|
-
* @title: Delete Query
|
|
988
|
-
* @description: Delete a document of the collection by query.
|
|
989
|
-
* @parameter:
|
|
990
|
-
* @name: query
|
|
991
|
-
* @description: The query object.
|
|
992
|
-
* @type: object
|
|
993
|
-
*/
|
|
994
|
-
async delete_query(query) {
|
|
995
|
-
if (typeof query !== "object" || query == null || Object.keys(query).length === 0) {
|
|
996
|
-
throw Error(`Parameter "query" has an invalid type "${typeof query}", the valid type is "object".`);
|
|
997
|
-
}
|
|
998
|
-
if (Object.keys(query).length === 0) {
|
|
999
|
-
throw Error(`Parameter "query" is an empty object.`);
|
|
1000
|
-
}
|
|
1001
|
-
return await this._col.delete_query(query);
|
|
1002
|
-
}
|
|
1003
|
-
// Delete all.
|
|
1004
|
-
async delete_all(uid, path = null) {
|
|
1005
|
-
if (typeof uid !== "string") {
|
|
1006
|
-
throw Error(`Parameter "uid" has an invalid type "${typeof uid}", the valid type is "string".`);
|
|
1007
|
-
}
|
|
1008
|
-
if (path == null) {
|
|
1009
|
-
return await this._col.delete_all({ _uid: uid });
|
|
1010
|
-
} else if (typeof path === "object") {
|
|
1011
|
-
return await this._col.delete_all({ ...path, _uid: uid });
|
|
1012
|
-
} else {
|
|
1013
|
-
return await this._col.delete_all({ _path: path, _uid: uid });
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
async delete_many(query) {
|
|
1017
|
-
return await this._col.delete_many(query);
|
|
1018
|
-
}
|
|
1019
|
-
/* @docs:
|
|
1020
|
-
* @title: Delete Collection
|
|
1021
|
-
* @description: Delete all documents of from the collection.
|
|
1022
|
-
*/
|
|
1023
|
-
async delete_collection() {
|
|
1024
|
-
await this._col.delete_collection();
|
|
1025
|
-
}
|
|
1026
|
-
/* @docs:
|
|
1027
|
-
* @title: Clean document
|
|
1028
|
-
* @description: Clean a document from all default system attributes.
|
|
1029
|
-
*/
|
|
1030
|
-
clean(doc) {
|
|
1031
|
-
return this._col.clean(doc);
|
|
1032
|
-
}
|
|
1033
|
-
/** Write bulk operations. */
|
|
1034
|
-
async bulk_operations(operations = []) {
|
|
1035
|
-
return await this.col.bulkWrite(operations, { ordered: true });
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
class Database {
|
|
1039
|
-
static constructor_scheme = {
|
|
1040
|
-
uri: { type: "string", default: null },
|
|
1041
|
-
source: { type: "string", default: null },
|
|
1042
|
-
config: { type: "object", default: {} },
|
|
1043
|
-
start_args: { type: "array", default: [] },
|
|
1044
|
-
client: { type: "object", default: {} },
|
|
1045
|
-
collections: { type: "array", default: [], value_scheme: {
|
|
1046
|
-
type: ["string", "object"],
|
|
1047
|
-
preprocess: (info) => typeof info === "string" ? { name: info } : info,
|
|
1048
|
-
scheme: {
|
|
1049
|
-
name: Collection.constructor_scheme.name,
|
|
1050
|
-
ttl: Collection.constructor_scheme.ttl,
|
|
1051
|
-
indexes: Collection.constructor_scheme.indexes
|
|
1052
|
-
}
|
|
1053
|
-
} },
|
|
1054
|
-
uid_collections: { type: "array", default: [], value_scheme: {
|
|
1055
|
-
type: ["string", "object"],
|
|
1056
|
-
preprocess: (info) => typeof info === "string" ? { name: info } : info,
|
|
1057
|
-
scheme: {
|
|
1058
|
-
name: Collection.constructor_scheme.name,
|
|
1059
|
-
ttl: Collection.constructor_scheme.ttl,
|
|
1060
|
-
indexes: Collection.constructor_scheme.indexes
|
|
1061
|
-
}
|
|
1062
|
-
} },
|
|
1063
|
-
preview: { type: "boolean", default: true },
|
|
1064
|
-
preview_ip_whitelist: { type: "array", default: [] },
|
|
1065
|
-
daemon: { type: ["object", "boolean"], default: {} },
|
|
1066
|
-
_server: { type: ["object", "undefined"] }
|
|
1067
|
-
};
|
|
1068
|
-
uri;
|
|
1069
|
-
// preview: boolean;
|
|
1070
|
-
// preview_ip_whitelist: string[];
|
|
1071
|
-
client_opts;
|
|
1072
|
-
config;
|
|
1073
|
-
source;
|
|
1074
|
-
// Using vlib.Path type
|
|
1075
|
-
start_args;
|
|
1076
|
-
_collections;
|
|
1077
|
-
_uid_collections;
|
|
1078
|
-
server;
|
|
1079
|
-
client;
|
|
1080
|
-
collections;
|
|
1081
|
-
proc;
|
|
1082
|
-
daemon;
|
|
1083
|
-
db;
|
|
1084
|
-
// System.
|
|
1085
|
-
_listed_cols;
|
|
1086
|
-
constructor({
|
|
1087
|
-
uri = null,
|
|
1088
|
-
source = null,
|
|
1089
|
-
config = null,
|
|
1090
|
-
start_args = [],
|
|
1091
|
-
client = null,
|
|
1092
|
-
collections = [],
|
|
1093
|
-
uid_collections = [],
|
|
1094
|
-
// preview = true,
|
|
1095
|
-
// preview_ip_whitelist = [],
|
|
1096
|
-
daemon = {},
|
|
1097
|
-
_server = void 0
|
|
1098
|
-
}) {
|
|
1099
|
-
if (!_server || _server.is_primary && uri == null) {
|
|
1100
|
-
({ uri, config, start_args, config, client } = import_vinc.vlib.Scheme.verify({
|
|
1101
|
-
object: arguments[0],
|
|
1102
|
-
check_unknown: true,
|
|
1103
|
-
throw_err: true,
|
|
1104
|
-
scheme: Database.constructor_scheme
|
|
1105
|
-
}));
|
|
1106
|
-
}
|
|
1107
|
-
this.uri = uri;
|
|
1108
|
-
this.client_opts = client;
|
|
1109
|
-
this.config = config || {};
|
|
1110
|
-
this.source = source != null ? new import_vinc.vlib.Path(source) : _server?.source.join(".db");
|
|
1111
|
-
this.start_args = start_args;
|
|
1112
|
-
this._collections = collections ?? [];
|
|
1113
|
-
this._uid_collections = uid_collections ?? [];
|
|
1114
|
-
this.server = _server;
|
|
1115
|
-
this.client = null;
|
|
1116
|
-
this.collections = {};
|
|
1117
|
-
if (this.server?.daemon && daemon !== false) {
|
|
1118
|
-
const log_source = this.server.source.join(".logs");
|
|
1119
|
-
if (!log_source.exists()) {
|
|
1120
|
-
log_source.mkdir_sync();
|
|
1121
|
-
}
|
|
1122
|
-
if (!this.server) {
|
|
1123
|
-
throw new Error("Parameter 'Database._server' must be defined for this behaviour.");
|
|
1124
|
-
}
|
|
1125
|
-
this.daemon = new import_vinc.vlib.Daemon({
|
|
1126
|
-
name: this.server.daemon.name + ".mongodb",
|
|
1127
|
-
user: daemon.user || this.server.daemon.user,
|
|
1128
|
-
group: daemon.group || this.server.daemon.group,
|
|
1129
|
-
command: "mongod",
|
|
1130
|
-
cwd: this.server.daemon.cwd,
|
|
1131
|
-
args: ["--config", this.source.join("mongod.json").str(), ...this.start_args],
|
|
1132
|
-
env: daemon.env || this.server.daemon.env,
|
|
1133
|
-
description: daemon.description || `Service daemon for the mongo database of website ${this.server.domain}.`,
|
|
1134
|
-
auto_restart: true,
|
|
1135
|
-
logs: daemon.logs || log_source.join("logs.mongodb").str(),
|
|
1136
|
-
errors: daemon.errors || log_source.join("errors.mongodb").str()
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
/* Database preview.
|
|
1141
|
-
_initialize_db_preview(): void {
|
|
1142
|
-
|
|
1143
|
-
if (this.preview && this.server.production === false) {
|
|
1144
|
-
this.server.endpoint(
|
|
1145
|
-
|
|
1146
|
-
// Database preview.
|
|
1147
|
-
{
|
|
1148
|
-
method: "GET" ,
|
|
1149
|
-
endpoint: "/volt/db/preview",
|
|
1150
|
-
view: {
|
|
1151
|
-
callback: () => {
|
|
1152
|
-
volt.utils.on_load(async () => {
|
|
1153
|
-
|
|
1154
|
-
// Style theme.
|
|
1155
|
-
const style = {
|
|
1156
|
-
// bg: "#151721",
|
|
1157
|
-
// sub_bg: "#191B28",
|
|
1158
|
-
// tag_bg: "#1C203A",
|
|
1159
|
-
// div_bg: "#282B40",
|
|
1160
|
-
// fg: "#FFFFFF",
|
|
1161
|
-
// sub_fg: "#FFFFFF99",
|
|
1162
|
-
// tag_fg: "#FFFFFF",
|
|
1163
|
-
|
|
1164
|
-
bg: "#F6F8F8",
|
|
1165
|
-
sub_bg: "#FFFFFF",
|
|
1166
|
-
tag_bg: "#F6F8F8",
|
|
1167
|
-
div_bg: "#00000010",
|
|
1168
|
-
fg: "#32334F",
|
|
1169
|
-
sub_fg: "#31344599",
|
|
1170
|
-
tag_fg: "#313445",
|
|
1171
|
-
};
|
|
1172
|
-
|
|
1173
|
-
// List all collections.
|
|
1174
|
-
const collections = (await volt.utils.request({url: "/volt/db/collections"})).collections;
|
|
1175
|
-
|
|
1176
|
-
// Render a list.
|
|
1177
|
-
const prev_lists = [];
|
|
1178
|
-
function RenderList ({
|
|
1179
|
-
title,
|
|
1180
|
-
list,
|
|
1181
|
-
doc = null,
|
|
1182
|
-
add_prev = true,
|
|
1183
|
-
}) {
|
|
1184
|
-
if (add_prev) {
|
|
1185
|
-
prev_lists.append({title, list, doc});
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
// Object view.
|
|
1189
|
-
const obj_view = VStack();
|
|
1190
|
-
const refresh_obj_view = () => {
|
|
1191
|
-
obj_view.inner_html("");
|
|
1192
|
-
let index = 0;
|
|
1193
|
-
obj_view.append(
|
|
1194
|
-
ForEach(list, (key, value) => {
|
|
1195
|
-
++index;
|
|
1196
|
-
let current_key = key;
|
|
1197
|
-
let value_type = Array.isArray(value) ? "array" : value == null ? "null" : typeof value;
|
|
1198
|
-
if (Array.isArray(value)) {
|
|
1199
|
-
value = JSON.stringify(value, null, 4)
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
// Key input.
|
|
1203
|
-
const key_input = Input("key")
|
|
1204
|
-
.value(key)
|
|
1205
|
-
.font_family("'Menlo', 'Consolas', monospace")
|
|
1206
|
-
.color(style.sub_fg)
|
|
1207
|
-
.font_size(14)
|
|
1208
|
-
.padding(0)
|
|
1209
|
-
.readonly(key === "_path" || key === "_uid" || key === "uid")
|
|
1210
|
-
.on_mouse_over(e => e.color(style.fg))
|
|
1211
|
-
.on_mouse_out(e => e.color(style.sub_fg))
|
|
1212
|
-
.on_render((e) => e.width(e.text_width(key)))
|
|
1213
|
-
.on_input((e) => {
|
|
1214
|
-
if (key != current_key) {
|
|
1215
|
-
list[e.value()] = list[current_key];
|
|
1216
|
-
delete list[current_key];
|
|
1217
|
-
current_key = e.value();
|
|
1218
|
-
}
|
|
1219
|
-
e.width(e.text_width(current_key));
|
|
1220
|
-
});
|
|
1221
|
-
|
|
1222
|
-
// Value input.
|
|
1223
|
-
const value_input = Input("value")
|
|
1224
|
-
.value(value == null ? "null" : value)
|
|
1225
|
-
.font_family("'Menlo', 'Consolas', monospace")
|
|
1226
|
-
.color(style.sub_fg)
|
|
1227
|
-
.display("inline-block")
|
|
1228
|
-
.width("fit-content")
|
|
1229
|
-
.font_size(14)
|
|
1230
|
-
.readonly(key === "_path" || key === "_uid")
|
|
1231
|
-
.stretch(true)
|
|
1232
|
-
.on_mouse_over(e => e.color(style.fg))
|
|
1233
|
-
.on_mouse_out(e => e.color(style.sub_fg))
|
|
1234
|
-
.on_input(() => {
|
|
1235
|
-
clearTimeout(value_input.timeout)
|
|
1236
|
-
value_input.timeout = setTimeout(update_value, 500);
|
|
1237
|
-
})
|
|
1238
|
-
|
|
1239
|
-
// Type select.
|
|
1240
|
-
const type_select = ExtendedSelect({items: ["null", "boolean", "number", "string", "array", "object"]})
|
|
1241
|
-
.center()
|
|
1242
|
-
.margin(0)
|
|
1243
|
-
.max_width(73)
|
|
1244
|
-
.color(style.sub_fg)
|
|
1245
|
-
.font_size(14)
|
|
1246
|
-
.border_radius(10)
|
|
1247
|
-
.background(style.tag_bg)
|
|
1248
|
-
.border_color(style.div_bg)
|
|
1249
|
-
.value(value_type)
|
|
1250
|
-
.container
|
|
1251
|
-
.padding(2.5, 5)
|
|
1252
|
-
.parent();
|
|
1253
|
-
|
|
1254
|
-
// Update the list after edits.
|
|
1255
|
-
const update_value = () => {
|
|
1256
|
-
const type = type_select.value();
|
|
1257
|
-
const value = value_input.value();
|
|
1258
|
-
if (type === "null") {
|
|
1259
|
-
list[current_key] = null;
|
|
1260
|
-
value_input.value(list[current_key].toString());
|
|
1261
|
-
}
|
|
1262
|
-
else if (type === "boolean") {
|
|
1263
|
-
list[current_key] = value == "true" || value == "True" || value == "TRUE" || value == "1";
|
|
1264
|
-
value_input.value(list[current_key].toString());
|
|
1265
|
-
}
|
|
1266
|
-
else if (type === "number") {
|
|
1267
|
-
if (value.indexOf(".") === -1) {
|
|
1268
|
-
list[current_key] = paseInt(value);
|
|
1269
|
-
} else {
|
|
1270
|
-
list[current_key] = paseFloat(value);
|
|
1271
|
-
}
|
|
1272
|
-
if (isNaN(list[key_input.key])) {
|
|
1273
|
-
list[current_key] = 0;
|
|
1274
|
-
}
|
|
1275
|
-
value_input.value(list[current_key].toString());
|
|
1276
|
-
}
|
|
1277
|
-
else if (type === "string") {
|
|
1278
|
-
list[current_key] = value;
|
|
1279
|
-
}
|
|
1280
|
-
else if (type === "object") {
|
|
1281
|
-
list[current_key] = JSON.parse(value);
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
// Row.
|
|
1286
|
-
const row = HStack(
|
|
1287
|
-
key_input,
|
|
1288
|
-
Text(" : ")
|
|
1289
|
-
.white_space("pre")
|
|
1290
|
-
.font_family("'Menlo', 'Consolas', monospace")
|
|
1291
|
-
.color(style.sub_fg)
|
|
1292
|
-
.font_size(14),
|
|
1293
|
-
value_input,
|
|
1294
|
-
type_select,
|
|
1295
|
-
|
|
1296
|
-
index < Object.keys(list).length ? null : VStack("add")
|
|
1297
|
-
.background(style.tag_bg)
|
|
1298
|
-
.padding(5, 12.5)
|
|
1299
|
-
.border_radius(10)
|
|
1300
|
-
.font_size(13)
|
|
1301
|
-
.color("#3B8553")
|
|
1302
|
-
.margin_left(10)
|
|
1303
|
-
.border(1, style.div_bg)
|
|
1304
|
-
.on_click(() => {
|
|
1305
|
-
list["_new"] = "";
|
|
1306
|
-
refresh_obj_view();
|
|
1307
|
-
}),
|
|
1308
|
-
|
|
1309
|
-
VStack("delete")
|
|
1310
|
-
.background(style.tag_bg)
|
|
1311
|
-
.color("#B2321E")
|
|
1312
|
-
.padding(5, 12.5)
|
|
1313
|
-
.border_radius(10)
|
|
1314
|
-
.font_size(13)
|
|
1315
|
-
.margin_left(10)
|
|
1316
|
-
.border(1, style.div_bg)
|
|
1317
|
-
.on_click(async () => {
|
|
1318
|
-
}),
|
|
1319
|
-
)
|
|
1320
|
-
.center_vertical()
|
|
1321
|
-
.padding(7.5, 0)
|
|
1322
|
-
if (volt.utils.is_obj(value)) {
|
|
1323
|
-
row.on_click(() => RenderList({title: `${title}.${key}`, list: value}));
|
|
1324
|
-
}
|
|
1325
|
-
return [
|
|
1326
|
-
row,
|
|
1327
|
-
Divider().background(style.div_bg),
|
|
1328
|
-
]
|
|
1329
|
-
})
|
|
1330
|
-
);
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
// Add.
|
|
1334
|
-
preview.inner_html("");
|
|
1335
|
-
preview.append(
|
|
1336
|
-
Scroller(
|
|
1337
|
-
VStack(
|
|
1338
|
-
HStack(
|
|
1339
|
-
Title("Database")
|
|
1340
|
-
.font_family("'Menlo', 'Consolas', monospace")
|
|
1341
|
-
.font_size(12)
|
|
1342
|
-
.color(style.tag_fg)
|
|
1343
|
-
.background(style.tag_bg)
|
|
1344
|
-
.padding(5, 12.5)
|
|
1345
|
-
.border_radius(10)
|
|
1346
|
-
.margin(0, 0, 0, 0)
|
|
1347
|
-
.border(1, style.div_bg)
|
|
1348
|
-
.width("fit-content"),
|
|
1349
|
-
|
|
1350
|
-
Spacer(),
|
|
1351
|
-
|
|
1352
|
-
doc == null ? null : Button("Update")
|
|
1353
|
-
.background(style.tag_bg)
|
|
1354
|
-
.color("#3B8553")
|
|
1355
|
-
.padding(5, 12.5)
|
|
1356
|
-
.margin_right(10)
|
|
1357
|
-
.border_radius(10)
|
|
1358
|
-
.border(1, style.div_bg)
|
|
1359
|
-
.on_click(() => {
|
|
1360
|
-
// --prev_lists.length;
|
|
1361
|
-
// const last = prev_lists[prev_lists.length - 1];
|
|
1362
|
-
// RenderList({...last, add_prev: false})
|
|
1363
|
-
}),
|
|
1364
|
-
|
|
1365
|
-
doc == null ? null : Button("Delete")
|
|
1366
|
-
.background(style.tag_bg)
|
|
1367
|
-
.color("#B2321E")
|
|
1368
|
-
.padding(5, 12.5)
|
|
1369
|
-
.margin_right(10)
|
|
1370
|
-
.border_radius(10)
|
|
1371
|
-
.border(1, style.div_bg)
|
|
1372
|
-
.on_click(async () => {
|
|
1373
|
-
volt.utils.request({
|
|
1374
|
-
method: "DELETE",
|
|
1375
|
-
url: "/volt/db/document",
|
|
1376
|
-
data: doc,
|
|
1377
|
-
})
|
|
1378
|
-
--prev_lists.length;
|
|
1379
|
-
const last = prev_lists[prev_lists.length - 1];
|
|
1380
|
-
|
|
1381
|
-
const __name = doc.uid != null ? `${doc.uid}:${doc.id}` : doc.id
|
|
1382
|
-
const filtered_list = [];
|
|
1383
|
-
last.list.iterate((item) => {
|
|
1384
|
-
if (item.__name !== __name) {
|
|
1385
|
-
filtered_list.append(item);
|
|
1386
|
-
}
|
|
1387
|
-
})
|
|
1388
|
-
last.list = filtered_list;
|
|
1389
|
-
RenderList({...last, add_prev: false})
|
|
1390
|
-
}),
|
|
1391
|
-
|
|
1392
|
-
prev_lists.length == 1 ? null : Button("Prev")
|
|
1393
|
-
.background(style.tag_bg)
|
|
1394
|
-
.color(style.tag_fg)
|
|
1395
|
-
.padding(5, 12.5)
|
|
1396
|
-
.border_radius(10)
|
|
1397
|
-
.border(1, style.div_bg)
|
|
1398
|
-
.on_click(() => {
|
|
1399
|
-
--prev_lists.length;
|
|
1400
|
-
const last = prev_lists[prev_lists.length - 1];
|
|
1401
|
-
RenderList({...last, add_prev: false})
|
|
1402
|
-
}),
|
|
1403
|
-
),
|
|
1404
|
-
|
|
1405
|
-
Title(title)
|
|
1406
|
-
.font_family("'Menlo', 'Consolas', monospace")
|
|
1407
|
-
.font_size(18)
|
|
1408
|
-
.color(style.fg)
|
|
1409
|
-
.margin(15, 0),
|
|
1410
|
-
|
|
1411
|
-
Divider().background(style.div_bg),
|
|
1412
|
-
|
|
1413
|
-
Array.isArray(list)
|
|
1414
|
-
? ForEach(list, (item) => {
|
|
1415
|
-
return [
|
|
1416
|
-
VStack(
|
|
1417
|
-
Text(item.__name)
|
|
1418
|
-
.font_family("'Menlo', 'Consolas', monospace")
|
|
1419
|
-
.color(style.sub_fg)
|
|
1420
|
-
.font_size(14)
|
|
1421
|
-
.on_mouse_over(e => e.color(style.fg))
|
|
1422
|
-
.on_mouse_out(e => e.color(style.sub_fg))
|
|
1423
|
-
)
|
|
1424
|
-
.padding(7.5, 0)
|
|
1425
|
-
.on_click(item.__click),
|
|
1426
|
-
|
|
1427
|
-
Divider().background(style.div_bg),
|
|
1428
|
-
]
|
|
1429
|
-
})
|
|
1430
|
-
: () => {refresh_obj_view(); return obj_view}
|
|
1431
|
-
)
|
|
1432
|
-
.margin(25, 50)
|
|
1433
|
-
.padding(25, 25)
|
|
1434
|
-
.background(style.sub_bg)
|
|
1435
|
-
.border_radius(10)
|
|
1436
|
-
.box_shadow("0px 0px 5px #00000090")
|
|
1437
|
-
)
|
|
1438
|
-
.font_family("Helvetica, sans-serif")
|
|
1439
|
-
.background(style.bg)
|
|
1440
|
-
.frame("100%", "100%")
|
|
1441
|
-
)
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
// Render the collections.
|
|
1445
|
-
const RenderCollections = () => {
|
|
1446
|
-
RenderList({title: "/", list: collections.iterate_append((item) => {
|
|
1447
|
-
return {
|
|
1448
|
-
__name: `${item}/`,
|
|
1449
|
-
__click: () => RenderCollection(item),
|
|
1450
|
-
}
|
|
1451
|
-
})})
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
// Render a collection.
|
|
1455
|
-
const RenderCollection = async (collection) => {
|
|
1456
|
-
const documents = (await volt.utils.request({url: "/volt/db/documents", data: {collection}})).documents;
|
|
1457
|
-
RenderList({title: `${collection}/`, list: documents.iterate_append((item) => {
|
|
1458
|
-
return {
|
|
1459
|
-
__name: item._uid != null ? `${item._uid}:${item._path}` : item._path,
|
|
1460
|
-
__click: () => RenderDocument(collection, item._path, item._uid),
|
|
1461
|
-
}
|
|
1462
|
-
})})
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
// Render a document.
|
|
1466
|
-
const RenderDocument = async (collection, path, uid = null) => {
|
|
1467
|
-
let doc = (await volt.utils.request({url: "/volt/db/document", data: {collection, path, uid}})).document
|
|
1468
|
-
if (Array.isArray(doc)) {
|
|
1469
|
-
doc = {_content: doc};
|
|
1470
|
-
}
|
|
1471
|
-
RenderList({
|
|
1472
|
-
title: uid != null ? `${collection}/${uid}:${path}` : `${collection}/${path}`,
|
|
1473
|
-
list: doc,
|
|
1474
|
-
doc: {collection, uid, path},
|
|
1475
|
-
})
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
// Stack.
|
|
1479
|
-
const preview = VStack()
|
|
1480
|
-
.position(0, 0, 0, 0);
|
|
1481
|
-
|
|
1482
|
-
// Render all collections.
|
|
1483
|
-
RenderCollections();
|
|
1484
|
-
|
|
1485
|
-
// Response.
|
|
1486
|
-
return preview;
|
|
1487
|
-
|
|
1488
|
-
});
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
},
|
|
1492
|
-
|
|
1493
|
-
// Get collections.
|
|
1494
|
-
{
|
|
1495
|
-
method: "GET",
|
|
1496
|
-
endpoint: "/volt/db/collections",
|
|
1497
|
-
content_type: "application/json",
|
|
1498
|
-
rate_limit: "global",
|
|
1499
|
-
callback: async (stream) => {
|
|
1500
|
-
|
|
1501
|
-
// Check ip whitelist.
|
|
1502
|
-
if (!this.preview_ip_whitelist.includes(stream.ip)) {
|
|
1503
|
-
return stream.error({status: Status.forbidden});
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
// Sign in.
|
|
1507
|
-
return stream.success({data: {
|
|
1508
|
-
message: "Successfully retrieved all collections.",
|
|
1509
|
-
collections: await this.get_collections(),
|
|
1510
|
-
}});
|
|
1511
|
-
}
|
|
1512
|
-
},
|
|
1513
|
-
|
|
1514
|
-
// Get collection documents.
|
|
1515
|
-
{
|
|
1516
|
-
method: "GET",
|
|
1517
|
-
endpoint: "/volt/db/documents",
|
|
1518
|
-
content_type: "application/json",
|
|
1519
|
-
rate_limit: "global",
|
|
1520
|
-
params: {
|
|
1521
|
-
collection: "string",
|
|
1522
|
-
},
|
|
1523
|
-
callback: async (stream, params) => {
|
|
1524
|
-
|
|
1525
|
-
// Check ip whitelist.
|
|
1526
|
-
if (!this.preview_ip_whitelist.includes(stream.ip)) {
|
|
1527
|
-
return stream.error({status: Status.forbidden});
|
|
1528
|
-
}
|
|
1529
|
-
|
|
1530
|
-
// Check collection.
|
|
1531
|
-
let col;
|
|
1532
|
-
if ((col = this.collections[params.collection]) == null) {
|
|
1533
|
-
return stream.error({data: {error: `Invalid collection "${params.collection}".`}})
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
|
-
// Load docs.
|
|
1537
|
-
let docs = await col.list_all();
|
|
1538
|
-
|
|
1539
|
-
// Sign in.
|
|
1540
|
-
return stream.success({data: {
|
|
1541
|
-
message: "Successfully loaded the document.",
|
|
1542
|
-
documents: docs,
|
|
1543
|
-
}});
|
|
1544
|
-
}
|
|
1545
|
-
},
|
|
1546
|
-
|
|
1547
|
-
// Get document.
|
|
1548
|
-
{
|
|
1549
|
-
method: "GET",
|
|
1550
|
-
endpoint: "/volt/db/document",
|
|
1551
|
-
content_type: "application/json",
|
|
1552
|
-
rate_limit: "global",
|
|
1553
|
-
params: {
|
|
1554
|
-
collection: "string",
|
|
1555
|
-
path: ["string", "object"],
|
|
1556
|
-
uid: {type: ["string", "null"], default: null},
|
|
1557
|
-
},
|
|
1558
|
-
callback: async (stream, params) => {
|
|
1559
|
-
|
|
1560
|
-
// Check ip whitelist.
|
|
1561
|
-
if (!this.preview_ip_whitelist.includes(stream.ip)) {
|
|
1562
|
-
return stream.error({status: Status.forbidden});
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
// Check collection.
|
|
1566
|
-
let col;
|
|
1567
|
-
if ((col = this.collections[params.collection]) == null) {
|
|
1568
|
-
return stream.error({data: {error: `Invalid collection "${params.collection}".`}})
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
// Load doc.
|
|
1572
|
-
let doc;
|
|
1573
|
-
if (params.uid == null) {
|
|
1574
|
-
doc = await col.load(params.path);
|
|
1575
|
-
} else {
|
|
1576
|
-
doc = await col.load(params.uid, params.path);
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
// Sign in.
|
|
1580
|
-
return stream.success({data: {
|
|
1581
|
-
message: "Successfully loaded the document.",
|
|
1582
|
-
document: doc,
|
|
1583
|
-
}});
|
|
1584
|
-
}
|
|
1585
|
-
},
|
|
1586
|
-
|
|
1587
|
-
// Delete document.
|
|
1588
|
-
{
|
|
1589
|
-
method: "DELETE",
|
|
1590
|
-
endpoint: "/volt/db/document",
|
|
1591
|
-
content_type: "application/json",
|
|
1592
|
-
rate_limit: "global",
|
|
1593
|
-
params: {
|
|
1594
|
-
collection: "string",
|
|
1595
|
-
path: ["string", "object"],
|
|
1596
|
-
uid: {type: ["string", "null"], default: null},
|
|
1597
|
-
},
|
|
1598
|
-
callback: async (stream, params) => {
|
|
1599
|
-
|
|
1600
|
-
// Check ip whitelist.
|
|
1601
|
-
if (!this.preview_ip_whitelist.includes(stream.ip)) {
|
|
1602
|
-
return stream.error({status: Status.forbidden});
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
// Check collection.
|
|
1606
|
-
let col;
|
|
1607
|
-
if ((col = this.collections[params.collection]) == null) {
|
|
1608
|
-
return stream.error({data: {error: `Invalid collection "${params.collection}".`}})
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
// Load doc.
|
|
1612
|
-
let doc;
|
|
1613
|
-
if (params.uid == null) {
|
|
1614
|
-
doc = await col.delete(params.path);
|
|
1615
|
-
} else {
|
|
1616
|
-
doc = await col.delete(params.uid, params.path);
|
|
1617
|
-
}
|
|
1618
|
-
|
|
1619
|
-
// Sign in.
|
|
1620
|
-
return stream.success({data: {
|
|
1621
|
-
message: "Successfully deleted the document.",
|
|
1622
|
-
}});
|
|
1623
|
-
}
|
|
1624
|
-
},
|
|
1625
|
-
|
|
1626
|
-
// Update document.
|
|
1627
|
-
{
|
|
1628
|
-
method: "PATCH",
|
|
1629
|
-
endpoint: "/volt/db/document",
|
|
1630
|
-
content_type: "application/json",
|
|
1631
|
-
rate_limit: "global",
|
|
1632
|
-
params: {
|
|
1633
|
-
collection: "string",
|
|
1634
|
-
path: ["string", "object"],
|
|
1635
|
-
uid: {type: ["string", "null"], default: null},
|
|
1636
|
-
content: "object",
|
|
1637
|
-
},
|
|
1638
|
-
callback: async (stream, params) => {
|
|
1639
|
-
|
|
1640
|
-
// Check ip whitelist.
|
|
1641
|
-
if (!this.preview_ip_whitelist.includes(stream.ip)) {
|
|
1642
|
-
return stream.error({status: Status.forbidden});
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
// Check collection.
|
|
1646
|
-
let col;
|
|
1647
|
-
if ((col = this.collections[params.collection]) == null) {
|
|
1648
|
-
return stream.error({data: {error: `Invalid collection "${params.collection}".`}})
|
|
1649
|
-
}
|
|
1650
|
-
|
|
1651
|
-
// Load doc.
|
|
1652
|
-
let doc;
|
|
1653
|
-
if (params.uid == null) {
|
|
1654
|
-
doc = await col.save(params.path, params.content);
|
|
1655
|
-
} else {
|
|
1656
|
-
doc = await col.save(params.uid, params.path, params.content);
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
// Sign in.
|
|
1660
|
-
return stream.success({data: {
|
|
1661
|
-
message: "Successfully updated the document.",
|
|
1662
|
-
}});
|
|
1663
|
-
}
|
|
1664
|
-
},
|
|
1665
|
-
)
|
|
1666
|
-
}
|
|
1667
|
-
}*/
|
|
1668
|
-
// Connect.
|
|
1669
|
-
async connect() {
|
|
1670
|
-
try {
|
|
1671
|
-
await this.client?.connect();
|
|
1672
|
-
if (this.client) {
|
|
1673
|
-
this.db = this.client.db();
|
|
1674
|
-
}
|
|
1675
|
-
} catch (error) {
|
|
1676
|
-
console.error(error);
|
|
1677
|
-
throw new Error("Error connecting to the database");
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
// Initialize.
|
|
1681
|
-
async initialize() {
|
|
1682
|
-
if (this.config.systemLog === void 0) {
|
|
1683
|
-
this.config.systemLog = {};
|
|
1684
|
-
}
|
|
1685
|
-
this.config.systemLog.path = this.source?.join("mongod.log").str();
|
|
1686
|
-
if (this.config.systemLog.destination === void 0) {
|
|
1687
|
-
this.config.systemLog.destination = "file";
|
|
1688
|
-
}
|
|
1689
|
-
if (this.config.systemLog.logAppend === void 0) {
|
|
1690
|
-
this.config.systemLog.logAppend = true;
|
|
1691
|
-
}
|
|
1692
|
-
if (this.config.systemLog.logRotate === void 0) {
|
|
1693
|
-
this.config.systemLog.logRotate = "reopen";
|
|
1694
|
-
}
|
|
1695
|
-
if (this.config.systemLog.verbosity === void 0 && this.server) {
|
|
1696
|
-
this.config.systemLog.verbosity = this.server.production ? 0 : 1;
|
|
1697
|
-
}
|
|
1698
|
-
if (this.config.storage === void 0) {
|
|
1699
|
-
this.config.storage = {};
|
|
1700
|
-
}
|
|
1701
|
-
if (this.source) {
|
|
1702
|
-
const db_path = this.source.join("db");
|
|
1703
|
-
this.config.storage.dbPath = db_path.str();
|
|
1704
|
-
if (!db_path.exists()) {
|
|
1705
|
-
db_path.mkdir_sync();
|
|
1706
|
-
}
|
|
1707
|
-
if (this.config.processManagement === void 0) {
|
|
1708
|
-
this.config.processManagement = {};
|
|
1709
|
-
}
|
|
1710
|
-
this.config.processManagement.pidFilePath = this.source.join("mongod.pid").str();
|
|
1711
|
-
}
|
|
1712
|
-
if (this.config.net === void 0) {
|
|
1713
|
-
this.config.net = {};
|
|
1714
|
-
}
|
|
1715
|
-
if (this.config.net.port === void 0) {
|
|
1716
|
-
this.config.net.port = 27017;
|
|
1717
|
-
}
|
|
1718
|
-
if (this.config.net.bindIp === void 0) {
|
|
1719
|
-
this.config.net.bindIp = "127.0.0.1";
|
|
1720
|
-
}
|
|
1721
|
-
if (this.server?.is_primary && this.uri == null) {
|
|
1722
|
-
if (!this.source.exists()) {
|
|
1723
|
-
this.source.mkdir_sync();
|
|
1724
|
-
}
|
|
1725
|
-
if (this.uri == null) {
|
|
1726
|
-
this.uri = `mongodb://${this.config.net.bindIp}:${this.config.net.port}/main`;
|
|
1727
|
-
}
|
|
1728
|
-
const config_path = this.source.join("mongod.json");
|
|
1729
|
-
config_path.save_sync(JSON.stringify(this.config));
|
|
1730
|
-
this.proc = (0, import_child_process.spawn)("mongod", ["--config", config_path.str(), ...this.start_args], {
|
|
1731
|
-
stdio: "pipe",
|
|
1732
|
-
detached: true,
|
|
1733
|
-
env: { ...process.env }
|
|
1734
|
-
});
|
|
1735
|
-
this.proc.stdout?.on("data", (data) => {
|
|
1736
|
-
console.log(data.toString());
|
|
1737
|
-
});
|
|
1738
|
-
this.proc.stderr?.on("data", (data) => {
|
|
1739
|
-
console.error(data.toString());
|
|
1740
|
-
});
|
|
1741
|
-
this.proc.on("error", (code, signal) => {
|
|
1742
|
-
console.error(`MongoDB crashed with error signal ${signal}.`);
|
|
1743
|
-
process.exit(code);
|
|
1744
|
-
});
|
|
1745
|
-
} else if (this.server && !this.server.is_primary && this.uri == null) {
|
|
1746
|
-
this.uri = `mongodb://${this.config.net.bindIp}:${this.config.net.port}/main`;
|
|
1747
|
-
}
|
|
1748
|
-
if (this.uri) {
|
|
1749
|
-
const opts = this.client_opts ?? {};
|
|
1750
|
-
opts.serverApi ??= {
|
|
1751
|
-
version: import_mongodb.ServerApiVersion.v1,
|
|
1752
|
-
strict: true,
|
|
1753
|
-
deprecationErrors: true
|
|
1754
|
-
};
|
|
1755
|
-
this.client = new import_mongodb.MongoClient(this.uri, opts);
|
|
1756
|
-
}
|
|
1757
|
-
await this.connect();
|
|
1758
|
-
const multiprocessing = true;
|
|
1759
|
-
const promises = [];
|
|
1760
|
-
for (const info of this._collections) {
|
|
1761
|
-
const promise = new Promise((resolve) => {
|
|
1762
|
-
if (this[info.name] !== void 0) {
|
|
1763
|
-
throw Error(`Unable to initialize database collection "${info.name}", this attribute name is reserved for a system value.`);
|
|
1764
|
-
}
|
|
1765
|
-
if (Array.isArray(info.indexes)) {
|
|
1766
|
-
for (let index = 0; index < info.indexes.length; index++) {
|
|
1767
|
-
let item = info.indexes[index];
|
|
1768
|
-
if (typeof item === "string") {
|
|
1769
|
-
info.indexes[index] = item = { keys: [item] };
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
this.create_collection(info).then((data) => {
|
|
1774
|
-
this[info.name] = data;
|
|
1775
|
-
resolve();
|
|
1776
|
-
});
|
|
1777
|
-
});
|
|
1778
|
-
if (multiprocessing) {
|
|
1779
|
-
promises.push(promise);
|
|
1780
|
-
} else {
|
|
1781
|
-
await promise;
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
for (const info of this._uid_collections) {
|
|
1785
|
-
const promise = new Promise((resolve) => {
|
|
1786
|
-
if (this[info.name] !== void 0) {
|
|
1787
|
-
throw Error(`Unable to initialize database collection "${info.name}", this attribute name is reserved for a system value.`);
|
|
1788
|
-
}
|
|
1789
|
-
if (Array.isArray(info.indexes)) {
|
|
1790
|
-
for (let index = 0; index < info.indexes.length; index++) {
|
|
1791
|
-
let item = info.indexes[index];
|
|
1792
|
-
if (typeof item === "string") {
|
|
1793
|
-
info.indexes[index] = item = {
|
|
1794
|
-
key: item
|
|
1795
|
-
};
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
}
|
|
1799
|
-
this.create_uid_collection(info).then((data) => {
|
|
1800
|
-
this[info.name] = data;
|
|
1801
|
-
resolve();
|
|
1802
|
-
});
|
|
1803
|
-
});
|
|
1804
|
-
if (multiprocessing) {
|
|
1805
|
-
promises.push(promise);
|
|
1806
|
-
} else {
|
|
1807
|
-
await promise;
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
if (multiprocessing) {
|
|
1811
|
-
await Promise.all(promises);
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
// Close.
|
|
1815
|
-
async close() {
|
|
1816
|
-
log(0, "Stopping the database.");
|
|
1817
|
-
await this.client?.close();
|
|
1818
|
-
}
|
|
1819
|
-
/* @docs:
|
|
1820
|
-
* @title: Create Collection
|
|
1821
|
-
* @description: Create a database collection.
|
|
1822
|
-
*/
|
|
1823
|
-
async create_collection(info) {
|
|
1824
|
-
let name;
|
|
1825
|
-
let indexes = [];
|
|
1826
|
-
let ttl = null;
|
|
1827
|
-
if (typeof info === "string") {
|
|
1828
|
-
name = info;
|
|
1829
|
-
} else {
|
|
1830
|
-
name = info.name;
|
|
1831
|
-
indexes = info.indexes || [];
|
|
1832
|
-
ttl = info.ttl || null;
|
|
1833
|
-
}
|
|
1834
|
-
if (name in this.collections) {
|
|
1835
|
-
throw Error(`Collection "${name}" is already initialized.`);
|
|
1836
|
-
}
|
|
1837
|
-
debug(2, `Initializing collection "${name}".`);
|
|
1838
|
-
if (this._listed_cols == null) {
|
|
1839
|
-
this._listed_cols = await this.db.listCollections().toArray();
|
|
1840
|
-
}
|
|
1841
|
-
if (!this._listed_cols.find((x) => x.name === name)) {
|
|
1842
|
-
log(0, `Creating collection "${name}".`);
|
|
1843
|
-
await this.db.createCollection(name);
|
|
1844
|
-
}
|
|
1845
|
-
const col = new Collection(name, this.db.collection(name), ttl, indexes);
|
|
1846
|
-
this.collections[name] = col;
|
|
1847
|
-
return col;
|
|
1848
|
-
}
|
|
1849
|
-
/* @docs:
|
|
1850
|
-
* @title: Create UID Based Collection
|
|
1851
|
-
* @description: Create a UID based database collection.
|
|
1852
|
-
*/
|
|
1853
|
-
async create_uid_collection(info) {
|
|
1854
|
-
let name;
|
|
1855
|
-
let indexes = [];
|
|
1856
|
-
let ttl = null;
|
|
1857
|
-
if (typeof info === "string") {
|
|
1858
|
-
name = info;
|
|
1859
|
-
} else {
|
|
1860
|
-
name = info.name;
|
|
1861
|
-
indexes = info.indexes || [];
|
|
1862
|
-
ttl = info.ttl || null;
|
|
1863
|
-
}
|
|
1864
|
-
if (name in this.collections) {
|
|
1865
|
-
throw Error(`Collection "${name}" is already initialized.`);
|
|
1866
|
-
}
|
|
1867
|
-
debug(2, `Initializing uid collection "${name}".`);
|
|
1868
|
-
const collections = await this.db.listCollections({ name }).toArray();
|
|
1869
|
-
if (collections.length === 0) {
|
|
1870
|
-
log(0, `Creating uid collection "${name}".`);
|
|
1871
|
-
await this.db.createCollection(name);
|
|
1872
|
-
}
|
|
1873
|
-
const col = new UIDCollection(name, this.db.collection(name), indexes, ttl);
|
|
1874
|
-
this.collections[name] = col;
|
|
1875
|
-
return col;
|
|
1876
|
-
}
|
|
1877
|
-
/* @docs:
|
|
1878
|
-
* @title: Get Collections
|
|
1879
|
-
* @description: Get the names of the initializated database collections.
|
|
1880
|
-
*/
|
|
1881
|
-
async get_collections() {
|
|
1882
|
-
const created = Object.keys(this.collections);
|
|
1883
|
-
const database = (await this.db.listCollections().toArray()).map((item) => item.name);
|
|
1884
|
-
return created.concat(database).filter((value, index, self) => self.indexOf(value) === index).sort((a, b) => {
|
|
1885
|
-
const result = a.toLowerCase().localeCompare(b.toLowerCase());
|
|
1886
|
-
if (a.startsWith("_") && b.startsWith("_")) {
|
|
1887
|
-
return result;
|
|
1888
|
-
}
|
|
1889
|
-
if (a.startsWith("_")) {
|
|
1890
|
-
return 1;
|
|
1891
|
-
}
|
|
1892
|
-
if (b.startsWith("_")) {
|
|
1893
|
-
return -1;
|
|
1894
|
-
}
|
|
1895
|
-
return result;
|
|
1896
|
-
});
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
class UIDDocument {
|
|
1900
|
-
col;
|
|
1901
|
-
data;
|
|
1902
|
-
def;
|
|
1903
|
-
uid;
|
|
1904
|
-
path;
|
|
1905
|
-
chunked;
|
|
1906
|
-
error_type;
|
|
1907
|
-
/** Constructor
|
|
1908
|
-
* @param def The default value, when the default value is an object then the attributes will be checked / inserted as well.
|
|
1909
|
-
*/
|
|
1910
|
-
constructor({ col, uid, path, data, def, chunked = false, external_errors = false }) {
|
|
1911
|
-
this.col = col;
|
|
1912
|
-
this.uid = uid;
|
|
1913
|
-
this.path = path;
|
|
1914
|
-
this.data = data;
|
|
1915
|
-
this.def = def;
|
|
1916
|
-
this.chunked = chunked;
|
|
1917
|
-
this.error_type = external_errors ? import_utils.ExternalError : import_utils.InternalError;
|
|
1918
|
-
}
|
|
1919
|
-
/** As database document. */
|
|
1920
|
-
document() {
|
|
1921
|
-
return this.data;
|
|
1922
|
-
}
|
|
1923
|
-
// ---------------------------------------------------------
|
|
1924
|
-
// Utils.
|
|
1925
|
-
/** Create error options. */
|
|
1926
|
-
not_found_error() {
|
|
1927
|
-
let id = this.uid + "/";
|
|
1928
|
-
if (typeof this.path === "string") {
|
|
1929
|
-
id += this.path;
|
|
1930
|
-
} else {
|
|
1931
|
-
id += Object.values(this.path).join("@");
|
|
1932
|
-
}
|
|
1933
|
-
return {
|
|
1934
|
-
type: "DocumentNotFound",
|
|
1935
|
-
message: `Requested document "${id}" does not exist.`,
|
|
1936
|
-
status: import_status.Status.bad_request
|
|
1937
|
-
};
|
|
1938
|
-
}
|
|
1939
|
-
not_loaded_error() {
|
|
1940
|
-
let id = this.uid + "/";
|
|
1941
|
-
if (typeof this.path === "string") {
|
|
1942
|
-
id += this.path;
|
|
1943
|
-
} else {
|
|
1944
|
-
id += Object.values(this.path).join("@");
|
|
1945
|
-
}
|
|
1946
|
-
return {
|
|
1947
|
-
type: "DocumentNotLoaded",
|
|
1948
|
-
message: `Requested document "${id}" does not exist.`,
|
|
1949
|
-
status: import_status.Status.bad_request
|
|
1950
|
-
};
|
|
1951
|
-
}
|
|
1952
|
-
/** Set defaults from constructor param `def`. */
|
|
1953
|
-
set_defaults() {
|
|
1954
|
-
if (this.data && this.def && !Array.isArray(this.def) && (typeof this.def === "object" || typeof this.def === "function")) {
|
|
1955
|
-
const set_defaults = (obj, defaults) => {
|
|
1956
|
-
Object.keys(defaults).forEach((key) => {
|
|
1957
|
-
if (obj[key] === void 0) {
|
|
1958
|
-
obj[key] = defaults[key];
|
|
1959
|
-
} else if (typeof obj[key] === "object" && !Array.isArray(obj[key]) && obj[key] != null && typeof defaults[key] === "object" && !Array.isArray(defaults[key]) && defaults[key] != null) {
|
|
1960
|
-
set_defaults(obj[key], defaults[key]);
|
|
1961
|
-
}
|
|
1962
|
-
});
|
|
1963
|
-
};
|
|
1964
|
-
set_defaults(this.data, typeof this.def === "function" ? this.def() : this.def);
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
// ---------------------------------------------------------
|
|
1968
|
-
// Callbacks.
|
|
1969
|
-
/** On load callback.
|
|
1970
|
-
* @note this is not called when default data is used for an empty document.
|
|
1971
|
-
* @warning the user MUST always call this function after manually loading the document.
|
|
1972
|
-
*/
|
|
1973
|
-
on_load() {
|
|
1974
|
-
this.set_defaults();
|
|
1975
|
-
}
|
|
1976
|
-
/** Assert load. */
|
|
1977
|
-
async assert_load() {
|
|
1978
|
-
if (!this.data) {
|
|
1979
|
-
await this.try_load();
|
|
1980
|
-
this.assert_load();
|
|
1981
|
-
}
|
|
1982
|
-
}
|
|
1983
|
-
/** Assert load */
|
|
1984
|
-
assert_loaded() {
|
|
1985
|
-
if (!this.data) {
|
|
1986
|
-
throw new this.error_type(this.not_loaded_error());
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
|
-
/** Check if a project exists.
|
|
1990
|
-
* @note this does not load the full document.
|
|
1991
|
-
*/
|
|
1992
|
-
async exists() {
|
|
1993
|
-
return await this.col.exists(this.uid, this.path);
|
|
1994
|
-
}
|
|
1995
|
-
/**
|
|
1996
|
-
* Load a project from the database
|
|
1997
|
-
* @param def the default value, when the default value is an object then the attributes will be checked / inserted as well.
|
|
1998
|
-
*/
|
|
1999
|
-
async load() {
|
|
2000
|
-
if (!await this.try_load() || !this.data) {
|
|
2001
|
-
if (this.def) {
|
|
2002
|
-
this.data = typeof this.def === "function" ? this.def() : this.def;
|
|
2003
|
-
} else {
|
|
2004
|
-
throw new this.error_type(this.not_found_error());
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
return this.data;
|
|
2008
|
-
}
|
|
2009
|
-
async try_load() {
|
|
2010
|
-
const data = await this.col.load(this.uid, this.path, { chunked: this.chunked });
|
|
2011
|
-
if (!data) {
|
|
2012
|
-
return;
|
|
2013
|
-
}
|
|
2014
|
-
this.data = data;
|
|
2015
|
-
this.on_load();
|
|
2016
|
-
return data;
|
|
2017
|
-
}
|
|
2018
|
-
/** Load partial by projection.
|
|
2019
|
-
* @note This automatically inserts the new values when the document is loaded in this specific scenario it also calls the on load callback.
|
|
2020
|
-
* @param fields The fields to load, nested fields should be separated by a dot (e.g. "a.b.c").
|
|
2021
|
-
*/
|
|
2022
|
-
async load_partial(...fields) {
|
|
2023
|
-
const data = await this.try_load_partial(...fields);
|
|
2024
|
-
if (!data) {
|
|
2025
|
-
throw new this.error_type(this.not_found_error());
|
|
2026
|
-
}
|
|
2027
|
-
return data;
|
|
2028
|
-
}
|
|
2029
|
-
async try_load_partial(...fields) {
|
|
2030
|
-
const projection = {};
|
|
2031
|
-
for (const field of fields) {
|
|
2032
|
-
projection[field] = 1;
|
|
2033
|
-
}
|
|
2034
|
-
const data = await this.col.load(this.uid, this.path, { projection });
|
|
2035
|
-
if (!data) {
|
|
2036
|
-
return void 0;
|
|
2037
|
-
}
|
|
2038
|
-
if (this.data) {
|
|
2039
|
-
UIDDocument.__insert_obj(this.data, data);
|
|
2040
|
-
this.on_load();
|
|
2041
|
-
}
|
|
2042
|
-
return data;
|
|
2043
|
-
}
|
|
2044
|
-
/** Save the project to the database */
|
|
2045
|
-
async save() {
|
|
2046
|
-
if (!this.data) {
|
|
2047
|
-
throw new this.error_type(this.not_loaded_error());
|
|
2048
|
-
}
|
|
2049
|
-
await this.col.save(this.uid, this.path, this.data, { chunked: this.chunked });
|
|
2050
|
-
}
|
|
2051
|
-
/** Save partial to the database
|
|
2052
|
-
* @note automatically inserts the new values when the document is loaded.
|
|
2053
|
-
*/
|
|
2054
|
-
async save_partial(partial_data) {
|
|
2055
|
-
if (this.chunked) {
|
|
2056
|
-
throw new this.error_type({
|
|
2057
|
-
type: "UnsupportedDocumentOperation",
|
|
2058
|
-
message: "Chunked documents do not support partial updates.",
|
|
2059
|
-
status: import_status.Status.bad_request
|
|
2060
|
-
});
|
|
2061
|
-
}
|
|
2062
|
-
if (this.data && typeof partial_data === "object" && !Array.isArray(this.data) && partial_data && typeof partial_data === "object" && !Array.isArray(partial_data)) {
|
|
2063
|
-
UIDDocument.__insert_obj(this.data, partial_data);
|
|
2064
|
-
}
|
|
2065
|
-
await this.col.save(this.uid, this.path, partial_data, { chunked: this.chunked });
|
|
2066
|
-
}
|
|
2067
|
-
/** Delete database record. */
|
|
2068
|
-
async delete(opts) {
|
|
2069
|
-
return this.col.delete(this.uid, this.path, {
|
|
2070
|
-
...opts,
|
|
2071
|
-
chunked: this.chunked
|
|
2072
|
-
});
|
|
2073
|
-
}
|
|
2074
|
-
/** Wrapper function to insert an obj into another
|
|
2075
|
-
* @note this is not a deep copy.
|
|
2076
|
-
*/
|
|
2077
|
-
static __insert_obj(obj, partial) {
|
|
2078
|
-
Object.keys(partial).forEach((key) => {
|
|
2079
|
-
const val = partial[key];
|
|
2080
|
-
if (val !== null && typeof val === "object" && !Array.isArray(val) && obj[key] !== null && typeof obj[key] === "object" && !Array.isArray(obj[key])) {
|
|
2081
|
-
UIDDocument.__insert_obj(obj[key], val);
|
|
2082
|
-
} else {
|
|
2083
|
-
obj[key] = val;
|
|
2084
|
-
}
|
|
2085
|
-
});
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
class DocumentRef {
|
|
2089
|
-
col;
|
|
2090
|
-
uid;
|
|
2091
|
-
path;
|
|
2092
|
-
def;
|
|
2093
|
-
chunked;
|
|
2094
|
-
record_version;
|
|
2095
|
-
error_type;
|
|
2096
|
-
transform_version;
|
|
2097
|
-
_on_load;
|
|
2098
|
-
/** Constructor
|
|
2099
|
-
* @param col The collection created by the server.
|
|
2100
|
-
* @param uid The uid of the document, this is only required when the collection is a UIDCollection.
|
|
2101
|
-
* @param path The path of the document, this can be a string or an object query.
|
|
2102
|
-
* @param def The default value, when the default value is an object then the attributes will be checked / inserted as well.
|
|
2103
|
-
* @param chunked If true then the document is stored in chunks.
|
|
2104
|
-
* @param external_errors If true then the errors are thrown as external errors, instead of internal errors.
|
|
2105
|
-
* @param record_version The record type version for the database.
|
|
2106
|
-
* This can be used in combination with parameter `transform_version` to ...
|
|
2107
|
-
* Transform older record versions to the current version.
|
|
2108
|
-
* @param transform_version The function to transform an older document version to the current version.
|
|
2109
|
-
* @param on_load The function to call when the document is loaded.
|
|
2110
|
-
*/
|
|
2111
|
-
constructor({ col, uid, path, def, chunked = false, external_errors = false, record_version = 1, transform_version, on_load }) {
|
|
2112
|
-
this.col = col;
|
|
2113
|
-
this.uid = uid;
|
|
2114
|
-
this.path = path;
|
|
2115
|
-
this.def = def;
|
|
2116
|
-
this.chunked = chunked;
|
|
2117
|
-
this.error_type = external_errors ? import_utils.ExternalError : import_utils.InternalError;
|
|
2118
|
-
this.record_version = record_version;
|
|
2119
|
-
this.transform_version = transform_version;
|
|
2120
|
-
this._on_load = on_load;
|
|
2121
|
-
if (this.col instanceof UIDCollection && !this.uid) {
|
|
2122
|
-
throw new this.error_type({
|
|
2123
|
-
type: "InvalidDocumentRef",
|
|
2124
|
-
message: "UIDCollection reference must have a uid.",
|
|
2125
|
-
status: import_status.Status.bad_request
|
|
2126
|
-
});
|
|
2127
|
-
}
|
|
2128
|
-
if (this.col instanceof Collection && this.uid) {
|
|
2129
|
-
throw new this.error_type({
|
|
2130
|
-
type: "InvalidDocumentRef",
|
|
2131
|
-
message: "Collection reference must not have a uid.",
|
|
2132
|
-
status: import_status.Status.bad_request
|
|
2133
|
-
});
|
|
2134
|
-
}
|
|
2135
|
-
if (this.record_version != 1 && !this.transform_version) {
|
|
2136
|
-
throw new this.error_type({
|
|
2137
|
-
type: "InvalidDocumentRef",
|
|
2138
|
-
message: "Transform version must be set when record version is set.",
|
|
2139
|
-
status: import_status.Status.bad_request
|
|
2140
|
-
});
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
/** Set defaults from constructor param `def`. */
|
|
2144
|
-
set_defaults(data) {
|
|
2145
|
-
if (data && this.def && !Array.isArray(this.def) && (typeof this.def === "object" || typeof this.def === "function")) {
|
|
2146
|
-
const set_defaults = (obj, defaults) => {
|
|
2147
|
-
Object.keys(defaults).forEach((key) => {
|
|
2148
|
-
if (obj[key] === void 0) {
|
|
2149
|
-
obj[key] = defaults[key];
|
|
2150
|
-
} else if (typeof obj[key] === "object" && !Array.isArray(obj[key]) && obj[key] != null && typeof defaults[key] === "object" && !Array.isArray(defaults[key]) && defaults[key] != null) {
|
|
2151
|
-
set_defaults(obj[key], defaults[key]);
|
|
2152
|
-
}
|
|
2153
|
-
});
|
|
2154
|
-
};
|
|
2155
|
-
set_defaults(data, typeof this.def === "function" ? this.def() : this.def);
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
/** Get the computed default value, when defined. */
|
|
2159
|
-
as_default() {
|
|
2160
|
-
if (this.def) {
|
|
2161
|
-
return typeof this.def === "function" ? this.def() : this.def;
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
/**
|
|
2165
|
-
* On load callback.
|
|
2166
|
-
* @note this is not called when default data is used for an empty document.
|
|
2167
|
-
*/
|
|
2168
|
-
on_load(data) {
|
|
2169
|
-
if (this.record_version && data.__record_version !== 1) {
|
|
2170
|
-
data = this.transform_version(this.record_version, data);
|
|
2171
|
-
}
|
|
2172
|
-
this.set_defaults(data);
|
|
2173
|
-
if (this._on_load) {
|
|
2174
|
-
data = this._on_load(data);
|
|
2175
|
-
}
|
|
2176
|
-
return data;
|
|
2177
|
-
}
|
|
2178
|
-
/** Check if a project exists.
|
|
2179
|
-
* @note this does not load the full document.
|
|
2180
|
-
*/
|
|
2181
|
-
async exists() {
|
|
2182
|
-
if (this.col instanceof UIDCollection) {
|
|
2183
|
-
return await this.col.exists(this.uid, this.path);
|
|
2184
|
-
}
|
|
2185
|
-
return await this.col.exists(this.path);
|
|
2186
|
-
}
|
|
2187
|
-
/**
|
|
2188
|
-
* Load a project from the database
|
|
2189
|
-
* @param def the default value, when the default value is an object then the attributes will be checked / inserted as well.
|
|
2190
|
-
*/
|
|
2191
|
-
async load() {
|
|
2192
|
-
const data = this.col instanceof UIDCollection ? await this.col.load(this.uid, this.path, { chunked: this.chunked }) : await this.col.load(this.path, { chunked: this.chunked });
|
|
2193
|
-
if (!data) {
|
|
2194
|
-
if (this.def) {
|
|
2195
|
-
return typeof this.def === "function" ? this.def() : this.def;
|
|
2196
|
-
}
|
|
2197
|
-
return;
|
|
2198
|
-
}
|
|
2199
|
-
return this.on_load(data);
|
|
2200
|
-
}
|
|
2201
|
-
/**
|
|
2202
|
-
* Load partial by projection.
|
|
2203
|
-
* @param fields The fields to load, nested fields should be separated by a dot (e.g. "a.b.c").
|
|
2204
|
-
*/
|
|
2205
|
-
async load_partial(...fields) {
|
|
2206
|
-
const projection = {};
|
|
2207
|
-
for (const field of fields) {
|
|
2208
|
-
projection[field] = 1;
|
|
2209
|
-
}
|
|
2210
|
-
return await (this.col instanceof UIDCollection ? this.col.load(this.uid, this.path, { projection }) : this.col.load(this.path, { projection }));
|
|
2211
|
-
}
|
|
2212
|
-
/** Save the project to the database */
|
|
2213
|
-
async save(data) {
|
|
2214
|
-
data.__record_version = this.record_version;
|
|
2215
|
-
return this.col instanceof UIDCollection ? this.col.save(this.uid, this.path, data, { chunked: this.chunked }) : this.col.save(this.path, data, { chunked: this.chunked });
|
|
2216
|
-
}
|
|
2217
|
-
/** Save partial to the database
|
|
2218
|
-
* @note automatically inserts the new values when the document is loaded.
|
|
2219
|
-
*/
|
|
2220
|
-
async save_partial(partial_data) {
|
|
2221
|
-
if (this.chunked) {
|
|
2222
|
-
throw new this.error_type({
|
|
2223
|
-
type: "UnsupportedDocumentOperation",
|
|
2224
|
-
message: "Chunked documents do not support partial updates.",
|
|
2225
|
-
status: import_status.Status.bad_request
|
|
2226
|
-
});
|
|
2227
|
-
}
|
|
2228
|
-
return this.col instanceof UIDCollection ? this.col.save(this.uid, this.path, partial_data, { chunked: this.chunked }) : this.col.save(this.path, partial_data, { chunked: this.chunked });
|
|
2229
|
-
}
|
|
2230
|
-
/** Delete database record. */
|
|
2231
|
-
async delete(opts) {
|
|
2232
|
-
return this.col instanceof UIDCollection ? this.col.delete(this.uid, this.path, {
|
|
2233
|
-
...opts,
|
|
2234
|
-
chunked: this.chunked
|
|
2235
|
-
}) : this.col.delete(this.path, {
|
|
2236
|
-
...opts,
|
|
2237
|
-
chunked: this.chunked
|
|
2238
|
-
});
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
2242
|
-
0 && (module.exports = {
|
|
2243
|
-
Collection,
|
|
2244
|
-
Database,
|
|
2245
|
-
DocumentRef,
|
|
2246
|
-
UIDCollection,
|
|
2247
|
-
UIDDocument
|
|
2248
|
-
});
|