@joystick.js/db-canary 0.0.0-canary.2209
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/API_KEY +1 -0
- package/README.md +1821 -0
- package/data/data.mdb +0 -0
- package/data/lock.mdb +0 -0
- package/dist/client/database.js +1 -0
- package/dist/client/index.js +1 -0
- package/dist/server/cluster/index.js +1 -0
- package/dist/server/cluster/master.js +20 -0
- package/dist/server/cluster/worker.js +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/lib/api_key_manager.js +9 -0
- package/dist/server/lib/auth_manager.js +1 -0
- package/dist/server/lib/auto_index_manager.js +1 -0
- package/dist/server/lib/backup_manager.js +1 -0
- package/dist/server/lib/connection_manager.js +1 -0
- package/dist/server/lib/disk_utils.js +2 -0
- package/dist/server/lib/http_server.js +405 -0
- package/dist/server/lib/index_manager.js +1 -0
- package/dist/server/lib/load_settings.js +1 -0
- package/dist/server/lib/logger.js +1 -0
- package/dist/server/lib/op_types.js +1 -0
- package/dist/server/lib/operation_dispatcher.js +1 -0
- package/dist/server/lib/operations/admin.js +1 -0
- package/dist/server/lib/operations/bulk_write.js +1 -0
- package/dist/server/lib/operations/create_index.js +1 -0
- package/dist/server/lib/operations/delete_one.js +1 -0
- package/dist/server/lib/operations/drop_index.js +1 -0
- package/dist/server/lib/operations/find.js +1 -0
- package/dist/server/lib/operations/find_one.js +1 -0
- package/dist/server/lib/operations/get_indexes.js +1 -0
- package/dist/server/lib/operations/insert_one.js +1 -0
- package/dist/server/lib/operations/update_one.js +1 -0
- package/dist/server/lib/performance_monitor.js +1 -0
- package/dist/server/lib/query_engine.js +1 -0
- package/dist/server/lib/recovery_manager.js +1 -0
- package/dist/server/lib/replication_manager.js +1 -0
- package/dist/server/lib/safe_json_parse.js +1 -0
- package/dist/server/lib/send_response.js +1 -0
- package/dist/server/lib/tcp_protocol.js +1 -0
- package/dist/server/lib/write_forwarder.js +1 -0
- package/dist/server/lib/write_queue.js +1 -0
- package/increment_version.js +3 -0
- package/logs/.013e15b54597d05db4b4b53ecc37b10c92a72927-audit.json +20 -0
- package/logs/.02de550a67ea0f5961faa2dfd458a4d06f59ebd1-audit.json +20 -0
- package/logs/.03494ba24eb3c72214b4068a77d54b8993bee651-audit.json +20 -0
- package/logs/.06309ec60b339be1259a7993dd09c732f8907fbc-audit.json +20 -0
- package/logs/.0663a04dcfa17285661e5e1b8cfa51f41523b210-audit.json +20 -0
- package/logs/.0f06e6c4c9b824622729e13927587479e5060391-audit.json +20 -0
- package/logs/.16ccf58682ecb22b3e3ec63f0da1b7fe9be56528-audit.json +20 -0
- package/logs/.1fa1a5d02f496474b1ab473524c65c984146a9ad-audit.json +20 -0
- package/logs/.2223c0ae3bea6f0d62c62b1d319cc8634856abb7-audit.json +20 -0
- package/logs/.23dc79ffda3e083665e6f5993f59397adcbf4a46-audit.json +20 -0
- package/logs/.28104f49b03906b189eefd1cd462cb46c3c0af22-audit.json +20 -0
- package/logs/.29cdbf13808abe6a0ce70ee2f2efdd680ce3fd8e-audit.json +20 -0
- package/logs/.2a9889afd071f77f41f5170d08703a0afca866b7-audit.json +20 -0
- package/logs/.2acec3d1940a2bbed487528b703ee5948959a599-audit.json +20 -0
- package/logs/.2fb60ff326338c02bfedbcd0e936444e4a216750-audit.json +20 -0
- package/logs/.318fc7a19530d76a345f030f7cad00dda15300e7-audit.json +20 -0
- package/logs/.3cf27043e19085f908cedc7701e6d013463208ee-audit.json +25 -0
- package/logs/.3d90d785415817fc443402843b7c95f8371adc9b-audit.json +20 -0
- package/logs/.4074bca620375f72966fc52dfd439577727671e5-audit.json +20 -0
- package/logs/.40eecf018417ea80a70ea8ec7a3cc9406bc6334b-audit.json +20 -0
- package/logs/.50e974f1ef7c365fca6a1251b2e2c2252914cb5e-audit.json +20 -0
- package/logs/.52cb7d9e4223cf26ba36006ac26b949a97c7923c-audit.json +20 -0
- package/logs/.54befcdb84c15aad980705a31bcc9f555c3577ab-audit.json +20 -0
- package/logs/.57dfb70e22eddb84db2e3c0ceeefac5c0b9baffa-audit.json +20 -0
- package/logs/.5f0b24705a1eaad4eca4968f2d86f91b3f9be683-audit.json +20 -0
- package/logs/.61ba98fdda7db58576b382fee07904e5db1169d6-audit.json +20 -0
- package/logs/.6235017727ef6b199d569a99d6aa8c8e80a1b475-audit.json +20 -0
- package/logs/.63db16193699219489d218a1ddea5dde3750cae4-audit.json +20 -0
- package/logs/.64fb67dfe14149c9eef728d79bf30a54da809c60-audit.json +20 -0
- package/logs/.669137453368987c1f311b5345342527afb54e50-audit.json +20 -0
- package/logs/.7a71f8c89ea28ae266d356aeff6306e876a30fbb-audit.json +20 -0
- package/logs/.7afbaa90fe9dc3a7d682676f9bb79f9a1b1fd9a6-audit.json +20 -0
- package/logs/.7ca29e322cd05327035de850099e7610864f2347-audit.json +20 -0
- package/logs/.83335ab3347e449dae03455a110aaf7f120d4802-audit.json +20 -0
- package/logs/.8c2487b5fd445d2c8e5c483c80b9fa99bbf1ca58-audit.json +20 -0
- package/logs/.8c8b9dc386922c9f3b4c13251af7052aac1d24c0-audit.json +20 -0
- package/logs/.8d6155d94640c4863301ae0fee5e4e7372a21446-audit.json +20 -0
- package/logs/.944a3119a243deea7c8270d5d9e582bb1d0eaa10-audit.json +20 -0
- package/logs/.9816a845c30fb2909f3b26a23eeb3538ebcad5db-audit.json +20 -0
- package/logs/.9dc08784e38b865488177c26d4af5934555e0323-audit.json +20 -0
- package/logs/.9dd27d2e0e454ac0a37600206d1cac5493b0d7ee-audit.json +20 -0
- package/logs/.a3d486feeac7654c59b547de96600e8849a06d4f-audit.json +20 -0
- package/logs/.a5b811f4def22250f86cc18870d7c4573625df22-audit.json +20 -0
- package/logs/.a61648eb5f830e0b6f508ac35e4f8f629d2ad4c7-audit.json +20 -0
- package/logs/.a89016d507045771b4b5a65656944a9c0f1e528b-audit.json +20 -0
- package/logs/.a99bee160a1c590be959af46bacc02724803f691-audit.json +20 -0
- package/logs/.ada7906d6243fd7da802f03d86c4ae5dd9df6236-audit.json +20 -0
- package/logs/.b518339ee942143b6af983af167f5bbb6983b4de-audit.json +20 -0
- package/logs/.b51b124b166d53c9519017856ea610d61d65fabe-audit.json +20 -0
- package/logs/.b7a6aee19f58e55633d5e4a3709041c47dfff975-audit.json +20 -0
- package/logs/.bd7a8a6ba9c55d557a4867ab53f02e3ec2e1553d-audit.json +20 -0
- package/logs/.c1435dafe453b169d6392b25065f3cf4ab6fbb21-audit.json +20 -0
- package/logs/.c17e1ce043109f77dc2f0e2aa290a9d1ed842c03-audit.json +20 -0
- package/logs/.ca62637ce9540e5a38a2fbedb2115febb6ad308a-audit.json +15 -0
- package/logs/.ccee67b9c176967f8977071409a41f5cb5cd6ad4-audit.json +20 -0
- package/logs/.db24043417ea79a6f14cd947476399e53930b48d-audit.json +20 -0
- package/logs/.e0f12acccb57829f5f33712bb2e2607ecd808147-audit.json +20 -0
- package/logs/.e9b6cc33d0bbd2e644c4e2bf44d177f850016557-audit.json +20 -0
- package/logs/.f15291d434808e3bdca7963ccd2e73893be027e6-audit.json +20 -0
- package/logs/.f4bdf9e21ef84f8a3fae3ffb32bbc39275991351-audit.json +15 -0
- package/logs/.fbac3aefac1e81b4230df5aa50667cb90d51024f-audit.json +20 -0
- package/logs/.fcfd495c0a9169db243f4a4f21878ee02b76413c-audit.json +20 -0
- package/logs/admin-2025-09-12.log +580 -0
- package/logs/admin-2025-09-15.log +283 -0
- package/logs/admin-error-2025-09-12.log +22 -0
- package/logs/admin-error-2025-09-15.log +10 -0
- package/logs/api_key_manager-2025-09-12.log +658 -0
- package/logs/api_key_manager-2025-09-15.log +295 -0
- package/logs/api_key_manager-error-2025-09-12.log +0 -0
- package/logs/api_key_manager-error-2025-09-15.log +0 -0
- package/logs/auth_manager-2025-09-12.log +4432 -0
- package/logs/auth_manager-2025-09-15.log +2000 -0
- package/logs/auth_manager-error-2025-09-12.log +11 -0
- package/logs/auth_manager-error-2025-09-15.log +5 -0
- package/logs/auto_index_manager-2025-09-12.log +84 -0
- package/logs/auto_index_manager-2025-09-15.log +45 -0
- package/logs/auto_index_manager-error-2025-09-12.log +6 -0
- package/logs/auto_index_manager-error-2025-09-15.log +0 -0
- package/logs/backup_manager-2025-09-12.log +198 -0
- package/logs/backup_manager-2025-09-15.log +90 -0
- package/logs/backup_manager-error-2025-09-12.log +198 -0
- package/logs/backup_manager-error-2025-09-15.log +90 -0
- package/logs/bulk_write-2025-09-12.log +66 -0
- package/logs/bulk_write-2025-09-15.log +38 -0
- package/logs/bulk_write-error-2025-09-12.log +0 -0
- package/logs/bulk_write-error-2025-09-15.log +0 -0
- package/logs/connection_manager-2025-09-12.log +2412 -0
- package/logs/connection_manager-2025-09-15.log +1132 -0
- package/logs/connection_manager-error-2025-09-12.log +0 -0
- package/logs/connection_manager-error-2025-09-15.log +0 -0
- package/logs/create_index-2025-09-12.log +302 -0
- package/logs/create_index-2025-09-15.log +158 -0
- package/logs/create_index-error-2025-09-12.log +30 -0
- package/logs/create_index-error-2025-09-15.log +13 -0
- package/logs/delete_one-2025-09-12.log +73 -0
- package/logs/delete_one-2025-09-15.log +43 -0
- package/logs/delete_one-error-2025-09-12.log +0 -0
- package/logs/delete_one-error-2025-09-15.log +0 -0
- package/logs/disk_utils-2025-09-12.log +4954 -0
- package/logs/disk_utils-2025-09-15.log +2446 -0
- package/logs/disk_utils-error-2025-09-12.log +0 -0
- package/logs/disk_utils-error-2025-09-15.log +0 -0
- package/logs/drop_index-2025-09-12.log +41 -0
- package/logs/drop_index-2025-09-15.log +23 -0
- package/logs/drop_index-error-2025-09-12.log +11 -0
- package/logs/drop_index-error-2025-09-15.log +5 -0
- package/logs/find-2025-09-12.log +1050 -0
- package/logs/find-2025-09-15.log +592 -0
- package/logs/find-error-2025-09-12.log +1 -0
- package/logs/find-error-2025-09-15.log +0 -0
- package/logs/find_one-2025-09-12.log +425 -0
- package/logs/find_one-2025-09-15.log +264 -0
- package/logs/find_one-error-2025-09-12.log +5 -0
- package/logs/find_one-error-2025-09-15.log +0 -0
- package/logs/get_indexes-2025-09-12.log +84 -0
- package/logs/get_indexes-2025-09-15.log +56 -0
- package/logs/get_indexes-error-2025-09-12.log +6 -0
- package/logs/get_indexes-error-2025-09-15.log +0 -0
- package/logs/http_server-2025-09-12.log +2772 -0
- package/logs/http_server-2025-09-15.log +1276 -0
- package/logs/http_server-error-2025-09-12.log +212 -0
- package/logs/http_server-error-2025-09-15.log +44 -0
- package/logs/index_manager-2025-09-12.log +5031 -0
- package/logs/index_manager-2025-09-15.log +2909 -0
- package/logs/index_manager-error-2025-09-12.log +80 -0
- package/logs/index_manager-error-2025-09-15.log +38 -0
- package/logs/insert_one-2025-09-12.log +2181 -0
- package/logs/insert_one-2025-09-15.log +1293 -0
- package/logs/insert_one-error-2025-09-12.log +0 -0
- package/logs/insert_one-error-2025-09-15.log +0 -0
- package/logs/master-2025-09-12.log +1882 -0
- package/logs/master-2025-09-15.log +910 -0
- package/logs/master-error-2025-09-12.log +80 -0
- package/logs/master-error-2025-09-15.log +0 -0
- package/logs/operation_dispatcher-2025-09-12.log +751 -0
- package/logs/operation_dispatcher-2025-09-15.log +359 -0
- package/logs/operation_dispatcher-error-2025-09-12.log +33 -0
- package/logs/operation_dispatcher-error-2025-09-15.log +11 -0
- package/logs/performance_monitor-2025-09-12.log +14889 -0
- package/logs/performance_monitor-2025-09-15.log +6803 -0
- package/logs/performance_monitor-error-2025-09-12.log +0 -0
- package/logs/performance_monitor-error-2025-09-15.log +0 -0
- package/logs/query_engine-2025-09-12.log +5310 -0
- package/logs/query_engine-2025-09-15.log +2639 -0
- package/logs/query_engine-error-2025-09-12.log +0 -0
- package/logs/query_engine-error-2025-09-15.log +0 -0
- package/logs/recovery_manager-2025-09-12.log +462 -0
- package/logs/recovery_manager-2025-09-15.log +210 -0
- package/logs/recovery_manager-error-2025-09-12.log +22 -0
- package/logs/recovery_manager-error-2025-09-15.log +10 -0
- package/logs/replication-2025-09-12.log +1923 -0
- package/logs/replication-2025-09-15.log +917 -0
- package/logs/replication-error-2025-09-12.log +33 -0
- package/logs/replication-error-2025-09-15.log +15 -0
- package/logs/server-2025-09-12.log +2601 -0
- package/logs/server-2025-09-15.log +1191 -0
- package/logs/server-error-2025-09-12.log +0 -0
- package/logs/server-error-2025-09-15.log +0 -0
- package/logs/tcp_protocol-2025-09-12.log +22 -0
- package/logs/tcp_protocol-2025-09-15.log +10 -0
- package/logs/tcp_protocol-error-2025-09-12.log +22 -0
- package/logs/tcp_protocol-error-2025-09-15.log +10 -0
- package/logs/test-2025-09-12.log +0 -0
- package/logs/test-2025-09-15.log +0 -0
- package/logs/test-error-2025-09-12.log +0 -0
- package/logs/test-error-2025-09-15.log +0 -0
- package/logs/update_one-2025-09-12.log +173 -0
- package/logs/update_one-2025-09-15.log +118 -0
- package/logs/update_one-error-2025-09-12.log +0 -0
- package/logs/update_one-error-2025-09-15.log +0 -0
- package/logs/worker-2025-09-12.log +1457 -0
- package/logs/worker-2025-09-15.log +695 -0
- package/logs/worker-error-2025-09-12.log +0 -0
- package/logs/worker-error-2025-09-15.log +0 -0
- package/logs/write_forwarder-2025-09-12.log +1956 -0
- package/logs/write_forwarder-2025-09-15.log +932 -0
- package/logs/write_forwarder-error-2025-09-12.log +66 -0
- package/logs/write_forwarder-error-2025-09-15.log +30 -0
- package/logs/write_queue-2025-09-12.log +612 -0
- package/logs/write_queue-2025-09-15.log +301 -0
- package/logs/write_queue-error-2025-09-12.log +184 -0
- package/logs/write_queue-error-2025-09-15.log +83 -0
- package/package.json +48 -0
- package/prompts/01-core-infrastructure.md +56 -0
- package/prompts/02-secondary-indexing.md +65 -0
- package/prompts/03-write-serialization.md +63 -0
- package/prompts/04-enhanced-authentication.md +75 -0
- package/prompts/05-comprehensive-admin-operations.md +75 -0
- package/prompts/06-backup-and-restore-system.md +106 -0
- package/prompts/07-production-safety-features.md +107 -0
- package/prompts/08-tcp-client-library.md +121 -0
- package/prompts/09-api-method-chaining.md +134 -0
- package/prompts/10-automatic-index-creation.md +223 -0
- package/prompts/11-operation-naming-consistency.md +268 -0
- package/prompts/12-tcp-replication-system.md +333 -0
- package/prompts/13-master-read-write-operations.md +57 -0
- package/prompts/14-index-upsert-operations.md +68 -0
- package/prompts/15-client-api-return-types.md +81 -0
- package/prompts/16-server-setup-ui.md +97 -0
- package/prompts/17-emergency-password-change.md +108 -0
- package/prompts/18-joystick-framework-integration.md +116 -0
- package/prompts/19-api-key-authentication-system.md +137 -0
- package/prompts/20-configurable-server-port.md +105 -0
- package/prompts/21-multi-database-support.md +161 -0
- package/prompts/FULL_TEXT_SEARCH.md +293 -0
- package/prompts/PROMPTS.md +158 -0
- package/prompts/README.md +221 -0
- package/prompts/TYPESCRIPT_GENERATION.md +179 -0
- package/src/client/database.js +166 -0
- package/src/client/index.js +752 -0
- package/src/server/cluster/index.js +53 -0
- package/src/server/cluster/master.js +774 -0
- package/src/server/cluster/worker.js +537 -0
- package/src/server/index.js +540 -0
- package/src/server/lib/api_key_manager.js +473 -0
- package/src/server/lib/auth_manager.js +375 -0
- package/src/server/lib/auto_index_manager.js +681 -0
- package/src/server/lib/backup_manager.js +650 -0
- package/src/server/lib/connection_manager.js +218 -0
- package/src/server/lib/disk_utils.js +118 -0
- package/src/server/lib/http_server.js +1165 -0
- package/src/server/lib/index_manager.js +756 -0
- package/src/server/lib/load_settings.js +143 -0
- package/src/server/lib/logger.js +135 -0
- package/src/server/lib/op_types.js +29 -0
- package/src/server/lib/operation_dispatcher.js +268 -0
- package/src/server/lib/operations/admin.js +808 -0
- package/src/server/lib/operations/bulk_write.js +367 -0
- package/src/server/lib/operations/create_index.js +68 -0
- package/src/server/lib/operations/delete_one.js +114 -0
- package/src/server/lib/operations/drop_index.js +58 -0
- package/src/server/lib/operations/find.js +340 -0
- package/src/server/lib/operations/find_one.js +319 -0
- package/src/server/lib/operations/get_indexes.js +52 -0
- package/src/server/lib/operations/insert_one.js +113 -0
- package/src/server/lib/operations/update_one.js +225 -0
- package/src/server/lib/performance_monitor.js +313 -0
- package/src/server/lib/query_engine.js +243 -0
- package/src/server/lib/recovery_manager.js +388 -0
- package/src/server/lib/replication_manager.js +727 -0
- package/src/server/lib/safe_json_parse.js +21 -0
- package/src/server/lib/send_response.js +47 -0
- package/src/server/lib/tcp_protocol.js +130 -0
- package/src/server/lib/write_forwarder.js +636 -0
- package/src/server/lib/write_queue.js +335 -0
- package/test_data/data.mdb +0 -0
- package/test_data/lock.mdb +0 -0
- package/tests/client/index.test.js +1232 -0
- package/tests/server/cluster/cluster.test.js +248 -0
- package/tests/server/cluster/master_read_write_operations.test.js +577 -0
- package/tests/server/index.test.js +651 -0
- package/tests/server/integration/authentication_integration.test.js +294 -0
- package/tests/server/integration/auto_indexing_integration.test.js +268 -0
- package/tests/server/integration/backup_integration.test.js +513 -0
- package/tests/server/integration/indexing_integration.test.js +126 -0
- package/tests/server/integration/production_safety_integration.test.js +358 -0
- package/tests/server/integration/replication_integration.test.js +227 -0
- package/tests/server/integration/write_serialization_integration.test.js +246 -0
- package/tests/server/lib/api_key_manager.test.js +516 -0
- package/tests/server/lib/auth_manager.test.js +317 -0
- package/tests/server/lib/auto_index_manager.test.js +275 -0
- package/tests/server/lib/backup_manager.test.js +238 -0
- package/tests/server/lib/connection_manager.test.js +221 -0
- package/tests/server/lib/disk_utils.test.js +63 -0
- package/tests/server/lib/http_server.test.js +389 -0
- package/tests/server/lib/index_manager.test.js +301 -0
- package/tests/server/lib/load_settings.test.js +107 -0
- package/tests/server/lib/load_settings_port_config.test.js +243 -0
- package/tests/server/lib/logger.test.js +282 -0
- package/tests/server/lib/operations/admin.test.js +638 -0
- package/tests/server/lib/operations/bulk_write.test.js +128 -0
- package/tests/server/lib/operations/create_index.test.js +138 -0
- package/tests/server/lib/operations/delete_one.test.js +52 -0
- package/tests/server/lib/operations/drop_index.test.js +72 -0
- package/tests/server/lib/operations/find.test.js +93 -0
- package/tests/server/lib/operations/find_one.test.js +91 -0
- package/tests/server/lib/operations/get_indexes.test.js +87 -0
- package/tests/server/lib/operations/insert_one.test.js +42 -0
- package/tests/server/lib/operations/update_one.test.js +89 -0
- package/tests/server/lib/performance_monitor.test.js +185 -0
- package/tests/server/lib/query_engine.test.js +46 -0
- package/tests/server/lib/recovery_manager.test.js +414 -0
- package/tests/server/lib/replication_manager.test.js +202 -0
- package/tests/server/lib/safe_json_parse.test.js +45 -0
- package/tests/server/lib/send_response.test.js +155 -0
- package/tests/server/lib/tcp_protocol.test.js +169 -0
- package/tests/server/lib/write_forwarder.test.js +258 -0
- package/tests/server/lib/write_queue.test.js +255 -0
- package/tsconfig.json +30 -0
- package/types/client/index.d.ts +447 -0
- package/types/server/cluster/index.d.ts +28 -0
- package/types/server/cluster/master.d.ts +115 -0
- package/types/server/cluster/worker.d.ts +1 -0
- package/types/server/lib/auth_manager.d.ts +13 -0
- package/types/server/lib/backup_manager.d.ts +43 -0
- package/types/server/lib/connection_manager.d.ts +15 -0
- package/types/server/lib/disk_utils.d.ts +3 -0
- package/types/server/lib/index_manager.d.ts +24 -0
- package/types/server/lib/load_settings.d.ts +4 -0
- package/types/server/lib/logger.d.ts +44 -0
- package/types/server/lib/op_types.d.ts +6 -0
- package/types/server/lib/performance_monitor.d.ts +68 -0
- package/types/server/lib/query_engine.d.ts +10 -0
- package/types/server/lib/safe_json_parse.d.ts +7 -0
- package/types/server/lib/send_response.d.ts +3 -0
- package/types/server/lib/tcp_protocol.d.ts +12 -0
- package/types/server/lib/write_queue.d.ts +2 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# Task 12: TCP Replication System
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
Implement TCP-based replication to read-only secondary nodes to provide high availability and read scaling. The system should track secondary nodes in settings, replicate data changes over secure TCP connections, and forward write requests from secondaries to the primary.
|
|
5
|
+
|
|
6
|
+
## Current State
|
|
7
|
+
- Single primary node handles all reads and writes
|
|
8
|
+
- No replication or high availability features
|
|
9
|
+
- No read scaling capabilities
|
|
10
|
+
- All data exists only on primary node
|
|
11
|
+
|
|
12
|
+
## Target State
|
|
13
|
+
- Primary node replicates data to multiple read-only secondary nodes
|
|
14
|
+
- Secondary nodes configured in settings.json with connection details
|
|
15
|
+
- Secure TCP connections using private keys for authentication
|
|
16
|
+
- Write requests to secondaries are forwarded to primary
|
|
17
|
+
- Read operations can be served by secondary nodes
|
|
18
|
+
- Automatic failover detection and reconnection
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
### 1. Secondary Node Configuration
|
|
23
|
+
- Track secondary nodes in settings.json configuration
|
|
24
|
+
- Support multiple secondary nodes with IP, port, and private key
|
|
25
|
+
- Validate secondary node configurations on startup
|
|
26
|
+
- Support dynamic addition/removal of secondary nodes
|
|
27
|
+
|
|
28
|
+
### 2. Replication Protocol
|
|
29
|
+
- Replicate all write operations from primary to secondary nodes
|
|
30
|
+
- Ensure data consistency across all nodes
|
|
31
|
+
- Handle replication failures gracefully
|
|
32
|
+
- Support batch replication for performance
|
|
33
|
+
|
|
34
|
+
### 3. Write Forwarding
|
|
35
|
+
- Secondary nodes forward write requests to primary
|
|
36
|
+
- Maintain client connection while forwarding request
|
|
37
|
+
- Return primary's response to original client
|
|
38
|
+
- Handle forwarding failures and timeouts
|
|
39
|
+
|
|
40
|
+
### 4. Security and Authentication
|
|
41
|
+
- Use private key authentication for secondary connections
|
|
42
|
+
- Encrypt replication traffic
|
|
43
|
+
- Validate secondary node identity
|
|
44
|
+
- Secure write forwarding between secondary and primary
|
|
45
|
+
|
|
46
|
+
### 5. Connection Management
|
|
47
|
+
- Maintain persistent connections to secondary nodes
|
|
48
|
+
- Automatic reconnection on connection failures
|
|
49
|
+
- Health monitoring of secondary nodes
|
|
50
|
+
- Connection pooling for multiple secondaries
|
|
51
|
+
|
|
52
|
+
## Technical Specifications
|
|
53
|
+
|
|
54
|
+
### Settings Configuration
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"replication": {
|
|
58
|
+
"enabled": true,
|
|
59
|
+
"mode": "async",
|
|
60
|
+
"timeout_ms": 5000,
|
|
61
|
+
"retry_attempts": 3,
|
|
62
|
+
"batch_size": 100,
|
|
63
|
+
"secondaries": [
|
|
64
|
+
{
|
|
65
|
+
"id": "secondary-1",
|
|
66
|
+
"ip": "192.168.1.100",
|
|
67
|
+
"port": 1984,
|
|
68
|
+
"private_key": "<base64-encoded-private-key>",
|
|
69
|
+
"enabled": true
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"id": "secondary-2",
|
|
73
|
+
"ip": "192.168.1.101",
|
|
74
|
+
"port": 1984,
|
|
75
|
+
"private_key": "<base64-encoded-private-key>",
|
|
76
|
+
"enabled": true
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Replication Message Protocol
|
|
84
|
+
```javascript
|
|
85
|
+
const replication_message = {
|
|
86
|
+
type: 'replication',
|
|
87
|
+
timestamp: Date.now(),
|
|
88
|
+
sequence_number: 12345,
|
|
89
|
+
operations: [
|
|
90
|
+
{
|
|
91
|
+
operation: 'insert_one',
|
|
92
|
+
collection: 'users',
|
|
93
|
+
data: { document: { name: 'John' } },
|
|
94
|
+
transaction_id: 'tx_123'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
operation: 'update_one',
|
|
98
|
+
collection: 'users',
|
|
99
|
+
data: { filter: { name: 'John' }, update: { $set: { age: 30 } } },
|
|
100
|
+
transaction_id: 'tx_124'
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
};
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Write Forwarding Protocol
|
|
107
|
+
```javascript
|
|
108
|
+
const forward_request = {
|
|
109
|
+
type: 'forward_write',
|
|
110
|
+
original_client_id: 'client_123',
|
|
111
|
+
operation: 'insert_one',
|
|
112
|
+
collection: 'users',
|
|
113
|
+
data: { document: { name: 'John' } },
|
|
114
|
+
forwarded_by: 'secondary-1',
|
|
115
|
+
timestamp: Date.now()
|
|
116
|
+
};
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Secondary Node Authentication
|
|
120
|
+
```javascript
|
|
121
|
+
const auth_message = {
|
|
122
|
+
type: 'replication_auth',
|
|
123
|
+
node_id: 'secondary-1',
|
|
124
|
+
timestamp: Date.now(),
|
|
125
|
+
signature: '<signed-with-private-key>'
|
|
126
|
+
};
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Implementation Details
|
|
130
|
+
|
|
131
|
+
### 1. Primary Node Components
|
|
132
|
+
|
|
133
|
+
#### Replication Manager
|
|
134
|
+
- Manage connections to all secondary nodes
|
|
135
|
+
- Queue and batch replication operations
|
|
136
|
+
- Handle replication failures and retries
|
|
137
|
+
- Monitor secondary node health
|
|
138
|
+
|
|
139
|
+
#### Write Operation Interceptor
|
|
140
|
+
- Intercept all write operations on primary
|
|
141
|
+
- Queue operations for replication
|
|
142
|
+
- Ensure operations are replicated before confirming success
|
|
143
|
+
- Handle replication acknowledgments
|
|
144
|
+
|
|
145
|
+
### 2. Secondary Node Components
|
|
146
|
+
|
|
147
|
+
#### Write Forwarder
|
|
148
|
+
- Detect write operations from clients
|
|
149
|
+
- Forward write requests to primary node
|
|
150
|
+
- Maintain client connection during forwarding
|
|
151
|
+
- Return primary's response to original client
|
|
152
|
+
|
|
153
|
+
#### Replication Receiver
|
|
154
|
+
- Accept replication messages from primary
|
|
155
|
+
- Apply replicated operations to local database
|
|
156
|
+
- Maintain data consistency with primary
|
|
157
|
+
- Handle replication sequence ordering
|
|
158
|
+
|
|
159
|
+
#### Read Handler
|
|
160
|
+
- Serve read-only operations locally
|
|
161
|
+
- Ensure read consistency
|
|
162
|
+
- Handle read preference routing
|
|
163
|
+
|
|
164
|
+
### 3. Connection Management
|
|
165
|
+
- Maintain persistent TCP connections between nodes
|
|
166
|
+
- Handle connection lifecycle (connect, disconnect, reconnect)
|
|
167
|
+
- Implement connection timeouts and health checks
|
|
168
|
+
- Load balance connections across multiple secondaries
|
|
169
|
+
|
|
170
|
+
### 4. Security Layer
|
|
171
|
+
- Implement private key authentication
|
|
172
|
+
- Encrypt replication and forwarding messages
|
|
173
|
+
- Validate message integrity
|
|
174
|
+
- Prevent replay attacks
|
|
175
|
+
|
|
176
|
+
## Testing Requirements
|
|
177
|
+
|
|
178
|
+
### Unit Tests
|
|
179
|
+
- Test replication manager functionality
|
|
180
|
+
- Verify write forwarding logic
|
|
181
|
+
- Test connection pool management
|
|
182
|
+
- Test operation interception and queuing
|
|
183
|
+
- Validate security and authentication
|
|
184
|
+
|
|
185
|
+
### Integration Tests
|
|
186
|
+
- Test end-to-end replication flow
|
|
187
|
+
- Test write forwarding from secondary to primary
|
|
188
|
+
- Verify data consistency across nodes
|
|
189
|
+
- Test connection failure scenarios
|
|
190
|
+
- Validate security protocols
|
|
191
|
+
|
|
192
|
+
### Performance Tests
|
|
193
|
+
- Measure replication latency
|
|
194
|
+
- Test write forwarding performance
|
|
195
|
+
- Test with high write volumes
|
|
196
|
+
- Verify batch replication performance
|
|
197
|
+
- Test connection pool efficiency
|
|
198
|
+
|
|
199
|
+
## Implementation Steps
|
|
200
|
+
|
|
201
|
+
1. **Configuration System**
|
|
202
|
+
- Add replication configuration to settings
|
|
203
|
+
- Implement configuration validation
|
|
204
|
+
- Add runtime configuration updates
|
|
205
|
+
|
|
206
|
+
2. **Connection Management**
|
|
207
|
+
- Implement TCP connection pool for secondaries
|
|
208
|
+
- Add connection health monitoring
|
|
209
|
+
- Implement automatic reconnection logic
|
|
210
|
+
|
|
211
|
+
3. **Security Layer**
|
|
212
|
+
- Implement private key authentication
|
|
213
|
+
- Add message encryption/decryption
|
|
214
|
+
- Implement message signing and verification
|
|
215
|
+
|
|
216
|
+
4. **Primary Node Replication**
|
|
217
|
+
- Create replication operation queue
|
|
218
|
+
- Implement batch replication logic
|
|
219
|
+
- Add failure handling and retries
|
|
220
|
+
- Intercept write operations
|
|
221
|
+
|
|
222
|
+
5. **Secondary Node Implementation**
|
|
223
|
+
- Implement secondary node server mode
|
|
224
|
+
- Add write forwarding to primary
|
|
225
|
+
- Implement replication message processing
|
|
226
|
+
- Add read-only operation handling
|
|
227
|
+
|
|
228
|
+
6. **Write Forwarding System**
|
|
229
|
+
- Detect write operations on secondary
|
|
230
|
+
- Forward requests to primary
|
|
231
|
+
- Handle forwarding responses
|
|
232
|
+
- Maintain client connections during forwarding
|
|
233
|
+
|
|
234
|
+
## API Extensions
|
|
235
|
+
|
|
236
|
+
### Admin Operations
|
|
237
|
+
```javascript
|
|
238
|
+
// Get replication status
|
|
239
|
+
await client.get_replication_status();
|
|
240
|
+
|
|
241
|
+
// Add secondary node
|
|
242
|
+
await client.add_secondary({
|
|
243
|
+
id: 'secondary-3',
|
|
244
|
+
ip: '192.168.1.102',
|
|
245
|
+
port: 1984,
|
|
246
|
+
private_key: '<key>'
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Remove secondary node
|
|
250
|
+
await client.remove_secondary('secondary-3');
|
|
251
|
+
|
|
252
|
+
// Force replication sync
|
|
253
|
+
await client.sync_secondaries();
|
|
254
|
+
|
|
255
|
+
// Get secondary node health
|
|
256
|
+
await client.get_secondary_health();
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Configuration Updates
|
|
260
|
+
```javascript
|
|
261
|
+
// Enable/disable replication
|
|
262
|
+
await client.update_settings({
|
|
263
|
+
replication: {
|
|
264
|
+
enabled: true,
|
|
265
|
+
mode: 'sync'
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Secondary Node Setup
|
|
271
|
+
|
|
272
|
+
### Secondary Node Configuration
|
|
273
|
+
```json
|
|
274
|
+
{
|
|
275
|
+
"mode": "secondary",
|
|
276
|
+
"primary": {
|
|
277
|
+
"ip": "192.168.1.10",
|
|
278
|
+
"port": 1983,
|
|
279
|
+
"public_key": "<primary-public-key>"
|
|
280
|
+
},
|
|
281
|
+
"replication": {
|
|
282
|
+
"port": 1984,
|
|
283
|
+
"private_key": "<secondary-private-key>",
|
|
284
|
+
"read_only": true,
|
|
285
|
+
"forward_writes": true
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Secondary Node Operations
|
|
291
|
+
- Accept client connections for read and write operations
|
|
292
|
+
- Serve read operations locally
|
|
293
|
+
- Forward write operations to primary
|
|
294
|
+
- Accept replication connections from primary
|
|
295
|
+
- Apply replicated operations to local database
|
|
296
|
+
- Report health status to primary
|
|
297
|
+
|
|
298
|
+
## Write Forwarding Flow
|
|
299
|
+
|
|
300
|
+
1. **Client connects to secondary** and sends write request
|
|
301
|
+
2. **Secondary detects write operation** and maintains client connection
|
|
302
|
+
3. **Secondary forwards request to primary** with forwarding metadata
|
|
303
|
+
4. **Primary processes write operation** and replicates to all secondaries
|
|
304
|
+
5. **Primary sends response back to forwarding secondary**
|
|
305
|
+
6. **Secondary returns response to original client**
|
|
306
|
+
7. **Secondary receives replicated operation** and applies it locally
|
|
307
|
+
|
|
308
|
+
## Success Criteria
|
|
309
|
+
|
|
310
|
+
- [ ] Secondary nodes can be configured in settings
|
|
311
|
+
- [ ] Primary replicates write operations to secondaries
|
|
312
|
+
- [ ] Secondaries forward write requests to primary
|
|
313
|
+
- [ ] Write forwarding maintains client connections
|
|
314
|
+
- [ ] Secure authentication using private keys works
|
|
315
|
+
- [ ] Connection management handles failures gracefully
|
|
316
|
+
- [ ] Data consistency is maintained across nodes
|
|
317
|
+
- [ ] Read operations work on secondary nodes
|
|
318
|
+
- [ ] Admin interface provides replication monitoring
|
|
319
|
+
- [ ] Performance impact on primary is minimal
|
|
320
|
+
- [ ] All existing tests continue to pass
|
|
321
|
+
- [ ] Comprehensive test coverage for replication features
|
|
322
|
+
|
|
323
|
+
## Notes
|
|
324
|
+
|
|
325
|
+
- Write forwarding allows clients to connect to any node
|
|
326
|
+
- Secondary nodes appear as full database servers to clients
|
|
327
|
+
- Replication ensures all nodes have consistent data
|
|
328
|
+
- Start with asynchronous replication for better performance
|
|
329
|
+
- Monitor replication lag and provide alerts
|
|
330
|
+
- Implement proper logging for replication and forwarding events
|
|
331
|
+
- Consider compression for replication messages over slow networks
|
|
332
|
+
- Plan for future features like automatic failover
|
|
333
|
+
- Ensure forwarding doesn't create circular request loops
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Task 13: Master Node Read and Write Operations
|
|
2
|
+
|
|
3
|
+
## Objective
|
|
4
|
+
Ensure that master nodes in the cluster can handle both read and write operations, not just writes. Currently, the master may be configured to only accept writes, but it should handle all operations.
|
|
5
|
+
|
|
6
|
+
## Current State
|
|
7
|
+
- Cluster system with master/worker architecture implemented
|
|
8
|
+
- Master nodes may be restricted to write operations only
|
|
9
|
+
- Secondary/worker nodes are read-only
|
|
10
|
+
- 423 passing tests from previous tasks
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
### 1. Master Node Operation Handling
|
|
15
|
+
- Verify master nodes can handle all operations:
|
|
16
|
+
- **Read operations**: `find`, `find_one`, `get_indexes`
|
|
17
|
+
- **Write operations**: `insert_one`, `update_one`, `delete_one`, `bulk_write`
|
|
18
|
+
- **Index operations**: `create_index`, `drop_index`
|
|
19
|
+
- **Admin operations**: All admin commands
|
|
20
|
+
- Remove any restrictions that prevent masters from handling reads
|
|
21
|
+
|
|
22
|
+
### 2. Operation Routing Review
|
|
23
|
+
- Review `src/server/cluster/master.js` for operation handling
|
|
24
|
+
- Ensure master processes both read and write operations locally
|
|
25
|
+
- Verify no artificial restrictions on read operations for master nodes
|
|
26
|
+
- Maintain existing write forwarding from workers to master
|
|
27
|
+
|
|
28
|
+
### 3. Load Balancing Considerations
|
|
29
|
+
- Masters should handle operations directly when they are the target node
|
|
30
|
+
- Maintain proper load distribution between master and worker nodes
|
|
31
|
+
- Ensure read operations can be served by both master and workers appropriately
|
|
32
|
+
|
|
33
|
+
### 4. Configuration Validation
|
|
34
|
+
- Review cluster configuration to ensure masters are not write-only
|
|
35
|
+
- Verify operation dispatcher routes all operation types to master correctly
|
|
36
|
+
- Check that master nodes have full database access permissions
|
|
37
|
+
|
|
38
|
+
### 5. Testing and Validation
|
|
39
|
+
- Add tests to verify master nodes handle read operations
|
|
40
|
+
- Test mixed read/write workloads on master nodes
|
|
41
|
+
- Ensure no performance degradation from handling both operation types
|
|
42
|
+
|
|
43
|
+
## Implementation Notes
|
|
44
|
+
- Follow existing code patterns: ESM syntax, snake_case, arrow functions
|
|
45
|
+
- Maintain all existing tests (423 tests must continue passing)
|
|
46
|
+
- Add tests specifically for master node read operations
|
|
47
|
+
- Ensure no breaking changes to existing cluster functionality
|
|
48
|
+
- Secondary nodes remain read-only as designed
|
|
49
|
+
|
|
50
|
+
## Success Criteria
|
|
51
|
+
- All existing tests pass (423 tests)
|
|
52
|
+
- Master nodes handle both read and write operations
|
|
53
|
+
- No artificial restrictions on master read operations
|
|
54
|
+
- New tests verify master read operation handling
|
|
55
|
+
- Cluster load balancing works correctly
|
|
56
|
+
- No performance regression for mixed workloads
|
|
57
|
+
- Secondary nodes remain properly read-only
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Task 14: Index Upsert Operations
|
|
2
|
+
|
|
3
|
+
## Objective
|
|
4
|
+
Implement index upsert functionality where indexes are created if they don't exist, or updated if they do exist, providing a seamless "create or update" operation for index management.
|
|
5
|
+
|
|
6
|
+
## Current State
|
|
7
|
+
- Secondary indexing system implemented with `create_index` and `drop_index` operations
|
|
8
|
+
- Current `create_index` fails if index already exists
|
|
9
|
+
- Index management requires manual checking of existing indexes
|
|
10
|
+
- 423 passing tests from previous tasks
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
### 1. Upsert Index Operation
|
|
15
|
+
- Modify `create_index` operation to support upsert behavior
|
|
16
|
+
- Add optional `upsert` parameter (default: false for backward compatibility)
|
|
17
|
+
- When `upsert: true`:
|
|
18
|
+
- Create index if it doesn't exist
|
|
19
|
+
- Update index definition if it exists with different configuration
|
|
20
|
+
- Return success in both cases
|
|
21
|
+
- When `upsert: false` (default): maintain current behavior (fail if exists)
|
|
22
|
+
|
|
23
|
+
### 2. Index Comparison Logic
|
|
24
|
+
- Implement index definition comparison to detect changes
|
|
25
|
+
- Compare index fields, types, and configuration options
|
|
26
|
+
- Determine if existing index needs to be updated or can be left as-is
|
|
27
|
+
- Handle cases where index structure is incompatible (require drop/recreate)
|
|
28
|
+
|
|
29
|
+
### 3. Update Index Implementation
|
|
30
|
+
- For compatible changes: update index metadata without rebuilding
|
|
31
|
+
- For incompatible changes: drop existing index and create new one
|
|
32
|
+
- Maintain data integrity during index updates
|
|
33
|
+
- Ensure atomic operations (all or nothing)
|
|
34
|
+
|
|
35
|
+
### 4. API Enhancement
|
|
36
|
+
- Update `src/server/lib/operations/create_index.js` with upsert logic
|
|
37
|
+
- Add validation for upsert parameter
|
|
38
|
+
- Enhance error handling for upsert scenarios
|
|
39
|
+
- Maintain backward compatibility with existing create_index calls
|
|
40
|
+
|
|
41
|
+
### 5. Client Library Integration
|
|
42
|
+
- Update client library to support upsert parameter
|
|
43
|
+
- Add convenience method `upsert_index()` for explicit upsert operations
|
|
44
|
+
- Update TypeScript definitions for new functionality
|
|
45
|
+
- Provide clear documentation for upsert behavior
|
|
46
|
+
|
|
47
|
+
### 6. Performance Considerations
|
|
48
|
+
- Optimize index existence checking
|
|
49
|
+
- Minimize index rebuilding when possible
|
|
50
|
+
- Add logging for upsert operations (created vs updated)
|
|
51
|
+
- Monitor performance impact of upsert operations
|
|
52
|
+
|
|
53
|
+
## Implementation Notes
|
|
54
|
+
- Follow existing code patterns: ESM syntax, snake_case, arrow functions
|
|
55
|
+
- Maintain all existing tests (423 tests must continue passing)
|
|
56
|
+
- Add comprehensive tests for upsert functionality
|
|
57
|
+
- Ensure backward compatibility with existing index operations
|
|
58
|
+
- Handle edge cases like concurrent index operations
|
|
59
|
+
|
|
60
|
+
## Success Criteria
|
|
61
|
+
- All existing tests pass (423 tests)
|
|
62
|
+
- `create_index` with `upsert: true` creates or updates indexes
|
|
63
|
+
- Backward compatibility maintained for existing `create_index` calls
|
|
64
|
+
- New tests for all upsert scenarios (create, update, no-change)
|
|
65
|
+
- Proper error handling for incompatible index changes
|
|
66
|
+
- Client library supports upsert operations
|
|
67
|
+
- Performance monitoring shows minimal impact
|
|
68
|
+
- Atomic operations ensure data integrity
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Task 15: Client API Return Types Enhancement
|
|
2
|
+
|
|
3
|
+
## Objective
|
|
4
|
+
Update the client API so that `find()` returns an array of matching documents and `find_one()` returns a single document (or null), providing more intuitive return types for developers.
|
|
5
|
+
|
|
6
|
+
## Current State
|
|
7
|
+
- Client library implemented with method chaining API
|
|
8
|
+
- Current `find()` and `find_one()` may return wrapped responses
|
|
9
|
+
- API method chaining allows `client.collection('name').find()`
|
|
10
|
+
- 423 passing tests from previous tasks
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
### 1. find() Method Enhancement
|
|
15
|
+
- Update `find()` to return an array of actual documents
|
|
16
|
+
- Remove any response wrapping for document data
|
|
17
|
+
- Return empty array `[]` when no documents match
|
|
18
|
+
- Maintain query filtering and options support
|
|
19
|
+
- Example expected behavior:
|
|
20
|
+
```javascript
|
|
21
|
+
const client = joystickdb.client();
|
|
22
|
+
const db = client.collection('example');
|
|
23
|
+
|
|
24
|
+
const docs = db.find({ status: 'active' });
|
|
25
|
+
// docs === [{ _id: '1', status: 'active', name: 'John' }, { _id: '2', status: 'active', name: 'Jane' }]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. find_one() Method Enhancement
|
|
29
|
+
- Update `find_one()` to return a single document object or null
|
|
30
|
+
- Return the actual document, not wrapped in response object
|
|
31
|
+
- Return `null` when no document matches the query
|
|
32
|
+
- Maintain query filtering and options support
|
|
33
|
+
- Example expected behavior:
|
|
34
|
+
```javascript
|
|
35
|
+
const client = joystickdb.client();
|
|
36
|
+
const db = client.collection('example');
|
|
37
|
+
|
|
38
|
+
const doc = db.find_one({ _id: '123' });
|
|
39
|
+
// doc === { _id: '123', name: 'John', status: 'active' } or null
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 3. Response Processing
|
|
43
|
+
- Update `src/client/index.js` to process server responses appropriately
|
|
44
|
+
- Extract document data from server response format
|
|
45
|
+
- Handle error cases and maintain proper error propagation
|
|
46
|
+
- Ensure consistent behavior across different query scenarios
|
|
47
|
+
|
|
48
|
+
### 4. Error Handling
|
|
49
|
+
- Maintain proper error handling for network issues
|
|
50
|
+
- Distinguish between "no results" and actual errors
|
|
51
|
+
- Preserve error messages and codes from server
|
|
52
|
+
- Ensure errors are thrown appropriately, not returned as values
|
|
53
|
+
|
|
54
|
+
### 5. Backward Compatibility Considerations
|
|
55
|
+
- Document any breaking changes in API behavior
|
|
56
|
+
- Consider if existing code might depend on current return format
|
|
57
|
+
- Provide migration guidance if needed
|
|
58
|
+
- Update TypeScript definitions to reflect new return types
|
|
59
|
+
|
|
60
|
+
### 6. Performance Optimization
|
|
61
|
+
- Minimize response processing overhead
|
|
62
|
+
- Ensure efficient array/object creation for results
|
|
63
|
+
- Maintain streaming capabilities where applicable
|
|
64
|
+
- Optimize memory usage for large result sets
|
|
65
|
+
|
|
66
|
+
## Implementation Notes
|
|
67
|
+
- Follow existing code patterns: ESM syntax, snake_case, arrow functions
|
|
68
|
+
- Maintain all existing tests (423 tests must continue passing)
|
|
69
|
+
- Update tests to expect new return formats
|
|
70
|
+
- Ensure client-server protocol remains compatible
|
|
71
|
+
- Update TypeScript definitions for new return types
|
|
72
|
+
|
|
73
|
+
## Success Criteria
|
|
74
|
+
- All existing tests pass with updated expectations (423 tests)
|
|
75
|
+
- `find()` returns array of actual documents
|
|
76
|
+
- `find_one()` returns single document or null
|
|
77
|
+
- No response wrapping for document data
|
|
78
|
+
- Proper error handling maintained
|
|
79
|
+
- TypeScript definitions updated
|
|
80
|
+
- Performance remains optimal
|
|
81
|
+
- Clear documentation of API changes
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Task 16: Server Setup UI
|
|
2
|
+
|
|
3
|
+
## Objective
|
|
4
|
+
Implement a minimalist web UI hosted by the server that provides a secure setup interface using a randomly generated token, eliminating the need to connect and disconnect a separate client for initial setup while preventing unauthorized access.
|
|
5
|
+
|
|
6
|
+
## Current State
|
|
7
|
+
- Server runs on TCP port 1983 with MessagePack protocol
|
|
8
|
+
- Setup command exists for password generation and initial configuration
|
|
9
|
+
- Currently requires separate client connection to run setup
|
|
10
|
+
- 423 passing tests from previous tasks
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
### 1. HTTP Server Integration
|
|
15
|
+
- Add HTTP server capability to existing TCP server
|
|
16
|
+
- Host HTTP server on port 1984 (TCP + 1) by default
|
|
17
|
+
- Keep existing TCP server on port 1983 unchanged
|
|
18
|
+
- Ensure HTTP server doesn't interfere with TCP operations
|
|
19
|
+
|
|
20
|
+
### 2. Setup Token Security
|
|
21
|
+
- On server startup, check if setup has been completed
|
|
22
|
+
- If not setup, generate random setup token (UUID or similar)
|
|
23
|
+
- Log clear setup message to console:
|
|
24
|
+
```
|
|
25
|
+
JoystickDB Setup Required
|
|
26
|
+
Visit: http://localhost:1984/setup?token=abc123def456
|
|
27
|
+
```
|
|
28
|
+
- Store token temporarily in memory (not persisted to disk)
|
|
29
|
+
- Token expires after first successful setup or server restart
|
|
30
|
+
|
|
31
|
+
### 3. Setup Endpoint with Token Validation
|
|
32
|
+
- Add HTTP endpoint `/setup` that requires valid token parameter
|
|
33
|
+
- Validate token matches the generated setup token
|
|
34
|
+
- Only allow setup when valid token is provided
|
|
35
|
+
- Call existing setup command after token validation
|
|
36
|
+
- Return JSON response with setup results and configuration details
|
|
37
|
+
|
|
38
|
+
### 4. Minimalist Setup UI
|
|
39
|
+
- Create simple HTML page served at `/setup?token=<valid_token>`
|
|
40
|
+
- Plain text styling - no fancy CSS or JavaScript frameworks
|
|
41
|
+
- Display setup form or confirmation button
|
|
42
|
+
- Show setup results directly in the browser after execution
|
|
43
|
+
- Include clear instructions about next steps
|
|
44
|
+
|
|
45
|
+
### 5. Response Format
|
|
46
|
+
- Display JSON response in readable format in browser
|
|
47
|
+
- Include instructions like:
|
|
48
|
+
```
|
|
49
|
+
Setup completed successfully!
|
|
50
|
+
|
|
51
|
+
Generated password: [password_here]
|
|
52
|
+
|
|
53
|
+
Next steps:
|
|
54
|
+
1. Set environment variable: JOYSTICKDB_PASSWORD=[password_here]
|
|
55
|
+
2. Restart your application
|
|
56
|
+
3. Connect using the TCP client on port 1983
|
|
57
|
+
|
|
58
|
+
Configuration saved to: [path_to_auth_file]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 6. Security Considerations
|
|
62
|
+
- Only allow setup when no authentication is configured
|
|
63
|
+
- Require valid setup token for all setup operations
|
|
64
|
+
- Token prevents unauthorized bots from hijacking setup
|
|
65
|
+
- Add basic rate limiting to prevent token brute force attempts
|
|
66
|
+
- Log all setup attempts for security monitoring
|
|
67
|
+
|
|
68
|
+
### 7. Error Handling
|
|
69
|
+
- Handle cases where setup has already been completed
|
|
70
|
+
- Provide clear error messages for invalid or missing tokens
|
|
71
|
+
- Display helpful troubleshooting information
|
|
72
|
+
- Ensure graceful degradation if HTTP server fails to start
|
|
73
|
+
|
|
74
|
+
### 8. Configuration Options
|
|
75
|
+
- Allow HTTP port configuration via settings
|
|
76
|
+
- Option to disable HTTP server entirely if not needed
|
|
77
|
+
- Maintain backward compatibility with existing configurations
|
|
78
|
+
- Document new HTTP server settings
|
|
79
|
+
|
|
80
|
+
## Implementation Notes
|
|
81
|
+
- Follow existing code patterns: ESM syntax, snake_case, arrow functions
|
|
82
|
+
- Maintain all existing tests (423 tests must continue passing)
|
|
83
|
+
- Add tests for HTTP server, token generation, and setup endpoint
|
|
84
|
+
- Keep HTTP server lightweight and minimal
|
|
85
|
+
- Ensure no dependencies on external web frameworks
|
|
86
|
+
|
|
87
|
+
## Success Criteria
|
|
88
|
+
- All existing tests pass (423 tests)
|
|
89
|
+
- HTTP server runs on port 1984 alongside TCP server
|
|
90
|
+
- Setup token generated and logged on startup when needed
|
|
91
|
+
- Setup UI accessible only with valid token
|
|
92
|
+
- Setup endpoint successfully calls existing setup command
|
|
93
|
+
- JSON response displayed clearly in browser
|
|
94
|
+
- Clear instructions provided for environment variable setup
|
|
95
|
+
- Security token prevents unauthorized setup attempts
|
|
96
|
+
- HTTP server can be disabled via configuration
|
|
97
|
+
- No impact on existing TCP server functionality
|