brackets-drizzle-db 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.
Files changed (139) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +136 -0
  3. package/dist/db/index.d.ts +7 -0
  4. package/dist/db/index.js +48 -0
  5. package/dist/db/schema/enums.d.ts +12 -0
  6. package/dist/db/schema/enums.js +41 -0
  7. package/dist/db/schema/group.d.ts +65 -0
  8. package/dist/db/schema/group.js +26 -0
  9. package/dist/db/schema/index.d.ts +8 -0
  10. package/dist/db/schema/index.js +26 -0
  11. package/dist/db/schema/match-game.d.ts +267 -0
  12. package/dist/db/schema/match-game.js +81 -0
  13. package/dist/db/schema/match.d.ts +303 -0
  14. package/dist/db/schema/match.js +94 -0
  15. package/dist/db/schema/participant.d.ts +82 -0
  16. package/dist/db/schema/participant.js +27 -0
  17. package/dist/db/schema/round.d.ts +82 -0
  18. package/dist/db/schema/round.js +33 -0
  19. package/dist/db/schema/stage.d.ts +344 -0
  20. package/dist/db/schema/stage.js +72 -0
  21. package/dist/db/schema/tournament.d.ts +115 -0
  22. package/dist/db/schema/tournament.js +25 -0
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.js +19 -0
  25. package/dist/storage-handlers/delete-handlers/group.d.ts +3 -0
  26. package/dist/storage-handlers/delete-handlers/group.js +27 -0
  27. package/dist/storage-handlers/delete-handlers/index.d.ts +7 -0
  28. package/dist/storage-handlers/delete-handlers/index.js +23 -0
  29. package/dist/storage-handlers/delete-handlers/match-game.d.ts +3 -0
  30. package/dist/storage-handlers/delete-handlers/match-game.js +43 -0
  31. package/dist/storage-handlers/delete-handlers/match.d.ts +3 -0
  32. package/dist/storage-handlers/delete-handlers/match.js +45 -0
  33. package/dist/storage-handlers/delete-handlers/participant.d.ts +3 -0
  34. package/dist/storage-handlers/delete-handlers/participant.js +27 -0
  35. package/dist/storage-handlers/delete-handlers/round.d.ts +3 -0
  36. package/dist/storage-handlers/delete-handlers/round.js +29 -0
  37. package/dist/storage-handlers/delete-handlers/stage.d.ts +3 -0
  38. package/dist/storage-handlers/delete-handlers/stage.js +48 -0
  39. package/dist/storage-handlers/delete-handlers/tournament.d.ts +3 -0
  40. package/dist/storage-handlers/delete-handlers/tournament.js +25 -0
  41. package/dist/storage-handlers/delete.d.ts +3 -0
  42. package/dist/storage-handlers/delete.js +24 -0
  43. package/dist/storage-handlers/index.d.ts +4 -0
  44. package/dist/storage-handlers/index.js +20 -0
  45. package/dist/storage-handlers/insert-handlers/group.d.ts +5 -0
  46. package/dist/storage-handlers/insert-handlers/group.js +21 -0
  47. package/dist/storage-handlers/insert-handlers/index.d.ts +7 -0
  48. package/dist/storage-handlers/insert-handlers/index.js +23 -0
  49. package/dist/storage-handlers/insert-handlers/match-game.d.ts +5 -0
  50. package/dist/storage-handlers/insert-handlers/match-game.js +66 -0
  51. package/dist/storage-handlers/insert-handlers/match.d.ts +5 -0
  52. package/dist/storage-handlers/insert-handlers/match.js +66 -0
  53. package/dist/storage-handlers/insert-handlers/participant.d.ts +5 -0
  54. package/dist/storage-handlers/insert-handlers/participant.js +25 -0
  55. package/dist/storage-handlers/insert-handlers/round.d.ts +5 -0
  56. package/dist/storage-handlers/insert-handlers/round.js +21 -0
  57. package/dist/storage-handlers/insert-handlers/stage.d.ts +5 -0
  58. package/dist/storage-handlers/insert-handlers/stage.js +44 -0
  59. package/dist/storage-handlers/insert-handlers/tournament.d.ts +5 -0
  60. package/dist/storage-handlers/insert-handlers/tournament.js +25 -0
  61. package/dist/storage-handlers/insert.d.ts +3 -0
  62. package/dist/storage-handlers/insert.js +25 -0
  63. package/dist/storage-handlers/select-handlers/group.d.ts +3 -0
  64. package/dist/storage-handlers/select-handlers/group.js +44 -0
  65. package/dist/storage-handlers/select-handlers/index.d.ts +7 -0
  66. package/dist/storage-handlers/select-handlers/index.js +23 -0
  67. package/dist/storage-handlers/select-handlers/match-game.d.ts +3 -0
  68. package/dist/storage-handlers/select-handlers/match-game.js +80 -0
  69. package/dist/storage-handlers/select-handlers/match.d.ts +3 -0
  70. package/dist/storage-handlers/select-handlers/match.js +86 -0
  71. package/dist/storage-handlers/select-handlers/participant.d.ts +3 -0
  72. package/dist/storage-handlers/select-handlers/participant.js +40 -0
  73. package/dist/storage-handlers/select-handlers/round.d.ts +3 -0
  74. package/dist/storage-handlers/select-handlers/round.js +46 -0
  75. package/dist/storage-handlers/select-handlers/stage.d.ts +3 -0
  76. package/dist/storage-handlers/select-handlers/stage.js +60 -0
  77. package/dist/storage-handlers/select-handlers/tournament.d.ts +3 -0
  78. package/dist/storage-handlers/select-handlers/tournament.js +38 -0
  79. package/dist/storage-handlers/select.d.ts +3 -0
  80. package/dist/storage-handlers/select.js +24 -0
  81. package/dist/storage-handlers/update-handlers/group.d.ts +3 -0
  82. package/dist/storage-handlers/update-handlers/group.js +33 -0
  83. package/dist/storage-handlers/update-handlers/index.d.ts +7 -0
  84. package/dist/storage-handlers/update-handlers/index.js +23 -0
  85. package/dist/storage-handlers/update-handlers/match-game.d.ts +3 -0
  86. package/dist/storage-handlers/update-handlers/match-game.js +99 -0
  87. package/dist/storage-handlers/update-handlers/match.d.ts +3 -0
  88. package/dist/storage-handlers/update-handlers/match.js +105 -0
  89. package/dist/storage-handlers/update-handlers/participant.d.ts +3 -0
  90. package/dist/storage-handlers/update-handlers/participant.js +40 -0
  91. package/dist/storage-handlers/update-handlers/round.d.ts +3 -0
  92. package/dist/storage-handlers/update-handlers/round.js +37 -0
  93. package/dist/storage-handlers/update-handlers/stage.d.ts +3 -0
  94. package/dist/storage-handlers/update-handlers/stage.js +61 -0
  95. package/dist/storage-handlers/update-handlers/tournament.d.ts +3 -0
  96. package/dist/storage-handlers/update-handlers/tournament.js +40 -0
  97. package/dist/storage-handlers/update.d.ts +3 -0
  98. package/dist/storage-handlers/update.js +24 -0
  99. package/dist/storage.d.ts +18 -0
  100. package/dist/storage.js +25 -0
  101. package/dist/transformers/enum/grand-final-type.d.ts +6 -0
  102. package/dist/transformers/enum/grand-final-type.js +25 -0
  103. package/dist/transformers/enum/index.d.ts +6 -0
  104. package/dist/transformers/enum/index.js +22 -0
  105. package/dist/transformers/enum/match-result.d.ts +6 -0
  106. package/dist/transformers/enum/match-result.js +25 -0
  107. package/dist/transformers/enum/match-status.d.ts +6 -0
  108. package/dist/transformers/enum/match-status.js +38 -0
  109. package/dist/transformers/enum/round-robin-mode.d.ts +6 -0
  110. package/dist/transformers/enum/round-robin-mode.js +21 -0
  111. package/dist/transformers/enum/seed-ordering.d.ts +6 -0
  112. package/dist/transformers/enum/seed-ordering.js +49 -0
  113. package/dist/transformers/enum/stage-type.d.ts +6 -0
  114. package/dist/transformers/enum/stage-type.js +25 -0
  115. package/dist/transformers/index.d.ts +2 -0
  116. package/dist/transformers/index.js +18 -0
  117. package/dist/transformers/model/group.d.ts +15 -0
  118. package/dist/transformers/model/group.js +18 -0
  119. package/dist/transformers/model/index.d.ts +9 -0
  120. package/dist/transformers/model/index.js +25 -0
  121. package/dist/transformers/model/match-game.d.ts +21 -0
  122. package/dist/transformers/model/match-game.js +90 -0
  123. package/dist/transformers/model/match.d.ts +23 -0
  124. package/dist/transformers/model/match.js +96 -0
  125. package/dist/transformers/model/participant-result.d.ts +21 -0
  126. package/dist/transformers/model/participant-result.js +26 -0
  127. package/dist/transformers/model/participant.d.ts +19 -0
  128. package/dist/transformers/model/participant.js +47 -0
  129. package/dist/transformers/model/round.d.ts +17 -0
  130. package/dist/transformers/model/round.js +20 -0
  131. package/dist/transformers/model/stage-settings.d.ts +18 -0
  132. package/dist/transformers/model/stage-settings.js +46 -0
  133. package/dist/transformers/model/stage.d.ts +22 -0
  134. package/dist/transformers/model/stage.js +26 -0
  135. package/dist/transformers/model/tournament.d.ts +30 -0
  136. package/dist/transformers/model/tournament.js +39 -0
  137. package/dist/types.d.ts +15 -0
  138. package/dist/types.js +2 -0
  139. package/package.json +45 -0
@@ -0,0 +1,3 @@
1
+ import { DataTypes } from 'brackets-manager/dist/types';
2
+ import type { DrizzleDatabase } from '../../db';
3
+ export declare function handleMatchGameDelete(db: DrizzleDatabase, filter?: Partial<DataTypes['match_game']>): Promise<boolean>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleMatchGameDelete = handleMatchGameDelete;
4
+ const transformers_1 = require("../../transformers");
5
+ const schema_1 = require("../../db/schema");
6
+ const drizzle_orm_1 = require("drizzle-orm");
7
+ async function handleMatchGameDelete(db, filter) {
8
+ try {
9
+ if (!filter) {
10
+ // Delete participant results first, then match games
11
+ await db.delete(schema_1.participantMatchGameResult);
12
+ await db.delete(schema_1.matchGame);
13
+ return true;
14
+ }
15
+ const conditions = [];
16
+ if (filter.id !== undefined)
17
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.matchGame.id, String(filter.id)));
18
+ if (filter.stage_id !== undefined)
19
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.matchGame.stageId, String(filter.stage_id)));
20
+ if (filter.parent_id !== undefined)
21
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.matchGame.matchId, String(filter.parent_id)));
22
+ if (filter.number !== undefined)
23
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.matchGame.number, filter.number));
24
+ if (filter.status !== undefined)
25
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.matchGame.status, transformers_1.MatchStatusTransformer.to(filter.status)));
26
+ // Find matching match games
27
+ const games = await db
28
+ .select({ id: schema_1.matchGame.id })
29
+ .from(schema_1.matchGame)
30
+ .where(conditions.length > 0 ? (0, drizzle_orm_1.and)(...conditions) : undefined);
31
+ if (games.length === 0)
32
+ return true;
33
+ const gameIds = games.map((g) => g.id);
34
+ // Delete related participant results first
35
+ await db.delete(schema_1.participantMatchGameResult).where((0, drizzle_orm_1.or)((0, drizzle_orm_1.inArray)(schema_1.participantMatchGameResult.opponent1MatchGameId, gameIds), (0, drizzle_orm_1.inArray)(schema_1.participantMatchGameResult.opponent2MatchGameId, gameIds)));
36
+ // Then delete the match games
37
+ await db.delete(schema_1.matchGame).where((0, drizzle_orm_1.inArray)(schema_1.matchGame.id, gameIds));
38
+ return true;
39
+ }
40
+ catch {
41
+ return false;
42
+ }
43
+ }
@@ -0,0 +1,3 @@
1
+ import { DataTypes } from 'brackets-manager/dist/types';
2
+ import type { DrizzleDatabase } from '../../db';
3
+ export declare function handleMatchDelete(db: DrizzleDatabase, filter?: Partial<DataTypes['match']>): Promise<boolean>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleMatchDelete = handleMatchDelete;
4
+ const transformers_1 = require("../../transformers");
5
+ const schema_1 = require("../../db/schema");
6
+ const drizzle_orm_1 = require("drizzle-orm");
7
+ async function handleMatchDelete(db, filter) {
8
+ try {
9
+ if (!filter) {
10
+ // Delete participant results first, then matches
11
+ await db.delete(schema_1.participantMatchResult);
12
+ await db.delete(schema_1.match);
13
+ return true;
14
+ }
15
+ const conditions = [];
16
+ if (filter.id !== undefined)
17
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.match.id, String(filter.id)));
18
+ if (filter.stage_id !== undefined)
19
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.match.stageId, String(filter.stage_id)));
20
+ if (filter.group_id !== undefined)
21
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.match.groupId, String(filter.group_id)));
22
+ if (filter.round_id !== undefined)
23
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.match.roundId, String(filter.round_id)));
24
+ if (filter.number !== undefined)
25
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.match.number, filter.number));
26
+ if (filter.status !== undefined)
27
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.match.status, transformers_1.MatchStatusTransformer.to(filter.status)));
28
+ // Find matching matches
29
+ const matches = await db
30
+ .select({ id: schema_1.match.id })
31
+ .from(schema_1.match)
32
+ .where(conditions.length > 0 ? (0, drizzle_orm_1.and)(...conditions) : undefined);
33
+ if (matches.length === 0)
34
+ return true;
35
+ const matchIds = matches.map((m) => m.id);
36
+ // Delete related participant results first
37
+ await db.delete(schema_1.participantMatchResult).where((0, drizzle_orm_1.or)((0, drizzle_orm_1.inArray)(schema_1.participantMatchResult.opponent1MatchId, matchIds), (0, drizzle_orm_1.inArray)(schema_1.participantMatchResult.opponent2MatchId, matchIds)));
38
+ // Then delete the matches
39
+ await db.delete(schema_1.match).where((0, drizzle_orm_1.inArray)(schema_1.match.id, matchIds));
40
+ return true;
41
+ }
42
+ catch {
43
+ return false;
44
+ }
45
+ }
@@ -0,0 +1,3 @@
1
+ import { DataTypes } from 'brackets-manager/dist/types';
2
+ import type { DrizzleDatabase } from '../../db';
3
+ export declare function handleParticipantDelete(db: DrizzleDatabase, filter?: Partial<DataTypes['participant']>): Promise<boolean>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleParticipantDelete = handleParticipantDelete;
4
+ const schema_1 = require("../../db/schema");
5
+ const drizzle_orm_1 = require("drizzle-orm");
6
+ async function handleParticipantDelete(db, filter) {
7
+ try {
8
+ if (!filter) {
9
+ await db.delete(schema_1.participant);
10
+ return true;
11
+ }
12
+ const conditions = [];
13
+ if (filter.id !== undefined)
14
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.participant.id, String(filter.id)));
15
+ if (filter.name !== undefined)
16
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.participant.name, filter.name));
17
+ if (filter.tournament_id !== undefined)
18
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.participant.tournamentId, String(filter.tournament_id)));
19
+ await db
20
+ .delete(schema_1.participant)
21
+ .where(conditions.length > 0 ? (0, drizzle_orm_1.and)(...conditions) : undefined);
22
+ return true;
23
+ }
24
+ catch {
25
+ return false;
26
+ }
27
+ }
@@ -0,0 +1,3 @@
1
+ import { DataTypes } from 'brackets-manager/dist/types';
2
+ import type { DrizzleDatabase } from '../../db';
3
+ export declare function handleRoundDelete(db: DrizzleDatabase, filter?: Partial<DataTypes['round']>): Promise<boolean>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleRoundDelete = handleRoundDelete;
4
+ const schema_1 = require("../../db/schema");
5
+ const drizzle_orm_1 = require("drizzle-orm");
6
+ async function handleRoundDelete(db, filter) {
7
+ try {
8
+ if (!filter) {
9
+ await db.delete(schema_1.round);
10
+ return true;
11
+ }
12
+ const conditions = [];
13
+ if (filter.id !== undefined)
14
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.round.id, String(filter.id)));
15
+ if (filter.stage_id !== undefined)
16
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.round.stageId, String(filter.stage_id)));
17
+ if (filter.group_id !== undefined)
18
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.round.groupId, String(filter.group_id)));
19
+ if (filter.number !== undefined)
20
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.round.number, filter.number));
21
+ await db
22
+ .delete(schema_1.round)
23
+ .where(conditions.length > 0 ? (0, drizzle_orm_1.and)(...conditions) : undefined);
24
+ return true;
25
+ }
26
+ catch {
27
+ return false;
28
+ }
29
+ }
@@ -0,0 +1,3 @@
1
+ import { DataTypes } from 'brackets-manager/dist/types';
2
+ import type { DrizzleDatabase } from '../../db';
3
+ export declare function handleStageDelete(db: DrizzleDatabase, filter?: Partial<DataTypes['stage']>): Promise<boolean>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleStageDelete = handleStageDelete;
4
+ const transformers_1 = require("../../transformers");
5
+ const schema_1 = require("../../db/schema");
6
+ const drizzle_orm_1 = require("drizzle-orm");
7
+ async function handleStageDelete(db, filter) {
8
+ try {
9
+ if (!filter) {
10
+ // No filter: delete in the right order to satisfy FK constraints
11
+ await db.delete(schema_1.stageSettings);
12
+ await db.delete(schema_1.stage);
13
+ return true;
14
+ }
15
+ const conditions = [];
16
+ if (filter.id !== undefined)
17
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.stage.id, String(filter.id)));
18
+ if (filter.name !== undefined)
19
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.stage.name, filter.name));
20
+ if (filter.number !== undefined)
21
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.stage.number, filter.number));
22
+ if (filter.tournament_id !== undefined)
23
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.stage.tournamentId, String(filter.tournament_id)));
24
+ if (filter.type !== undefined)
25
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.stage.type, transformers_1.StageTypeTransformer.to(filter.type)));
26
+ // Find matching stages
27
+ const stages = await db
28
+ .select({ id: schema_1.stage.id })
29
+ .from(schema_1.stage)
30
+ .where(conditions.length > 0 ? (0, drizzle_orm_1.and)(...conditions) : undefined);
31
+ if (stages.length === 0)
32
+ return true;
33
+ const stageIds = stages.map((s) => s.id);
34
+ // Delete related StageSettings first to satisfy FK constraints
35
+ await db
36
+ .delete(schema_1.stageSettings)
37
+ .where((0, drizzle_orm_1.inArray)(schema_1.stageSettings.stageId, stageIds));
38
+ // Then delete the stages
39
+ await db.delete(schema_1.stage).where((0, drizzle_orm_1.inArray)(schema_1.stage.id, stageIds));
40
+ return true;
41
+ }
42
+ catch (e) {
43
+ console.error(new Error(`Error deleting stages with filter ${JSON.stringify(filter)}`, {
44
+ cause: e,
45
+ }));
46
+ return false;
47
+ }
48
+ }
@@ -0,0 +1,3 @@
1
+ import { Tournament } from '../../transformers';
2
+ import type { DrizzleDatabase } from '../../db';
3
+ export declare function handleTournamentDelete(db: DrizzleDatabase, filter?: Partial<Tournament>): Promise<boolean>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleTournamentDelete = handleTournamentDelete;
4
+ const schema_1 = require("../../db/schema");
5
+ const drizzle_orm_1 = require("drizzle-orm");
6
+ async function handleTournamentDelete(db, filter) {
7
+ try {
8
+ if (!filter) {
9
+ await db.delete(schema_1.tournament);
10
+ return true;
11
+ }
12
+ const conditions = [];
13
+ if (filter.id !== undefined)
14
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.tournament.id, String(filter.id)));
15
+ if (filter.name !== undefined)
16
+ conditions.push((0, drizzle_orm_1.eq)(schema_1.tournament.name, filter.name));
17
+ await db
18
+ .delete(schema_1.tournament)
19
+ .where(conditions.length > 0 ? (0, drizzle_orm_1.and)(...conditions) : undefined);
20
+ return true;
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ }
@@ -0,0 +1,3 @@
1
+ import { DataTypes } from 'brackets-manager/dist/types';
2
+ import type { DrizzleDatabase } from '../db';
3
+ export declare function handleDelete<T extends keyof DataTypes>(db: DrizzleDatabase, table: T | 'tournament', filter?: Partial<DataTypes[T]>): Promise<boolean>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleDelete = handleDelete;
4
+ const delete_handlers_1 = require("./delete-handlers");
5
+ async function handleDelete(db, table, filter) {
6
+ switch (table) {
7
+ case 'tournament':
8
+ return (0, delete_handlers_1.handleTournamentDelete)(db, filter);
9
+ case 'participant':
10
+ return (0, delete_handlers_1.handleParticipantDelete)(db, filter);
11
+ case 'stage':
12
+ return (0, delete_handlers_1.handleStageDelete)(db, filter);
13
+ case 'group':
14
+ return (0, delete_handlers_1.handleGroupDelete)(db, filter);
15
+ case 'round':
16
+ return (0, delete_handlers_1.handleRoundDelete)(db, filter);
17
+ case 'match':
18
+ return (0, delete_handlers_1.handleMatchDelete)(db, filter);
19
+ case 'match_game':
20
+ return (0, delete_handlers_1.handleMatchGameDelete)(db, filter);
21
+ default:
22
+ return false;
23
+ }
24
+ }
@@ -0,0 +1,4 @@
1
+ export * from './delete';
2
+ export * from './insert';
3
+ export * from './select';
4
+ export * from './update';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./delete"), exports);
18
+ __exportStar(require("./insert"), exports);
19
+ __exportStar(require("./select"), exports);
20
+ __exportStar(require("./update"), exports);
@@ -0,0 +1,5 @@
1
+ import { DataTypes } from 'brackets-manager/dist/types';
2
+ import type { DrizzleDatabase } from '../../db';
3
+ type GroupInsertInput = DataTypes['group'];
4
+ export declare function handleGroupInsert(db: DrizzleDatabase, values: GroupInsertInput | GroupInsertInput[]): Promise<string | boolean>;
5
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleGroupInsert = handleGroupInsert;
4
+ const transformers_1 = require("../../transformers");
5
+ const schema_1 = require("../../db/schema");
6
+ async function handleGroupInsert(db, values) {
7
+ try {
8
+ if (Array.isArray(values)) {
9
+ await db.insert(schema_1.group).values(values.map((g) => ({ id: String(g.id), ...transformers_1.GroupTransformer.to(g) })));
10
+ return true;
11
+ }
12
+ const result = await db
13
+ .insert(schema_1.group)
14
+ .values({ id: String(values.id), ...transformers_1.GroupTransformer.to(values) })
15
+ .returning({ id: schema_1.group.id });
16
+ return result[0]?.id ?? '';
17
+ }
18
+ catch {
19
+ return Array.isArray(values) ? false : '';
20
+ }
21
+ }
@@ -0,0 +1,7 @@
1
+ export * from './group';
2
+ export * from './match';
3
+ export * from './match-game';
4
+ export * from './participant';
5
+ export * from './round';
6
+ export * from './stage';
7
+ export * from './tournament';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./group"), exports);
18
+ __exportStar(require("./match"), exports);
19
+ __exportStar(require("./match-game"), exports);
20
+ __exportStar(require("./participant"), exports);
21
+ __exportStar(require("./round"), exports);
22
+ __exportStar(require("./stage"), exports);
23
+ __exportStar(require("./tournament"), exports);
@@ -0,0 +1,5 @@
1
+ import type { DrizzleDatabase } from '../../db';
2
+ import type { MatchGameWithExtra } from '../../types';
3
+ type MatchGameInsertInput = MatchGameWithExtra;
4
+ export declare function handleMatchGameInsert(db: DrizzleDatabase, values: MatchGameInsertInput | MatchGameInsertInput[]): Promise<string | boolean>;
5
+ export {};
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleMatchGameInsert = handleMatchGameInsert;
4
+ const transformers_1 = require("../../transformers");
5
+ const schema_1 = require("../../db/schema");
6
+ const crypto_1 = require("crypto");
7
+ async function handleMatchGameInsert(db, values) {
8
+ try {
9
+ if (Array.isArray(values)) {
10
+ for (const value of values) {
11
+ await insertSingleMatchGame(db, value);
12
+ }
13
+ return true;
14
+ }
15
+ const result = await insertSingleMatchGame(db, values);
16
+ return result ?? '';
17
+ }
18
+ catch {
19
+ return Array.isArray(values) ? false : '';
20
+ }
21
+ }
22
+ async function insertSingleMatchGame(db, value) {
23
+ const matchGameData = transformers_1.MatchGameTransformer.to(value);
24
+ const matchGameId = String(value.id);
25
+ const matchGameResult = await db
26
+ .insert(schema_1.matchGame)
27
+ .values({
28
+ id: matchGameId,
29
+ ...matchGameData,
30
+ extra: value.extra ?? null,
31
+ })
32
+ .returning({ id: schema_1.matchGame.id });
33
+ const insertedMatchGameId = matchGameResult[0]?.id;
34
+ if (!insertedMatchGameId) {
35
+ throw new Error('Failed to insert match game');
36
+ }
37
+ // Insert opponent1 result if provided
38
+ if (value.opponent1) {
39
+ await db.insert(schema_1.participantMatchGameResult).values({
40
+ id: (0, crypto_1.randomUUID)(),
41
+ participantId: value.opponent1.id != null ? String(value.opponent1.id) : null,
42
+ forfeit: value.opponent1.forfeit ?? null,
43
+ position: value.opponent1.position ?? null,
44
+ score: value.opponent1.score ?? null,
45
+ result: value.opponent1.result
46
+ ? transformers_1.MatchResultTransformer.to(value.opponent1.result)
47
+ : null,
48
+ opponent1MatchGameId: insertedMatchGameId,
49
+ });
50
+ }
51
+ // Insert opponent2 result if provided
52
+ if (value.opponent2) {
53
+ await db.insert(schema_1.participantMatchGameResult).values({
54
+ id: (0, crypto_1.randomUUID)(),
55
+ participantId: value.opponent2.id != null ? String(value.opponent2.id) : null,
56
+ forfeit: value.opponent2.forfeit ?? null,
57
+ position: value.opponent2.position ?? null,
58
+ score: value.opponent2.score ?? null,
59
+ result: value.opponent2.result
60
+ ? transformers_1.MatchResultTransformer.to(value.opponent2.result)
61
+ : null,
62
+ opponent2MatchGameId: insertedMatchGameId,
63
+ });
64
+ }
65
+ return insertedMatchGameId;
66
+ }
@@ -0,0 +1,5 @@
1
+ import type { DrizzleDatabase } from '../../db';
2
+ import type { MatchWithExtra } from '../../types';
3
+ type MatchInsertInput = MatchWithExtra;
4
+ export declare function handleMatchInsert(db: DrizzleDatabase, values: MatchInsertInput | MatchInsertInput[]): Promise<string | boolean>;
5
+ export {};
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleMatchInsert = handleMatchInsert;
4
+ const transformers_1 = require("../../transformers");
5
+ const schema_1 = require("../../db/schema");
6
+ const crypto_1 = require("crypto");
7
+ async function handleMatchInsert(db, values) {
8
+ try {
9
+ if (Array.isArray(values)) {
10
+ for (const value of values) {
11
+ await insertSingleMatch(db, value);
12
+ }
13
+ return true;
14
+ }
15
+ const result = await insertSingleMatch(db, values);
16
+ return result ?? '';
17
+ }
18
+ catch {
19
+ return Array.isArray(values) ? false : '';
20
+ }
21
+ }
22
+ async function insertSingleMatch(db, value) {
23
+ const matchData = transformers_1.MatchTransformer.to(value);
24
+ const matchId = String(value.id);
25
+ const matchResult = await db
26
+ .insert(schema_1.match)
27
+ .values({
28
+ id: matchId,
29
+ ...matchData,
30
+ extra: value.extra ?? null,
31
+ })
32
+ .returning({ id: schema_1.match.id });
33
+ const insertedMatchId = matchResult[0]?.id;
34
+ if (!insertedMatchId) {
35
+ throw new Error('Failed to insert match');
36
+ }
37
+ // Insert opponent1 result if provided
38
+ if (value.opponent1) {
39
+ await db.insert(schema_1.participantMatchResult).values({
40
+ id: (0, crypto_1.randomUUID)(),
41
+ participantId: value.opponent1.id != null ? String(value.opponent1.id) : null,
42
+ forfeit: value.opponent1.forfeit ?? null,
43
+ position: value.opponent1.position ?? null,
44
+ score: value.opponent1.score ?? null,
45
+ result: value.opponent1.result
46
+ ? transformers_1.MatchResultTransformer.to(value.opponent1.result)
47
+ : null,
48
+ opponent1MatchId: insertedMatchId,
49
+ });
50
+ }
51
+ // Insert opponent2 result if provided
52
+ if (value.opponent2) {
53
+ await db.insert(schema_1.participantMatchResult).values({
54
+ id: (0, crypto_1.randomUUID)(),
55
+ participantId: value.opponent2.id != null ? String(value.opponent2.id) : null,
56
+ forfeit: value.opponent2.forfeit ?? null,
57
+ position: value.opponent2.position ?? null,
58
+ score: value.opponent2.score ?? null,
59
+ result: value.opponent2.result
60
+ ? transformers_1.MatchResultTransformer.to(value.opponent2.result)
61
+ : null,
62
+ opponent2MatchId: insertedMatchId,
63
+ });
64
+ }
65
+ return insertedMatchId;
66
+ }
@@ -0,0 +1,5 @@
1
+ import { DataTypes } from 'brackets-manager/dist/types';
2
+ import type { DrizzleDatabase } from '../../db';
3
+ type ParticipantInsertInput = DataTypes['participant'];
4
+ export declare function handleParticipantInsert(db: DrizzleDatabase, values: ParticipantInsertInput | ParticipantInsertInput[]): Promise<string | boolean>;
5
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleParticipantInsert = handleParticipantInsert;
4
+ const transformers_1 = require("../../transformers");
5
+ const schema_1 = require("../../db/schema");
6
+ async function handleParticipantInsert(db, values) {
7
+ try {
8
+ if (Array.isArray(values)) {
9
+ await db.insert(schema_1.participant).values(values.map((p) => {
10
+ const value = transformers_1.ParticipantTransformer.to(p);
11
+ return { id: String(p.id), ...value, extra: value.extra ?? undefined };
12
+ }));
13
+ return true;
14
+ }
15
+ const value = transformers_1.ParticipantTransformer.to(values);
16
+ const result = await db
17
+ .insert(schema_1.participant)
18
+ .values({ id: String(values.id), ...value, extra: value.extra ?? undefined })
19
+ .returning({ id: schema_1.participant.id });
20
+ return result[0]?.id ?? '';
21
+ }
22
+ catch {
23
+ return Array.isArray(values) ? false : '';
24
+ }
25
+ }
@@ -0,0 +1,5 @@
1
+ import { DataTypes } from 'brackets-manager/dist/types';
2
+ import type { DrizzleDatabase } from '../../db';
3
+ type RoundInsertInput = DataTypes['round'];
4
+ export declare function handleRoundInsert(db: DrizzleDatabase, values: RoundInsertInput | RoundInsertInput[]): Promise<string | boolean>;
5
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleRoundInsert = handleRoundInsert;
4
+ const transformers_1 = require("../../transformers");
5
+ const schema_1 = require("../../db/schema");
6
+ async function handleRoundInsert(db, values) {
7
+ try {
8
+ if (Array.isArray(values)) {
9
+ await db.insert(schema_1.round).values(values.map((r) => ({ id: String(r.id), ...transformers_1.RoundTransformer.to(r) })));
10
+ return true;
11
+ }
12
+ const result = await db
13
+ .insert(schema_1.round)
14
+ .values({ id: String(values.id), ...transformers_1.RoundTransformer.to(values) })
15
+ .returning({ id: schema_1.round.id });
16
+ return result[0]?.id ?? '';
17
+ }
18
+ catch {
19
+ return Array.isArray(values) ? false : '';
20
+ }
21
+ }
@@ -0,0 +1,5 @@
1
+ import { DataTypes } from 'brackets-manager/dist/types';
2
+ import type { DrizzleDatabase } from '../../db';
3
+ type StageInsertInput = DataTypes['stage'];
4
+ export declare function handleStageInsert(db: DrizzleDatabase, values: StageInsertInput | StageInsertInput[]): Promise<string | boolean>;
5
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleStageInsert = handleStageInsert;
4
+ const transformers_1 = require("../../transformers");
5
+ const schema_1 = require("../../db/schema");
6
+ const crypto_1 = require("crypto");
7
+ async function handleStageInsert(db, values) {
8
+ try {
9
+ if (Array.isArray(values)) {
10
+ // For batch insert, we need to insert stages first, then settings
11
+ for (const v of values) {
12
+ const stageId = String(v.id);
13
+ const stageResult = await db
14
+ .insert(schema_1.stage)
15
+ .values({ id: stageId, ...transformers_1.StageTransformer.to(v) })
16
+ .returning({ id: schema_1.stage.id });
17
+ if (stageResult[0] && v.settings) {
18
+ await db.insert(schema_1.stageSettings).values({
19
+ id: (0, crypto_1.randomUUID)(),
20
+ stageId: stageResult[0].id,
21
+ ...transformers_1.StageSettingsTransformer.to(v.settings),
22
+ });
23
+ }
24
+ }
25
+ return true;
26
+ }
27
+ const stageId = String(values.id);
28
+ const stageResult = await db
29
+ .insert(schema_1.stage)
30
+ .values({ id: stageId, ...transformers_1.StageTransformer.to(values) })
31
+ .returning({ id: schema_1.stage.id });
32
+ if (stageResult[0] && values.settings) {
33
+ await db.insert(schema_1.stageSettings).values({
34
+ id: (0, crypto_1.randomUUID)(),
35
+ stageId: stageResult[0].id,
36
+ ...transformers_1.StageSettingsTransformer.to(values.settings),
37
+ });
38
+ }
39
+ return stageResult[0]?.id ?? '';
40
+ }
41
+ catch {
42
+ return Array.isArray(values) ? false : '';
43
+ }
44
+ }
@@ -0,0 +1,5 @@
1
+ import { Tournament } from '../../transformers';
2
+ import type { DrizzleDatabase } from '../../db';
3
+ type TournamentInsertInput = Tournament;
4
+ export declare function handleTournamentInsert(db: DrizzleDatabase, values: TournamentInsertInput | TournamentInsertInput[]): Promise<string | boolean>;
5
+ export {};