@ravxd/velocitydb 0.1.0 → 0.1.2
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 +271 -0
- package/dist/index.d.cts +1218 -0
- package/dist/index.d.ts +1218 -0
- package/dist/index.js +235 -0
- package/package.json +14 -2
- package/.env.example +0 -1
- package/bun.lock +0 -211
- package/drizzle/0000_bright_tony_stark.sql +0 -74
- package/drizzle/meta/0000_snapshot.json +0 -564
- package/drizzle/meta/_journal.json +0 -13
- package/drizzle.config.ts +0 -11
- package/src/client.ts +0 -25
- package/src/helpers.ts +0 -43
- package/src/index.ts +0 -3
- package/src/schema.ts +0 -142
- package/tsconfig.json +0 -13
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
afkEntries: () => afkEntries,
|
|
34
|
+
authAccounts: () => authAccounts,
|
|
35
|
+
authSessions: () => authSessions,
|
|
36
|
+
authUsers: () => authUsers,
|
|
37
|
+
authVerificationTokens: () => authVerificationTokens,
|
|
38
|
+
characters: () => characters,
|
|
39
|
+
formatWeekRange: () => formatWeekRange,
|
|
40
|
+
getCurrentWeekStart: () => getCurrentWeekStart,
|
|
41
|
+
getDb: () => getDb,
|
|
42
|
+
getWeekStart: () => getWeekStart,
|
|
43
|
+
linkStatusEnum: () => linkStatusEnum,
|
|
44
|
+
memberRoleEnum: () => memberRoleEnum,
|
|
45
|
+
members: () => members,
|
|
46
|
+
requestStatusEnum: () => requestStatusEnum,
|
|
47
|
+
requests: () => requests,
|
|
48
|
+
syncState: () => syncState,
|
|
49
|
+
weekStartToString: () => weekStartToString
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(index_exports);
|
|
52
|
+
|
|
53
|
+
// src/schema.ts
|
|
54
|
+
var schema_exports = {};
|
|
55
|
+
__export(schema_exports, {
|
|
56
|
+
afkEntries: () => afkEntries,
|
|
57
|
+
authAccounts: () => authAccounts,
|
|
58
|
+
authSessions: () => authSessions,
|
|
59
|
+
authUsers: () => authUsers,
|
|
60
|
+
authVerificationTokens: () => authVerificationTokens,
|
|
61
|
+
characters: () => characters,
|
|
62
|
+
linkStatusEnum: () => linkStatusEnum,
|
|
63
|
+
memberRoleEnum: () => memberRoleEnum,
|
|
64
|
+
members: () => members,
|
|
65
|
+
requestStatusEnum: () => requestStatusEnum,
|
|
66
|
+
requests: () => requests,
|
|
67
|
+
syncState: () => syncState
|
|
68
|
+
});
|
|
69
|
+
var import_pg_core = require("drizzle-orm/pg-core");
|
|
70
|
+
var authUsers = (0, import_pg_core.pgTable)("user", {
|
|
71
|
+
id: (0, import_pg_core.text)("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
72
|
+
name: (0, import_pg_core.text)("name"),
|
|
73
|
+
email: (0, import_pg_core.text)("email").unique(),
|
|
74
|
+
emailVerified: (0, import_pg_core.timestamp)("emailVerified", { mode: "date" }),
|
|
75
|
+
image: (0, import_pg_core.text)("image")
|
|
76
|
+
});
|
|
77
|
+
var authAccounts = (0, import_pg_core.pgTable)(
|
|
78
|
+
"account",
|
|
79
|
+
{
|
|
80
|
+
userId: (0, import_pg_core.text)("userId").notNull().references(() => authUsers.id, { onDelete: "cascade" }),
|
|
81
|
+
type: (0, import_pg_core.text)("type").$type().notNull(),
|
|
82
|
+
provider: (0, import_pg_core.text)("provider").notNull(),
|
|
83
|
+
providerAccountId: (0, import_pg_core.text)("providerAccountId").notNull(),
|
|
84
|
+
refresh_token: (0, import_pg_core.text)("refresh_token"),
|
|
85
|
+
access_token: (0, import_pg_core.text)("access_token"),
|
|
86
|
+
expires_at: (0, import_pg_core.integer)("expires_at"),
|
|
87
|
+
token_type: (0, import_pg_core.text)("token_type"),
|
|
88
|
+
scope: (0, import_pg_core.text)("scope"),
|
|
89
|
+
id_token: (0, import_pg_core.text)("id_token"),
|
|
90
|
+
session_state: (0, import_pg_core.text)("session_state")
|
|
91
|
+
},
|
|
92
|
+
(t) => [(0, import_pg_core.primaryKey)({ columns: [t.provider, t.providerAccountId] })]
|
|
93
|
+
);
|
|
94
|
+
var authSessions = (0, import_pg_core.pgTable)("session", {
|
|
95
|
+
sessionToken: (0, import_pg_core.text)("sessionToken").primaryKey(),
|
|
96
|
+
userId: (0, import_pg_core.text)("userId").notNull().references(() => authUsers.id, { onDelete: "cascade" }),
|
|
97
|
+
expires: (0, import_pg_core.timestamp)("expires", { mode: "date" }).notNull()
|
|
98
|
+
});
|
|
99
|
+
var authVerificationTokens = (0, import_pg_core.pgTable)(
|
|
100
|
+
"verificationToken",
|
|
101
|
+
{
|
|
102
|
+
identifier: (0, import_pg_core.text)("identifier").notNull(),
|
|
103
|
+
token: (0, import_pg_core.text)("token").notNull(),
|
|
104
|
+
expires: (0, import_pg_core.timestamp)("expires", { mode: "date" }).notNull()
|
|
105
|
+
},
|
|
106
|
+
(t) => [(0, import_pg_core.primaryKey)({ columns: [t.identifier, t.token] })]
|
|
107
|
+
);
|
|
108
|
+
var memberRoleEnum = (0, import_pg_core.pgEnum)("member_role", [
|
|
109
|
+
"member",
|
|
110
|
+
"officer",
|
|
111
|
+
"guildmaster"
|
|
112
|
+
]);
|
|
113
|
+
var linkStatusEnum = (0, import_pg_core.pgEnum)("link_status", [
|
|
114
|
+
"unlinked",
|
|
115
|
+
"linked",
|
|
116
|
+
"pending"
|
|
117
|
+
// picked from unclaimed list, awaiting admin approval — reserved for future use
|
|
118
|
+
]);
|
|
119
|
+
var requestStatusEnum = (0, import_pg_core.pgEnum)("request_status", [
|
|
120
|
+
"pending",
|
|
121
|
+
"approved",
|
|
122
|
+
"rejected"
|
|
123
|
+
]);
|
|
124
|
+
var members = (0, import_pg_core.pgTable)(
|
|
125
|
+
"members",
|
|
126
|
+
{
|
|
127
|
+
id: (0, import_pg_core.uuid)("id").primaryKey().defaultRandom(),
|
|
128
|
+
discordId: (0, import_pg_core.text)("discord_id").notNull().unique(),
|
|
129
|
+
discordUsername: (0, import_pg_core.text)("discord_username").notNull(),
|
|
130
|
+
displayName: (0, import_pg_core.text)("display_name").notNull(),
|
|
131
|
+
battletag: (0, import_pg_core.text)("battletag"),
|
|
132
|
+
role: memberRoleEnum("role").notNull().default("member"),
|
|
133
|
+
isAdmin: (0, import_pg_core.boolean)("is_admin").notNull().default(false),
|
|
134
|
+
// WoWUtils link
|
|
135
|
+
wowutilsMemberId: (0, import_pg_core.text)("wowutils_member_id").unique(),
|
|
136
|
+
wowutilsAlias: (0, import_pg_core.text)("wowutils_alias"),
|
|
137
|
+
wowutilsRank: (0, import_pg_core.text)("wowutils_rank"),
|
|
138
|
+
wowutilsMainRole: (0, import_pg_core.text)("wowutils_main_role"),
|
|
139
|
+
linkStatus: linkStatusEnum("link_status").notNull().default("unlinked"),
|
|
140
|
+
createdAt: (0, import_pg_core.timestamp)("created_at").notNull().defaultNow(),
|
|
141
|
+
updatedAt: (0, import_pg_core.timestamp)("updated_at").notNull().defaultNow()
|
|
142
|
+
},
|
|
143
|
+
(t) => [(0, import_pg_core.index)("members_discord_id_idx").on(t.discordId)]
|
|
144
|
+
);
|
|
145
|
+
var characters = (0, import_pg_core.pgTable)(
|
|
146
|
+
"characters",
|
|
147
|
+
{
|
|
148
|
+
id: (0, import_pg_core.uuid)("id").primaryKey().defaultRandom(),
|
|
149
|
+
memberId: (0, import_pg_core.uuid)("member_id").notNull().references(() => members.id, { onDelete: "cascade" }),
|
|
150
|
+
name: (0, import_pg_core.text)("name").notNull(),
|
|
151
|
+
realm: (0, import_pg_core.text)("realm").notNull(),
|
|
152
|
+
class: (0, import_pg_core.text)("class").notNull(),
|
|
153
|
+
spec: (0, import_pg_core.text)("spec").notNull(),
|
|
154
|
+
status: (0, import_pg_core.text)("status").notNull().default("active"),
|
|
155
|
+
isMain: (0, import_pg_core.boolean)("is_main").notNull().default(false),
|
|
156
|
+
// Synced from WoWUtils — null if manually added
|
|
157
|
+
wowutilsCharacterId: (0, import_pg_core.text)("wowutils_character_id").unique(),
|
|
158
|
+
createdAt: (0, import_pg_core.timestamp)("created_at").notNull().defaultNow(),
|
|
159
|
+
updatedAt: (0, import_pg_core.timestamp)("updated_at").notNull().defaultNow()
|
|
160
|
+
},
|
|
161
|
+
(t) => [(0, import_pg_core.index)("characters_member_id_idx").on(t.memberId)]
|
|
162
|
+
);
|
|
163
|
+
var requests = (0, import_pg_core.pgTable)(
|
|
164
|
+
"requests",
|
|
165
|
+
{
|
|
166
|
+
id: (0, import_pg_core.uuid)("id").primaryKey().defaultRandom(),
|
|
167
|
+
memberId: (0, import_pg_core.uuid)("member_id").notNull().references(() => members.id, { onDelete: "cascade" }),
|
|
168
|
+
characterId: (0, import_pg_core.uuid)("character_id").references(() => characters.id, {
|
|
169
|
+
onDelete: "set null"
|
|
170
|
+
}),
|
|
171
|
+
// Denormalised snapshot in case character record changes later
|
|
172
|
+
characterName: (0, import_pg_core.text)("character_name").notNull(),
|
|
173
|
+
classSpec: (0, import_pg_core.text)("class_spec").notNull(),
|
|
174
|
+
notes: (0, import_pg_core.text)("notes"),
|
|
175
|
+
weekStart: (0, import_pg_core.date)("week_start").notNull(),
|
|
176
|
+
// Wednesday of the tracking week
|
|
177
|
+
status: requestStatusEnum("status").notNull().default("pending"),
|
|
178
|
+
createdAt: (0, import_pg_core.timestamp)("created_at").notNull().defaultNow(),
|
|
179
|
+
updatedAt: (0, import_pg_core.timestamp)("updated_at").notNull().defaultNow()
|
|
180
|
+
},
|
|
181
|
+
(t) => [
|
|
182
|
+
(0, import_pg_core.index)("requests_week_start_idx").on(t.weekStart),
|
|
183
|
+
(0, import_pg_core.index)("requests_member_id_idx").on(t.memberId)
|
|
184
|
+
]
|
|
185
|
+
);
|
|
186
|
+
var afkEntries = (0, import_pg_core.pgTable)(
|
|
187
|
+
"afk_entries",
|
|
188
|
+
{
|
|
189
|
+
id: (0, import_pg_core.uuid)("id").primaryKey().defaultRandom(),
|
|
190
|
+
memberId: (0, import_pg_core.uuid)("member_id").notNull().references(() => members.id, { onDelete: "cascade" }),
|
|
191
|
+
afkDate: (0, import_pg_core.date)("afk_date").notNull(),
|
|
192
|
+
notes: (0, import_pg_core.text)("notes"),
|
|
193
|
+
createdAt: (0, import_pg_core.timestamp)("created_at").notNull().defaultNow()
|
|
194
|
+
},
|
|
195
|
+
(t) => [
|
|
196
|
+
(0, import_pg_core.index)("afk_entries_member_id_idx").on(t.memberId),
|
|
197
|
+
(0, import_pg_core.index)("afk_entries_date_idx").on(t.afkDate)
|
|
198
|
+
]
|
|
199
|
+
);
|
|
200
|
+
var syncState = (0, import_pg_core.pgTable)("sync_state", {
|
|
201
|
+
id: (0, import_pg_core.uuid)("id").primaryKey().defaultRandom(),
|
|
202
|
+
lastSyncedAt: (0, import_pg_core.timestamp)("last_synced_at").notNull().defaultNow(),
|
|
203
|
+
syncedBy: (0, import_pg_core.text)("synced_by")
|
|
204
|
+
// discord username or "system"
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// src/client.ts
|
|
208
|
+
var import_postgres_js = require("drizzle-orm/postgres-js");
|
|
209
|
+
var import_postgres = __toESM(require("postgres"), 1);
|
|
210
|
+
var _db = null;
|
|
211
|
+
function getDb() {
|
|
212
|
+
if (_db) return _db;
|
|
213
|
+
const connectionString = process.env.DATABASE_URL;
|
|
214
|
+
if (!connectionString) {
|
|
215
|
+
throw new Error("DATABASE_URL environment variable is not set");
|
|
216
|
+
}
|
|
217
|
+
const client = (0, import_postgres.default)(connectionString, {
|
|
218
|
+
max: 10,
|
|
219
|
+
idle_timeout: 20,
|
|
220
|
+
connect_timeout: 10
|
|
221
|
+
});
|
|
222
|
+
_db = (0, import_postgres_js.drizzle)(client, { schema: schema_exports });
|
|
223
|
+
return _db;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/helpers.ts
|
|
227
|
+
function getWeekStart(date2 = /* @__PURE__ */ new Date()) {
|
|
228
|
+
const d = new Date(date2);
|
|
229
|
+
d.setUTCHours(0, 0, 0, 0);
|
|
230
|
+
const day = d.getUTCDay();
|
|
231
|
+
const daysSinceWed = (day + 4) % 7;
|
|
232
|
+
d.setUTCDate(d.getUTCDate() - daysSinceWed);
|
|
233
|
+
return d;
|
|
234
|
+
}
|
|
235
|
+
function weekStartToString(date2) {
|
|
236
|
+
return date2.toISOString().split("T")[0];
|
|
237
|
+
}
|
|
238
|
+
function getCurrentWeekStart(date2) {
|
|
239
|
+
return weekStartToString(getWeekStart(date2));
|
|
240
|
+
}
|
|
241
|
+
function formatWeekRange(weekStart) {
|
|
242
|
+
const start = typeof weekStart === "string" ? /* @__PURE__ */ new Date(weekStart + "T00:00:00Z") : weekStart;
|
|
243
|
+
const end = new Date(start);
|
|
244
|
+
end.setUTCDate(end.getUTCDate() + 6);
|
|
245
|
+
const fmt = new Intl.DateTimeFormat("en-US", {
|
|
246
|
+
month: "short",
|
|
247
|
+
day: "numeric",
|
|
248
|
+
timeZone: "UTC"
|
|
249
|
+
});
|
|
250
|
+
return `${fmt.format(start)} \u2013 ${fmt.format(end)}`;
|
|
251
|
+
}
|
|
252
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
253
|
+
0 && (module.exports = {
|
|
254
|
+
afkEntries,
|
|
255
|
+
authAccounts,
|
|
256
|
+
authSessions,
|
|
257
|
+
authUsers,
|
|
258
|
+
authVerificationTokens,
|
|
259
|
+
characters,
|
|
260
|
+
formatWeekRange,
|
|
261
|
+
getCurrentWeekStart,
|
|
262
|
+
getDb,
|
|
263
|
+
getWeekStart,
|
|
264
|
+
linkStatusEnum,
|
|
265
|
+
memberRoleEnum,
|
|
266
|
+
members,
|
|
267
|
+
requestStatusEnum,
|
|
268
|
+
requests,
|
|
269
|
+
syncState,
|
|
270
|
+
weekStartToString
|
|
271
|
+
});
|