WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit fa41147

Browse files
committed
docs(changeset):
fix: 5.8.3 is preferred Typescript version rn fix: added error handling to filesWithTags. improved query consitency
1 parent a7e80c7 commit fa41147

File tree

5 files changed

+48
-56
lines changed

5 files changed

+48
-56
lines changed

.changeset/soft-chicken-work.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nimbus/server": patch
3+
---
4+
5+
fix: 5.8.3 is preferred Typescript version rn fix: added error handling to filesWithTags. improved query consitency

apps/server/src/routes/files/file-service.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ export class FileService {
4343
return null;
4444
}
4545

46-
// Add tags to files
46+
// Add tags to files, handling any tag retrieval failures
4747
const filesWithTags = await Promise.all(
4848
res.items.map(async item => {
4949
if (!item.id) return { ...item, tags: [] };
50-
const tags = await this.tagService.getFileTags(item.id, user.id);
51-
return { ...item, tags };
50+
try {
51+
const tags = await this.tagService.getFileTags(item.id, user.id);
52+
return { ...item, tags };
53+
} catch (error) {
54+
console.error(`Failed to get tags for file ${item.id}:`, error);
55+
return { ...item, tags: [] };
56+
}
5257
})
5358
);
5459

apps/server/src/routes/tags/tag-service.ts

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export class TagService {
1616
// Get all tags for a user with file counts
1717
async getUserTags(userId: string): Promise<Tag[]> {
1818
// Get all tags for the user
19-
const userTags = await this.c.var.db.select().from(tag).where(eq(tag.userId, userId)).orderBy(tag.name);
19+
const userTags = await this.c.var.db.query.tag.findMany({
20+
where: (table, { eq }) => eq(table.userId, userId),
21+
orderBy: (table, { asc }) => asc(table.name),
22+
});
2023

2124
// Get file counts for each tag
2225
const tagsWithCounts = await Promise.all(
@@ -42,22 +45,17 @@ export class TagService {
4245

4346
// Get a specific tag by ID
4447
async getTagById(tagId: string, userId: string): Promise<Tag | null> {
45-
const tagRecord = await this.c.var.db
46-
.select()
47-
.from(tag)
48-
.where(and(eq(tag.id, tagId), eq(tag.userId, userId)))
49-
.limit(1);
48+
const record = await this.c.var.db.query.tag.findFirst({
49+
where: (table, { and, eq }) => and(eq(table.id, tagId), eq(table.userId, userId)),
50+
});
5051

51-
if (!tagRecord.length) return null;
52+
if (!record) return null;
5253

5354
const fileCount = await this.c.var.db
5455
.select({ count: count() })
5556
.from(fileTag)
5657
.where(and(eq(fileTag.tagId, tagId), eq(fileTag.userId, userId)));
5758

58-
const record = tagRecord[0];
59-
if (!record) return null;
60-
6159
return {
6260
id: record.id,
6361
name: record.name,
@@ -85,9 +83,11 @@ export class TagService {
8583
? and(eq(tag.name, name), eq(tag.userId, userId), eq(tag.parentId, parentId))
8684
: and(eq(tag.name, name), eq(tag.userId, userId), isNull(tag.parentId));
8785

88-
const existingTag = await this.c.var.db.select().from(tag).where(existingTagQuery).limit(1);
86+
const existingTag = await this.c.var.db.query.tag.findFirst({
87+
where: existingTagQuery,
88+
});
8989

90-
if (existingTag.length > 0) {
90+
if (existingTag) {
9191
throw new Error("Tag with this name already exists");
9292
}
9393

@@ -140,9 +140,11 @@ export class TagService {
140140
? and(eq(tag.name, updates.name), eq(tag.userId, userId), eq(tag.parentId, newParentId))
141141
: and(eq(tag.name, updates.name), eq(tag.userId, userId), isNull(tag.parentId));
142142

143-
const nameConflict = await this.c.var.db.select().from(tag).where(nameConflictQuery).limit(1);
143+
const nameConflict = await this.c.var.db.query.tag.findFirst({
144+
where: nameConflictQuery,
145+
});
144146

145-
if (nameConflict.length > 0) {
147+
if (nameConflict) {
146148
throw new Error("Tag with this name already exists");
147149
}
148150
}
@@ -191,10 +193,10 @@ export class TagService {
191193
}
192194

193195
// Check for existing associations
194-
const existingAssociations = await this.c.var.db
195-
.select()
196-
.from(fileTag)
197-
.where(and(eq(fileTag.fileId, fileId), inArray(fileTag.tagId, tagIds), eq(fileTag.userId, userId)));
196+
const existingAssociations = await this.c.var.db.query.fileTag.findMany({
197+
where: (table, { and, eq, inArray }) =>
198+
and(eq(table.fileId, fileId), inArray(table.tagId, tagIds), eq(table.userId, userId)),
199+
});
198200

199201
const existingTagIds = existingAssociations.map(assoc => assoc.tagId);
200202
const newTagIds = tagIds.filter(tagId => !existingTagIds.includes(tagId));
@@ -239,21 +241,17 @@ export class TagService {
239241

240242
// Get all tags for a specific file
241243
async getFileTags(fileId: string, userId: string): Promise<Tag[]> {
242-
const fileTagAssociations = await this.c.var.db
243-
.select({
244-
tagId: fileTag.tagId,
245-
})
246-
.from(fileTag)
247-
.where(and(eq(fileTag.fileId, fileId), eq(fileTag.userId, userId)));
244+
const fileTagAssociations = await this.c.var.db.query.fileTag.findMany({
245+
where: (table, { and, eq }) => and(eq(table.fileId, fileId), eq(table.userId, userId)),
246+
});
248247

249248
const tagIds = fileTagAssociations.map(assoc => assoc.tagId);
250249

251250
if (tagIds.length === 0) return [];
252251

253-
const tags = await this.c.var.db
254-
.select()
255-
.from(tag)
256-
.where(and(inArray(tag.id, tagIds), eq(tag.userId, userId)));
252+
const tags = await this.c.var.db.query.tag.findMany({
253+
where: (table, { and, inArray, eq }) => and(inArray(table.id, tagIds), eq(table.userId, userId)),
254+
});
257255

258256
return tags.map(tagRecord => ({
259257
...tagRecord,
@@ -265,10 +263,9 @@ export class TagService {
265263

266264
// Get all child tag IDs recursively
267265
private async getAllChildTagIds(parentId: string, userId: string): Promise<string[]> {
268-
const childTags = await this.c.var.db
269-
.select({ id: tag.id })
270-
.from(tag)
271-
.where(and(eq(tag.parentId, parentId), eq(tag.userId, userId)));
266+
const childTags = await this.c.var.db.query.tag.findMany({
267+
where: (table, { and, eq }) => and(eq(table.parentId, parentId), eq(table.userId, userId)),
268+
});
272269

273270
const childIds = childTags.map(tag => tag.id);
274271
const grandChildIds = await Promise.all(childIds.map(childId => this.getAllChildTagIds(childId, userId)));

apps/server/src/routes/waitlist/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { sendError, sendSuccess } from "../utils";
33
import { zValidator } from "@hono/zod-validator";
44
import { createPublicRouter } from "../../hono";
55
import { waitlist } from "@nimbus/db/schema";
6-
import { count, eq } from "drizzle-orm";
6+
import { count } from "drizzle-orm";
77
import { nanoid } from "nanoid";
88

99
const waitlistRouter = createPublicRouter()
@@ -29,12 +29,9 @@ const waitlistRouter = createPublicRouter()
2929
try {
3030
const email = c.req.valid("json").email;
3131

32-
const existing = await c.var.db
33-
.select()
34-
.from(waitlist)
35-
.where(eq(waitlist.email, email.toLowerCase().trim()))
36-
.limit(1)
37-
.then(rows => rows[0]);
32+
const existing = await c.var.db.query.waitlist.findFirst({
33+
where: (table, { eq }) => eq(table.email, email.toLowerCase().trim()),
34+
});
3835

3936
if (existing) {
4037
return sendError(c, { message: "This email is already on the waitlist", status: 400 });

bun.lock

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@
937937

938938
"@tanstack/query-core": ["@tanstack/[email protected]", "", {}, "sha512-OG69LQgT7jSp+5pPuCfzltq/+7l2xoweggjme9vlbCPa/d7D7zaqv5vN/S82SzSYZ4EDLTxNO1PWrv49RAS64Q=="],
939939

940-
"@tanstack/react-query": ["@tanstack/react-query@5.83.1", "", { "dependencies": { "@tanstack/query-core": "5.83.1" }, "peerDependencies": { "react": "^18 || ^19" } }, "sha512-JHZ3xox3p0sqCgM7ykBRtMWSLmWgjR7I+oJMAZ1beK/O/gfShI2b/PdovL2/ivVLUZklXgBenQu4ZjPhIM+yrw=="],
940+
"@tanstack/react-query": ["@tanstack/react-query@5.84.0", "", { "dependencies": { "@tanstack/query-core": "5.83.1" }, "peerDependencies": { "react": "^18 || ^19" } }, "sha512-iPycFGLq5lltDE16Jf13Nx7SOvtfoopfOH/+Ahbdd+z4QqOfYu/SOkY86AVYVcKjneuqPxTm8e85lSGhwe0cog=="],
941941

942942
"@tanstack/react-table": ["@tanstack/[email protected]", "", { "dependencies": { "@tanstack/table-core": "8.21.3" }, "peerDependencies": { "react": ">=16.8", "react-dom": ">=16.8" } }, "sha512-5nNMTSETP4ykGegmVkhjcS8tTLW6Vl4axfEGQN3v0zdHYbK4UfoqfPChclTrJ4EoK9QynqAu9oUf8VEmrpZ5Ww=="],
943943

@@ -2229,7 +2229,7 @@
22292229

22302230
"typed-array-length": ["[email protected]", "", { "dependencies": { "call-bind": "^1.0.7", "for-each": "^0.3.3", "gopd": "^1.0.1", "is-typed-array": "^1.1.13", "possible-typed-array-names": "^1.0.0", "reflect.getprototypeof": "^1.0.6" } }, "sha512-3KS2b+kL7fsuk/eJZ7EQdnEmQoaho/r6KUef7hxvltNA5DR8NAUM+8wJMbJyZ4G9/7i3v5zPBIMN5aybAh2/Jg=="],
22312231

2232-
"typescript": ["typescript@5.9.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A=="],
2232+
"typescript": ["typescript@5.8.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A=="],
22332233

22342234
"typescript-eslint": ["[email protected]", "", { "dependencies": { "@typescript-eslint/eslint-plugin": "8.38.0", "@typescript-eslint/parser": "8.38.0", "@typescript-eslint/typescript-estree": "8.38.0", "@typescript-eslint/utils": "8.38.0" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-FsZlrYK6bPDGoLeZRuvx2v6qrM03I0U0SnfCLPs/XCCPCFD80xU9Pg09H/K+XFa68uJuZo7l/Xhs+eDRg2l3hg=="],
22352235

@@ -2345,12 +2345,8 @@
23452345

23462346
"@aws-crypto/sha1-browser/@aws-sdk/types": ["@aws-sdk/[email protected]", "", { "dependencies": { "@smithy/types": "^4.3.1", "tslib": "^2.6.2" } }, "sha512-xliuHaUFZxEx1NSXeLLZ9Dyu6+EJVQKEoD+yM+zqUo3YDZ7medKJWY6fIOKiPX/N7XbLdBYwajb15Q7IL8KkeA=="],
23472347

2348-
"@aws-crypto/sha256-browser/@aws-sdk/types": ["@aws-sdk/[email protected]", "", { "dependencies": { "@smithy/types": "^4.3.1", "tslib": "^2.6.2" } }, "sha512-xliuHaUFZxEx1NSXeLLZ9Dyu6+EJVQKEoD+yM+zqUo3YDZ7medKJWY6fIOKiPX/N7XbLdBYwajb15Q7IL8KkeA=="],
2349-
23502348
"@aws-crypto/sha256-browser/tslib": ["[email protected]", "", {}, "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="],
23512349

2352-
"@aws-crypto/sha256-js/@aws-sdk/types": ["@aws-sdk/[email protected]", "", { "dependencies": { "@smithy/types": "^4.3.1", "tslib": "^2.6.2" } }, "sha512-xliuHaUFZxEx1NSXeLLZ9Dyu6+EJVQKEoD+yM+zqUo3YDZ7medKJWY6fIOKiPX/N7XbLdBYwajb15Q7IL8KkeA=="],
2353-
23542350
"@aws-crypto/sha256-js/tslib": ["[email protected]", "", {}, "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="],
23552351

23562352
"@aws-crypto/supports-web-crypto/tslib": ["[email protected]", "", {}, "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="],
@@ -3083,14 +3079,6 @@
30833079

30843080
"@aws-crypto/sha1-browser/@aws-sdk/types/@smithy/types": ["@smithy/[email protected]", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-UqKOQBL2x6+HWl3P+3QqFD4ncKq0I8Nuz9QItGv5WuKuMHuuwlhvqcZCoXGfc+P1QmfJE7VieykoYYmrOoFJxA=="],
30853081

3086-
"@aws-crypto/sha256-browser/@aws-sdk/types/@smithy/types": ["@smithy/[email protected]", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-UqKOQBL2x6+HWl3P+3QqFD4ncKq0I8Nuz9QItGv5WuKuMHuuwlhvqcZCoXGfc+P1QmfJE7VieykoYYmrOoFJxA=="],
3087-
3088-
"@aws-crypto/sha256-browser/@aws-sdk/types/tslib": ["[email protected]", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
3089-
3090-
"@aws-crypto/sha256-js/@aws-sdk/types/@smithy/types": ["@smithy/[email protected]", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-UqKOQBL2x6+HWl3P+3QqFD4ncKq0I8Nuz9QItGv5WuKuMHuuwlhvqcZCoXGfc+P1QmfJE7VieykoYYmrOoFJxA=="],
3091-
3092-
"@aws-crypto/sha256-js/@aws-sdk/types/tslib": ["[email protected]", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
3093-
30943082
"@aws-crypto/util/@aws-sdk/types/@smithy/types": ["@smithy/[email protected]", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-UqKOQBL2x6+HWl3P+3QqFD4ncKq0I8Nuz9QItGv5WuKuMHuuwlhvqcZCoXGfc+P1QmfJE7VieykoYYmrOoFJxA=="],
30953083

30963084
"@aws-crypto/util/@aws-sdk/types/tslib": ["[email protected]", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],

0 commit comments

Comments
 (0)