{ "version": 3, "sources": ["../../../server/team-validator-async.ts"], "sourcesContent": ["/**\r\n * Team Validator\r\n * Pokemon Showdown - http://pokemonshowdown.com/\r\n *\r\n * Spawns a child process to validate teams.\r\n *\r\n * @license MIT\r\n */\r\n\r\nimport {TeamValidator} from '../sim/team-validator';\r\n\r\nexport class TeamValidatorAsync {\r\n\tformat: Format;\r\n\r\n\tconstructor(format: string) {\r\n\t\tthis.format = Dex.formats.get(format);\r\n\t}\r\n\r\n\tvalidateTeam(team: string, options?: {removeNicknames?: boolean}) {\r\n\t\tlet formatid = this.format.id;\r\n\t\tif (this.format.customRules) formatid += '@@@' + this.format.customRules.join(',');\r\n\t\treturn PM.query({formatid, options, team});\r\n\t}\r\n\r\n\tstatic get(format: string) {\r\n\t\treturn new TeamValidatorAsync(format);\r\n\t}\r\n}\r\n\r\nexport const get = TeamValidatorAsync.get;\r\n\r\n/*********************************************************\r\n * Process manager\r\n *********************************************************/\r\n\r\nimport {QueryProcessManager} from '../lib/process-manager';\r\n\r\nexport const PM = new QueryProcessManager<{\r\n\tformatid: string, options?: {removeNicknames?: boolean}, team: string,\r\n}>(module, message => {\r\n\tconst {formatid, options, team} = message;\r\n\tconst parsedTeam = Teams.unpack(team);\r\n\r\n\tif (Config.debugvalidatorprocesses && process.send) {\r\n\t\tprocess.send('DEBUG\\n' + JSON.stringify(message));\r\n\t}\r\n\r\n\tlet problems;\r\n\ttry {\r\n\t\tproblems = TeamValidator.get(formatid).validateTeam(parsedTeam, options);\r\n\t} catch (err) {\r\n\t\tMonitor.crashlog(err, 'A team validation', {\r\n\t\t\tformatid,\r\n\t\t\tteam,\r\n\t\t});\r\n\t\tproblems = [\r\n\t\t\t`Your team crashed the validator. We'll fix this crash within a few hours (we're automatically notified),` +\r\n\t\t\t` but if you don't want to wait, just use a different team for now.`,\r\n\t\t];\r\n\t}\r\n\r\n\tif (problems?.length) {\r\n\t\treturn '0' + problems.join('\\n');\r\n\t}\r\n\tconst packedTeam = Teams.pack(parsedTeam);\r\n\t// console.log('FROM: ' + message.substr(pipeIndex2 + 1));\r\n\t// console.log('TO: ' + packedTeam);\r\n\treturn '1' + packedTeam;\r\n});\r\n\r\nif (!PM.isParentProcess) {\r\n\t// This is a child process!\r\n\tglobal.Config = require('./config-loader');\r\n\r\n\tglobal.Monitor = {\r\n\t\tcrashlog(error: Error, source = 'A team validator process', details: AnyObject | null = null) {\r\n\t\t\tconst repr = JSON.stringify([error.name, error.message, source, details]);\r\n\t\t\tprocess.send!(`THROW\\n@!!@${repr}\\n${error.stack}`);\r\n\t\t},\r\n\t};\r\n\r\n\tif (Config.crashguard) {\r\n\t\tprocess.on('uncaughtException', (err: Error) => {\r\n\t\t\tMonitor.crashlog(err, `A team validator process`);\r\n\t\t});\r\n\t\tprocess.on('unhandledRejection', err => {\r\n\t\t\tMonitor.crashlog(err as any || {}, 'A team validator process Promise');\r\n\t\t});\r\n\t}\r\n\r\n\tglobal.Dex = require('../sim/dex').Dex.includeData();\r\n\tglobal.Teams = require('../sim/teams').Teams;\r\n\r\n\t// eslint-disable-next-line no-eval\r\n\trequire('../lib/repl').Repl.start(`team-validator-${process.pid}`, (cmd: string) => eval(cmd));\r\n} else {\r\n\tPM.spawn(global.Config ? Config.validatorprocesses : 1);\r\n}\r\n"], "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,4BAA4B;AA0B5B,6BAAkC;AAnClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,MAAM,mBAAmB;AAAA,EAG/B,YAAY,QAAgB;AAC3B,SAAK,SAAS,IAAI,QAAQ,IAAI,MAAM;AAAA,EACrC;AAAA,EAEA,aAAa,MAAc,SAAuC;AACjE,QAAI,WAAW,KAAK,OAAO;AAC3B,QAAI,KAAK,OAAO;AAAa,kBAAY,QAAQ,KAAK,OAAO,YAAY,KAAK,GAAG;AACjF,WAAO,GAAG,MAAM,EAAC,UAAU,SAAS,KAAI,CAAC;A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