@senators/bifrost-cli 0.0.0-stage → 7.0.0
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/LICENSE +21 -0
- package/README.md +180 -2
- package/out/accountEditor-CQB91PVf.js +2 -0
- package/out/accountEditor-CQB91PVf.js.map +1 -0
- package/out/achievements-Df5qqpYQ.js +2 -0
- package/out/achievements-Df5qqpYQ.js.map +1 -0
- package/out/active-CnUKpiEo.js +2 -0
- package/out/active-CnUKpiEo.js.map +1 -0
- package/out/alliance-BsPnhi7w.js +2 -0
- package/out/alliance-BsPnhi7w.js.map +1 -0
- package/out/allianceAdmin-Bkyl6ev4.js +2 -0
- package/out/allianceAdmin-Bkyl6ev4.js.map +1 -0
- package/out/arsenal-BMCmAHzv.js +2 -0
- package/out/arsenal-BMCmAHzv.js.map +1 -0
- package/out/ban-BXNvHPMq.js +2 -0
- package/out/ban-BXNvHPMq.js.map +1 -0
- package/out/banList-3DbCToEy.js +2 -0
- package/out/banList-3DbCToEy.js.map +1 -0
- package/out/banList-dT5GF5eO.js +2 -0
- package/out/banList-dT5GF5eO.js.map +1 -0
- package/out/battleHall-C4BALP6S.js +2 -0
- package/out/battleHall-C4BALP6S.js.map +1 -0
- package/out/battleHall-P7Co1jS5.js +2 -0
- package/out/battleHall-P7Co1jS5.js.map +1 -0
- package/out/battleReport-BG0-S-bF.js +2 -0
- package/out/battleReport-BG0-S-bF.js.map +1 -0
- package/out/battleReport-C3PQTXxc.js +2 -0
- package/out/battleReport-C3PQTXxc.js.map +1 -0
- package/out/battleSimulator-BOySErLn.js +2 -0
- package/out/battleSimulator-BOySErLn.js.map +1 -0
- package/out/board-CsNgDx4j.js +2 -0
- package/out/board-CsNgDx4j.js.map +1 -0
- package/out/board-DSCl8eU8.js +2 -0
- package/out/board-DSCl8eU8.js.map +1 -0
- package/out/bonusSummary-Dmm646zj.js +2 -0
- package/out/bonusSummary-Dmm646zj.js.map +1 -0
- package/out/buddyList-B50t-9_g.js +2 -0
- package/out/buddyList-B50t-9_g.js.map +1 -0
- package/out/buildings-CXrMgFyb.js +2 -0
- package/out/buildings-CXrMgFyb.js.map +1 -0
- package/out/catalog-DmSXp_YG.js +2 -0
- package/out/catalog-DmSXp_YG.js.map +1 -0
- package/out/chat-BvtMl-I7.js +2 -0
- package/out/chat-BvtMl-I7.js.map +1 -0
- package/out/clearCache-79cjREI0.js +2 -0
- package/out/clearCache-79cjREI0.js.map +1 -0
- package/out/cli.js +3 -0
- package/out/cli.js.map +1 -0
- package/out/containers-BhguCCkz.js +2 -0
- package/out/containers-BhguCCkz.js.map +1 -0
- package/out/control-IJRy1LDx.js +2 -0
- package/out/control-IJRy1LDx.js.map +1 -0
- package/out/create-D-IygCER.js +2 -0
- package/out/create-D-IygCER.js.map +1 -0
- package/out/createMoon-BMWjdwO0.js +2 -0
- package/out/createMoon-BMWjdwO0.js.map +1 -0
- package/out/cronjob-CCJKDSuv.js +2 -0
- package/out/cronjob-CCJKDSuv.js.map +1 -0
- package/out/dailyBonus-2UwWD4D0.js +2 -0
- package/out/dailyBonus-2UwWD4D0.js.map +1 -0
- package/out/delivery-d8NKP-f1.js +2 -0
- package/out/delivery-d8NKP-f1.js.map +1 -0
- package/out/disclaimer-BmejHZqk.js +2 -0
- package/out/disclaimer-BmejHZqk.js.map +1 -0
- package/out/dump--mJa5m3e.js +2 -0
- package/out/dump--mJa5m3e.js.map +1 -0
- package/out/endpoints-CbZGTbF-.js +2 -0
- package/out/endpoints-CbZGTbF-.js.map +1 -0
- package/out/externalAuth-Dwl3VAHa.js +2 -0
- package/out/externalAuth-Dwl3VAHa.js.map +1 -0
- package/out/findDebris-DOMvMC1l.js +2 -0
- package/out/findDebris-DOMvMC1l.js.map +1 -0
- package/out/fleet-DyITa_Xu.js +2 -0
- package/out/fleet-DyITa_Xu.js.map +1 -0
- package/out/fleetAjax-BGxyUtdi.js +2 -0
- package/out/fleetAjax-BGxyUtdi.js.map +1 -0
- package/out/fleetDealer-n6LM_8IT.js +2 -0
- package/out/fleetDealer-n6LM_8IT.js.map +1 -0
- package/out/fleetMissile-CucQvNmZ.js +2 -0
- package/out/fleetMissile-CucQvNmZ.js.map +1 -0
- package/out/fleetStep1-wp-NgTsC.js +2 -0
- package/out/fleetStep1-wp-NgTsC.js.map +1 -0
- package/out/fleetStep2-C-GzHXyn.js +2 -0
- package/out/fleetStep2-C-GzHXyn.js.map +1 -0
- package/out/fleetStep3-D_fqImWm.js +2 -0
- package/out/fleetStep3-D_fqImWm.js.map +1 -0
- package/out/fleetTable-BpWLh0R1.js +2 -0
- package/out/fleetTable-BpWLh0R1.js.map +1 -0
- package/out/flyingFleet-ClIrGPJz.js +2 -0
- package/out/flyingFleet-ClIrGPJz.js.map +1 -0
- package/out/galaxy-B12wKQUU.js +2 -0
- package/out/galaxy-B12wKQUU.js.map +1 -0
- package/out/get-Cn2hFvGS.js +2 -0
- package/out/get-Cn2hFvGS.js.map +1 -0
- package/out/giveaway-CDWEArOF.js +2 -0
- package/out/giveaway-CDWEArOF.js.map +1 -0
- package/out/growth-C_-C8rLD.js +2 -0
- package/out/growth-C_-C8rLD.js.map +1 -0
- package/out/index.d.ts +29 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +1 -0
- package/out/information-CqfqYCH1.js +2 -0
- package/out/information-CqfqYCH1.js.map +1 -0
- package/out/information-DK93hgyE.js +2 -0
- package/out/information-DK93hgyE.js.map +1 -0
- package/out/log-BBE1Jt9i.js +2 -0
- package/out/log-BBE1Jt9i.js.map +1 -0
- package/out/login--4vqysQx.js +2 -0
- package/out/login--4vqysQx.js.map +1 -0
- package/out/login-C_DqRApn.js +2 -0
- package/out/login-C_DqRApn.js.map +1 -0
- package/out/logout-BYnLiMja.js +2 -0
- package/out/logout-BYnLiMja.js.map +1 -0
- package/out/logout-BsCSXzv8.js +2 -0
- package/out/logout-BsCSXzv8.js.map +1 -0
- package/out/lostPassword-Pc_1CUBD.js +2 -0
- package/out/lostPassword-Pc_1CUBD.js.map +1 -0
- package/out/market-DN8cY1tr.js +2 -0
- package/out/market-DN8cY1tr.js.map +1 -0
- package/out/messageList-k_zW_D0G.js +2 -0
- package/out/messageList-k_zW_D0G.js.map +1 -0
- package/out/messages-D461yIe6.js +2 -0
- package/out/messages-D461yIe6.js.map +1 -0
- package/out/missions-5zZtlLIm.js +2 -0
- package/out/missions-5zZtlLIm.js.map +1 -0
- package/out/module-BEPeTBhK.js +2 -0
- package/out/module-BEPeTBhK.js.map +1 -0
- package/out/multiIp-CP3lub1T.js +2 -0
- package/out/multiIp-CP3lub1T.js.map +1 -0
- package/out/new-star-BaVTTcIn.js +2 -0
- package/out/new-star-BaVTTcIn.js.map +1 -0
- package/out/news-BdDDcd-M.js +2 -0
- package/out/news-BdDDcd-M.js.map +1 -0
- package/out/news-Dd1C9JDl.js +2 -0
- package/out/news-Dd1C9JDl.js.map +1 -0
- package/out/notes-DLngBta3.js +2 -0
- package/out/notes-DLngBta3.js.map +1 -0
- package/out/overview-CzcSTNla.js +2 -0
- package/out/overview-CzcSTNla.js.map +1 -0
- package/out/overview-wQWIR_CB.js +2 -0
- package/out/overview-wQWIR_CB.js.map +1 -0
- package/out/password-ZA_1lStC.js +2 -0
- package/out/password-ZA_1lStC.js.map +1 -0
- package/out/phalanx-DaMaoJCT.js +2 -0
- package/out/phalanx-DaMaoJCT.js.map +1 -0
- package/out/planet-CecZ2cAZ.js +2 -0
- package/out/planet-CecZ2cAZ.js.map +1 -0
- package/out/playerCard-BG711xQi.js +2 -0
- package/out/playerCard-BG711xQi.js.map +1 -0
- package/out/post-C_ywAss7.js +2 -0
- package/out/post-C_ywAss7.js.map +1 -0
- package/out/production-D8SZfez8.js +2 -0
- package/out/production-D8SZfez8.js.map +1 -0
- package/out/public-TVVf75qu.js +2 -0
- package/out/public-TVVf75qu.js.map +1 -0
- package/out/questions-NwzZ5_fL.js +2 -0
- package/out/questions-NwzZ5_fL.js.map +1 -0
- package/out/quickEditor-DEJQFH0f.js +2 -0
- package/out/quickEditor-DEJQFH0f.js.map +1 -0
- package/out/records-CDVglYGy.js +2 -0
- package/out/records-CDVglYGy.js.map +1 -0
- package/out/records-Djjz9kxk.js +2 -0
- package/out/records-Djjz9kxk.js.map +1 -0
- package/out/reduceFleet-y8p89weR.js +2 -0
- package/out/reduceFleet-y8p89weR.js.map +1 -0
- package/out/reduceResources-CnGJ9fuf.js +2 -0
- package/out/reduceResources-CnGJ9fuf.js.map +1 -0
- package/out/refreshStatistics-CjGWyNc_.js +2 -0
- package/out/refreshStatistics-CjGWyNc_.js.map +1 -0
- package/out/register-4x5hZcWe.js +2 -0
- package/out/register-4x5hZcWe.js.map +1 -0
- package/out/research-dTK3-tOW.js +2 -0
- package/out/research-dTK3-tOW.js.map +1 -0
- package/out/reset-CHiMI9rj.js +2 -0
- package/out/reset-CHiMI9rj.js.map +1 -0
- package/out/resources-CjnevA41.js +2 -0
- package/out/resources-CjnevA41.js.map +1 -0
- package/out/rights-WPf-j_YF.js +2 -0
- package/out/rights-WPf-j_YF.js.map +1 -0
- package/out/rules-E29jtQRj.js +2 -0
- package/out/rules-E29jtQRj.js.map +1 -0
- package/out/runner-C2bQQS2G.js +43 -0
- package/out/runner-C2bQQS2G.js.map +1 -0
- package/out/scan-RvWZeyyM.js +2 -0
- package/out/scan-RvWZeyyM.js.map +1 -0
- package/out/screens-CZ4g-KNp.js +2 -0
- package/out/screens-CZ4g-KNp.js.map +1 -0
- package/out/search-BYvqiUBF.js +2 -0
- package/out/search-BYvqiUBF.js.map +1 -0
- package/out/search-auPbK2Xc.js +2 -0
- package/out/search-auPbK2Xc.js.map +1 -0
- package/out/sendMessages-B2Uj3PW4.js +2 -0
- package/out/sendMessages-B2Uj3PW4.js.map +1 -0
- package/out/settings-DFFa6Ush.js +2 -0
- package/out/settings-DFFa6Ush.js.map +1 -0
- package/out/settings-Ddez5x9U.js +2 -0
- package/out/settings-Ddez5x9U.js.map +1 -0
- package/out/shared-DoaW4mlX.js +2 -0
- package/out/shared-DoaW4mlX.js.map +1 -0
- package/out/shipyard-DXr745hR.js +2 -0
- package/out/shipyard-DXr745hR.js.map +1 -0
- package/out/shops-CEE02c0g.js +2 -0
- package/out/shops-CEE02c0g.js.map +1 -0
- package/out/snapshot-CrJ8l50N.js +2 -0
- package/out/snapshot-CrJ8l50N.js.map +1 -0
- package/out/social-1Gdni-jZ.js +2 -0
- package/out/social-1Gdni-jZ.js.map +1 -0
- package/out/spec-CrkWB0BN.js +2 -0
- package/out/spec-CrkWB0BN.js.map +1 -0
- package/out/statistics-zg3aVAvW.js +2 -0
- package/out/statistics-zg3aVAvW.js.map +1 -0
- package/out/store-dXG7NoB4.js +2 -0
- package/out/store-dXG7NoB4.js.map +1 -0
- package/out/support-DisUQr57.js +2 -0
- package/out/support-DisUQr57.js.map +1 -0
- package/out/techtree-Ba3FEH5_.js +2 -0
- package/out/techtree-Ba3FEH5_.js.map +1 -0
- package/out/ticket-O_8jTKW8.js +2 -0
- package/out/ticket-O_8jTKW8.js.map +1 -0
- package/out/trader-zFDGaHZ9.js +2 -0
- package/out/trader-zFDGaHZ9.js.map +1 -0
- package/out/universe-DO32RnLQ.js +2 -0
- package/out/universe-DO32RnLQ.js.map +1 -0
- package/out/universeSettings-S7enRJR4.js +2 -0
- package/out/universeSettings-S7enRJR4.js.map +1 -0
- package/out/values-gwcnIHXs.js +2 -0
- package/out/values-gwcnIHXs.js.map +1 -0
- package/out/verify-sYnZ9juV.js +2 -0
- package/out/verify-sYnZ9juV.js.map +1 -0
- package/out/version-Cgs-grc5.js +2 -0
- package/out/version-Cgs-grc5.js.map +1 -0
- package/package.json +65 -4
- package/src/admin.ts +317 -0
- package/src/arguments.ts +323 -0
- package/src/catalog.ts +117 -0
- package/src/cli.ts +29 -0
- package/src/commands/admin/accountEditor.ts +33 -0
- package/src/commands/admin/active.ts +25 -0
- package/src/commands/admin/ban.ts +59 -0
- package/src/commands/admin/clearCache.ts +12 -0
- package/src/commands/admin/create.ts +59 -0
- package/src/commands/admin/cronjob.ts +94 -0
- package/src/commands/admin/dump.ts +25 -0
- package/src/commands/admin/flyingFleet.ts +25 -0
- package/src/commands/admin/giveaway.ts +37 -0
- package/src/commands/admin/information.ts +12 -0
- package/src/commands/admin/log.ts +37 -0
- package/src/commands/admin/login.ts +15 -0
- package/src/commands/admin/logout.ts +12 -0
- package/src/commands/admin/messageList.ts +19 -0
- package/src/commands/admin/module.ts +25 -0
- package/src/commands/admin/multiIp.ts +25 -0
- package/src/commands/admin/news.ts +40 -0
- package/src/commands/admin/overview.ts +12 -0
- package/src/commands/admin/password.ts +18 -0
- package/src/commands/admin/quickEditor.ts +30 -0
- package/src/commands/admin/refreshStatistics.ts +12 -0
- package/src/commands/admin/reset.ts +26 -0
- package/src/commands/admin/rights.ts +68 -0
- package/src/commands/admin/search.ts +31 -0
- package/src/commands/admin/sendMessages.ts +26 -0
- package/src/commands/admin/support.ts +48 -0
- package/src/commands/admin/universe.ts +49 -0
- package/src/commands/admin/universeSettings.ts +32 -0
- package/src/commands/game/achievements.ts +18 -0
- package/src/commands/game/alliance.ts +248 -0
- package/src/commands/game/allianceAdmin.ts +236 -0
- package/src/commands/game/arsenal.ts +12 -0
- package/src/commands/game/banList.ts +20 -0
- package/src/commands/game/battleHall.ts +21 -0
- package/src/commands/game/battleReport.ts +20 -0
- package/src/commands/game/battleSimulator.ts +41 -0
- package/src/commands/game/board.ts +12 -0
- package/src/commands/game/bonusSummary.ts +12 -0
- package/src/commands/game/buddyList.ts +76 -0
- package/src/commands/game/buildings.ts +81 -0
- package/src/commands/game/chat.ts +12 -0
- package/src/commands/game/containers.ts +33 -0
- package/src/commands/game/control.ts +16 -0
- package/src/commands/game/createMoon.ts +28 -0
- package/src/commands/game/dailyBonus.ts +18 -0
- package/src/commands/game/delivery.ts +34 -0
- package/src/commands/game/endpoints.ts +61 -0
- package/src/commands/game/findDebris.ts +16 -0
- package/src/commands/game/fleetAjax.ts +24 -0
- package/src/commands/game/fleetDealer.ts +36 -0
- package/src/commands/game/fleetMissile.ts +25 -0
- package/src/commands/game/fleetStep1.ts +74 -0
- package/src/commands/game/fleetStep2.ts +27 -0
- package/src/commands/game/fleetStep3.ts +28 -0
- package/src/commands/game/fleetTable.ts +96 -0
- package/src/commands/game/galaxy.ts +26 -0
- package/src/commands/game/growth.ts +313 -0
- package/src/commands/game/information.ts +56 -0
- package/src/commands/game/logout.ts +12 -0
- package/src/commands/game/market.ts +67 -0
- package/src/commands/game/messages.ts +129 -0
- package/src/commands/game/notes.ts +65 -0
- package/src/commands/game/overview.ts +49 -0
- package/src/commands/game/phalanx.ts +23 -0
- package/src/commands/game/planet.ts +78 -0
- package/src/commands/game/playerCard.ts +20 -0
- package/src/commands/game/questions.ts +23 -0
- package/src/commands/game/records.ts +16 -0
- package/src/commands/game/reduceFleet.ts +41 -0
- package/src/commands/game/reduceResources.ts +35 -0
- package/src/commands/game/research.ts +80 -0
- package/src/commands/game/resources.ts +49 -0
- package/src/commands/game/scan.ts +12 -0
- package/src/commands/game/search.ts +44 -0
- package/src/commands/game/settings.ts +121 -0
- package/src/commands/game/shipyard.ts +61 -0
- package/src/commands/game/shops.ts +89 -0
- package/src/commands/game/statistics.ts +22 -0
- package/src/commands/game/store.ts +12 -0
- package/src/commands/game/techtree.ts +16 -0
- package/src/commands/game/ticket.ts +44 -0
- package/src/commands/game/trader.ts +51 -0
- package/src/commands/game/workflows/fleet.ts +12 -0
- package/src/commands/game/workflows/snapshot.ts +84 -0
- package/src/commands/game/workflows/social.ts +37 -0
- package/src/commands/http/get.ts +13 -0
- package/src/commands/http/post.ts +44 -0
- package/src/commands/public/banList.ts +21 -0
- package/src/commands/public/battleHall.ts +20 -0
- package/src/commands/public/battleReport.ts +20 -0
- package/src/commands/public/board.ts +20 -0
- package/src/commands/public/disclaimer.ts +20 -0
- package/src/commands/public/externalAuth.ts +17 -0
- package/src/commands/public/index.ts +22 -0
- package/src/commands/public/login.ts +20 -0
- package/src/commands/public/lostPassword.ts +57 -0
- package/src/commands/public/news.ts +20 -0
- package/src/commands/public/register.ts +46 -0
- package/src/commands/public/rules.ts +20 -0
- package/src/commands/public/screens.ts +20 -0
- package/src/commands/public/verify.ts +38 -0
- package/src/commands/rules/new-star.ts +221 -0
- package/src/commands/rules/production.ts +51 -0
- package/src/completion/BifrostCompletion.psm1 +47 -0
- package/src/completion.ts +445 -0
- package/src/connection.ts +106 -0
- package/src/destination.ts +64 -0
- package/src/game.ts +978 -0
- package/src/help.ts +203 -0
- package/src/i18n.ts +45 -0
- package/src/index.ts +2 -0
- package/src/input/admin/accountEditor.ts +156 -0
- package/src/input/admin/ban.ts +23 -0
- package/src/input/admin/create.ts +36 -0
- package/src/input/admin/cronjob.ts +22 -0
- package/src/input/admin/fields.ts +432 -0
- package/src/input/admin/login.ts +9 -0
- package/src/input/admin/messageList.ts +21 -0
- package/src/input/admin/news.ts +29 -0
- package/src/input/admin/quickEditor.ts +115 -0
- package/src/input/admin/records.ts +68 -0
- package/src/input/admin/reset.ts +29 -0
- package/src/input/admin/search.ts +23 -0
- package/src/input/admin/sendMessages.ts +21 -0
- package/src/input/admin/universeSettings.ts +46 -0
- package/src/input/files.ts +65 -0
- package/src/input/game/allianceAdmin.ts +55 -0
- package/src/input/game/battleSimulator.ts +25 -0
- package/src/input/game/fleetStep1.ts +14 -0
- package/src/input/game/settings.ts +46 -0
- package/src/input/game/ticket.ts +16 -0
- package/src/input/parse.ts +173 -0
- package/src/input/paths.ts +392 -0
- package/src/input/protocol/context.ts +10 -0
- package/src/input/protocol/missions.ts +6 -0
- package/src/input/protocol/routes.ts +15 -0
- package/src/input/protocol/settings.ts +126 -0
- package/src/input/protocol/values.ts +13 -0
- package/src/input/public/externalAuth.ts +26 -0
- package/src/input/public/register.ts +9 -0
- package/src/input/rules/new-star.ts +21 -0
- package/src/input/rules/production.ts +14 -0
- package/src/input/shared.ts +51 -0
- package/src/input/spec.ts +155 -0
- package/src/input/values.ts +114 -0
- package/src/input/workflows/fleet.ts +22 -0
- package/src/input/workflows/snapshot.ts +74 -0
- package/src/locales/en-US/commands.ts +377 -0
- package/src/locales/en-US/diagnostics.ts +89 -0
- package/src/locales/en-US.ts +61 -0
- package/src/locales/zh-CN/commands.ts +307 -0
- package/src/locales/zh-CN/diagnostics.ts +81 -0
- package/src/locales/zh-CN.ts +57 -0
- package/src/options.ts +48 -0
- package/src/output.ts +201 -0
- package/src/pointer.ts +46 -0
- package/src/presentation.ts +96 -0
- package/src/public.ts +99 -0
- package/src/registry.ts +67 -0
- package/src/requests.ts +13 -0
- package/src/result.ts +27 -0
- package/src/rules.ts +77 -0
- package/src/runner.ts +214 -0
- package/src/selection.ts +44 -0
- package/src/terminal.ts +27 -0
- package/src/types.ts +110 -0
- package/src/version.ts +11 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { messages } from '../i18n.ts'
|
|
2
|
+
import { flagName } from '../options.ts'
|
|
3
|
+
import { UsageError } from '../result.ts'
|
|
4
|
+
import type { Fields, Primitive } from '../types.ts'
|
|
5
|
+
import { matchesInput, matchingBranch, numericKey } from './parse.ts'
|
|
6
|
+
import type { InputNode } from './spec.ts'
|
|
7
|
+
import { isObject, numberKey } from './values.ts'
|
|
8
|
+
|
|
9
|
+
export type InputLookup = (
|
|
10
|
+
command: string,
|
|
11
|
+
) => InputNode | undefined | Promise<InputNode | undefined>
|
|
12
|
+
export type PathStep =
|
|
13
|
+
| { kind: 'object'; key: string }
|
|
14
|
+
| { kind: 'array'; key: number }
|
|
15
|
+
| { kind: 'map'; key: string | number }
|
|
16
|
+
export type InputPath = {
|
|
17
|
+
steps: readonly [PathStep, ...PathStep[]]
|
|
18
|
+
schema: InputNode
|
|
19
|
+
contextual?: boolean
|
|
20
|
+
}
|
|
21
|
+
export type InputOption = {
|
|
22
|
+
name: string
|
|
23
|
+
schema: InputNode
|
|
24
|
+
optional: boolean
|
|
25
|
+
conditional?: boolean
|
|
26
|
+
}
|
|
27
|
+
export type InputLabel = { kind: 'type'; text: string } | { kind: 'value'; value: Primitive }
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Slots a caller fills itself: a collection's key and an array's index. They appear inside generated
|
|
31
|
+
* option names, so help, completion and path generation all have to recognise the same spellings.
|
|
32
|
+
*
|
|
33
|
+
* 由调用方自行填写的槽位:集合的键与数组的下标。它们出现在生成的参数名中,
|
|
34
|
+
* 因此帮助、补全与路径生成必须识别同一组拼写。
|
|
35
|
+
*/
|
|
36
|
+
export const KEY_SLOT = '<key>'
|
|
37
|
+
export const INDEX_SLOT = '<index>'
|
|
38
|
+
export const PATH_SLOTS: readonly string[] = [KEY_SLOT, INDEX_SLOT]
|
|
39
|
+
|
|
40
|
+
export function member(value: unknown, key: string | number): unknown {
|
|
41
|
+
if (Array.isArray(value) && typeof key === 'number') return value[key]
|
|
42
|
+
return isObject(value) && Object.hasOwn(value, key) ? value[key] : undefined
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function branches(
|
|
46
|
+
schema: InputNode,
|
|
47
|
+
value: unknown,
|
|
48
|
+
parent: unknown,
|
|
49
|
+
lookup?: InputLookup,
|
|
50
|
+
): Promise<readonly InputNode[]> {
|
|
51
|
+
if (schema.reference === 'command') {
|
|
52
|
+
const target =
|
|
53
|
+
isObject(parent) && typeof parent.command === 'string'
|
|
54
|
+
? await lookup?.(parent.command)
|
|
55
|
+
: undefined
|
|
56
|
+
return target === undefined ? [] : branches(target, value, undefined, lookup)
|
|
57
|
+
}
|
|
58
|
+
if (schema.kind === 'union') {
|
|
59
|
+
const selected = schema.variants.filter((variant) => matchingBranch(variant, value))
|
|
60
|
+
return (
|
|
61
|
+
await Promise.all(
|
|
62
|
+
(selected.length === 0 ? schema.variants : selected).map((variant) =>
|
|
63
|
+
branches(variant, value, parent, lookup),
|
|
64
|
+
),
|
|
65
|
+
)
|
|
66
|
+
).flat()
|
|
67
|
+
}
|
|
68
|
+
if (schema.kind === 'custom' && schema.input !== undefined)
|
|
69
|
+
return branches(schema.input, value, parent, lookup)
|
|
70
|
+
return [schema]
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function prepend(step: PathStep, paths: readonly InputPath[]): InputPath[] {
|
|
74
|
+
return paths.map((path) => ({ ...path, steps: [step, ...path.steps] }))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function resolve(
|
|
78
|
+
schema: InputNode,
|
|
79
|
+
name: string,
|
|
80
|
+
value: unknown,
|
|
81
|
+
parent: unknown,
|
|
82
|
+
root: boolean,
|
|
83
|
+
lookup?: InputLookup,
|
|
84
|
+
inheritedContext = false,
|
|
85
|
+
): Promise<InputPath[]> {
|
|
86
|
+
const found: InputPath[] = []
|
|
87
|
+
const contextual = inheritedContext || schema.reference !== undefined
|
|
88
|
+
for (const node of await branches(schema, value, parent, lookup)) {
|
|
89
|
+
if (node.kind === 'object') {
|
|
90
|
+
for (const [key, field] of Object.entries(node.fields)) {
|
|
91
|
+
const spelling = flagName(key, root)
|
|
92
|
+
const step = { kind: 'object', key } satisfies PathStep
|
|
93
|
+
if (name === spelling) found.push({ steps: [step], schema: field.schema, contextual })
|
|
94
|
+
else if (name.startsWith(spelling + '.'))
|
|
95
|
+
found.push(
|
|
96
|
+
...prepend(
|
|
97
|
+
step,
|
|
98
|
+
await resolve(
|
|
99
|
+
field.schema,
|
|
100
|
+
name.slice(spelling.length + 1),
|
|
101
|
+
member(value, key),
|
|
102
|
+
value,
|
|
103
|
+
false,
|
|
104
|
+
lookup,
|
|
105
|
+
contextual,
|
|
106
|
+
),
|
|
107
|
+
),
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (node.kind === 'array') {
|
|
112
|
+
const separator = name.indexOf('.')
|
|
113
|
+
const spelling = separator < 0 ? name : name.slice(0, separator)
|
|
114
|
+
if (!/^(0|[1-9]\d*)$/.test(spelling)) continue
|
|
115
|
+
const key = Number(spelling)
|
|
116
|
+
if (key > 4_294_967_294) continue
|
|
117
|
+
const step = { kind: 'array', key } satisfies PathStep
|
|
118
|
+
if (separator < 0) found.push({ steps: [step], schema: node.item, contextual })
|
|
119
|
+
else
|
|
120
|
+
found.push(
|
|
121
|
+
...prepend(
|
|
122
|
+
step,
|
|
123
|
+
await resolve(
|
|
124
|
+
node.item,
|
|
125
|
+
name.slice(separator + 1),
|
|
126
|
+
member(value, key),
|
|
127
|
+
value,
|
|
128
|
+
false,
|
|
129
|
+
lookup,
|
|
130
|
+
contextual,
|
|
131
|
+
),
|
|
132
|
+
),
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
if (node.kind === 'map') {
|
|
136
|
+
const candidates: InputPath[] = []
|
|
137
|
+
const boundaries = [...name.matchAll(/\./g)].map((match) => match.index)
|
|
138
|
+
boundaries.push(name.length)
|
|
139
|
+
for (const boundary of boundaries) {
|
|
140
|
+
const spelling = name.slice(0, boundary)
|
|
141
|
+
const key = numericKey(node.key) ? numberKey(spelling) : spelling
|
|
142
|
+
if (key === undefined || !matchesInput(node.key, key)) continue
|
|
143
|
+
const step = { kind: 'map', key } satisfies PathStep
|
|
144
|
+
if (boundary === name.length)
|
|
145
|
+
candidates.push({ steps: [step], schema: node.value, contextual })
|
|
146
|
+
else
|
|
147
|
+
candidates.push(
|
|
148
|
+
...prepend(
|
|
149
|
+
step,
|
|
150
|
+
await resolve(
|
|
151
|
+
node.value,
|
|
152
|
+
name.slice(boundary + 1),
|
|
153
|
+
member(value, key),
|
|
154
|
+
value,
|
|
155
|
+
false,
|
|
156
|
+
lookup,
|
|
157
|
+
contextual,
|
|
158
|
+
),
|
|
159
|
+
),
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
const depth = Math.max(0, ...candidates.map((path) => path.steps.length))
|
|
163
|
+
found.push(...candidates.filter((path) => path.steps.length === depth))
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return found
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function pathIdentity(path: InputPath): string {
|
|
170
|
+
return JSON.stringify(path.steps)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Resolve declared field names before dynamic keys, including literal dots in server field names.
|
|
175
|
+
*
|
|
176
|
+
* 先按声明的字段名解析,再处理动态键;服务端字段名中的字面点号得以保留。
|
|
177
|
+
*/
|
|
178
|
+
export async function resolvePath(
|
|
179
|
+
schema: InputNode,
|
|
180
|
+
name: string,
|
|
181
|
+
input?: unknown,
|
|
182
|
+
lookup?: InputLookup,
|
|
183
|
+
): Promise<InputPath | undefined> {
|
|
184
|
+
const paths = await resolve(schema, name, input, undefined, true, lookup)
|
|
185
|
+
const first = paths[0]
|
|
186
|
+
if (first === undefined || paths.length === 1) return first
|
|
187
|
+
const identity = pathIdentity(first)
|
|
188
|
+
if (paths.some((path, index) => index > 0 && pathIdentity(path) !== identity))
|
|
189
|
+
throw new UsageError(messages().diagnostics.ambiguousOption(name))
|
|
190
|
+
return {
|
|
191
|
+
steps: first.steps,
|
|
192
|
+
schema: { kind: 'union', variants: paths.map((path) => path.schema) },
|
|
193
|
+
contextual: paths.some((path) => path.contextual === true),
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Order paths so parents precede their children; sibling order never depends on the runtime locale.
|
|
199
|
+
*
|
|
200
|
+
* 排序使父路径先于子路径;同级顺序不依赖运行期区域设置。
|
|
201
|
+
*/
|
|
202
|
+
export function comparePaths(left: InputPath, right: InputPath): number {
|
|
203
|
+
for (const [index, a] of left.steps.entries()) {
|
|
204
|
+
const b = right.steps[index]
|
|
205
|
+
if (b === undefined) return 1
|
|
206
|
+
if (a.key === b.key) continue
|
|
207
|
+
if (typeof a.key === 'number' && typeof b.key === 'number') return a.key - b.key
|
|
208
|
+
return String(a.key) < String(b.key) ? -1 : 1
|
|
209
|
+
}
|
|
210
|
+
return left.steps.length - right.steps.length
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function assign(value: unknown, steps: readonly PathStep[], replacement: unknown): unknown {
|
|
214
|
+
const step = steps[0]
|
|
215
|
+
if (step === undefined) return replacement
|
|
216
|
+
const rest = steps.slice(1)
|
|
217
|
+
const child = member(value, step.key)
|
|
218
|
+
if (step.kind === 'array') {
|
|
219
|
+
if (value !== undefined && !Array.isArray(value))
|
|
220
|
+
throw new UsageError(messages().diagnostics.expectedArray)
|
|
221
|
+
const result: unknown[] = Array.isArray(value) ? [...value] : []
|
|
222
|
+
if (step.key > result.length)
|
|
223
|
+
throw new UsageError(messages().diagnostics.missingArrayIndex(result.length))
|
|
224
|
+
result[step.key] = assign(child, rest, replacement)
|
|
225
|
+
return result
|
|
226
|
+
}
|
|
227
|
+
if (value !== undefined && !isObject(value))
|
|
228
|
+
throw new UsageError(
|
|
229
|
+
step.kind === 'map'
|
|
230
|
+
? messages().diagnostics.expectedMap
|
|
231
|
+
: messages().diagnostics.expectedObject,
|
|
232
|
+
)
|
|
233
|
+
return Object.fromEntries([
|
|
234
|
+
...Object.entries(value ?? {}),
|
|
235
|
+
[step.key, assign(child, rest, replacement)],
|
|
236
|
+
])
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function assignPath(input: Fields, path: InputPath, value: unknown): Fields {
|
|
240
|
+
const [step, ...rest] = path.steps
|
|
241
|
+
return Object.fromEntries([
|
|
242
|
+
...Object.entries(input),
|
|
243
|
+
[step.key, assign(member(input, step.key), rest, value)],
|
|
244
|
+
])
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Resolve pending options against each updated input, applying independent selectors before
|
|
249
|
+
* contextual paths and parents before children. Callers own decoding and failure handling.
|
|
250
|
+
* Resolution errors returned as values reach unresolved only when no path can proceed;
|
|
251
|
+
* rejected promises stop processing immediately.
|
|
252
|
+
*
|
|
253
|
+
* 每次更新输入后重新解析待处理选项,独立选择字段先于上下文路径,父路径先于子路径。
|
|
254
|
+
* 解码与失败处理由调用方决定。作为返回值的解析错误仅在没有可处理路径时交给 unresolved;
|
|
255
|
+
* Promise 拒绝则立即终止处理。
|
|
256
|
+
*/
|
|
257
|
+
export async function assignOptions(
|
|
258
|
+
options: readonly { name: string; text: string }[],
|
|
259
|
+
input: Fields,
|
|
260
|
+
policy: {
|
|
261
|
+
resolve: (name: string, input: Fields) => Promise<InputPath | UsageError | undefined>
|
|
262
|
+
assign: (
|
|
263
|
+
input: Fields,
|
|
264
|
+
option: { name: string; text: string },
|
|
265
|
+
path: InputPath,
|
|
266
|
+
) => Fields | Promise<Fields>
|
|
267
|
+
unresolved: (name: string, errors: readonly UsageError[]) => void
|
|
268
|
+
},
|
|
269
|
+
): Promise<Fields> {
|
|
270
|
+
let pending = options
|
|
271
|
+
while (pending[0] !== undefined) {
|
|
272
|
+
const errors: UsageError[] = []
|
|
273
|
+
const resolved: { name: string; text: string; path: InputPath }[] = []
|
|
274
|
+
for (const option of pending) {
|
|
275
|
+
const path = await policy.resolve(option.name, input)
|
|
276
|
+
if (path instanceof UsageError) errors.push(path)
|
|
277
|
+
else if (path !== undefined) resolved.push({ ...option, path })
|
|
278
|
+
}
|
|
279
|
+
const independent = resolved.filter(({ path }) => !path.contextual)
|
|
280
|
+
const entry = (independent.length > 0 ? independent : resolved).toSorted((left, right) =>
|
|
281
|
+
comparePaths(left.path, right.path),
|
|
282
|
+
)[0]
|
|
283
|
+
if (entry === undefined) {
|
|
284
|
+
policy.unresolved(pending[0].name, errors)
|
|
285
|
+
break
|
|
286
|
+
}
|
|
287
|
+
input = await policy.assign(input, entry, entry.path)
|
|
288
|
+
pending = pending.filter(({ name }) => name !== entry.name)
|
|
289
|
+
}
|
|
290
|
+
return input
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function inputOptions(
|
|
294
|
+
schema: InputNode,
|
|
295
|
+
prefix = '',
|
|
296
|
+
optional = false,
|
|
297
|
+
conditional = false,
|
|
298
|
+
): InputOption[] {
|
|
299
|
+
if (schema.kind === 'union') {
|
|
300
|
+
const variants = schema.variants.map((variant) =>
|
|
301
|
+
inputOptions(variant, prefix, optional, conditional),
|
|
302
|
+
)
|
|
303
|
+
const options = variants.flat()
|
|
304
|
+
const unique = new Map<string, InputNode>()
|
|
305
|
+
for (const option of options) {
|
|
306
|
+
const existing = unique.get(option.name)
|
|
307
|
+
unique.set(
|
|
308
|
+
option.name,
|
|
309
|
+
existing === undefined
|
|
310
|
+
? option.schema
|
|
311
|
+
: { kind: 'union', variants: [existing, option.schema] },
|
|
312
|
+
)
|
|
313
|
+
}
|
|
314
|
+
return [...unique].map(([name, node]) => {
|
|
315
|
+
const required = variants.map((variant) =>
|
|
316
|
+
variant.some((entry) => entry.name === name && !entry.optional),
|
|
317
|
+
)
|
|
318
|
+
const conditionallyRequired = variants.some((variant) =>
|
|
319
|
+
variant.some((entry) => entry.name === name && entry.conditional === true),
|
|
320
|
+
)
|
|
321
|
+
return {
|
|
322
|
+
name,
|
|
323
|
+
schema: node,
|
|
324
|
+
optional: !required.every(Boolean),
|
|
325
|
+
conditional: (conditionallyRequired || required.some(Boolean)) && !required.every(Boolean),
|
|
326
|
+
}
|
|
327
|
+
})
|
|
328
|
+
}
|
|
329
|
+
if (schema.kind === 'custom' && schema.input !== undefined && schema.reference === undefined)
|
|
330
|
+
return inputOptions(schema.input, prefix, optional, conditional)
|
|
331
|
+
const own: InputOption[] =
|
|
332
|
+
prefix === ''
|
|
333
|
+
? []
|
|
334
|
+
: [
|
|
335
|
+
{
|
|
336
|
+
name: prefix,
|
|
337
|
+
schema,
|
|
338
|
+
optional: optional || conditional,
|
|
339
|
+
...(conditional && !optional ? { conditional: true } : {}),
|
|
340
|
+
},
|
|
341
|
+
]
|
|
342
|
+
if (schema.kind === 'object') {
|
|
343
|
+
const fields = Object.entries(schema.fields).flatMap(([name, field]) => {
|
|
344
|
+
const path = prefix === '' ? flagName(name) : `${prefix}.${flagName(name, false)}`
|
|
345
|
+
return inputOptions(field.schema, path, field.optional, conditional || optional)
|
|
346
|
+
})
|
|
347
|
+
return [...own, ...fields]
|
|
348
|
+
}
|
|
349
|
+
if (schema.kind === 'array')
|
|
350
|
+
return [...own, ...inputOptions(schema.item, `${prefix}.${INDEX_SLOT}`, false, true)]
|
|
351
|
+
if (schema.kind === 'map')
|
|
352
|
+
return [...own, ...inputOptions(schema.value, `${prefix}.${KEY_SLOT}`, false, true)]
|
|
353
|
+
return own
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export function inputChoices(schema: InputNode): string[] {
|
|
357
|
+
return [
|
|
358
|
+
...new Set(
|
|
359
|
+
inputLabels(schema).flatMap((label) => (label.kind === 'value' ? [String(label.value)] : [])),
|
|
360
|
+
),
|
|
361
|
+
]
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export function inputLabels(schema: InputNode): InputLabel[] {
|
|
365
|
+
if (schema.kind === 'custom' && schema.input !== undefined) return inputLabels(schema.input)
|
|
366
|
+
if (schema.kind === 'union') return schema.variants.flatMap(inputLabels)
|
|
367
|
+
if (schema.kind === 'enum' && schema.values.length > 0)
|
|
368
|
+
return schema.values.map((value) => ({ kind: 'value', value }))
|
|
369
|
+
if (schema.kind === 'boolean')
|
|
370
|
+
return [
|
|
371
|
+
{ kind: 'value', value: true },
|
|
372
|
+
{ kind: 'value', value: false },
|
|
373
|
+
]
|
|
374
|
+
if (schema.kind === 'null') return [{ kind: 'value', value: null }]
|
|
375
|
+
const label = messages().help
|
|
376
|
+
if (schema.kind === 'string') return [{ kind: 'type', text: label.stringType }]
|
|
377
|
+
if (schema.kind === 'number') return [{ kind: 'type', text: label.numberType }]
|
|
378
|
+
return [
|
|
379
|
+
{ kind: 'type', text: 'JSON' },
|
|
380
|
+
{ kind: 'type', text: `@${label.file}#/${label.pointer}` },
|
|
381
|
+
]
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export function inputLabel(schema: InputNode): string {
|
|
385
|
+
return [
|
|
386
|
+
...new Set(
|
|
387
|
+
inputLabels(schema).map((label) =>
|
|
388
|
+
label.kind === 'type' ? label.text : String(label.value),
|
|
389
|
+
),
|
|
390
|
+
),
|
|
391
|
+
].join('|')
|
|
392
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PLANET_STOCK_IDS, RESOURCE_IDS, isSupplyResourceId } from '@senators/bifrost'
|
|
2
|
+
import type { PlanetStockId, SupplyResourceId } from '@senators/bifrost'
|
|
3
|
+
|
|
4
|
+
import { enumeration } from '../spec.ts'
|
|
5
|
+
import type { InputSpec } from '../spec.ts'
|
|
6
|
+
|
|
7
|
+
export const planetStockIdInput: InputSpec<PlanetStockId> = enumeration(PLANET_STOCK_IDS)
|
|
8
|
+
export const supplyResourceIdInput: InputSpec<SupplyResourceId> = enumeration(
|
|
9
|
+
RESOURCE_IDS.filter(isSupplyResourceId),
|
|
10
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SEARCH_TYPES } from '@senators/bifrost'
|
|
2
|
+
import type { SearchType } from '@senators/bifrost'
|
|
3
|
+
|
|
4
|
+
import { enumeration } from '../spec.ts'
|
|
5
|
+
import type { InputSpec } from '../spec.ts'
|
|
6
|
+
|
|
7
|
+
function isSearchType(value: unknown): value is SearchType {
|
|
8
|
+
return typeof value === 'string' && Object.hasOwn(SEARCH_TYPES, value)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const searchTypeInput: InputSpec<SearchType> = {
|
|
12
|
+
kind: 'custom',
|
|
13
|
+
input: enumeration(Object.keys(SEARCH_TYPES)),
|
|
14
|
+
accepts: isSearchType,
|
|
15
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { AllianceSettingsInput, AllianceTextKind, SettingsInput } from '@senators/bifrost'
|
|
2
|
+
|
|
3
|
+
import type { Fields } from '../../types.ts'
|
|
4
|
+
import {
|
|
5
|
+
arrayInput,
|
|
6
|
+
booleanInput,
|
|
7
|
+
enumeration,
|
|
8
|
+
numberInput,
|
|
9
|
+
optional,
|
|
10
|
+
stringInput,
|
|
11
|
+
} from '../spec.ts'
|
|
12
|
+
import type { InputSpec } from '../spec.ts'
|
|
13
|
+
import {
|
|
14
|
+
fieldsMatch,
|
|
15
|
+
isArrayOf,
|
|
16
|
+
isBoolean,
|
|
17
|
+
isChoice,
|
|
18
|
+
isNumber,
|
|
19
|
+
isObject,
|
|
20
|
+
isString,
|
|
21
|
+
optionalFieldsMatch,
|
|
22
|
+
} from '../values.ts'
|
|
23
|
+
|
|
24
|
+
export const allianceTextKindInput: InputSpec<AllianceTextKind> & { kind: 'enum' } = enumeration([
|
|
25
|
+
'external',
|
|
26
|
+
'internal',
|
|
27
|
+
'application',
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
export const settingsPatchInput: InputSpec<SettingsInput> = {
|
|
31
|
+
kind: 'object',
|
|
32
|
+
fields: {
|
|
33
|
+
avatarUrl: optional(stringInput),
|
|
34
|
+
backgroundUrl: optional(stringInput),
|
|
35
|
+
timezone: optional(stringInput),
|
|
36
|
+
language: optional(stringInput),
|
|
37
|
+
theme: optional(stringInput),
|
|
38
|
+
planetSort: optional(numberInput),
|
|
39
|
+
planetOrder: optional(numberInput),
|
|
40
|
+
probeCount: optional(numberInput),
|
|
41
|
+
fleetActionLimit: optional(numberInput),
|
|
42
|
+
queueMessagesEnabled: optional(booleanInput),
|
|
43
|
+
hideEmptySpyEntries: optional(booleanInput),
|
|
44
|
+
blockPrivateMessages: optional(booleanInput),
|
|
45
|
+
galaxySpyEnabled: optional(booleanInput),
|
|
46
|
+
galaxyMessagesEnabled: optional(booleanInput),
|
|
47
|
+
galaxyBuddyRequestsEnabled: optional(booleanInput),
|
|
48
|
+
galaxyMissilesEnabled: optional(booleanInput),
|
|
49
|
+
adminProtectionEnabled: optional(booleanInput),
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const allianceSettingsPatchInput: InputSpec<AllianceSettingsInput> = {
|
|
54
|
+
kind: 'object',
|
|
55
|
+
fields: {
|
|
56
|
+
tag: optional(stringInput),
|
|
57
|
+
name: optional(stringInput),
|
|
58
|
+
ownerRankName: optional(stringInput),
|
|
59
|
+
websiteUrl: optional(stringInput),
|
|
60
|
+
imageUrl: optional(stringInput),
|
|
61
|
+
text: optional(stringInput),
|
|
62
|
+
maximumMembers: optional(numberInput),
|
|
63
|
+
minimumApplicationPoints: optional(numberInput),
|
|
64
|
+
applicationsClosed: optional(booleanInput),
|
|
65
|
+
showStatistics: optional(booleanInput),
|
|
66
|
+
showDiplomacy: optional(booleanInput),
|
|
67
|
+
eventMissions: optional(arrayInput(numberInput)),
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const SETTINGS_NUMBERS = ['planetSort', 'planetOrder', 'probeCount', 'fleetActionLimit']
|
|
72
|
+
const ACCOUNT_BOOLEANS = [
|
|
73
|
+
'queueMessagesEnabled',
|
|
74
|
+
'hideEmptySpyEntries',
|
|
75
|
+
'blockPrivateMessages',
|
|
76
|
+
'galaxySpyEnabled',
|
|
77
|
+
'galaxyMessagesEnabled',
|
|
78
|
+
'galaxyBuddyRequestsEnabled',
|
|
79
|
+
'galaxyMissilesEnabled',
|
|
80
|
+
]
|
|
81
|
+
const ALLIANCE_STRINGS = ['tag', 'name', 'ownerRankName', 'websiteUrl', 'imageUrl', 'text']
|
|
82
|
+
const ALLIANCE_NUMBERS = ['maximumMembers', 'minimumApplicationPoints']
|
|
83
|
+
const ALLIANCE_BOOLEANS = ['applicationsClosed', 'showStatistics', 'showDiplomacy']
|
|
84
|
+
|
|
85
|
+
function isMissionList(value: unknown): boolean {
|
|
86
|
+
return isArrayOf(value, isNumber)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function isAccountSettingsValues(value: Fields): boolean {
|
|
90
|
+
return (
|
|
91
|
+
optionalFieldsMatch(value, ['language', 'theme'], isString) &&
|
|
92
|
+
optionalFieldsMatch(value, ['adminProtectionEnabled'], isBoolean) &&
|
|
93
|
+
fieldsMatch(value, ['avatarUrl', 'backgroundUrl', 'timezone'], isString) &&
|
|
94
|
+
fieldsMatch(value, SETTINGS_NUMBERS, isNumber) &&
|
|
95
|
+
fieldsMatch(value, ACCOUNT_BOOLEANS, isBoolean)
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function isAllianceSettingsValues(value: Fields): boolean {
|
|
100
|
+
return (
|
|
101
|
+
fieldsMatch(value, ALLIANCE_STRINGS, isString) &&
|
|
102
|
+
fieldsMatch(value, ALLIANCE_NUMBERS, (item) => item === null || isNumber(item)) &&
|
|
103
|
+
fieldsMatch(value, ALLIANCE_BOOLEANS, isBoolean) &&
|
|
104
|
+
isMissionList(value.eventMissions)
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function isAllianceTextKind(value: unknown): boolean {
|
|
109
|
+
return isChoice(value, allianceTextKindInput.values)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function isFormChoices(
|
|
113
|
+
value: unknown,
|
|
114
|
+
names: readonly string[],
|
|
115
|
+
accepts: (input: unknown) => boolean,
|
|
116
|
+
): boolean {
|
|
117
|
+
return (
|
|
118
|
+
isObject(value) &&
|
|
119
|
+
optionalFieldsMatch(value, names, (options) =>
|
|
120
|
+
isArrayOf(
|
|
121
|
+
options,
|
|
122
|
+
(option) => isObject(option) && isString(option.label) && accepts(option.value),
|
|
123
|
+
),
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PRODUCTION_ELEMENT_IDS } from '@senators/bifrost'
|
|
2
|
+
import type { FleetSpeed, ProducerElementId, ProductionStep } from '@senators/bifrost'
|
|
3
|
+
|
|
4
|
+
import { enumeration } from '../spec.ts'
|
|
5
|
+
import type { InputSpec } from '../spec.ts'
|
|
6
|
+
|
|
7
|
+
export const fleetSpeedInput: InputSpec<FleetSpeed> = enumeration([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
|
|
8
|
+
export const producerElementIdInput: InputSpec<ProducerElementId> =
|
|
9
|
+
enumeration(PRODUCTION_ELEMENT_IDS)
|
|
10
|
+
export const productionStepInput: InputSpec<ProductionStep> = enumeration([
|
|
11
|
+
0,
|
|
12
|
+
...fleetSpeedInput.values,
|
|
13
|
+
])
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PublicExternalAuthOptions } from '@senators/bifrost'
|
|
2
|
+
|
|
3
|
+
import { enumeration, optional, required, stringInput, unionInput } from '../spec.ts'
|
|
4
|
+
import type { InputSpec } from '../spec.ts'
|
|
5
|
+
|
|
6
|
+
export const publicExternalAuthInput: InputSpec<PublicExternalAuthOptions> = unionInput(
|
|
7
|
+
{
|
|
8
|
+
kind: 'object',
|
|
9
|
+
fields: {
|
|
10
|
+
method: required(enumeration(['facebook'])),
|
|
11
|
+
language: optional(stringInput),
|
|
12
|
+
code: optional(stringInput),
|
|
13
|
+
errorReason: optional(stringInput),
|
|
14
|
+
signedRequest: optional(stringInput),
|
|
15
|
+
state: optional(stringInput),
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
kind: 'object',
|
|
20
|
+
fields: {
|
|
21
|
+
method: required(enumeration(['openid'])),
|
|
22
|
+
language: optional(stringInput),
|
|
23
|
+
identifier: required(stringInput),
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PublicExternalAuthIdentity } from '@senators/bifrost'
|
|
2
|
+
|
|
3
|
+
import { required, stringInput } from '../spec.ts'
|
|
4
|
+
import type { InputSpec } from '../spec.ts'
|
|
5
|
+
|
|
6
|
+
export const publicExternalAuthIdentityInput: InputSpec<PublicExternalAuthIdentity> = {
|
|
7
|
+
kind: 'object',
|
|
8
|
+
fields: { account: required(stringInput), method: required(stringInput) },
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FlightShip, SupplyBalance } from '@senators/bifrost'
|
|
2
|
+
|
|
3
|
+
import { numberInput, required } from '../spec.ts'
|
|
4
|
+
import type { InputSpec } from '../spec.ts'
|
|
5
|
+
|
|
6
|
+
export const supplyBalanceInput: InputSpec<SupplyBalance> = {
|
|
7
|
+
kind: 'object',
|
|
8
|
+
fields: {
|
|
9
|
+
consumption: required(numberInput),
|
|
10
|
+
total: required(numberInput),
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const flightShipInput: InputSpec<FlightShip> = {
|
|
15
|
+
kind: 'object',
|
|
16
|
+
fields: {
|
|
17
|
+
amount: required(numberInput),
|
|
18
|
+
consumption: required(numberInput),
|
|
19
|
+
speed: required(numberInput),
|
|
20
|
+
},
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ResourceProducer } from '@senators/bifrost'
|
|
2
|
+
|
|
3
|
+
import { producerElementIdInput, productionStepInput } from '../protocol/values.ts'
|
|
4
|
+
import { numberInput, required } from '../spec.ts'
|
|
5
|
+
import type { InputSpec } from '../spec.ts'
|
|
6
|
+
|
|
7
|
+
export const resourceProducerInput: InputSpec<ResourceProducer> = {
|
|
8
|
+
kind: 'object',
|
|
9
|
+
fields: {
|
|
10
|
+
elementId: required(producerElementIdInput),
|
|
11
|
+
level: required(numberInput),
|
|
12
|
+
step: required(productionStepInput),
|
|
13
|
+
},
|
|
14
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Coordinate,
|
|
3
|
+
ElementInput,
|
|
4
|
+
Location,
|
|
5
|
+
PlanetReference,
|
|
6
|
+
PlanetStockId,
|
|
7
|
+
ProducerElementId,
|
|
8
|
+
ProductionStep,
|
|
9
|
+
ResourceInput,
|
|
10
|
+
} from '@senators/bifrost'
|
|
11
|
+
|
|
12
|
+
import { planetStockIdInput } from './protocol/context.ts'
|
|
13
|
+
import { producerElementIdInput, productionStepInput } from './protocol/values.ts'
|
|
14
|
+
import { enumeration, mapInput, numberInput, optional, required } from './spec.ts'
|
|
15
|
+
import type { InputSpec } from './spec.ts'
|
|
16
|
+
|
|
17
|
+
export const coordinateInput: InputSpec<Coordinate> = {
|
|
18
|
+
kind: 'object',
|
|
19
|
+
fields: {
|
|
20
|
+
galaxy: required(numberInput),
|
|
21
|
+
system: required(numberInput),
|
|
22
|
+
planet: required(numberInput),
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const locationInput: InputSpec<Location> = {
|
|
27
|
+
kind: 'object',
|
|
28
|
+
fields: { ...coordinateInput.fields, type: required(enumeration([1, 2, 3])) },
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const planetReferenceInput: InputSpec<PlanetReference> = {
|
|
32
|
+
kind: 'object',
|
|
33
|
+
fields: { planetId: required(numberInput) },
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const resourceInput: InputSpec<ResourceInput> = {
|
|
37
|
+
kind: 'object',
|
|
38
|
+
fields: {
|
|
39
|
+
metal: optional(numberInput),
|
|
40
|
+
crystal: optional(numberInput),
|
|
41
|
+
deuterium: optional(numberInput),
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const elementInput: InputSpec<ElementInput> = mapInput(numberInput, numberInput)
|
|
46
|
+
export const productionStepsInput: InputSpec<ElementInput<ProducerElementId, ProductionStep>> =
|
|
47
|
+
mapInput(producerElementIdInput, productionStepInput)
|
|
48
|
+
export const stockAmountsInput: InputSpec<ElementInput<PlanetStockId>> = mapInput(
|
|
49
|
+
planetStockIdInput,
|
|
50
|
+
numberInput,
|
|
51
|
+
)
|