shadow_aya
shadow_aya15mo ago

Query typing malfunction

I've got an issue where the destroy method from my session store doesn't work. Upon further inspection, I found out that one of my Convex functions returns random values (table entries with seemingly valid data that don't exist in reality). I cleared my siteSessions table, and still got results for non-existent documents. Even when there are results, _id is in mismatch. My other tables are small enough as of now that I even checked elsewhere, and the logged _id was nowhere to be found. I'm not sure why this is happening, all my code is attached. I hope I made a stupid mistake or overlooked something rather than there being an underlying issue. Note that I deleted some documents by hand, but I don't think that should have any effect. session.Store#destroy method
class ConvexSiteSessionStore extends session.Store {

// ...

destroy(sid: string, callback?: ((err?: any) => void) | undefined) {

convex.query(api.siteSessions.findBySid, {sid: sid}).then((session) => {

console.log(session); // logging here

if (!session) callback();
else convex.mutation(api.siteSessions.remove, {id: session._id}).then(() => {
callback();
}).catch((err) => {
callback(err);
});
}).catch((err) => {
callback(err);
});

}
}
class ConvexSiteSessionStore extends session.Store {

// ...

destroy(sid: string, callback?: ((err?: any) => void) | undefined) {

convex.query(api.siteSessions.findBySid, {sid: sid}).then((session) => {

console.log(session); // logging here

if (!session) callback();
else convex.mutation(api.siteSessions.remove, {id: session._id}).then(() => {
callback();
}).catch((err) => {
callback(err);
});
}).catch((err) => {
callback(err);
});

}
}
siteSessions#findBySid Convex function
export const findBySid = query({
args: {
sid: v.string(),
},
async handler(ctx, args) {
return await ctx.db
.query("siteSessions")
.withIndex("by_sid") // also tried without the index
.filter((q) =>
q.eq(q.field("sid"), args.sid)
)
.first();
},
});
export const findBySid = query({
args: {
sid: v.string(),
},
async handler(ctx, args) {
return await ctx.db
.query("siteSessions")
.withIndex("by_sid") // also tried without the index
.filter((q) =>
q.eq(q.field("sid"), args.sid)
)
.first();
},
});
siteSessions table schema
siteSessions: defineTable({
sid: v.string(),
data: v.string(),
expires: v.number(),
})
.index("by_sid", ["sid"])
siteSessions: defineTable({
sid: v.string(),
data: v.string(),
expires: v.number(),
})
.index("by_sid", ["sid"])
8 Replies
shadow_aya
shadow_ayaOP15mo ago
it gets more confusing the more I look into it
shadow_aya
shadow_ayaOP15mo ago
here's another query in use, with the return type of the document
No description
shadow_aya
shadow_ayaOP15mo ago
but the query in its definition also returns null, obviously because it could find nothing
No description
shadow_aya
shadow_ayaOP15mo ago
Nevermind, I just found out a session gets rapidly created, logged, and deleted. Sorry! But I still don't understand why the return type doesn't include null, when the query could find nothing
lee
lee15mo ago
that's weird, it doesn't repro for me on the default settings. but i can repro if i set strictNullChecks to false. what is your project's tsconfig? i don't especially like the behavior, but it seems reasonable-ish to strip null from the inferred type if typescript is ignoring null anyway.
No description
No description
shadow_aya
shadow_ayaOP15mo ago
just left my pc, will report back tomorrow
{
"compilerOptions": {
"allowJs": true,
"outDir": "../../serverDist",
"module": "NodeNext",
"target": "es6",
"esModuleInterop": true,
"typeRoots": ["../../typings"],
"lib": ["es2021"]
},
"include": [
"./**/*.ts",
"../../typings/**/*.ts",
"../../convex/**/*.*",
"../../convex/*.*"
],
}
{
"compilerOptions": {
"allowJs": true,
"outDir": "../../serverDist",
"module": "NodeNext",
"target": "es6",
"esModuleInterop": true,
"typeRoots": ["../../typings"],
"lib": ["es2021"]
},
"include": [
"./**/*.ts",
"../../typings/**/*.ts",
"../../convex/**/*.*",
"../../convex/*.*"
],
}
this is my tsconfig didn't change strictNullChecks, let me try strict oh.. yep, that's it thanks for the tip
lee
lee15mo ago
interesting, thanks for sharing. We'll look into why this tsconfig might strip nulls
shadow_aya
shadow_ayaOP15mo ago
:ScaraNod: (this particularly confused me because a part of my monorepo has this particular tsconfig, while the rest has NextJS's generated one, and I forgot about strict)

Did you find this page helpful?