brackets-prisma-db 2.0.0 → 2.1.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/README.md +47 -4
- package/dist/storage-handlers/insert-handlers/match-game.d.ts +3 -2
- package/dist/storage-handlers/insert-handlers/match-game.js +1 -0
- package/dist/storage-handlers/insert-handlers/match.d.ts +3 -2
- package/dist/storage-handlers/insert-handlers/match.js +1 -0
- package/dist/storage-handlers/insert-handlers/participant.js +6 -2
- package/dist/storage-handlers/select-handlers/group.js +1 -0
- package/dist/storage-handlers/select-handlers/match-game.d.ts +2 -2
- package/dist/storage-handlers/select-handlers/match-game.js +0 -2
- package/dist/storage-handlers/select-handlers/match.d.ts +2 -2
- package/dist/storage-handlers/select-handlers/match.js +0 -1
- package/dist/storage-handlers/update-handlers/match-game.d.ts +2 -2
- package/dist/storage-handlers/update-handlers/match-game.js +39 -23
- package/dist/storage-handlers/update-handlers/match.d.ts +2 -2
- package/dist/storage-handlers/update-handlers/match.js +40 -24
- package/dist/storage-handlers/update-handlers/participant.js +3 -0
- package/dist/transformers/model/match-game.d.ts +18 -18
- package/dist/transformers/model/match-game.js +62 -1
- package/dist/transformers/model/match.d.ts +20 -22
- package/dist/transformers/model/match.js +64 -1
- package/dist/transformers/model/participant.d.ts +4 -0
- package/dist/transformers/model/participant.js +21 -2
- package/dist/types.d.ts +10 -0
- package/dist/types.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,10 +10,10 @@ uses [prisma](https://www.prisma.io/) to store the data in an SQL Database.
|
|
|
10
10
|
|
|
11
11
|
Currently there are some features of the [manager](https://github.com/Drarig29/brackets-manager.js) that can't be used.
|
|
12
12
|
|
|
13
|
-
| **Feature** | **Status**
|
|
14
|
-
| ------------------- |
|
|
15
|
-
| Custom Participants | Implemented
|
|
16
|
-
| Custom Matches |
|
|
13
|
+
| **Feature** | **Status** |
|
|
14
|
+
| ------------------- | ----------- |
|
|
15
|
+
| Custom Participants | Implemented |
|
|
16
|
+
| Custom Matches | Implemented |
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
@@ -40,3 +40,46 @@ const prisma = new PrismaClient();
|
|
|
40
40
|
const storage = new SqlDatabase(prisma);
|
|
41
41
|
const manager = new BracketsManager(storage);
|
|
42
42
|
```
|
|
43
|
+
|
|
44
|
+
Example with custom matches and participants:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { SqlDatabase } from 'brackets-prisma-db'
|
|
48
|
+
import { PrismaClient } from '@prisma/client'
|
|
49
|
+
import { BracketsManager } from 'brackets-manager'
|
|
50
|
+
import type { Match } from 'brackets-model'
|
|
51
|
+
|
|
52
|
+
type MatchWithWeather = Match & {
|
|
53
|
+
extra: {
|
|
54
|
+
weather: 'sunny' | 'rainy' | 'cloudy' | 'snowy'
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const storage = new SqlDatabase(new PrismaClient())
|
|
59
|
+
const manager = new BracketsManager(storage)
|
|
60
|
+
|
|
61
|
+
const stage = await manager.create.stage({
|
|
62
|
+
tournamentId: 1,
|
|
63
|
+
name: 'Example',
|
|
64
|
+
type: 'single_elimination',
|
|
65
|
+
seeding: [
|
|
66
|
+
{ name: 'Team 1', color: 'red' },
|
|
67
|
+
{ name: 'Team 2', color: 'blue' },
|
|
68
|
+
{ name: 'Team 3', color: 'green' },
|
|
69
|
+
{ name: 'Team 4', color: 'yellow' },
|
|
70
|
+
],
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const currentMatches = await manager.get.currentMatches(stage.id)
|
|
74
|
+
|
|
75
|
+
await manager.update.match<MatchWithWeather>({
|
|
76
|
+
id: currentMatches[0].id,
|
|
77
|
+
opponent1: { result: 'win' },
|
|
78
|
+
extra: {
|
|
79
|
+
weather: 'sunny',
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const database = await manager.get.tournamentData(1)
|
|
84
|
+
console.log(database)
|
|
85
|
+
```
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OmitId } from 'brackets-manager/dist/types';
|
|
2
2
|
import { PrismaClient } from '@prisma/client';
|
|
3
|
-
|
|
3
|
+
import type { MatchGameWithExtra } from '../../types';
|
|
4
|
+
export declare function handleMatchGameInsert(prisma: PrismaClient, values: OmitId<MatchGameWithExtra> | OmitId<MatchGameWithExtra>[]): Promise<number> | Promise<boolean>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OmitId } from 'brackets-manager/dist/types';
|
|
2
2
|
import { PrismaClient } from '@prisma/client';
|
|
3
|
-
|
|
3
|
+
import type { MatchWithExtra } from '../../types';
|
|
4
|
+
export declare function handleMatchInsert(prisma: PrismaClient, values: OmitId<MatchWithExtra> | OmitId<MatchWithExtra>[]): Promise<number> | Promise<boolean>;
|
|
@@ -6,14 +6,18 @@ function handleParticipantInsert(prisma, values) {
|
|
|
6
6
|
if (Array.isArray(values)) {
|
|
7
7
|
return prisma.participant
|
|
8
8
|
.createMany({
|
|
9
|
-
data: values.map(
|
|
9
|
+
data: values.map(p => {
|
|
10
|
+
const value = transformers_1.ParticipantTransformer.to(p);
|
|
11
|
+
return { ...value, extra: value.extra ?? undefined };
|
|
12
|
+
}),
|
|
10
13
|
})
|
|
11
14
|
.then(() => true)
|
|
12
15
|
.catch(() => false);
|
|
13
16
|
}
|
|
17
|
+
const value = transformers_1.ParticipantTransformer.to(values);
|
|
14
18
|
return prisma.participant
|
|
15
19
|
.create({
|
|
16
|
-
data:
|
|
20
|
+
data: { ...value, extra: value.extra ?? undefined },
|
|
17
21
|
})
|
|
18
22
|
.then((v) => v.id)
|
|
19
23
|
.catch(() => -1);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handleGroupSelect = void 0;
|
|
4
|
+
// @ts-ignore
|
|
4
5
|
const transformers_1 = require("../../transformers");
|
|
5
6
|
async function handleGroupSelect(prisma, filter) {
|
|
6
7
|
if (filter === undefined) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from 'brackets-manager/dist/types';
|
|
2
1
|
import { PrismaClient } from '@prisma/client';
|
|
3
|
-
|
|
2
|
+
import type { MatchGameWithExtra } from '../../types';
|
|
3
|
+
export declare function handleMatchGameSelect(prisma: PrismaClient, filter?: Partial<MatchGameWithExtra> | number): Promise<MatchGameWithExtra[] | MatchGameWithExtra | null>;
|
|
@@ -4,7 +4,6 @@ exports.handleMatchGameSelect = void 0;
|
|
|
4
4
|
const transformers_1 = require("../../transformers");
|
|
5
5
|
async function handleMatchGameSelect(prisma, filter) {
|
|
6
6
|
if (filter === undefined) {
|
|
7
|
-
// Query all entries of table
|
|
8
7
|
return prisma.matchGame
|
|
9
8
|
.findMany({
|
|
10
9
|
include: {
|
|
@@ -17,7 +16,6 @@ async function handleMatchGameSelect(prisma, filter) {
|
|
|
17
16
|
.catch(() => []);
|
|
18
17
|
}
|
|
19
18
|
if (typeof filter === 'number') {
|
|
20
|
-
// Find by Id
|
|
21
19
|
return prisma.matchGame
|
|
22
20
|
.findFirst({
|
|
23
21
|
where: { id: filter },
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from 'brackets-manager/dist/types';
|
|
2
1
|
import { PrismaClient } from '@prisma/client';
|
|
3
|
-
|
|
2
|
+
import type { MatchWithExtra } from '../../types';
|
|
3
|
+
export declare function handleMatchSelect(prisma: PrismaClient, filter?: Partial<MatchWithExtra> | number): Promise<MatchWithExtra[] | MatchWithExtra | null>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from 'brackets-manager/dist/types';
|
|
2
1
|
import { PrismaClient } from '@prisma/client';
|
|
3
|
-
|
|
2
|
+
import type { MatchGameWithExtra } from '../../types';
|
|
3
|
+
export declare function handleMatchGameUpdate(prisma: PrismaClient, filter: Partial<MatchGameWithExtra> | number, value: Partial<MatchGameWithExtra> | MatchGameWithExtra): Promise<boolean>;
|
|
@@ -26,7 +26,9 @@ function getParticipantResultUpsertData(value) {
|
|
|
26
26
|
},
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
function getUpdateData(value) {
|
|
29
|
+
function getUpdateData(value, previousExtra) {
|
|
30
|
+
const extrasInput = value;
|
|
31
|
+
const extra = (0, transformers_1.matchGameExtraFromInput)(extrasInput, previousExtra);
|
|
30
32
|
return {
|
|
31
33
|
stageId: value.stage_id,
|
|
32
34
|
matchId: value.parent_id,
|
|
@@ -40,39 +42,53 @@ function getUpdateData(value) {
|
|
|
40
42
|
opponent2Result: value.opponent2
|
|
41
43
|
? getParticipantResultUpsertData(value.opponent2)
|
|
42
44
|
: undefined,
|
|
45
|
+
extra: extra ?? undefined
|
|
43
46
|
};
|
|
44
47
|
}
|
|
45
|
-
function updateById(prisma, id, value) {
|
|
48
|
+
async function updateById(prisma, id, value, previousExtra) {
|
|
49
|
+
let extraSource = previousExtra ?? null;
|
|
50
|
+
if (previousExtra === undefined) {
|
|
51
|
+
const existing = await prisma.matchGame.findUnique({
|
|
52
|
+
where: { id },
|
|
53
|
+
select: { extra: true },
|
|
54
|
+
});
|
|
55
|
+
extraSource = existing?.extra ?? null;
|
|
56
|
+
}
|
|
46
57
|
return prisma.matchGame.update({
|
|
47
58
|
where: {
|
|
48
59
|
id,
|
|
49
60
|
},
|
|
50
|
-
data: getUpdateData(value),
|
|
61
|
+
data: getUpdateData(value, extraSource),
|
|
51
62
|
});
|
|
52
63
|
}
|
|
53
64
|
async function handleMatchGameUpdate(prisma, filter, value) {
|
|
54
65
|
if (typeof filter === 'number') {
|
|
55
66
|
// Update by Id
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
try {
|
|
68
|
+
await updateById(prisma, filter, value);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const games = await prisma.matchGame.findMany({
|
|
77
|
+
where: {
|
|
78
|
+
id: filter.id,
|
|
79
|
+
number: filter.number,
|
|
80
|
+
stageId: filter.stage_id,
|
|
81
|
+
matchId: filter.parent_id,
|
|
82
|
+
status: filter.status
|
|
83
|
+
? transformers_1.MatchStatusTransformer.to(filter.status)
|
|
84
|
+
: undefined,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
await Promise.all(games.map((game) => updateById(prisma, game.id, value, game.extra ?? null)));
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return false;
|
|
59
92
|
}
|
|
60
|
-
return prisma.matchGame
|
|
61
|
-
.findMany({
|
|
62
|
-
where: {
|
|
63
|
-
id: filter.id,
|
|
64
|
-
number: filter.number,
|
|
65
|
-
stageId: filter.stage_id,
|
|
66
|
-
matchId: filter.parent_id,
|
|
67
|
-
status: filter.status
|
|
68
|
-
? transformers_1.MatchStatusTransformer.to(filter.status)
|
|
69
|
-
: undefined,
|
|
70
|
-
},
|
|
71
|
-
})
|
|
72
|
-
.then((games) => {
|
|
73
|
-
return Promise.all(games.map((game) => updateById(prisma, game.id, value)));
|
|
74
|
-
})
|
|
75
|
-
.then(() => true)
|
|
76
|
-
.catch(() => false);
|
|
77
93
|
}
|
|
78
94
|
exports.handleMatchGameUpdate = handleMatchGameUpdate;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from 'brackets-manager/dist/types';
|
|
2
1
|
import { PrismaClient } from '@prisma/client';
|
|
3
|
-
|
|
2
|
+
import type { MatchWithExtra } from '../../types';
|
|
3
|
+
export declare function handleMatchUpdate(prisma: PrismaClient, filter: Partial<MatchWithExtra> | number, value: Partial<MatchWithExtra> | MatchWithExtra): Promise<boolean>;
|
|
@@ -26,7 +26,9 @@ function getParticipantResultUpsertData(value) {
|
|
|
26
26
|
},
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
function getUpdateData(value) {
|
|
29
|
+
function getUpdateData(value, previousExtra) {
|
|
30
|
+
const extrasInput = value;
|
|
31
|
+
const extra = (0, transformers_1.matchExtraFromInput)(extrasInput, previousExtra);
|
|
30
32
|
return {
|
|
31
33
|
stageId: value.stage_id,
|
|
32
34
|
groupId: value.group_id,
|
|
@@ -42,40 +44,54 @@ function getUpdateData(value) {
|
|
|
42
44
|
opponent2Result: value.opponent2
|
|
43
45
|
? getParticipantResultUpsertData(value.opponent2)
|
|
44
46
|
: undefined,
|
|
47
|
+
extra: extra ?? undefined,
|
|
45
48
|
};
|
|
46
49
|
}
|
|
47
|
-
function updateById(prisma, id, value) {
|
|
50
|
+
async function updateById(prisma, id, value, previousExtra) {
|
|
51
|
+
let extraSource = previousExtra ?? null;
|
|
52
|
+
if (previousExtra === undefined) {
|
|
53
|
+
const existing = await prisma.match.findUnique({
|
|
54
|
+
where: { id },
|
|
55
|
+
select: { extra: true },
|
|
56
|
+
});
|
|
57
|
+
extraSource = existing?.extra ?? null;
|
|
58
|
+
}
|
|
48
59
|
return prisma.match.update({
|
|
49
60
|
where: {
|
|
50
61
|
id,
|
|
51
62
|
},
|
|
52
|
-
data: getUpdateData(value),
|
|
63
|
+
data: getUpdateData(value, extraSource),
|
|
53
64
|
});
|
|
54
65
|
}
|
|
55
66
|
async function handleMatchUpdate(prisma, filter, value) {
|
|
56
67
|
if (typeof filter === 'number') {
|
|
57
68
|
// Update by Id
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
try {
|
|
70
|
+
await updateById(prisma, filter, value);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const matches = await prisma.match.findMany({
|
|
79
|
+
where: {
|
|
80
|
+
id: filter.id,
|
|
81
|
+
number: filter.number,
|
|
82
|
+
stageId: filter.stage_id,
|
|
83
|
+
groupId: filter.group_id,
|
|
84
|
+
roundId: filter.round_id,
|
|
85
|
+
status: filter.status
|
|
86
|
+
? transformers_1.MatchStatusTransformer.to(filter.status)
|
|
87
|
+
: undefined,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
await Promise.all(matches.map((match) => updateById(prisma, match.id, value, match.extra ?? null)));
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return false;
|
|
61
95
|
}
|
|
62
|
-
return prisma.match
|
|
63
|
-
.findMany({
|
|
64
|
-
where: {
|
|
65
|
-
id: filter.id,
|
|
66
|
-
number: filter.number,
|
|
67
|
-
stageId: filter.stage_id,
|
|
68
|
-
groupId: filter.group_id,
|
|
69
|
-
roundId: filter.round_id,
|
|
70
|
-
status: filter.status
|
|
71
|
-
? transformers_1.MatchStatusTransformer.to(filter.status)
|
|
72
|
-
: undefined,
|
|
73
|
-
},
|
|
74
|
-
})
|
|
75
|
-
.then((matches) => {
|
|
76
|
-
return Promise.all(matches.map((match) => updateById(prisma, match.id, value)));
|
|
77
|
-
})
|
|
78
|
-
.then(() => true)
|
|
79
|
-
.catch(() => false);
|
|
80
96
|
}
|
|
81
97
|
exports.handleMatchUpdate = handleMatchUpdate;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handleParticipantUpdate = void 0;
|
|
4
|
+
const transformers_1 = require("../../transformers");
|
|
4
5
|
async function handleParticipantUpdate(prisma, filter, value) {
|
|
5
6
|
if (typeof filter === 'number') {
|
|
6
7
|
// Update by Id
|
|
@@ -12,6 +13,7 @@ async function handleParticipantUpdate(prisma, filter, value) {
|
|
|
12
13
|
data: {
|
|
13
14
|
name: value.name,
|
|
14
15
|
tournamentId: value.tournament_id,
|
|
16
|
+
extra: (0, transformers_1.participantExtraFromInput)(value) ?? undefined,
|
|
15
17
|
},
|
|
16
18
|
})
|
|
17
19
|
.then(() => true)
|
|
@@ -28,6 +30,7 @@ async function handleParticipantUpdate(prisma, filter, value) {
|
|
|
28
30
|
data: {
|
|
29
31
|
name: value.name,
|
|
30
32
|
tournamentId: value.tournament_id,
|
|
33
|
+
extra: (0, transformers_1.participantExtraFromInput)(value) ?? undefined,
|
|
31
34
|
},
|
|
32
35
|
})
|
|
33
36
|
.then(() => true)
|
|
@@ -1,28 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { MatchGame } from 'brackets-model';
|
|
1
|
+
import { Prisma, MatchGame as PrismaMatchGame, ParticipantMatchGameResult as PrismaParticipantMatchGameResult } from '@prisma/client';
|
|
3
2
|
import { OmitId } from 'brackets-manager';
|
|
3
|
+
import type { MatchGameExtrasInput, MatchGameWithExtra } from '../../types';
|
|
4
|
+
type PrismaMatchGameWithRelations = PrismaMatchGame & {
|
|
5
|
+
opponent1Result: PrismaParticipantMatchGameResult | null;
|
|
6
|
+
opponent2Result: PrismaParticipantMatchGameResult | null;
|
|
7
|
+
extra: Prisma.JsonValue | null;
|
|
8
|
+
};
|
|
9
|
+
export declare function matchGameExtraFromInput(input: MatchGameExtrasInput, previousExtra?: Prisma.JsonValue | null): Prisma.JsonValue | null | undefined;
|
|
4
10
|
export declare const MatchGameTransformer: {
|
|
5
|
-
to(input: Omit<OmitId<
|
|
11
|
+
to(input: Omit<OmitId<MatchGameWithExtra>, 'opponent1' | 'opponent2'>): {
|
|
12
|
+
extra?: Prisma.JsonValue | undefined;
|
|
6
13
|
status: "LOCKED" | "WAITING" | "READY" | "RUNNING" | "COMPLETED" | "ARCHIVED";
|
|
7
14
|
stageId: number;
|
|
8
15
|
matchId: number;
|
|
9
16
|
number: number;
|
|
10
17
|
};
|
|
11
|
-
from(output: {
|
|
12
|
-
|
|
13
|
-
id: number;
|
|
14
|
-
status: Prisma.$Enums.MatchStatus;
|
|
15
|
-
stageId: number;
|
|
16
|
-
matchId: number;
|
|
17
|
-
} & {
|
|
18
|
-
opponent1Result: Prisma.ParticipantMatchGameResult | null;
|
|
19
|
-
opponent2Result: Prisma.ParticipantMatchGameResult | null;
|
|
20
|
-
}): {
|
|
21
|
-
id: number;
|
|
22
|
-
status: import("brackets-model").Status;
|
|
23
|
-
stage_id: number;
|
|
24
|
-
parent_id: number;
|
|
25
|
-
number: number;
|
|
18
|
+
from(output: PrismaMatchGameWithRelations): {
|
|
19
|
+
extra: string | number | boolean | Prisma.JsonObject | Prisma.JsonArray | undefined;
|
|
26
20
|
opponent1: {
|
|
27
21
|
id: number | null;
|
|
28
22
|
forfeit: boolean | undefined;
|
|
@@ -37,5 +31,11 @@ export declare const MatchGameTransformer: {
|
|
|
37
31
|
score: number | undefined;
|
|
38
32
|
result: "win" | "draw" | "loss" | undefined;
|
|
39
33
|
} | null;
|
|
34
|
+
id: number;
|
|
35
|
+
status: import("brackets-model").Status;
|
|
36
|
+
stage_id: number;
|
|
37
|
+
parent_id: number;
|
|
38
|
+
number: number;
|
|
40
39
|
};
|
|
41
40
|
};
|
|
41
|
+
export {};
|
|
@@ -1,23 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MatchGameTransformer = void 0;
|
|
3
|
+
exports.MatchGameTransformer = exports.matchGameExtraFromInput = void 0;
|
|
4
4
|
const __1 = require("..");
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function getMatchGameExtras(input) {
|
|
9
|
+
const clone = { ...input };
|
|
10
|
+
delete clone.id;
|
|
11
|
+
delete clone.status;
|
|
12
|
+
delete clone.stage_id;
|
|
13
|
+
delete clone.parent_id;
|
|
14
|
+
delete clone.number;
|
|
15
|
+
delete clone.opponent1;
|
|
16
|
+
delete clone.opponent2;
|
|
17
|
+
delete clone.extra;
|
|
18
|
+
return Object.entries(clone).reduce((extras, [key, value]) => {
|
|
19
|
+
if (value !== undefined) {
|
|
20
|
+
extras[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return extras;
|
|
23
|
+
}, {});
|
|
24
|
+
}
|
|
25
|
+
function normalizeMatchGameExtras(extra) {
|
|
26
|
+
if (!isRecord(extra)) {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
return extra;
|
|
30
|
+
}
|
|
31
|
+
function hasOwnExtraProperty(input) {
|
|
32
|
+
return Object.prototype.hasOwnProperty.call(input, 'extra');
|
|
33
|
+
}
|
|
34
|
+
function matchGameExtraFromInput(input, previousExtra) {
|
|
35
|
+
const customFields = getMatchGameExtras(input);
|
|
36
|
+
const hasCustomFields = Object.keys(customFields).length > 0;
|
|
37
|
+
if (hasOwnExtraProperty(input)) {
|
|
38
|
+
const providedExtra = input.extra;
|
|
39
|
+
if (providedExtra === undefined) {
|
|
40
|
+
return hasCustomFields ? customFields : undefined;
|
|
41
|
+
}
|
|
42
|
+
if (isRecord(providedExtra)) {
|
|
43
|
+
const normalized = providedExtra;
|
|
44
|
+
return hasCustomFields
|
|
45
|
+
? { ...normalized, ...customFields }
|
|
46
|
+
: normalized;
|
|
47
|
+
}
|
|
48
|
+
return providedExtra ?? null;
|
|
49
|
+
}
|
|
50
|
+
if (!hasCustomFields) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
if (isRecord(previousExtra)) {
|
|
54
|
+
const normalized = previousExtra;
|
|
55
|
+
return { ...normalized, ...customFields };
|
|
56
|
+
}
|
|
57
|
+
return customFields;
|
|
58
|
+
}
|
|
59
|
+
exports.matchGameExtraFromInput = matchGameExtraFromInput;
|
|
5
60
|
exports.MatchGameTransformer = {
|
|
6
61
|
to(input) {
|
|
62
|
+
const extrasInput = input;
|
|
63
|
+
const extra = matchGameExtraFromInput(extrasInput);
|
|
7
64
|
return {
|
|
8
65
|
status: __1.MatchStatusTransformer.to(input.status),
|
|
9
66
|
stageId: input.stage_id,
|
|
10
67
|
matchId: input.parent_id,
|
|
11
68
|
number: input.number,
|
|
69
|
+
...(extra !== undefined ? { extra } : {}),
|
|
12
70
|
};
|
|
13
71
|
},
|
|
14
72
|
from(output) {
|
|
73
|
+
const normalizedExtras = normalizeMatchGameExtras(output.extra);
|
|
15
74
|
return {
|
|
16
75
|
id: output.id,
|
|
17
76
|
status: __1.MatchStatusTransformer.from(output.status),
|
|
18
77
|
stage_id: output.stageId,
|
|
19
78
|
parent_id: output.matchId,
|
|
20
79
|
number: output.number,
|
|
80
|
+
...normalizedExtras,
|
|
81
|
+
extra: output.extra ?? undefined,
|
|
21
82
|
opponent1: output.opponent1Result
|
|
22
83
|
? __1.ParticipantMatchResultTransformer.from(output.opponent1Result)
|
|
23
84
|
: null,
|
|
@@ -1,34 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Match } from 'brackets-model';
|
|
1
|
+
import type { Match as PrismaMatch, ParticipantMatchResult as PrismaParticipantMatchResult, Prisma } from '@prisma/client';
|
|
3
2
|
import { OmitId } from 'brackets-manager';
|
|
3
|
+
import type { MatchExtrasInput, MatchWithExtra } from '../../types';
|
|
4
|
+
type PrismaMatchWithRelations = PrismaMatch & {
|
|
5
|
+
opponent1Result: PrismaParticipantMatchResult | null;
|
|
6
|
+
opponent2Result: PrismaParticipantMatchResult | null;
|
|
7
|
+
extra: Prisma.JsonValue | null;
|
|
8
|
+
};
|
|
9
|
+
export declare function matchExtraFromInput(input: MatchExtrasInput, previousExtra?: Prisma.JsonValue | null): Prisma.JsonValue | null | undefined;
|
|
4
10
|
export declare const MatchTransformer: {
|
|
5
|
-
to(input: Omit<OmitId<
|
|
11
|
+
to(input: Omit<OmitId<MatchWithExtra>, 'opponent1' | 'opponent2'>): {
|
|
6
12
|
status: "LOCKED" | "WAITING" | "READY" | "RUNNING" | "COMPLETED" | "ARCHIVED";
|
|
7
13
|
stageId: number;
|
|
8
14
|
groupId: number;
|
|
9
15
|
roundId: number;
|
|
10
16
|
number: number;
|
|
11
17
|
childCount: number;
|
|
18
|
+
extra: string | number | boolean | Prisma.JsonObject | Prisma.JsonArray | null;
|
|
12
19
|
};
|
|
13
|
-
from(output: {
|
|
14
|
-
|
|
15
|
-
id: number;
|
|
16
|
-
status: Prisma.$Enums.MatchStatus;
|
|
17
|
-
stageId: number;
|
|
18
|
-
groupId: number;
|
|
19
|
-
roundId: number;
|
|
20
|
-
childCount: number;
|
|
21
|
-
} & {
|
|
22
|
-
opponent1Result: Prisma.ParticipantMatchResult | null;
|
|
23
|
-
opponent2Result: Prisma.ParticipantMatchResult | null;
|
|
24
|
-
}): {
|
|
25
|
-
id: number;
|
|
26
|
-
status: import("brackets-model").Status;
|
|
27
|
-
stage_id: number;
|
|
28
|
-
group_id: number;
|
|
29
|
-
round_id: number;
|
|
30
|
-
number: number;
|
|
31
|
-
child_count: number;
|
|
20
|
+
from(output: PrismaMatchWithRelations): {
|
|
21
|
+
extra: string | number | boolean | Prisma.JsonObject | Prisma.JsonArray | undefined;
|
|
32
22
|
opponent1: {
|
|
33
23
|
id: number | null;
|
|
34
24
|
forfeit: boolean | undefined;
|
|
@@ -43,5 +33,13 @@ export declare const MatchTransformer: {
|
|
|
43
33
|
score: number | undefined;
|
|
44
34
|
result: "win" | "draw" | "loss" | undefined;
|
|
45
35
|
} | null;
|
|
36
|
+
id: number;
|
|
37
|
+
status: import("brackets-model").Status;
|
|
38
|
+
stage_id: number;
|
|
39
|
+
group_id: number;
|
|
40
|
+
round_id: number;
|
|
41
|
+
number: number;
|
|
42
|
+
child_count: number;
|
|
46
43
|
};
|
|
47
44
|
};
|
|
45
|
+
export {};
|
|
@@ -1,9 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MatchTransformer = void 0;
|
|
3
|
+
exports.MatchTransformer = exports.matchExtraFromInput = void 0;
|
|
4
4
|
const __1 = require("..");
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function getMatchExtras(input) {
|
|
9
|
+
const clone = { ...input };
|
|
10
|
+
delete clone.id;
|
|
11
|
+
delete clone.status;
|
|
12
|
+
delete clone.stage_id;
|
|
13
|
+
delete clone.group_id;
|
|
14
|
+
delete clone.round_id;
|
|
15
|
+
delete clone.number;
|
|
16
|
+
delete clone.child_count;
|
|
17
|
+
delete clone.opponent1;
|
|
18
|
+
delete clone.opponent2;
|
|
19
|
+
delete clone.extra;
|
|
20
|
+
return Object.entries(clone).reduce((extras, [key, value]) => {
|
|
21
|
+
if (value !== undefined) {
|
|
22
|
+
extras[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return extras;
|
|
25
|
+
}, {});
|
|
26
|
+
}
|
|
27
|
+
function normalizeMatchExtras(extra) {
|
|
28
|
+
if (!isRecord(extra)) {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
return extra;
|
|
32
|
+
}
|
|
33
|
+
function hasOwnExtraProperty(input) {
|
|
34
|
+
return Object.prototype.hasOwnProperty.call(input, 'extra');
|
|
35
|
+
}
|
|
36
|
+
function matchExtraFromInput(input, previousExtra) {
|
|
37
|
+
const customFields = getMatchExtras(input);
|
|
38
|
+
const hasCustomFields = Object.keys(customFields).length > 0;
|
|
39
|
+
if (hasOwnExtraProperty(input)) {
|
|
40
|
+
const providedExtra = input.extra;
|
|
41
|
+
if (providedExtra === undefined) {
|
|
42
|
+
return hasCustomFields ? customFields : undefined;
|
|
43
|
+
}
|
|
44
|
+
if (isRecord(providedExtra)) {
|
|
45
|
+
const normalized = providedExtra;
|
|
46
|
+
return hasCustomFields
|
|
47
|
+
? { ...normalized, ...customFields }
|
|
48
|
+
: normalized;
|
|
49
|
+
}
|
|
50
|
+
return providedExtra ?? null;
|
|
51
|
+
}
|
|
52
|
+
if (!hasCustomFields) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
if (isRecord(previousExtra)) {
|
|
56
|
+
const normalized = previousExtra;
|
|
57
|
+
return { ...normalized, ...customFields };
|
|
58
|
+
}
|
|
59
|
+
return customFields;
|
|
60
|
+
}
|
|
61
|
+
exports.matchExtraFromInput = matchExtraFromInput;
|
|
5
62
|
exports.MatchTransformer = {
|
|
6
63
|
to(input) {
|
|
64
|
+
const extrasInput = input;
|
|
65
|
+
const extra = matchExtraFromInput(extrasInput);
|
|
7
66
|
return {
|
|
8
67
|
status: __1.MatchStatusTransformer.to(input.status),
|
|
9
68
|
stageId: input.stage_id,
|
|
@@ -11,9 +70,11 @@ exports.MatchTransformer = {
|
|
|
11
70
|
roundId: input.round_id,
|
|
12
71
|
number: input.number,
|
|
13
72
|
childCount: input.child_count,
|
|
73
|
+
extra: extra ?? null,
|
|
14
74
|
};
|
|
15
75
|
},
|
|
16
76
|
from(output) {
|
|
77
|
+
const normalizedExtras = normalizeMatchExtras(output.extra);
|
|
17
78
|
return {
|
|
18
79
|
id: output.id,
|
|
19
80
|
status: __1.MatchStatusTransformer.from(output.status),
|
|
@@ -22,6 +83,8 @@ exports.MatchTransformer = {
|
|
|
22
83
|
round_id: output.roundId,
|
|
23
84
|
number: output.number,
|
|
24
85
|
child_count: output.childCount,
|
|
86
|
+
...normalizedExtras,
|
|
87
|
+
extra: output.extra ?? undefined,
|
|
25
88
|
opponent1: output.opponent1Result
|
|
26
89
|
? __1.ParticipantMatchResultTransformer.from(output.opponent1Result)
|
|
27
90
|
: null,
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import { Prisma } from '@prisma/client';
|
|
1
2
|
import { Participant } from 'brackets-model';
|
|
2
3
|
import { OmitId } from 'brackets-manager';
|
|
4
|
+
export declare function participantExtraFromInput(input: Partial<Participant> & Record<string, unknown>): Prisma.JsonValue | null;
|
|
3
5
|
export declare const ParticipantTransformer: {
|
|
4
6
|
to(input: OmitId<Participant>): {
|
|
5
7
|
name: string;
|
|
6
8
|
tournamentId: number;
|
|
9
|
+
extra: Prisma.JsonValue;
|
|
7
10
|
};
|
|
8
11
|
from(output: {
|
|
9
12
|
id: number;
|
|
10
13
|
name: string;
|
|
11
14
|
tournamentId: number;
|
|
15
|
+
extra: Prisma.JsonValue;
|
|
12
16
|
}): {
|
|
13
17
|
id: number;
|
|
14
18
|
name: string;
|
|
@@ -1,21 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ParticipantTransformer = void 0;
|
|
3
|
+
exports.ParticipantTransformer = exports.participantExtraFromInput = void 0;
|
|
4
4
|
function getParticipantExtras(input) {
|
|
5
5
|
const clone = { ...input };
|
|
6
6
|
// Delete Participant fields
|
|
7
7
|
delete clone.id;
|
|
8
8
|
delete clone.name;
|
|
9
9
|
delete clone.tournament_id;
|
|
10
|
+
delete clone.extra;
|
|
10
11
|
// Return Extras
|
|
11
12
|
return clone;
|
|
12
13
|
}
|
|
14
|
+
function getParticipantExtraValue(input) {
|
|
15
|
+
const extra = getParticipantExtras(input);
|
|
16
|
+
return Object.keys(extra).length > 0 ? extra : null;
|
|
17
|
+
}
|
|
18
|
+
function isRecord(value) {
|
|
19
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
function normalizeParticipantExtras(extra) {
|
|
22
|
+
if (!isRecord(extra)) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
return extra;
|
|
26
|
+
}
|
|
27
|
+
function participantExtraFromInput(input) {
|
|
28
|
+
return getParticipantExtraValue(input);
|
|
29
|
+
}
|
|
30
|
+
exports.participantExtraFromInput = participantExtraFromInput;
|
|
13
31
|
exports.ParticipantTransformer = {
|
|
14
32
|
to(input) {
|
|
15
33
|
return {
|
|
16
34
|
name: input.name,
|
|
17
35
|
tournamentId: input.tournament_id,
|
|
18
|
-
|
|
36
|
+
extra: getParticipantExtraValue(input),
|
|
19
37
|
};
|
|
20
38
|
},
|
|
21
39
|
from(output) {
|
|
@@ -23,6 +41,7 @@ exports.ParticipantTransformer = {
|
|
|
23
41
|
id: output.id,
|
|
24
42
|
name: output.name,
|
|
25
43
|
tournament_id: output.tournamentId,
|
|
44
|
+
...normalizeParticipantExtras(output.extra),
|
|
26
45
|
};
|
|
27
46
|
},
|
|
28
47
|
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DataTypes } from 'brackets-manager/dist/types';
|
|
2
|
+
import { Prisma } from '@prisma/client';
|
|
3
|
+
export type MatchWithExtra = DataTypes['match'] & {
|
|
4
|
+
extra?: Prisma.JsonValue | null;
|
|
5
|
+
};
|
|
6
|
+
export type MatchExtrasInput = Partial<MatchWithExtra> & Record<string, unknown>;
|
|
7
|
+
export type MatchGameWithExtra = DataTypes['match_game'] & {
|
|
8
|
+
extra?: Prisma.JsonValue | null;
|
|
9
|
+
};
|
|
10
|
+
export type MatchGameExtrasInput = Partial<MatchGameWithExtra> & Record<string, unknown>;
|
package/dist/types.js
ADDED