Closed hugil closed 1 year ago
I submitted a PR #101 to resolve this. The interface did only allow string as data type for my prisma session model.
I'm not sure what code or type changes need to be made, but I was able to get this working with type json
by doing the following:
schema.prisma
model Session {
id String @id
sid String @unique
data Json
expiresAt DateTime
}
and in the middleware:
store: new PrismaSessionStore(
// @ts-ignore
new PrismaClient(),
{
serializer: {
// @ts-ignore
stringify: value => value,
// @ts-ignore
parse: value => value,
},
}
),
Obviously adding ts-ignore
s everywhere isn't great, but it at least unblocks me (and may be helpful for others).
Essentially, I'm just disabling serialization and ignoring the fact that prisma-session-store
is expecting data
to be a string
Hi @jessethomson - thanks for pointing this out.
We've actually got a PR in the works to address this, but it hasn't landed yet. Good to know you've got a work-around in the meantime, though.
-K
@hugil, @jessethomson - is still a problem? I'm currently using prisma
4.3.0, with prisma-session-store
3.1.9, and not encountering any type issues related to string vs. json, using:
const sessionStore = new PrismaSessionStore(
prisma,
{
checkPeriod: 2 * 60 * 1000, //ms
dbRecordIdIsSessionId: true,
dbRecordIdFunction: undefined,
logger:console,
loggerLevel:'log',
}
)
According to Prisma's database features table, not all dbs support json as a type - which suggests that where the db is concerned, we should probably stick with the lowest common denominator (string
) as the default, so as not to exclude users of unsupported dbs - even though @hugil I agree, json would provide greater type safety.
But just to double check: Are you still experiencing this issue, with the latest published versions of prisma
, and prisma-session-store
?
As I'm not seeing the issue, using the examples given above, I'm going to assume this is resolved, for the moment. Feel free to post/re-open, if I'm wrong here.
I can confirm this is happening with the following packages:
"@prisma/client": "3.15.2",
"@quixo3/prisma-session-store": "^3.1.10",
The error I get from eslint is the following:
typescript: Argument of type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>' is not assignable to parameter of type 'IPrisma<"session">'.
Property 'session' is missing in type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>' but required in type 'Record<"session", { create(args: ICreateArgs): Promise<IPrismaSession>; delete(args: IDeleteArgs): Promise<IPrismaSession>; deleteMany(args?: unknown): Promise<...>; findMany(args?: IFindManyArgs | undefined): Promise<...>; findUnique(args: IFindUniqueArgs): Promise<...>; update(args: IUpdateArgs): Promise<...>; }>'.
@pixelprogrammer - thanks; appreciate the additional "data point" here...
Cancel that. I didn't read the documentation properly.
I forgot to add this and then do a prisma generate:
model Session {
id String @id
sid String @unique
data String
expiresAt DateTime
}
Thats what adds the session
property thats missing. I am a doofus.
No worries - the error message you posted above will almost certainly help the next person who goes down the same path.
Since updating Prisma we seem to have a type error.
package.json
app.ts