This commit is contained in:
syuilo
2021-12-09 23:58:30 +09:00
parent 0abe2dfee0
commit c69b72e199
573 changed files with 3318 additions and 3318 deletions

View File

@@ -11,7 +11,7 @@ export const meta = {
params: {
limit: {
validator: $.optional.num.range(1, 100),
default: 10
default: 10,
},
sinceId: {
@@ -24,8 +24,8 @@ export const meta = {
my: {
validator: $.optional.bool,
default: false
}
default: false,
},
},
res: {
@@ -38,86 +38,86 @@ export const meta = {
id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
format: 'id',
},
createdAt: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'date-time'
format: 'date-time',
},
startedAt: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'date-time'
format: 'date-time',
},
isStarted: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
optional: false as const, nullable: false as const,
},
isEnded: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
optional: false as const, nullable: false as const,
},
form1: {
type: 'any' as const,
optional: false as const, nullable: true as const
optional: false as const, nullable: true as const,
},
form2: {
type: 'any' as const,
optional: false as const, nullable: true as const
optional: false as const, nullable: true as const,
},
user1Accepted: {
type: 'boolean' as const,
optional: false as const, nullable: false as const,
default: false
default: false,
},
user2Accepted: {
type: 'boolean' as const,
optional: false as const, nullable: false as const,
default: false
default: false,
},
user1Id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
format: 'id',
},
user2Id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
format: 'id',
},
user1: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'User'
ref: 'User',
},
user2: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'User'
ref: 'User',
},
winnerId: {
type: 'string' as const,
optional: false as const, nullable: true as const,
format: 'id'
format: 'id',
},
winner: {
type: 'object' as const,
optional: false as const, nullable: true as const,
ref: 'User'
ref: 'User',
},
surrendered: {
type: 'string' as const,
optional: false as const, nullable: true as const,
format: 'id'
format: 'id',
},
black: {
type: 'number' as const,
optional: false as const, nullable: true as const
optional: false as const, nullable: true as const,
},
bw: {
type: 'string' as const,
optional: false as const, nullable: false as const
optional: false as const, nullable: false as const,
},
isLlotheo: {
type: 'boolean' as const,
@@ -125,15 +125,15 @@ export const meta = {
},
canPutEverywhere: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
optional: false as const, nullable: false as const,
},
loopedBoard: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
}
}
}
}
optional: false as const, nullable: false as const,
},
},
},
},
};
export default define(meta, async (ps, user) => {
@@ -151,6 +151,6 @@ export default define(meta, async (ps, user) => {
const games = await query.take(ps.limit!).getMany();
return await Promise.all(games.map((g) => ReversiGames.pack(g, user, {
detail: false
detail: false,
})));
});

View File

@@ -18,7 +18,7 @@ export const meta = {
noSuchGame: {
message: 'No such game.',
code: 'NO_SUCH_GAME',
id: 'f13a03db-fae1-46c9-87f3-43c8165419e1'
id: 'f13a03db-fae1-46c9-87f3-43c8165419e1',
},
},
@@ -32,86 +32,86 @@ export const meta = {
id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
format: 'id',
},
createdAt: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'date-time'
format: 'date-time',
},
startedAt: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'date-time'
format: 'date-time',
},
isStarted: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
optional: false as const, nullable: false as const,
},
isEnded: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
optional: false as const, nullable: false as const,
},
form1: {
type: 'any' as const,
optional: false as const, nullable: true as const
optional: false as const, nullable: true as const,
},
form2: {
type: 'any' as const,
optional: false as const, nullable: true as const
optional: false as const, nullable: true as const,
},
user1Accepted: {
type: 'boolean' as const,
optional: false as const, nullable: false as const,
default: false
default: false,
},
user2Accepted: {
type: 'boolean' as const,
optional: false as const, nullable: false as const,
default: false
default: false,
},
user1Id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
format: 'id',
},
user2Id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
format: 'id',
},
user1: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'User'
ref: 'User',
},
user2: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'User'
ref: 'User',
},
winnerId: {
type: 'string' as const,
optional: false as const, nullable: true as const,
format: 'id'
format: 'id',
},
winner: {
type: 'object' as const,
optional: false as const, nullable: true as const,
ref: 'User'
ref: 'User',
},
surrendered: {
type: 'string' as const,
optional: false as const, nullable: true as const,
format: 'id'
format: 'id',
},
black: {
type: 'number' as const,
optional: false as const, nullable: true as const
optional: false as const, nullable: true as const,
},
bw: {
type: 'string' as const,
optional: false as const, nullable: false as const
optional: false as const, nullable: false as const,
},
isLlotheo: {
type: 'boolean' as const,
@@ -119,27 +119,27 @@ export const meta = {
},
canPutEverywhere: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
optional: false as const, nullable: false as const,
},
loopedBoard: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
optional: false as const, nullable: false as const,
},
board: {
type: 'array' as const,
optional: false as const, nullable: false as const,
items: {
type: 'any' as const,
optional: false as const, nullable: false as const
}
optional: false as const, nullable: false as const,
},
},
turn: {
type: 'any' as const,
optional: false as const, nullable: false as const
}
}
}
}
optional: false as const, nullable: false as const,
},
},
},
},
};
export default define(meta, async (ps, user) => {
@@ -152,7 +152,7 @@ export default define(meta, async (ps, user) => {
const o = new Reversi(game.map, {
isLlotheo: game.isLlotheo,
canPutEverywhere: game.canPutEverywhere,
loopedBoard: game.loopedBoard
loopedBoard: game.loopedBoard,
});
for (const log of game.logs) {
@@ -163,6 +163,6 @@ export default define(meta, async (ps, user) => {
return Object.assign({
board: o.board,
turn: o.turn
turn: o.turn,
}, packed);
});

View File

@@ -13,28 +13,28 @@ export const meta = {
params: {
gameId: {
validator: $.type(ID),
}
},
},
errors: {
noSuchGame: {
message: 'No such game.',
code: 'NO_SUCH_GAME',
id: 'ace0b11f-e0a6-4076-a30d-e8284c81b2df'
id: 'ace0b11f-e0a6-4076-a30d-e8284c81b2df',
},
alreadyEnded: {
message: 'That game has already ended.',
code: 'ALREADY_ENDED',
id: '6c2ad4a6-cbf1-4a5b-b187-b772826cfc6d'
id: '6c2ad4a6-cbf1-4a5b-b187-b772826cfc6d',
},
accessDenied: {
message: 'Access denied.',
code: 'ACCESS_DENIED',
id: '6e04164b-a992-4c93-8489-2123069973e1'
id: '6e04164b-a992-4c93-8489-2123069973e1',
},
}
},
};
export default define(meta, async (ps, user) => {
@@ -57,11 +57,11 @@ export default define(meta, async (ps, user) => {
await ReversiGames.update(game.id, {
surrendered: user.id,
isEnded: true,
winnerId: winnerId
winnerId: winnerId,
});
publishReversiGameStream(game.id, 'ended', {
winnerId: winnerId,
game: await ReversiGames.pack(game.id, user)
game: await ReversiGames.pack(game.id, user),
});
});

View File

@@ -16,42 +16,42 @@ export const meta = {
id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
format: 'id',
},
createdAt: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'date-time'
format: 'date-time',
},
parentId: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
format: 'id',
},
parent: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'User'
ref: 'User',
},
childId: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
format: 'id',
},
child: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'User'
}
}
}
}
ref: 'User',
},
},
},
},
};
export default define(meta, async (ps, user) => {
// Find session
const invitations = await ReversiMatchings.find({
childId: user.id
childId: user.id,
});
return await Promise.all(invitations.map((i) => ReversiMatchings.pack(i, user)));

View File

@@ -25,15 +25,15 @@ export const meta = {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: '0b4f0559-b484-4e31-9581-3f73cee89b28'
id: '0b4f0559-b484-4e31-9581-3f73cee89b28',
},
isYourself: {
message: 'Target user is yourself.',
code: 'TARGET_IS_YOURSELF',
id: '96fd7bd6-d2bc-426c-a865-d055dcd2828e'
id: '96fd7bd6-d2bc-426c-a865-d055dcd2828e',
},
}
},
};
export default define(meta, async (ps, user) => {
@@ -45,7 +45,7 @@ export default define(meta, async (ps, user) => {
// Find session
const exist = await ReversiMatchings.findOne({
parentId: ps.userId,
childId: user.id
childId: user.id,
});
if (exist) {
@@ -65,13 +65,13 @@ export default define(meta, async (ps, user) => {
logs: [],
map: eighteight.data,
bw: 'random',
isLlotheo: false
isLlotheo: false,
} as Partial<ReversiGame>);
publishReversiStream(exist.parentId, 'matched', await ReversiGames.pack(game, { id: exist.parentId }));
const other = await ReversiMatchings.count({
childId: user.id
childId: user.id,
});
if (other == 0) {
@@ -88,7 +88,7 @@ export default define(meta, async (ps, user) => {
// 以前のセッションはすべて削除しておく
await ReversiMatchings.delete({
parentId: user.id
parentId: user.id,
});
// セッションを作成
@@ -96,7 +96,7 @@ export default define(meta, async (ps, user) => {
id: genId(),
createdAt: new Date(),
parentId: user.id,
childId: child.id
childId: child.id,
} as ReversiMatching);
const packed = await ReversiMatchings.pack(matching, child);

View File

@@ -4,11 +4,11 @@ import { ReversiMatchings } from '@/models/index';
export const meta = {
tags: ['games'],
requireCredential: true as const
requireCredential: true as const,
};
export default define(meta, async (ps, user) => {
await ReversiMatchings.delete({
parentId: user.id
parentId: user.id,
});
});