|
| 1 | +"use strict"; |
| 2 | +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { |
| 3 | + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; |
| 4 | + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); |
| 5 | + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; |
| 6 | + return c > 3 && r && Object.defineProperty(target, key, r), r; |
| 7 | +}; |
| 8 | +var __metadata = (this && this.__metadata) || function (k, v) { |
| 9 | + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); |
| 10 | +}; |
| 11 | +var __param = (this && this.__param) || function (paramIndex, decorator) { |
| 12 | + return function (target, key) { decorator(target, key, paramIndex); } |
| 13 | +}; |
| 14 | +var __importDefault = (this && this.__importDefault) || function (mod) { |
| 15 | + return (mod && mod.__esModule) ? mod : { "default": mod }; |
| 16 | +}; |
| 17 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 18 | +exports.RulesInput = exports.OptionsInput = exports.InstructionInput = exports.OperandInput = void 0; |
| 19 | +const MutationResult_1 = __importDefault(require("@/resolvers/MutationResult")); |
| 20 | +const Hill_1 = __importDefault(require("@/schema/Hill")); |
| 21 | +const HillService_1 = require("@/services/HillService"); |
| 22 | +const corewar_1 = require("corewar"); |
| 23 | +const type_graphql_1 = require("type-graphql"); |
| 24 | +let OperandInput = class OperandInput { |
| 25 | +}; |
| 26 | +exports.OperandInput = OperandInput; |
| 27 | +__decorate([ |
| 28 | + (0, type_graphql_1.Field)(), |
| 29 | + __metadata("design:type", String) |
| 30 | +], OperandInput.prototype, "mode", void 0); |
| 31 | +__decorate([ |
| 32 | + (0, type_graphql_1.Field)(), |
| 33 | + __metadata("design:type", Number) |
| 34 | +], OperandInput.prototype, "address", void 0); |
| 35 | +exports.OperandInput = OperandInput = __decorate([ |
| 36 | + (0, type_graphql_1.InputType)() |
| 37 | +], OperandInput); |
| 38 | +let InstructionInput = class InstructionInput { |
| 39 | +}; |
| 40 | +exports.InstructionInput = InstructionInput; |
| 41 | +__decorate([ |
| 42 | + (0, type_graphql_1.Field)(), |
| 43 | + __metadata("design:type", Number) |
| 44 | +], InstructionInput.prototype, "address", void 0); |
| 45 | +__decorate([ |
| 46 | + (0, type_graphql_1.Field)(), |
| 47 | + __metadata("design:type", String) |
| 48 | +], InstructionInput.prototype, "opcode", void 0); |
| 49 | +__decorate([ |
| 50 | + (0, type_graphql_1.Field)(), |
| 51 | + __metadata("design:type", String) |
| 52 | +], InstructionInput.prototype, "modifier", void 0); |
| 53 | +__decorate([ |
| 54 | + (0, type_graphql_1.Field)(), |
| 55 | + __metadata("design:type", OperandInput) |
| 56 | +], InstructionInput.prototype, "aOperand", void 0); |
| 57 | +__decorate([ |
| 58 | + (0, type_graphql_1.Field)(), |
| 59 | + __metadata("design:type", OperandInput) |
| 60 | +], InstructionInput.prototype, "bOperand", void 0); |
| 61 | +exports.InstructionInput = InstructionInput = __decorate([ |
| 62 | + (0, type_graphql_1.InputType)() |
| 63 | +], InstructionInput); |
| 64 | +let OptionsInput = class OptionsInput { |
| 65 | +}; |
| 66 | +exports.OptionsInput = OptionsInput; |
| 67 | +__decorate([ |
| 68 | + (0, type_graphql_1.Field)({ nullable: true }), |
| 69 | + __metadata("design:type", Number) |
| 70 | +], OptionsInput.prototype, "coresize", void 0); |
| 71 | +__decorate([ |
| 72 | + (0, type_graphql_1.Field)({ nullable: true }), |
| 73 | + __metadata("design:type", Number) |
| 74 | +], OptionsInput.prototype, "maximumCycles", void 0); |
| 75 | +__decorate([ |
| 76 | + (0, type_graphql_1.Field)({ nullable: true }), |
| 77 | + __metadata("design:type", InstructionInput) |
| 78 | +], OptionsInput.prototype, "initialInstruction", void 0); |
| 79 | +__decorate([ |
| 80 | + (0, type_graphql_1.Field)({ nullable: true }), |
| 81 | + __metadata("design:type", Number) |
| 82 | +], OptionsInput.prototype, "instructionLimit", void 0); |
| 83 | +__decorate([ |
| 84 | + (0, type_graphql_1.Field)({ nullable: true }), |
| 85 | + __metadata("design:type", Number) |
| 86 | +], OptionsInput.prototype, "maxTasks", void 0); |
| 87 | +__decorate([ |
| 88 | + (0, type_graphql_1.Field)({ nullable: true }), |
| 89 | + __metadata("design:type", Number) |
| 90 | +], OptionsInput.prototype, "minSeparation", void 0); |
| 91 | +__decorate([ |
| 92 | + (0, type_graphql_1.Field)({ nullable: true }), |
| 93 | + __metadata("design:type", Number) |
| 94 | +], OptionsInput.prototype, "standard", void 0); |
| 95 | +exports.OptionsInput = OptionsInput = __decorate([ |
| 96 | + (0, type_graphql_1.InputType)() |
| 97 | +], OptionsInput); |
| 98 | +let RulesInput = class RulesInput { |
| 99 | +}; |
| 100 | +exports.RulesInput = RulesInput; |
| 101 | +__decorate([ |
| 102 | + (0, type_graphql_1.Field)(), |
| 103 | + __metadata("design:type", Number) |
| 104 | +], RulesInput.prototype, "rounds", void 0); |
| 105 | +__decorate([ |
| 106 | + (0, type_graphql_1.Field)(), |
| 107 | + __metadata("design:type", Number) |
| 108 | +], RulesInput.prototype, "size", void 0); |
| 109 | +__decorate([ |
| 110 | + (0, type_graphql_1.Field)(), |
| 111 | + __metadata("design:type", OptionsInput) |
| 112 | +], RulesInput.prototype, "options", void 0); |
| 113 | +exports.RulesInput = RulesInput = __decorate([ |
| 114 | + (0, type_graphql_1.InputType)() |
| 115 | +], RulesInput); |
| 116 | +let HillArgs = class HillArgs { |
| 117 | +}; |
| 118 | +__decorate([ |
| 119 | + (0, type_graphql_1.Field)(), |
| 120 | + __metadata("design:type", String) |
| 121 | +], HillArgs.prototype, "id", void 0); |
| 122 | +HillArgs = __decorate([ |
| 123 | + (0, type_graphql_1.ArgsType)() |
| 124 | +], HillArgs); |
| 125 | +let CreateHillArgs = class CreateHillArgs { |
| 126 | +}; |
| 127 | +__decorate([ |
| 128 | + (0, type_graphql_1.Field)(), |
| 129 | + __metadata("design:type", RulesInput) |
| 130 | +], CreateHillArgs.prototype, "rules", void 0); |
| 131 | +CreateHillArgs = __decorate([ |
| 132 | + (0, type_graphql_1.ArgsType)() |
| 133 | +], CreateHillArgs); |
| 134 | +let CreateHillResult = class CreateHillResult extends MutationResult_1.default { |
| 135 | +}; |
| 136 | +__decorate([ |
| 137 | + (0, type_graphql_1.Field)(), |
| 138 | + __metadata("design:type", Hill_1.default) |
| 139 | +], CreateHillResult.prototype, "result", void 0); |
| 140 | +CreateHillResult = __decorate([ |
| 141 | + (0, type_graphql_1.ObjectType)() |
| 142 | +], CreateHillResult); |
| 143 | +let DeleteHillResult = class DeleteHillResult extends MutationResult_1.default { |
| 144 | +}; |
| 145 | +__decorate([ |
| 146 | + (0, type_graphql_1.Field)({ nullable: true }), |
| 147 | + __metadata("design:type", String) |
| 148 | +], DeleteHillResult.prototype, "result", void 0); |
| 149 | +DeleteHillResult = __decorate([ |
| 150 | + (0, type_graphql_1.ObjectType)() |
| 151 | +], DeleteHillResult); |
| 152 | +let ChallengeHillArgs = class ChallengeHillArgs { |
| 153 | +}; |
| 154 | +__decorate([ |
| 155 | + (0, type_graphql_1.Field)(), |
| 156 | + __metadata("design:type", String) |
| 157 | +], ChallengeHillArgs.prototype, "warriorId", void 0); |
| 158 | +__decorate([ |
| 159 | + (0, type_graphql_1.Field)(), |
| 160 | + __metadata("design:type", String) |
| 161 | +], ChallengeHillArgs.prototype, "hillId", void 0); |
| 162 | +ChallengeHillArgs = __decorate([ |
| 163 | + (0, type_graphql_1.ArgsType)() |
| 164 | +], ChallengeHillArgs); |
| 165 | +let ChallengeHillResult = class ChallengeHillResult extends MutationResult_1.default { |
| 166 | +}; |
| 167 | +__decorate([ |
| 168 | + (0, type_graphql_1.Field)({ nullable: true }), |
| 169 | + __metadata("design:type", Hill_1.default) |
| 170 | +], ChallengeHillResult.prototype, "result", void 0); |
| 171 | +ChallengeHillResult = __decorate([ |
| 172 | + (0, type_graphql_1.ObjectType)() |
| 173 | +], ChallengeHillResult); |
| 174 | +let HillResolver = class HillResolver { |
| 175 | + getService() { |
| 176 | + return (0, HillService_1.buildHillService)(); |
| 177 | + } |
| 178 | + async hill({ id }) { |
| 179 | + return this.getService().getById(id); |
| 180 | + } |
| 181 | + async hills() { |
| 182 | + return this.getService().getAll(); |
| 183 | + } |
| 184 | + async createHill({ rules }) { |
| 185 | + try { |
| 186 | + return { |
| 187 | + success: true, |
| 188 | + result: await this.getService().createHill(rules) |
| 189 | + }; |
| 190 | + } |
| 191 | + catch (e) { |
| 192 | + return { |
| 193 | + success: false, |
| 194 | + message: e instanceof Error ? e.message : String(e) |
| 195 | + }; |
| 196 | + } |
| 197 | + } |
| 198 | + async deleteHill({ id }) { |
| 199 | + try { |
| 200 | + return { |
| 201 | + success: true, |
| 202 | + result: await this.getService().deleteHill(id) |
| 203 | + }; |
| 204 | + } |
| 205 | + catch (e) { |
| 206 | + return { |
| 207 | + success: false, |
| 208 | + message: e instanceof Error ? e.message : String(e) |
| 209 | + }; |
| 210 | + } |
| 211 | + } |
| 212 | + async challengeHill({ hillId, warriorId }) { |
| 213 | + try { |
| 214 | + return { |
| 215 | + success: true, |
| 216 | + result: await this.getService().challengeHill(hillId, warriorId) |
| 217 | + }; |
| 218 | + } |
| 219 | + catch (e) { |
| 220 | + return { |
| 221 | + success: false, |
| 222 | + message: e instanceof Error ? e.message : String(e) |
| 223 | + }; |
| 224 | + } |
| 225 | + } |
| 226 | +}; |
| 227 | +__decorate([ |
| 228 | + (0, type_graphql_1.Query)(() => Hill_1.default), |
| 229 | + __param(0, (0, type_graphql_1.Args)()), |
| 230 | + __metadata("design:type", Function), |
| 231 | + __metadata("design:paramtypes", [HillArgs]), |
| 232 | + __metadata("design:returntype", Promise) |
| 233 | +], HillResolver.prototype, "hill", null); |
| 234 | +__decorate([ |
| 235 | + (0, type_graphql_1.Query)(() => [Hill_1.default]), |
| 236 | + __metadata("design:type", Function), |
| 237 | + __metadata("design:paramtypes", []), |
| 238 | + __metadata("design:returntype", Promise) |
| 239 | +], HillResolver.prototype, "hills", null); |
| 240 | +__decorate([ |
| 241 | + (0, type_graphql_1.Mutation)(() => CreateHillResult), |
| 242 | + __param(0, (0, type_graphql_1.Args)()), |
| 243 | + __metadata("design:type", Function), |
| 244 | + __metadata("design:paramtypes", [CreateHillArgs]), |
| 245 | + __metadata("design:returntype", Promise) |
| 246 | +], HillResolver.prototype, "createHill", null); |
| 247 | +__decorate([ |
| 248 | + (0, type_graphql_1.Mutation)(() => DeleteHillResult), |
| 249 | + __param(0, (0, type_graphql_1.Args)()), |
| 250 | + __metadata("design:type", Function), |
| 251 | + __metadata("design:paramtypes", [HillArgs]), |
| 252 | + __metadata("design:returntype", Promise) |
| 253 | +], HillResolver.prototype, "deleteHill", null); |
| 254 | +__decorate([ |
| 255 | + (0, type_graphql_1.Mutation)(() => ChallengeHillResult), |
| 256 | + __param(0, (0, type_graphql_1.Args)()), |
| 257 | + __metadata("design:type", Function), |
| 258 | + __metadata("design:paramtypes", [ChallengeHillArgs]), |
| 259 | + __metadata("design:returntype", Promise) |
| 260 | +], HillResolver.prototype, "challengeHill", null); |
| 261 | +HillResolver = __decorate([ |
| 262 | + (0, type_graphql_1.Resolver)(Hill_1.default) |
| 263 | +], HillResolver); |
| 264 | +exports.default = HillResolver; |
0 commit comments