@joystick.js/node-canary 0.0.0-canary.47 → 0.0.0-canary.470
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/.build/getFilesToBuild.js +26 -0
- package/.build/getPlatformSafeFilePath.js +6 -0
- package/.build/getPlatformSafePath.js +6 -0
- package/.build/index.js +88 -0
- package/.build/isWindows.js +3 -0
- package/dist/action/class.js +1 -82
- package/dist/action/index.js +1 -8
- package/dist/app/accounts/default_user_output_fields.js +1 -0
- package/dist/app/accounts/delete_user.js +1 -0
- package/dist/app/accounts/generate_account_session.js +1 -0
- package/dist/app/accounts/generate_password_reset_token.js +1 -0
- package/dist/app/accounts/get_browser_safe_user.js +1 -0
- package/dist/app/accounts/has_login_token_expired.js +1 -0
- package/dist/app/accounts/index.js +1 -29
- package/dist/app/accounts/login.js +1 -59
- package/dist/app/accounts/recover_password.js +1 -0
- package/dist/app/accounts/reset_password.js +1 -0
- package/dist/app/accounts/roles/add.js +1 -7
- package/dist/app/accounts/roles/grant.js +1 -7
- package/dist/app/accounts/roles/index.js +1 -17
- package/dist/app/accounts/roles/list.js +1 -7
- package/dist/app/accounts/roles/remove.js +1 -7
- package/dist/app/accounts/roles/revoke.js +1 -7
- package/dist/app/accounts/roles/user_has_role.js +1 -0
- package/dist/app/accounts/send_email_verification.js +1 -0
- package/dist/app/accounts/set_account_cookie.js +1 -0
- package/dist/app/accounts/set_password.js +1 -0
- package/dist/app/accounts/signup.js +1 -97
- package/dist/app/accounts/unset_account_cookie.js +1 -0
- package/dist/app/accounts/verify_email.js +1 -0
- package/dist/app/api/accounts/authenticated.js +1 -0
- package/dist/app/api/accounts/login.js +1 -0
- package/dist/app/api/accounts/logout.js +1 -0
- package/dist/app/api/accounts/recover_password.js +1 -0
- package/dist/app/api/accounts/reset_password.js +1 -0
- package/dist/app/api/accounts/signup.js +1 -0
- package/dist/app/api/accounts/user.js +1 -0
- package/dist/app/api/accounts/verify_email.js +1 -0
- package/dist/app/api/format_api_error.js +1 -0
- package/dist/app/api/get.js +2 -0
- package/dist/app/api/get_api_context.js +1 -0
- package/dist/app/api/get_api_for_data_functions.js +1 -0
- package/dist/app/api/get_api_url_component.js +1 -0
- package/dist/app/api/get_output.js +1 -0
- package/dist/app/api/get_value_from_object.js +1 -0
- package/dist/app/api/handle_api_error.js +1 -0
- package/dist/app/api/input_validators.js +1 -0
- package/dist/app/api/is_array_path.js +1 -0
- package/dist/app/api/push/health.js +2 -0
- package/dist/app/api/register_getters.js +1 -0
- package/dist/app/api/register_setters.js +1 -0
- package/dist/app/api/sanitize_api_response.js +1 -0
- package/dist/app/api/set.js +2 -0
- package/dist/app/api/test/accounts/delete.js +1 -0
- package/dist/app/api/test/accounts/signup.js +1 -0
- package/dist/app/api/test/bootstrap.js +1 -0
- package/dist/app/api/test/process.js +1 -0
- package/dist/app/api/test/queues.js +1 -0
- package/dist/app/api/validate_input.js +1 -0
- package/dist/app/api/validate_session.js +1 -0
- package/dist/app/api/validate_type.js +1 -0
- package/dist/app/browser/hmr_client.js +1 -0
- package/dist/app/browser/process_polyfill.js +1 -0
- package/dist/app/cron_jobs/register.js +1 -0
- package/dist/app/databases/database_type_map.js +1 -0
- package/dist/app/databases/get_target_database_connection.js +1 -0
- package/dist/app/databases/mongodb/available_query_parameters.js +1 -0
- package/dist/app/databases/mongodb/build_connection_string.js +1 -0
- package/dist/app/databases/mongodb/build_query_parameters.js +1 -0
- package/dist/app/databases/mongodb/connect.js +6 -0
- package/dist/app/databases/mongodb/create_indexes.js +1 -0
- package/dist/app/databases/postgresql/accounts/create_accounts_metadata_table_columns.js +1 -0
- package/dist/app/databases/postgresql/connect.js +30 -0
- package/dist/app/databases/postgresql/create_indexes.js +1 -0
- package/dist/app/databases/postgresql/create_tables.js +1 -0
- package/dist/app/databases/postgresql/handle_cleanup_queues.js +5 -0
- package/dist/app/databases/postgresql/handle_cleanup_sessions.js +1 -0
- package/dist/app/databases/queries/accounts.js +1 -0
- package/dist/app/databases/queries/map.js +1 -0
- package/dist/app/databases/queries/mongodb/accounts.js +1 -0
- package/dist/app/databases/queries/mongodb/queues.js +1 -0
- package/dist/app/databases/queries/mongodb/sessions.js +1 -0
- package/dist/app/databases/queries/postgresql/accounts.js +1 -0
- package/dist/app/databases/queries/postgresql/queues.js +123 -0
- package/dist/app/databases/queries/postgresql/sessions.js +14 -0
- package/dist/app/databases/queries/sessions.js +1 -0
- package/dist/app/databases/register_database.js +1 -0
- package/dist/app/databases/sql.js +1 -0
- package/dist/app/email/send.js +1 -0
- package/dist/app/email/validate_smtp_settings.js +1 -0
- package/dist/app/fixture/index.js +1 -0
- package/dist/app/generate_machine_id.js +1 -0
- package/dist/app/generate_process_id.js +1 -0
- package/dist/app/get_ssl_certificates.js +1 -0
- package/dist/app/handle_process_errors.js +1 -0
- package/dist/app/index.js +1 -656
- package/dist/app/middleware/account.js +1 -0
- package/dist/app/middleware/body_parser.js +1 -0
- package/dist/app/middleware/build_error.js +1 -0
- package/dist/app/middleware/built_in.js +1 -0
- package/dist/app/middleware/context.js +1 -0
- package/dist/app/middleware/cors.js +1 -22
- package/dist/app/middleware/csp.js +1 -48
- package/dist/app/middleware/generate_insecure_page.js +65 -0
- package/dist/app/middleware/generate_joystick_error_page.js +147 -0
- package/dist/app/middleware/hmr_client.js +1 -0
- package/dist/app/middleware/insecure.js +1 -11
- package/dist/app/middleware/process_browser_polyfill.js +1 -0
- package/dist/app/middleware/render/get_url.js +1 -0
- package/dist/app/middleware/render/index.js +1 -0
- package/dist/app/middleware/request_methods.js +1 -0
- package/dist/app/middleware/session.js +1 -24
- package/dist/app/push_logs.js +1 -0
- package/dist/app/queues/index.js +1 -119
- package/dist/app/register_app_options.js +1 -0
- package/dist/app/routes/register_route_from_function.js +1 -0
- package/dist/app/routes/register_route_from_object.js +1 -0
- package/dist/app/routes/supported_http_methods.js +1 -0
- package/dist/app/settings/load.js +1 -0
- package/dist/app/ssr/index.js +33 -0
- package/dist/app/ssr/set_base_attributes_in_html.js +1 -0
- package/dist/app/ssr/set_head_tags_in_html.js +1 -0
- package/dist/app/start_express.js +1 -0
- package/dist/app/start_node_as_cluster.js +1 -0
- package/dist/app/uploaders/local_upload_progress_middleware.js +1 -0
- package/dist/app/uploaders/register.js +1 -0
- package/dist/app/uploaders/run_upload.js +1 -0
- package/dist/app/uploaders/validate_options.js +1 -0
- package/dist/app/uploaders/validate_uploads.js +1 -0
- package/dist/app/websockets/emit_event.js +1 -0
- package/dist/app/websockets/index.js +1 -0
- package/dist/app/websockets/register.js +1 -0
- package/dist/index.js +4 -76
- package/dist/lib/camel_pascal_to_snake.js +1 -0
- package/dist/lib/constants.js +1 -13
- package/dist/lib/dynamic_import.js +1 -0
- package/dist/lib/escape_html.js +1 -0
- package/dist/lib/escape_key_value_pair.js +1 -0
- package/dist/lib/float_to_decimal_place.js +1 -0
- package/dist/lib/generate_id.js +1 -0
- package/dist/lib/get_browser_safe_request.js +1 -0
- package/dist/lib/get_joystick_build_path.js +1 -0
- package/dist/lib/get_origin.js +1 -0
- package/dist/lib/get_platform_safe_path.js +1 -0
- package/dist/lib/get_sanitized_context.js +1 -0
- package/dist/lib/get_translations.js +1 -0
- package/dist/lib/hash_string.js +1 -0
- package/dist/lib/is_valid_json.js +1 -0
- package/dist/lib/log.js +13 -49
- package/dist/lib/node_path_polyfills.js +1 -0
- package/dist/lib/parse_json.js +1 -0
- package/dist/lib/path_exists.js +1 -0
- package/dist/lib/rainbow_road.js +1 -0
- package/dist/lib/serialize_query_parameters.js +1 -0
- package/dist/lib/set_cookie.js +1 -0
- package/dist/lib/string_to_slug.js +1 -0
- package/dist/lib/timestamps.js +1 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/unset_cookie.js +1 -0
- package/dist/lib/wait.js +1 -0
- package/dist/test/track_function_call.js +1 -0
- package/increment_version.js +3 -0
- package/package.json +27 -44
- package/src/action/class.js +137 -0
- package/src/action/index.js +8 -0
- package/src/app/accounts/default_user_output_fields.js +10 -0
- package/src/app/accounts/delete_user.js +18 -0
- package/src/app/accounts/generate_account_session.js +11 -0
- package/src/app/accounts/generate_password_reset_token.js +16 -0
- package/src/app/accounts/get_browser_safe_user.js +29 -0
- package/src/app/accounts/has_login_token_expired.js +9 -0
- package/src/app/accounts/index.js +38 -0
- package/src/app/accounts/login.js +82 -0
- package/src/app/accounts/recover_password.js +58 -0
- package/src/app/accounts/reset_password.js +69 -0
- package/src/app/accounts/roles/add.js +7 -0
- package/src/app/accounts/roles/grant.js +7 -0
- package/src/app/accounts/roles/index.js +18 -0
- package/src/app/accounts/roles/list.js +7 -0
- package/src/app/accounts/roles/remove.js +7 -0
- package/src/app/accounts/roles/revoke.js +7 -0
- package/src/app/accounts/roles/user_has_role.js +7 -0
- package/src/app/accounts/send_email_verification.js +48 -0
- package/src/app/accounts/set_account_cookie.js +12 -0
- package/src/app/accounts/set_password.js +46 -0
- package/src/app/accounts/signup.js +158 -0
- package/src/app/accounts/unset_account_cookie.js +12 -0
- package/src/app/accounts/verify_email.js +32 -0
- package/src/app/api/accounts/authenticated.js +17 -0
- package/src/app/api/accounts/login.js +36 -0
- package/src/app/api/accounts/logout.js +20 -0
- package/src/app/api/accounts/recover_password.js +16 -0
- package/src/app/api/accounts/reset_password.js +24 -0
- package/src/app/api/accounts/signup.js +49 -0
- package/src/app/api/accounts/user.js +21 -0
- package/src/app/api/accounts/verify_email.js +11 -0
- package/src/app/api/format_api_error.js +10 -0
- package/src/app/api/get.js +119 -0
- package/src/app/api/get_api_context.js +27 -0
- package/src/app/api/get_api_for_data_functions.js +37 -0
- package/src/app/api/get_api_url_component.js +5 -0
- package/src/app/api/get_output.js +116 -0
- package/src/app/api/get_value_from_object.js +8 -0
- package/src/app/api/handle_api_error.js +28 -0
- package/src/app/api/input_validators.js +227 -0
- package/src/app/api/is_array_path.js +6 -0
- package/src/app/api/push/health.js +17 -0
- package/src/app/api/register_getters.js +57 -0
- package/src/app/api/register_setters.js +55 -0
- package/src/app/api/sanitize_api_response.js +35 -0
- package/src/app/api/set.js +119 -0
- package/src/app/api/test/accounts/delete.js +8 -0
- package/src/app/api/test/accounts/signup.js +50 -0
- package/src/app/api/test/bootstrap.js +39 -0
- package/src/app/api/test/process.js +7 -0
- package/src/app/api/test/queues.js +25 -0
- package/src/app/api/validate_input.js +130 -0
- package/src/app/api/validate_session.js +20 -0
- package/src/app/api/validate_type.js +24 -0
- package/src/app/browser/hmr_client.js +196 -0
- package/src/app/browser/process_polyfill.js +11 -0
- package/src/app/cron_jobs/register.js +29 -0
- package/src/app/databases/database_type_map.js +6 -0
- package/src/app/databases/get_target_database_connection.js +25 -0
- package/{dist/app/databases/mongodb/availableQueryParameters.js → src/app/databases/mongodb/available_query_parameters.js} +3 -4
- package/src/app/databases/mongodb/build_connection_string.js +30 -0
- package/src/app/databases/mongodb/build_query_parameters.js +17 -0
- package/src/app/databases/mongodb/connect.js +42 -0
- package/src/app/databases/mongodb/create_indexes.js +35 -0
- package/src/app/databases/postgresql/accounts/create_accounts_metadata_table_columns.js +18 -0
- package/src/app/databases/postgresql/connect.js +128 -0
- package/src/app/databases/postgresql/create_indexes.js +58 -0
- package/src/app/databases/postgresql/create_tables.js +70 -0
- package/src/app/databases/postgresql/handle_cleanup_queues.js +36 -0
- package/src/app/databases/postgresql/handle_cleanup_sessions.js +5 -0
- package/src/app/databases/queries/accounts.js +17 -0
- package/src/app/databases/queries/map.js +21 -0
- package/src/app/databases/queries/mongodb/accounts.js +360 -0
- package/src/app/databases/queries/mongodb/queues.js +164 -0
- package/src/app/databases/queries/mongodb/sessions.js +22 -0
- package/src/app/databases/queries/postgresql/accounts.js +379 -0
- package/src/app/databases/queries/postgresql/queues.js +294 -0
- package/src/app/databases/queries/postgresql/sessions.js +37 -0
- package/src/app/databases/queries/sessions.js +17 -0
- package/src/app/databases/register_database.js +30 -0
- package/src/app/databases/sql.js +63 -0
- package/src/app/email/send.js +108 -0
- package/src/app/email/validate_smtp_settings.js +53 -0
- package/src/app/fixture/index.js +50 -0
- package/src/app/generate_machine_id.js +26 -0
- package/src/app/generate_process_id.js +30 -0
- package/src/app/get_ssl_certificates.js +23 -0
- package/src/app/handle_process_errors.js +101 -0
- package/src/app/index.js +253 -0
- package/src/app/middleware/account.js +28 -0
- package/src/app/middleware/body_parser.js +18 -0
- package/src/app/middleware/build_error.js +18 -0
- package/src/app/middleware/built_in.js +76 -0
- package/src/app/middleware/context.js +34 -0
- package/src/app/middleware/cors.js +23 -0
- package/src/app/middleware/csp.js +54 -0
- package/src/app/middleware/generate_insecure_page.js +71 -0
- package/{dist/lib/generateErrorPage.js → src/app/middleware/generate_joystick_error_page.js} +25 -21
- package/src/app/middleware/hmr_client.js +12 -0
- package/src/app/middleware/insecure.js +22 -0
- package/src/app/middleware/process_browser_polyfill.js +12 -0
- package/src/app/middleware/render/get_url.js +15 -0
- package/src/app/middleware/render/index.js +93 -0
- package/src/app/middleware/request_methods.js +21 -0
- package/src/app/middleware/session.js +31 -0
- package/src/app/push_logs.js +44 -0
- package/src/app/queues/index.js +268 -0
- package/src/app/register_app_options.js +7 -0
- package/src/app/routes/register_route_from_function.js +10 -0
- package/src/app/routes/register_route_from_object.js +34 -0
- package/src/app/routes/supported_http_methods.js +9 -0
- package/src/app/settings/load.js +33 -0
- package/src/app/ssr/index.js +133 -0
- package/src/app/ssr/set_base_attributes_in_html.js +43 -0
- package/src/app/ssr/set_head_tags_in_html.js +104 -0
- package/src/app/start_express.js +50 -0
- package/src/app/start_node_as_cluster.js +30 -0
- package/src/app/uploaders/local_upload_progress_middleware.js +24 -0
- package/src/app/uploaders/register.js +169 -0
- package/src/app/uploaders/run_upload.js +136 -0
- package/src/app/uploaders/validate_options.js +74 -0
- package/src/app/uploaders/validate_uploads.js +127 -0
- package/src/app/websockets/emit_event.js +14 -0
- package/src/app/websockets/index.js +16 -0
- package/src/app/websockets/register.js +175 -0
- package/src/index.js +81 -0
- package/{dist/lib/camelPascalToSnake.js → src/lib/camel_pascal_to_snake.js} +3 -4
- package/src/lib/constants.js +21 -0
- package/src/lib/dynamic_import.js +8 -0
- package/src/lib/escape_html.js +9 -0
- package/src/lib/escape_key_value_pair.js +15 -0
- package/src/lib/float_to_decimal_place.js +5 -0
- package/src/lib/generate_id.js +15 -0
- package/src/lib/get_browser_safe_request.js +17 -0
- package/src/lib/get_joystick_build_path.js +22 -0
- package/src/lib/get_origin.js +7 -0
- package/src/lib/get_platform_safe_path.js +8 -0
- package/src/lib/get_sanitized_context.js +51 -0
- package/src/lib/get_translations.js +109 -0
- package/src/lib/hash_string.js +7 -0
- package/src/lib/is_valid_json.js +10 -0
- package/src/lib/log.js +42 -0
- package/src/lib/node_path_polyfills.js +23 -0
- package/src/lib/parse_json.js +9 -0
- package/src/lib/path_exists.js +12 -0
- package/src/lib/rainbow_road.js +7 -0
- package/src/lib/serialize_query_parameters.js +7 -0
- package/src/lib/set_cookie.js +16 -0
- package/src/lib/string_to_slug.js +14 -0
- package/src/lib/timestamps.js +48 -0
- package/src/lib/types.js +59 -0
- package/src/lib/unset_cookie.js +11 -0
- package/src/lib/wait.js +9 -0
- package/src/test/track_function_call.js +16 -0
- package/README.md +0 -8
- package/_package.json +0 -63
- package/canary.js +0 -12
- package/dist/api/get.js +0 -29
- package/dist/api/getOrigin.js +0 -6
- package/dist/api/index.js +0 -9
- package/dist/api/set.js +0 -29
- package/dist/app/accounts/defaultUserOutputFields.js +0 -9
- package/dist/app/accounts/generateResetToken.js +0 -28
- package/dist/app/accounts/generateSession.js +0 -15
- package/dist/app/accounts/getBrowserSafeUser.js +0 -24
- package/dist/app/accounts/hasLoginTokenExpired.js +0 -17
- package/dist/app/accounts/hashString.js +0 -7
- package/dist/app/accounts/recoverPassword.js +0 -30
- package/dist/app/accounts/resetPassword.js +0 -73
- package/dist/app/accounts/roles/userHasRole.js +0 -7
- package/dist/app/accounts/runUserQuery.js +0 -15
- package/dist/app/accounts/sendEmailVerification.js +0 -65
- package/dist/app/accounts/setAuthenticationCookie.js +0 -11
- package/dist/app/accounts/setPassword.js +0 -45
- package/dist/app/accounts/unsetAuthenticationCookie.js +0 -11
- package/dist/app/accounts/verifyEmail.js +0 -46
- package/dist/app/databases/getTargetDatabase.js +0 -10
- package/dist/app/databases/getTargetDatabaseConnection.js +0 -19
- package/dist/app/databases/getTargetDatabaseProvider.js +0 -10
- package/dist/app/databases/mongodb/buildConnectionString.js +0 -22
- package/dist/app/databases/mongodb/buildQueryParameters.js +0 -14
- package/dist/app/databases/mongodb/index.js +0 -40
- package/dist/app/databases/mongodb/queries/accounts.js +0 -266
- package/dist/app/databases/mongodb/queries/queues.js +0 -111
- package/dist/app/databases/postgresql/addColumnToTable.js +0 -6
- package/dist/app/databases/postgresql/createAccountsIndexes.js +0 -21
- package/dist/app/databases/postgresql/createAccountsTables.js +0 -39
- package/dist/app/databases/postgresql/createDatabase.js +0 -0
- package/dist/app/databases/postgresql/index.js +0 -55
- package/dist/app/databases/postgresql/queries/accounts.js +0 -186
- package/dist/app/databases/postgresql/queries/queues.js +0 -211
- package/dist/app/databases/queryMap.js +0 -17
- package/dist/app/databases/typesMap.js +0 -7
- package/dist/app/getAPIContext.js +0 -25
- package/dist/app/getAPIURLComponent.js +0 -6
- package/dist/app/getBrowserSafeRequest.js +0 -14
- package/dist/app/getOutput.js +0 -74
- package/dist/app/handleProcessErrors.js +0 -73
- package/dist/app/initExpress.js +0 -41
- package/dist/app/middleware/bodyParser.js +0 -16
- package/dist/app/middleware/hmr/client.js +0 -113
- package/dist/app/middleware/index.js +0 -89
- package/dist/app/middleware/render.js +0 -213
- package/dist/app/middleware/requestMethods.js +0 -19
- package/dist/app/registerGetters.js +0 -45
- package/dist/app/registerSetters.js +0 -45
- package/dist/app/runGetter.js +0 -103
- package/dist/app/runSetter.js +0 -103
- package/dist/app/runUploader.js +0 -143
- package/dist/app/sanitizeAPIResponse.js +0 -27
- package/dist/app/utils/process.js +0 -193
- package/dist/app/validateSession.js +0 -19
- package/dist/app/validateUploaderOptions.js +0 -53
- package/dist/app/validateUploads.js +0 -102
- package/dist/email/render.js +0 -50
- package/dist/email/send.js +0 -55
- package/dist/email/templates/base.css +0 -194
- package/dist/email/templates/base.html +0 -28
- package/dist/email/templates/reset-password.js +0 -13
- package/dist/email/validateSMTPSettings.js +0 -27
- package/dist/lib/escapeHTML.js +0 -9
- package/dist/lib/escapeKeyValuePair.js +0 -13
- package/dist/lib/formatAPIError.js +0 -12
- package/dist/lib/formatErrorString.js +0 -8
- package/dist/lib/generateCookie.js +0 -14
- package/dist/lib/generateId.js +0 -13
- package/dist/lib/generateMachineId.js +0 -15
- package/dist/lib/getBuildPath.js +0 -10
- package/dist/lib/getErrorObject.js +0 -9
- package/dist/lib/getPlatformSafeFilePath.js +0 -8
- package/dist/lib/getPlatformSafePath.js +0 -8
- package/dist/lib/getSSLCertificates.js +0 -19
- package/dist/lib/isValidHTTPMethod.js +0 -7
- package/dist/lib/isValidJSONString.js +0 -11
- package/dist/lib/nodeUrlPolyfills.js +0 -14
- package/dist/lib/objectToSQLKeysString.js +0 -18
- package/dist/lib/objectToSQLValuesString.js +0 -16
- package/dist/lib/obscenedb/debounce.js +0 -12
- package/dist/lib/obscenedb/index.js +0 -61
- package/dist/lib/parseDatabasesFromEnvironment.js +0 -9
- package/dist/lib/rainbowRoad.js +0 -7
- package/dist/lib/readDirectory.js +0 -24
- package/dist/lib/replaceBackslashesWithForwardSlashes.js +0 -8
- package/dist/lib/replaceFileProtocol.js +0 -8
- package/dist/lib/replaceForwardSlashesWithBackslashes.js +0 -8
- package/dist/lib/serializeQueryParameters.js +0 -8
- package/dist/lib/serverAvailable.js +0 -0
- package/dist/lib/setCookie.js +0 -16
- package/dist/lib/supportedHTTPMethods.js +0 -4
- package/dist/lib/unsetCookie.js +0 -13
- package/dist/push/logs/index.js +0 -55
- package/dist/settings/index.js +0 -5
- package/dist/settings/load.js +0 -30
- package/dist/ssr/compileCSS.js +0 -85
- package/dist/ssr/findComponentInTree.js +0 -29
- package/dist/ssr/formatCSS.js +0 -6
- package/dist/ssr/getCSSFromTree.js +0 -33
- package/dist/ssr/index.js +0 -441
- package/dist/ssr/replaceWhenTags.js +0 -37
- package/dist/ssr/setHeadTagsInHTML.js +0 -84
- package/dist/validation/index.js +0 -10
- package/dist/validation/index.test.js +0 -463
- package/dist/validation/inputWithSchema/index.js +0 -105
- package/dist/validation/lib/constants.js +0 -162
- package/dist/validation/lib/getValueFromObject.js +0 -12
- package/dist/validation/lib/getValueFromObject.test.js +0 -7
- package/dist/validation/lib/isArrayPath.js +0 -6
- package/dist/validation/lib/throwError.js +0 -6
- package/dist/validation/lib/typeValidators.js +0 -38
- package/dist/validation/lib/validateType.js +0 -33
- package/dist/validation/schema/index.js +0 -44
- package/dist/websockets/emitWebsocketEvent.js +0 -12
- package/dist/websockets/index.js +0 -12
- package/notes +0 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import get_value_from_object from './get_value_from_object.js';
|
|
2
|
+
import input_validators from './input_validators.js';
|
|
3
|
+
import is_array_path from './is_array_path.js';
|
|
4
|
+
import types from '../../lib/types.js';
|
|
5
|
+
|
|
6
|
+
export const handle_get_input_value = (
|
|
7
|
+
input = null,
|
|
8
|
+
path = '',
|
|
9
|
+
types_only_schema = false
|
|
10
|
+
) => {
|
|
11
|
+
if (path && !types.is_string(path)) {
|
|
12
|
+
throw new Error('path must be passed as a string');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (types_only_schema || (!types_only_schema && !types.is_object(input))) {
|
|
16
|
+
return input;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (path.includes(".$.")) {
|
|
20
|
+
const [array_path] = path.split(".$.");
|
|
21
|
+
return get_value_from_object(input, array_path);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return get_value_from_object(input, path);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const get_array_path_key = (array_path = "") => {
|
|
28
|
+
if (!array_path) {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (array_path && !types.is_string(array_path)) {
|
|
33
|
+
throw new Error('array_path must be a type of string');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const array_path_parts = array_path.split(".");
|
|
37
|
+
|
|
38
|
+
return array_path_parts.pop();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const add_validation_task = ({ queue, rules, input, path, types_only_schema }) => {
|
|
42
|
+
if (rules && rules.type === "object") {
|
|
43
|
+
queue = add_to_validation_queue(queue, rules.properties, input, path);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (rules && rules.type === "array" && types.is_object(rules.element)) {
|
|
47
|
+
queue = add_to_validation_queue(queue, rules.element, input, `${path}.$`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const path_to_value = is_array_path(path) ? get_array_path_key(path) : path;
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
path,
|
|
54
|
+
rules,
|
|
55
|
+
input_value: handle_get_input_value(input, path_to_value, types_only_schema),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const add_to_validation_queue = (
|
|
60
|
+
queue = [],
|
|
61
|
+
schema = {},
|
|
62
|
+
input = {},
|
|
63
|
+
parent_path = ''
|
|
64
|
+
) => {
|
|
65
|
+
// NOTE: If schema.type is present, we're forcing the schema for an array
|
|
66
|
+
// item that's not an object (see element rule in input_validators.js).
|
|
67
|
+
|
|
68
|
+
// const types_only_schema = !!schema.type; // if schema.type is present, this is true.
|
|
69
|
+
const types_only_schema = !!(schema.type && input_validators.types.includes(schema.type));
|
|
70
|
+
|
|
71
|
+
if (!types_only_schema) {
|
|
72
|
+
const schema_definitions = Object.entries(schema || {});
|
|
73
|
+
|
|
74
|
+
for (let i = 0; i < schema_definitions?.length; i += 1) {
|
|
75
|
+
const [field, rules] = schema_definitions[i];
|
|
76
|
+
const validation_task = add_validation_task({
|
|
77
|
+
queue,
|
|
78
|
+
rules,
|
|
79
|
+
input,
|
|
80
|
+
path: field,
|
|
81
|
+
types_only_schema,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
queue = [...queue, validation_task];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (types_only_schema) {
|
|
89
|
+
const validation_task = add_validation_task({
|
|
90
|
+
queue,
|
|
91
|
+
rules: schema,
|
|
92
|
+
input,
|
|
93
|
+
path: parent_path,
|
|
94
|
+
types_only_schema,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
queue = [...queue, validation_task];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return queue;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const validate_input = async (input = {}, schema = {}, parent_path = '') => {
|
|
104
|
+
const validation_errors = [];
|
|
105
|
+
const queue = add_to_validation_queue([], schema, input, parent_path);
|
|
106
|
+
|
|
107
|
+
await Promise.all(queue.flatMap((validation_task) => {
|
|
108
|
+
return Object.entries(validation_task.rules || {}).flatMap(async ([rule_name, rule_value]) => {
|
|
109
|
+
const validator = input_validators.rules[rule_name];
|
|
110
|
+
|
|
111
|
+
if (validator && !validation_task.path.includes('.$.')) {
|
|
112
|
+
// NOTE: We pass validate_input as the final argument here so we can run
|
|
113
|
+
// validation on nested array and objects. This avoids creating a circular
|
|
114
|
+
// dependency error if we import validate_input into the input_validators file.
|
|
115
|
+
const result = await validator(rule_value, validation_task.input_value, validation_task.path, validate_input);
|
|
116
|
+
|
|
117
|
+
if (result && !result.valid) {
|
|
118
|
+
for (let i = 0; i < result.errors.length; i += 1) {
|
|
119
|
+
const error = result.errors[i];
|
|
120
|
+
validation_errors.push(error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}));
|
|
126
|
+
|
|
127
|
+
return validation_errors;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export default validate_input;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import run_session_query from "../databases/queries/sessions.js";
|
|
2
|
+
|
|
3
|
+
const validate_session = async (req = null, res = null) => {
|
|
4
|
+
const csrf_token = req?.headers['x-joystick-csrf'];
|
|
5
|
+
const session = await run_session_query('get_session', {
|
|
6
|
+
session_id: req?.cookies?.joystick_session,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
if (csrf_token === 'joystick_test') {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (!session || session && session.csrf !== csrf_token) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default validate_session;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import types from "../../lib/types.js";
|
|
2
|
+
|
|
3
|
+
const validate_type = (type, value) => {
|
|
4
|
+
switch (type) {
|
|
5
|
+
case "any":
|
|
6
|
+
return types.is_any(value);
|
|
7
|
+
case "array":
|
|
8
|
+
return types.is_array(value);
|
|
9
|
+
case "boolean":
|
|
10
|
+
return types.is_boolean(value);
|
|
11
|
+
case "float":
|
|
12
|
+
return types.is_float(value);
|
|
13
|
+
case "integer":
|
|
14
|
+
return types.is_integer(value);
|
|
15
|
+
case "number":
|
|
16
|
+
return types.is_number(value);
|
|
17
|
+
case "object":
|
|
18
|
+
return types.is_object(value);
|
|
19
|
+
case "string":
|
|
20
|
+
return types.is_string(value);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default validate_type;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
let reconnect_interval = null;
|
|
2
|
+
let reconnect_attempts = 0;
|
|
3
|
+
|
|
4
|
+
const websocket_client = (options = {}, on_connect = null) => {
|
|
5
|
+
let client = new WebSocket(
|
|
6
|
+
`ws://localhost:${window.__joystick_hmr_port__}/_joystick/hmr?${new URLSearchParams(options.query).toString()}`
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
if (reconnect_interval) {
|
|
10
|
+
clearInterval(reconnect_interval);
|
|
11
|
+
reconnect_interval = null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const connection = {
|
|
15
|
+
client,
|
|
16
|
+
send: (message = {}) => {
|
|
17
|
+
if (options.queryParams) {
|
|
18
|
+
message = { ...message, ...options.queryParams };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return client.send(JSON.stringify(message));
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
client.addEventListener("open", () => {
|
|
26
|
+
console.log(`[hmr] Listening for changes...`);
|
|
27
|
+
reconnect_attempts = 0;
|
|
28
|
+
if (on_connect) on_connect(connection);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
client.addEventListener("message", (event) => {
|
|
32
|
+
if (event?.data && options.onMessage) {
|
|
33
|
+
options.onMessage(JSON.parse(event.data), connection);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
client.addEventListener("close", () => {
|
|
38
|
+
console.log(`[hmr] Disconnected from server.`);
|
|
39
|
+
|
|
40
|
+
client = null;
|
|
41
|
+
|
|
42
|
+
if (options.autoReconnect && !reconnect_interval) {
|
|
43
|
+
reconnect_interval = setInterval(() => {
|
|
44
|
+
client = null;
|
|
45
|
+
|
|
46
|
+
// NOTE: 12 attempts === try to reconnect for up to 1 minute (12 * 5 seconds between each attempt).
|
|
47
|
+
if (reconnect_attempts < 12) {
|
|
48
|
+
websocket_client(options, on_connect);
|
|
49
|
+
|
|
50
|
+
console.log(
|
|
51
|
+
`[hmr] Attempting to reconnect (${reconnect_attempts + 1}/12)...`
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
reconnect_attempts += 1;
|
|
55
|
+
} else {
|
|
56
|
+
console.log(
|
|
57
|
+
`[hmr] Reconnection attempts exhausted. Server is unavailable.`
|
|
58
|
+
);
|
|
59
|
+
clearInterval(reconnect_interval);
|
|
60
|
+
}
|
|
61
|
+
}, 5000);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return connection;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const remount_standalone_page = async () => {
|
|
69
|
+
const page_component_file = await import_page_component();
|
|
70
|
+
|
|
71
|
+
window.joystick.mount(
|
|
72
|
+
page_component_file,
|
|
73
|
+
Object.assign({}, window.__joystick_ssr_props__),
|
|
74
|
+
document.getElementById("app")
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const import_page_component = async () => {
|
|
79
|
+
const page_component_file = await import(`${window.__joystick_page_url__}?v=${new Date().getTime()}`).catch((error) => {
|
|
80
|
+
// NOTE: If this fails, the file was likely deleted or renamed. Trigger a full reload
|
|
81
|
+
// so the developer is aware.
|
|
82
|
+
location.reload();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return page_component_file?.default;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const import_layout_component = async () => {
|
|
89
|
+
const layout_component_file = await import(`${window.__joystick_layout_url__}?v=${new Date().getTime()}`).catch((error) => {
|
|
90
|
+
// NOTE: If this fails, the file was likely deleted or renamed. Trigger a full reload
|
|
91
|
+
// so the developer is aware.
|
|
92
|
+
location.reload();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return layout_component_file?.default;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const remount_page_in_layout = async () => {
|
|
99
|
+
const layout_component_file = await import_layout_component();
|
|
100
|
+
const page_component_file = await import_page_component();
|
|
101
|
+
|
|
102
|
+
window.joystick.mount(
|
|
103
|
+
layout_component_file,
|
|
104
|
+
Object.assign({ page: page_component_file }, window.__joystick_ssr_props__),
|
|
105
|
+
document.getElementById("app")
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const update_index_css = (joystick_index_css) => {
|
|
110
|
+
const updated_css = document.createElement("link");
|
|
111
|
+
|
|
112
|
+
updated_css.setAttribute("rel", "stylesheet");
|
|
113
|
+
updated_css.setAttribute("href", `/_joystick/index.css`);
|
|
114
|
+
|
|
115
|
+
document.head.replaceChild(updated_css, joystick_index_css);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const update_index_client_js = (joystick_index_client_js = {}) => {
|
|
119
|
+
const updated_index_client_js = document.createElement("script");
|
|
120
|
+
|
|
121
|
+
updated_index_client_js.setAttribute("type", "text/javascript");
|
|
122
|
+
updated_index_client_js.setAttribute(
|
|
123
|
+
"src",
|
|
124
|
+
`/_joystick/index.client.js`
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
joystick_index_client_js.parentNode.replaceChild(updated_index_client_js, joystick_index_client_js);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const hmr_client = (() =>
|
|
131
|
+
websocket_client({
|
|
132
|
+
autoReconnect: true,
|
|
133
|
+
query: {
|
|
134
|
+
user_language: window?.__joystick_user__?.language || '',
|
|
135
|
+
browser_language: navigator?.language || '',
|
|
136
|
+
page_component_path: window.__joystick_page_url__?.replace('/_joystick/', ''),
|
|
137
|
+
},
|
|
138
|
+
onMessage: async (message = {}, websocket_client_connection = {}) => {
|
|
139
|
+
const is_build_error = message && message.type && message.type === "BUILD_ERROR";
|
|
140
|
+
|
|
141
|
+
if (is_build_error) {
|
|
142
|
+
return location.reload();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// NOTE: Set this to disable the auto mount code in layouts/pages when
|
|
146
|
+
// working in an HMR/development context.
|
|
147
|
+
window.__joystick_hmr_update__ = true;
|
|
148
|
+
window.__joystick_hmr_previous_tree__ = [...(window.joystick._internal.tree || [])];
|
|
149
|
+
window.__joystick_hmr_previous_websockets__ = [...(window.joystick._internal.websockets || [])];
|
|
150
|
+
|
|
151
|
+
const previous_window_position = Object.assign({}, { scrollTop: window.scrollY });
|
|
152
|
+
|
|
153
|
+
const is_file_change = message && message.type && message.type === "FILE_CHANGE";
|
|
154
|
+
const is_page_in_layout = !!window.__joystick_layout_url__ && !!window.__joystick_page_url__;
|
|
155
|
+
const joystick_index_css = document.head.querySelector('link[href="/_joystick/index.css"]');
|
|
156
|
+
const joystick_index_client_js = document.body.querySelector('script[src="/_joystick/index.client.js"]');
|
|
157
|
+
|
|
158
|
+
if (message?.index_html_changed) {
|
|
159
|
+
location.reload();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (message?.i18n) {
|
|
163
|
+
window.__joystick_i18n__ = message?.i18n;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (message?.settings) {
|
|
167
|
+
window.__joystick_settings__ = message?.settings;
|
|
168
|
+
window.joystick.settings = message?.settings;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (joystick_index_client_js && message?.index_client_changed) {
|
|
172
|
+
update_index_client_js(joystick_index_client_js);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (joystick_index_css && message?.index_css_changed) {
|
|
176
|
+
update_index_css(joystick_index_css);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (is_file_change && is_page_in_layout) {
|
|
180
|
+
remount_page_in_layout(websocket_client_connection);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (is_file_change && !is_page_in_layout) {
|
|
184
|
+
remount_standalone_page(websocket_client_connection);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// NOTE: Set scroll back to what it was before the HMR update.
|
|
188
|
+
window.scrollTo(0, previous_window_position.scrollTop);
|
|
189
|
+
|
|
190
|
+
if (websocket_client_connection.send) {
|
|
191
|
+
websocket_client_connection.send({ type: "HMR_UPDATE_COMPLETE" });
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
}))();
|
|
195
|
+
|
|
196
|
+
export default hmr_client;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import cron from 'node-cron';
|
|
2
|
+
import types from "../../lib/types.js";
|
|
3
|
+
|
|
4
|
+
const register = (cron_jobs = {}) => {
|
|
5
|
+
if (types.is_object(cron_jobs)) {
|
|
6
|
+
const cron_job_definitions = Object.entries(cron_jobs || {});
|
|
7
|
+
for (let i = 0; i < cron_job_definitions.length; i += 1) {
|
|
8
|
+
const [cron_job_name, cron_job_options] = cron_job_definitions[i];
|
|
9
|
+
if (cron_job_options?.schedule && cron_job_options?.run && types.is_function(cron_job_options?.run)
|
|
10
|
+
) {
|
|
11
|
+
process.cron = {
|
|
12
|
+
...(process.queues || {}),
|
|
13
|
+
[cron_job_name]: cron.schedule(cron_job_options?.schedule, () => {
|
|
14
|
+
if (
|
|
15
|
+
(cron_job_options?.logAtRunTime && types.is_string(cron_job_options?.logAtRunTime)) ||
|
|
16
|
+
(cron_job_options?.log_at_run_time && types.is_string(cron_job_options?.log_at_run_time))
|
|
17
|
+
) {
|
|
18
|
+
console.log(cron_job_options.logAtRunTime || cron_job_options?.log_at_run_time);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
cron_job_options.run();
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default register;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import load_settings from "../settings/load.js";
|
|
2
|
+
|
|
3
|
+
const get_target_database_connection = (database_type = 'users') => {
|
|
4
|
+
const settings = load_settings();
|
|
5
|
+
const databases = settings?.config?.databases || [];
|
|
6
|
+
const target_database_index = databases.findIndex((database) => !!database[database_type]);
|
|
7
|
+
const target_database_in_settings = databases[target_database_index];
|
|
8
|
+
|
|
9
|
+
if (!target_database_in_settings) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const has_multiple_of_provider = (databases?.filter((database) => database?.provider === target_database_in_settings?.provider))?.length > 1;
|
|
14
|
+
const database_port = (parseInt(process.env.PORT, 10) + 10) + target_database_index;
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
database_type,
|
|
18
|
+
provider: target_database_in_settings?.provider,
|
|
19
|
+
connection: !has_multiple_of_provider ?
|
|
20
|
+
process.databases[target_database_in_settings?.provider] :
|
|
21
|
+
process.databases[target_database_in_settings?.provider][target_database_in_settings?.name || `${target_database_in_settings?.provider}_${database_port}`],
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default get_target_database_connection;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const available_query_parameters = [
|
|
2
2
|
"replicaSet",
|
|
3
3
|
"tls",
|
|
4
4
|
"ssl",
|
|
@@ -37,6 +37,5 @@ var availableQueryParameters_default = [
|
|
|
37
37
|
"retryWrites",
|
|
38
38
|
"uuidRepresentation"
|
|
39
39
|
];
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
40
|
+
|
|
41
|
+
export default available_query_parameters;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import build_query_parameters from "./build_query_parameters.js";
|
|
2
|
+
import serialize_query_parameters from "../../../lib/serialize_query_parameters.js";
|
|
3
|
+
|
|
4
|
+
const build_connection_string = (connection = {}) => {
|
|
5
|
+
let connection_string = "mongodb://";
|
|
6
|
+
|
|
7
|
+
if (connection && (connection.username || connection.password)) {
|
|
8
|
+
connection_string = `${connection_string}${connection.username || connection.password ? `${connection.username || ""}${!!connection.username && !!connection.password ? ':' : ''}${connection.password || ""}@` : ''}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (connection && connection.hosts && Array.isArray(connection.hosts)) {
|
|
12
|
+
connection_string = `${connection_string}${connection.hosts
|
|
13
|
+
.map((host) => `${host.hostname}:${host.port}`)
|
|
14
|
+
.join(",")}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (connection && connection.database) {
|
|
18
|
+
connection_string = `${connection_string}/${connection.database}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const query_parameters = build_query_parameters(connection);
|
|
22
|
+
|
|
23
|
+
if (Object.keys(query_parameters || {})?.length > 0 ) {
|
|
24
|
+
connection_string = `${connection_string}?${serialize_query_parameters(query_parameters)}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return connection_string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default build_connection_string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import available_query_parameters from "./available_query_parameters.js";
|
|
2
|
+
|
|
3
|
+
const build_query_parameters = (connection = {}) => {
|
|
4
|
+
const query_parameters = {};
|
|
5
|
+
|
|
6
|
+
for (let i = 0; i < available_query_parameters.length; i += 1) {
|
|
7
|
+
const available_parameter = available_query_parameters[i];
|
|
8
|
+
|
|
9
|
+
if (connection && connection[available_parameter]) {
|
|
10
|
+
query_parameters[available_parameter] = connection[available_parameter];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return query_parameters;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default build_query_parameters;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { MongoClient } from "mongodb";
|
|
4
|
+
import mongo_uri from "mongo-uri-tool";
|
|
5
|
+
import build_connection_string from "./build_connection_string.js";
|
|
6
|
+
|
|
7
|
+
const connect_mongodb = async (database_settings = {}, database_port = 2610) => {
|
|
8
|
+
try {
|
|
9
|
+
const connection = database_settings?.connection || {
|
|
10
|
+
hosts: [
|
|
11
|
+
{ hostname: "127.0.0.1", port: database_port },
|
|
12
|
+
],
|
|
13
|
+
database: "app",
|
|
14
|
+
replicaSet: `joystick_${database_port}`,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const connection_string = build_connection_string(connection);
|
|
18
|
+
const parsed_uri = mongo_uri.parseUri(connection_string);
|
|
19
|
+
|
|
20
|
+
const connection_options = {
|
|
21
|
+
ssl: !['development', 'test'].includes(process.env.NODE_ENV),
|
|
22
|
+
...(database_settings?.options || {})
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
if (database_settings?.options?.ca) {
|
|
26
|
+
connection_options.ca = fs.readFileSync(database_settings?.options?.ca);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const client = await MongoClient.connect(connection_string, connection_options);
|
|
30
|
+
const db = client.db(parsed_uri.db);
|
|
31
|
+
|
|
32
|
+
return Promise.resolve(db);
|
|
33
|
+
} catch (exception) {
|
|
34
|
+
console.warn(
|
|
35
|
+
chalk.yellowBright(
|
|
36
|
+
`\nFailed to connect to MongoDB. Please double-check connection settings and try again.\n\nError from MongoDB:\n\n${chalk.redBright(exception?.message)}`
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default connect_mongodb;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import types from "../../../lib/types.js";
|
|
2
|
+
|
|
3
|
+
const indexes = {
|
|
4
|
+
// NOTE: queue indexes are set dynamically when initializing the queue in
|
|
5
|
+
// app/databases/queries/<provider>/queues.js initialize_database function
|
|
6
|
+
// to account for developer customization options.
|
|
7
|
+
sessions: async () => {
|
|
8
|
+
await process.databases._sessions?.collection('sessions').createIndex('sessions', { _id: 1 });
|
|
9
|
+
await process.databases._sessions?.collection('sessions').createIndex('sessions', { createdAt: 1 }, { expireAfterSeconds: 3600 });
|
|
10
|
+
},
|
|
11
|
+
users: async () => {
|
|
12
|
+
// Users
|
|
13
|
+
await process.databases._users?.collection('users').createIndex({ _id: 1 });
|
|
14
|
+
await process.databases._users?.collection('users').createIndex({ emailAddress: 1 });
|
|
15
|
+
await process.databases._users?.collection('users').createIndex({ username: 1 });
|
|
16
|
+
await process.databases._users?.collection('users').createIndex({ 'sessions.token': 1 });
|
|
17
|
+
await process.databases._users?.collection('users').createIndex({ 'passwordResetTokens.token': 1 });
|
|
18
|
+
await process.databases._users?.collection('users').createIndex({ 'passwordResetTokens.token': 1, _id: 1 });
|
|
19
|
+
await process.databases._users?.collection('users').createIndex({ roles: 1 });
|
|
20
|
+
await process.databases._users?.collection('users').createIndex({ roles: 1, _id: 1 });
|
|
21
|
+
await process.databases._users?.collection('roles').createIndex({ role: 1 });
|
|
22
|
+
await process.databases._users?.collection('roles').createIndex({ role: 1, userId: 1 });
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const create_indexes = async (database_types_to_index = []) => {
|
|
27
|
+
for (let i = 0; i < database_types_to_index?.length; i += 1) {
|
|
28
|
+
const database_type = database_types_to_index[i];
|
|
29
|
+
if (types.is_function(indexes[database_type])) {
|
|
30
|
+
await indexes[database_type]();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default create_indexes;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import escape from 'pg-escape';
|
|
2
|
+
|
|
3
|
+
const create_accounts_metadata_table_columns = async (users_database = '', sqlized_metadata = {}) => {
|
|
4
|
+
if (users_database === 'postgresql') {
|
|
5
|
+
const columns = Object.keys(sqlized_metadata || {});
|
|
6
|
+
|
|
7
|
+
for (let i = 0; i < columns?.length; i += 1) {
|
|
8
|
+
await process.databases.postgresql.query(
|
|
9
|
+
escape(
|
|
10
|
+
`ALTER TABLE users ADD COLUMN IF NOT EXISTS %I TEXT;`,
|
|
11
|
+
columns[i],
|
|
12
|
+
),
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default create_accounts_metadata_table_columns;
|