Skip to content

Commit f94a205

Browse files
Merge pull request #106 from corewar/the-turbo-repo-an-ing
Add public marketing site to monorepo
2 parents 7180d6d + a10ecaa commit f94a205

File tree

224 files changed

+11896
-11205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+11896
-11205
lines changed

packages/corewar-api/.turbo/turbo-lint.log

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/corewar-api/.turbo/turbo-test.log

Lines changed: 0 additions & 780 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.WARRIOR_COLLECTION = exports.HILL_COLLECTION = exports.DATABASE_NAME = exports.MONGO_URL = void 0;
4+
exports.MONGO_URL = 'mongodb://localhost:27017';
5+
exports.DATABASE_NAME = 'corewar';
6+
exports.HILL_COLLECTION = 'hills';
7+
exports.WARRIOR_COLLECTION = 'warriors';
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const constants_1 = require("@/constants");
4+
const mongodb_1 = require("mongodb");
5+
class Repository {
6+
constructor(collectionName) {
7+
this.collectionName = collectionName;
8+
}
9+
async getClient() {
10+
const client = new mongodb_1.MongoClient(constants_1.MONGO_URL);
11+
await client.connect();
12+
return client;
13+
}
14+
async getAll() {
15+
const client = await this.getClient();
16+
try {
17+
const database = client.db(constants_1.DATABASE_NAME);
18+
const collection = database.collection(this.collectionName);
19+
return (await collection.find().toArray());
20+
}
21+
finally {
22+
client.close();
23+
}
24+
}
25+
async getById(id) {
26+
const client = await this.getClient();
27+
try {
28+
const database = client.db(constants_1.DATABASE_NAME);
29+
const collection = database.collection(this.collectionName);
30+
return (await collection.findOne({ id }));
31+
}
32+
finally {
33+
client.close();
34+
}
35+
}
36+
/* eslint-disable-next-line */
37+
async getOneBy(filter) {
38+
const client = await this.getClient();
39+
try {
40+
const database = client.db(constants_1.DATABASE_NAME);
41+
const collection = database.collection(this.collectionName);
42+
return (await collection.findOne(filter));
43+
}
44+
finally {
45+
client.close();
46+
}
47+
}
48+
/* eslint-disable-next-line */
49+
async getManyBy(filter) {
50+
const client = await this.getClient();
51+
try {
52+
const database = client.db(constants_1.DATABASE_NAME);
53+
const collection = database.collection(this.collectionName);
54+
return (await collection.find(filter).toArray());
55+
}
56+
finally {
57+
client.close();
58+
}
59+
}
60+
async upsert(data) {
61+
const client = await this.getClient();
62+
try {
63+
const database = client.db(constants_1.DATABASE_NAME);
64+
const collection = database.collection(this.collectionName);
65+
const existing = await collection.findOne({ id: data.id });
66+
if (!existing) {
67+
await collection.insertOne(data);
68+
}
69+
else {
70+
await collection.updateOne({ id: data.id }, { $set: data });
71+
}
72+
}
73+
finally {
74+
client.close();
75+
}
76+
}
77+
async delete(id) {
78+
const client = await this.getClient();
79+
try {
80+
const database = client.db(constants_1.DATABASE_NAME);
81+
const collection = database.collection(this.collectionName);
82+
await collection.deleteOne({ id });
83+
}
84+
finally {
85+
client.close();
86+
}
87+
}
88+
}
89+
exports.default = Repository;
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
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;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
Object.defineProperty(exports, "__esModule", { value: true });
12+
const type_graphql_1 = require("type-graphql");
13+
let MutationResult = class MutationResult {
14+
};
15+
__decorate([
16+
(0, type_graphql_1.Field)(),
17+
__metadata("design:type", Boolean)
18+
], MutationResult.prototype, "success", void 0);
19+
__decorate([
20+
(0, type_graphql_1.Field)({ nullable: true }),
21+
__metadata("design:type", String)
22+
], MutationResult.prototype, "message", void 0);
23+
MutationResult = __decorate([
24+
(0, type_graphql_1.ObjectType)()
25+
], MutationResult);
26+
exports.default = MutationResult;

0 commit comments

Comments
 (0)