@opprs/db-prisma 2.2.1-canary.5b08a34 → 2.2.1-canary.73ad5c6
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/dist/index.cjs +296 -0
- package/dist/index.d.cts +275 -2
- package/dist/index.d.ts +275 -2
- package/dist/index.js +267 -0
- package/package.json +2 -2
- package/prisma/schema.prisma +91 -0
package/dist/index.cjs
CHANGED
|
@@ -20,18 +20,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
MAX_API_KEYS_PER_USER: () => MAX_API_KEYS_PER_USER,
|
|
23
24
|
applyRDDecayForInactivePlayers: () => applyRDDecayForInactivePlayers,
|
|
24
25
|
connect: () => connect,
|
|
26
|
+
countBlogPosts: () => countBlogPosts,
|
|
27
|
+
countBlogTags: () => countBlogTags,
|
|
25
28
|
countEntries: () => countEntries,
|
|
26
29
|
countLocations: () => countLocations,
|
|
27
30
|
countMatches: () => countMatches,
|
|
28
31
|
countOpprPlayerRankings: () => countOpprPlayerRankings,
|
|
29
32
|
countOpprRankingHistory: () => countOpprRankingHistory,
|
|
30
33
|
countPlayers: () => countPlayers,
|
|
34
|
+
countPublishedBlogPosts: () => countPublishedBlogPosts,
|
|
31
35
|
countRounds: () => countRounds,
|
|
32
36
|
countStandings: () => countStandings,
|
|
33
37
|
countTournaments: () => countTournaments,
|
|
38
|
+
countUserApiKeys: () => countUserApiKeys,
|
|
34
39
|
countUsers: () => countUsers,
|
|
40
|
+
createApiKey: () => createApiKey,
|
|
41
|
+
createBlogPost: () => createBlogPost,
|
|
42
|
+
createBlogTag: () => createBlogTag,
|
|
35
43
|
createEntry: () => createEntry,
|
|
36
44
|
createLocation: () => createLocation,
|
|
37
45
|
createManyEntries: () => createManyEntries,
|
|
@@ -47,6 +55,9 @@ __export(index_exports, {
|
|
|
47
55
|
createTournament: () => createTournament,
|
|
48
56
|
createUser: () => createUser,
|
|
49
57
|
createUserWithPlayer: () => createUserWithPlayer,
|
|
58
|
+
deleteApiKey: () => deleteApiKey,
|
|
59
|
+
deleteBlogPost: () => deleteBlogPost,
|
|
60
|
+
deleteBlogTag: () => deleteBlogTag,
|
|
50
61
|
deleteEntriesByMatch: () => deleteEntriesByMatch,
|
|
51
62
|
deleteEntry: () => deleteEntry,
|
|
52
63
|
deleteLocation: () => deleteLocation,
|
|
@@ -61,7 +72,16 @@ __export(index_exports, {
|
|
|
61
72
|
deleteStandingsByTournament: () => deleteStandingsByTournament,
|
|
62
73
|
deleteTournament: () => deleteTournament,
|
|
63
74
|
deleteUser: () => deleteUser,
|
|
75
|
+
deleteUserApiKey: () => deleteUserApiKey,
|
|
64
76
|
disconnect: () => disconnect,
|
|
77
|
+
findApiKeyById: () => findApiKeyById,
|
|
78
|
+
findApiKeysByPrefix: () => findApiKeysByPrefix,
|
|
79
|
+
findBlogPostById: () => findBlogPostById,
|
|
80
|
+
findBlogPostBySlug: () => findBlogPostBySlug,
|
|
81
|
+
findBlogPosts: () => findBlogPosts,
|
|
82
|
+
findBlogTagById: () => findBlogTagById,
|
|
83
|
+
findBlogTagBySlug: () => findBlogTagBySlug,
|
|
84
|
+
findBlogTags: () => findBlogTags,
|
|
65
85
|
findEntries: () => findEntries,
|
|
66
86
|
findEntryById: () => findEntryById,
|
|
67
87
|
findEntryByMatchAndPlayer: () => findEntryByMatchAndPlayer,
|
|
@@ -78,6 +98,7 @@ __export(index_exports, {
|
|
|
78
98
|
findPlayerByPlayerNumber: () => findPlayerByPlayerNumber,
|
|
79
99
|
findPlayerByUserEmail: () => findPlayerByUserEmail,
|
|
80
100
|
findPlayers: () => findPlayers,
|
|
101
|
+
findPublishedBlogPosts: () => findPublishedBlogPosts,
|
|
81
102
|
findRoundById: () => findRoundById,
|
|
82
103
|
findRoundByTournamentAndNumber: () => findRoundByTournamentAndNumber,
|
|
83
104
|
findRounds: () => findRounds,
|
|
@@ -91,6 +112,8 @@ __export(index_exports, {
|
|
|
91
112
|
findUserById: () => findUserById,
|
|
92
113
|
findUsers: () => findUsers,
|
|
93
114
|
generateUniquePlayerNumber: () => generateUniquePlayerNumber,
|
|
115
|
+
getBlogTagWithPostCount: () => getBlogTagWithPostCount,
|
|
116
|
+
getBlogTagsWithPostCounts: () => getBlogTagsWithPostCounts,
|
|
94
117
|
getFinalsRounds: () => getFinalsRounds,
|
|
95
118
|
getFinalsStandings: () => getFinalsStandings,
|
|
96
119
|
getLatestOpprRankingHistory: () => getLatestOpprRankingHistory,
|
|
@@ -126,16 +149,22 @@ __export(index_exports, {
|
|
|
126
149
|
getTournamentWithResults: () => getTournamentWithResults,
|
|
127
150
|
getTournamentsByBoosterType: () => getTournamentsByBoosterType,
|
|
128
151
|
getTournamentsByDateRange: () => getTournamentsByDateRange,
|
|
152
|
+
getUserApiKeys: () => getUserApiKeys,
|
|
129
153
|
getUserByEmailWithPlayer: () => getUserByEmailWithPlayer,
|
|
130
154
|
getUserWithPlayer: () => getUserWithPlayer,
|
|
131
155
|
isValidPlayerNumber: () => isValidPlayerNumber,
|
|
132
156
|
linkPlayerToUser: () => linkPlayerToUser,
|
|
133
157
|
prisma: () => prisma,
|
|
134
158
|
recalculateTimeDecay: () => recalculateTimeDecay,
|
|
159
|
+
searchBlogPosts: () => searchBlogPosts,
|
|
160
|
+
searchBlogTags: () => searchBlogTags,
|
|
135
161
|
searchLocations: () => searchLocations,
|
|
136
162
|
searchPlayers: () => searchPlayers,
|
|
137
163
|
searchTournaments: () => searchTournaments,
|
|
138
164
|
testConnection: () => testConnection,
|
|
165
|
+
updateApiKeyLastUsed: () => updateApiKeyLastUsed,
|
|
166
|
+
updateBlogPost: () => updateBlogPost,
|
|
167
|
+
updateBlogTag: () => updateBlogTag,
|
|
139
168
|
updateEntry: () => updateEntry,
|
|
140
169
|
updateLocation: () => updateLocation,
|
|
141
170
|
updateMatch: () => updateMatch,
|
|
@@ -1341,6 +1370,65 @@ async function linkPlayerToUser(userId, playerId) {
|
|
|
1341
1370
|
});
|
|
1342
1371
|
}
|
|
1343
1372
|
|
|
1373
|
+
// src/api-keys.ts
|
|
1374
|
+
var MAX_API_KEYS_PER_USER = 5;
|
|
1375
|
+
async function createApiKey(data) {
|
|
1376
|
+
return prisma.apiKey.create({ data });
|
|
1377
|
+
}
|
|
1378
|
+
async function findApiKeyById(id) {
|
|
1379
|
+
return prisma.apiKey.findUnique({ where: { id } });
|
|
1380
|
+
}
|
|
1381
|
+
async function findApiKeysByPrefix(keyPrefix) {
|
|
1382
|
+
const keys = await prisma.apiKey.findMany({
|
|
1383
|
+
where: { keyPrefix },
|
|
1384
|
+
include: {
|
|
1385
|
+
user: {
|
|
1386
|
+
select: {
|
|
1387
|
+
id: true,
|
|
1388
|
+
email: true,
|
|
1389
|
+
role: true
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1394
|
+
return keys;
|
|
1395
|
+
}
|
|
1396
|
+
async function getUserApiKeys(userId) {
|
|
1397
|
+
return prisma.apiKey.findMany({
|
|
1398
|
+
where: { userId },
|
|
1399
|
+
select: {
|
|
1400
|
+
id: true,
|
|
1401
|
+
name: true,
|
|
1402
|
+
keyPrefix: true,
|
|
1403
|
+
expiresAt: true,
|
|
1404
|
+
lastUsedAt: true,
|
|
1405
|
+
createdAt: true
|
|
1406
|
+
},
|
|
1407
|
+
orderBy: { createdAt: "desc" }
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
async function countUserApiKeys(userId) {
|
|
1411
|
+
return prisma.apiKey.count({ where: { userId } });
|
|
1412
|
+
}
|
|
1413
|
+
async function updateApiKeyLastUsed(id) {
|
|
1414
|
+
await prisma.apiKey.update({
|
|
1415
|
+
where: { id },
|
|
1416
|
+
data: { lastUsedAt: /* @__PURE__ */ new Date() }
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
async function deleteApiKey(id) {
|
|
1420
|
+
return prisma.apiKey.delete({ where: { id } });
|
|
1421
|
+
}
|
|
1422
|
+
async function deleteUserApiKey(id, userId) {
|
|
1423
|
+
const key = await prisma.apiKey.findFirst({
|
|
1424
|
+
where: { id, userId }
|
|
1425
|
+
});
|
|
1426
|
+
if (!key) {
|
|
1427
|
+
return null;
|
|
1428
|
+
}
|
|
1429
|
+
return prisma.apiKey.delete({ where: { id } });
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1344
1432
|
// src/locations.ts
|
|
1345
1433
|
async function createLocation(data) {
|
|
1346
1434
|
return prisma.location.create({
|
|
@@ -1406,20 +1494,207 @@ async function getLocationWithTournaments(id) {
|
|
|
1406
1494
|
}
|
|
1407
1495
|
});
|
|
1408
1496
|
}
|
|
1497
|
+
|
|
1498
|
+
// src/blog-posts.ts
|
|
1499
|
+
var defaultInclude = {
|
|
1500
|
+
author: {
|
|
1501
|
+
select: { id: true, email: true }
|
|
1502
|
+
},
|
|
1503
|
+
tags: {
|
|
1504
|
+
select: { id: true, name: true, slug: true }
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
async function createBlogPost(data) {
|
|
1508
|
+
const { tagIds, ...postData } = data;
|
|
1509
|
+
return prisma.blogPost.create({
|
|
1510
|
+
data: {
|
|
1511
|
+
...postData,
|
|
1512
|
+
tags: tagIds?.length ? { connect: tagIds.map((id) => ({ id })) } : void 0
|
|
1513
|
+
},
|
|
1514
|
+
include: defaultInclude
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
async function findBlogPostById(id) {
|
|
1518
|
+
return prisma.blogPost.findUnique({
|
|
1519
|
+
where: { id },
|
|
1520
|
+
include: defaultInclude
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
async function findBlogPostBySlug(slug) {
|
|
1524
|
+
return prisma.blogPost.findUnique({
|
|
1525
|
+
where: { slug },
|
|
1526
|
+
include: defaultInclude
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
async function findBlogPosts(options = {}) {
|
|
1530
|
+
return prisma.blogPost.findMany({
|
|
1531
|
+
take: options.take,
|
|
1532
|
+
skip: options.skip,
|
|
1533
|
+
where: options.where,
|
|
1534
|
+
orderBy: options.orderBy ?? { createdAt: "desc" },
|
|
1535
|
+
include: options.include ?? defaultInclude
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
async function findPublishedBlogPosts(options = {}) {
|
|
1539
|
+
const { tagSlug, ...restOptions } = options;
|
|
1540
|
+
const where = {
|
|
1541
|
+
status: "PUBLISHED",
|
|
1542
|
+
publishedAt: { not: null },
|
|
1543
|
+
...tagSlug && {
|
|
1544
|
+
tags: {
|
|
1545
|
+
some: { slug: tagSlug }
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
return findBlogPosts({
|
|
1550
|
+
...restOptions,
|
|
1551
|
+
where,
|
|
1552
|
+
orderBy: options.orderBy ?? { publishedAt: "desc" }
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
async function searchBlogPosts(query, limit = 20, publishedOnly = true) {
|
|
1556
|
+
const where = {
|
|
1557
|
+
OR: [
|
|
1558
|
+
{ title: { contains: query, mode: "insensitive" } },
|
|
1559
|
+
{ excerpt: { contains: query, mode: "insensitive" } }
|
|
1560
|
+
],
|
|
1561
|
+
...publishedOnly && {
|
|
1562
|
+
status: "PUBLISHED",
|
|
1563
|
+
publishedAt: { not: null }
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1566
|
+
return findBlogPosts({
|
|
1567
|
+
take: limit,
|
|
1568
|
+
where,
|
|
1569
|
+
orderBy: { publishedAt: "desc" }
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
async function updateBlogPost(id, data) {
|
|
1573
|
+
const { tagIds, ...postData } = data;
|
|
1574
|
+
return prisma.blogPost.update({
|
|
1575
|
+
where: { id },
|
|
1576
|
+
data: {
|
|
1577
|
+
...postData,
|
|
1578
|
+
// If tagIds is provided, replace all tags
|
|
1579
|
+
...tagIds !== void 0 && {
|
|
1580
|
+
tags: {
|
|
1581
|
+
set: tagIds.map((tagId) => ({ id: tagId }))
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
},
|
|
1585
|
+
include: defaultInclude
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
async function deleteBlogPost(id) {
|
|
1589
|
+
return prisma.blogPost.delete({
|
|
1590
|
+
where: { id }
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
async function countBlogPosts(where) {
|
|
1594
|
+
return prisma.blogPost.count({ where });
|
|
1595
|
+
}
|
|
1596
|
+
async function countPublishedBlogPosts(tagSlug) {
|
|
1597
|
+
return countBlogPosts({
|
|
1598
|
+
status: "PUBLISHED",
|
|
1599
|
+
publishedAt: { not: null },
|
|
1600
|
+
...tagSlug && {
|
|
1601
|
+
tags: {
|
|
1602
|
+
some: { slug: tagSlug }
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
// src/blog-tags.ts
|
|
1609
|
+
async function createBlogTag(data) {
|
|
1610
|
+
return prisma.blogTag.create({
|
|
1611
|
+
data
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
async function findBlogTagById(id) {
|
|
1615
|
+
return prisma.blogTag.findUnique({
|
|
1616
|
+
where: { id }
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
async function findBlogTagBySlug(slug) {
|
|
1620
|
+
return prisma.blogTag.findUnique({
|
|
1621
|
+
where: { slug }
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
async function findBlogTags(options = {}) {
|
|
1625
|
+
return prisma.blogTag.findMany({
|
|
1626
|
+
take: options.take,
|
|
1627
|
+
skip: options.skip,
|
|
1628
|
+
where: options.where,
|
|
1629
|
+
orderBy: options.orderBy ?? { name: "asc" },
|
|
1630
|
+
include: options.include
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
async function searchBlogTags(query, limit = 20) {
|
|
1634
|
+
return findBlogTags({
|
|
1635
|
+
take: limit,
|
|
1636
|
+
where: {
|
|
1637
|
+
name: { contains: query, mode: "insensitive" }
|
|
1638
|
+
},
|
|
1639
|
+
orderBy: { name: "asc" }
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
async function updateBlogTag(id, data) {
|
|
1643
|
+
return prisma.blogTag.update({
|
|
1644
|
+
where: { id },
|
|
1645
|
+
data
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
async function deleteBlogTag(id) {
|
|
1649
|
+
return prisma.blogTag.delete({
|
|
1650
|
+
where: { id }
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
async function countBlogTags(where) {
|
|
1654
|
+
return prisma.blogTag.count({ where });
|
|
1655
|
+
}
|
|
1656
|
+
async function getBlogTagWithPostCount(id) {
|
|
1657
|
+
return prisma.blogTag.findUnique({
|
|
1658
|
+
where: { id },
|
|
1659
|
+
include: {
|
|
1660
|
+
_count: {
|
|
1661
|
+
select: { posts: true }
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
});
|
|
1665
|
+
}
|
|
1666
|
+
async function getBlogTagsWithPostCounts() {
|
|
1667
|
+
return prisma.blogTag.findMany({
|
|
1668
|
+
include: {
|
|
1669
|
+
_count: {
|
|
1670
|
+
select: { posts: true }
|
|
1671
|
+
}
|
|
1672
|
+
},
|
|
1673
|
+
orderBy: { name: "asc" }
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1409
1676
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1410
1677
|
0 && (module.exports = {
|
|
1678
|
+
MAX_API_KEYS_PER_USER,
|
|
1411
1679
|
applyRDDecayForInactivePlayers,
|
|
1412
1680
|
connect,
|
|
1681
|
+
countBlogPosts,
|
|
1682
|
+
countBlogTags,
|
|
1413
1683
|
countEntries,
|
|
1414
1684
|
countLocations,
|
|
1415
1685
|
countMatches,
|
|
1416
1686
|
countOpprPlayerRankings,
|
|
1417
1687
|
countOpprRankingHistory,
|
|
1418
1688
|
countPlayers,
|
|
1689
|
+
countPublishedBlogPosts,
|
|
1419
1690
|
countRounds,
|
|
1420
1691
|
countStandings,
|
|
1421
1692
|
countTournaments,
|
|
1693
|
+
countUserApiKeys,
|
|
1422
1694
|
countUsers,
|
|
1695
|
+
createApiKey,
|
|
1696
|
+
createBlogPost,
|
|
1697
|
+
createBlogTag,
|
|
1423
1698
|
createEntry,
|
|
1424
1699
|
createLocation,
|
|
1425
1700
|
createManyEntries,
|
|
@@ -1435,6 +1710,9 @@ async function getLocationWithTournaments(id) {
|
|
|
1435
1710
|
createTournament,
|
|
1436
1711
|
createUser,
|
|
1437
1712
|
createUserWithPlayer,
|
|
1713
|
+
deleteApiKey,
|
|
1714
|
+
deleteBlogPost,
|
|
1715
|
+
deleteBlogTag,
|
|
1438
1716
|
deleteEntriesByMatch,
|
|
1439
1717
|
deleteEntry,
|
|
1440
1718
|
deleteLocation,
|
|
@@ -1449,7 +1727,16 @@ async function getLocationWithTournaments(id) {
|
|
|
1449
1727
|
deleteStandingsByTournament,
|
|
1450
1728
|
deleteTournament,
|
|
1451
1729
|
deleteUser,
|
|
1730
|
+
deleteUserApiKey,
|
|
1452
1731
|
disconnect,
|
|
1732
|
+
findApiKeyById,
|
|
1733
|
+
findApiKeysByPrefix,
|
|
1734
|
+
findBlogPostById,
|
|
1735
|
+
findBlogPostBySlug,
|
|
1736
|
+
findBlogPosts,
|
|
1737
|
+
findBlogTagById,
|
|
1738
|
+
findBlogTagBySlug,
|
|
1739
|
+
findBlogTags,
|
|
1453
1740
|
findEntries,
|
|
1454
1741
|
findEntryById,
|
|
1455
1742
|
findEntryByMatchAndPlayer,
|
|
@@ -1466,6 +1753,7 @@ async function getLocationWithTournaments(id) {
|
|
|
1466
1753
|
findPlayerByPlayerNumber,
|
|
1467
1754
|
findPlayerByUserEmail,
|
|
1468
1755
|
findPlayers,
|
|
1756
|
+
findPublishedBlogPosts,
|
|
1469
1757
|
findRoundById,
|
|
1470
1758
|
findRoundByTournamentAndNumber,
|
|
1471
1759
|
findRounds,
|
|
@@ -1479,6 +1767,8 @@ async function getLocationWithTournaments(id) {
|
|
|
1479
1767
|
findUserById,
|
|
1480
1768
|
findUsers,
|
|
1481
1769
|
generateUniquePlayerNumber,
|
|
1770
|
+
getBlogTagWithPostCount,
|
|
1771
|
+
getBlogTagsWithPostCounts,
|
|
1482
1772
|
getFinalsRounds,
|
|
1483
1773
|
getFinalsStandings,
|
|
1484
1774
|
getLatestOpprRankingHistory,
|
|
@@ -1514,16 +1804,22 @@ async function getLocationWithTournaments(id) {
|
|
|
1514
1804
|
getTournamentWithResults,
|
|
1515
1805
|
getTournamentsByBoosterType,
|
|
1516
1806
|
getTournamentsByDateRange,
|
|
1807
|
+
getUserApiKeys,
|
|
1517
1808
|
getUserByEmailWithPlayer,
|
|
1518
1809
|
getUserWithPlayer,
|
|
1519
1810
|
isValidPlayerNumber,
|
|
1520
1811
|
linkPlayerToUser,
|
|
1521
1812
|
prisma,
|
|
1522
1813
|
recalculateTimeDecay,
|
|
1814
|
+
searchBlogPosts,
|
|
1815
|
+
searchBlogTags,
|
|
1523
1816
|
searchLocations,
|
|
1524
1817
|
searchPlayers,
|
|
1525
1818
|
searchTournaments,
|
|
1526
1819
|
testConnection,
|
|
1820
|
+
updateApiKeyLastUsed,
|
|
1821
|
+
updateBlogPost,
|
|
1822
|
+
updateBlogTag,
|
|
1527
1823
|
updateEntry,
|
|
1528
1824
|
updateLocation,
|
|
1529
1825
|
updateMatch,
|