Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: DrizzleSQLiteAdapter type error breaks build #1664

Open
bdrtsky opened this issue Aug 15, 2024 · 7 comments
Open

[Bug]: DrizzleSQLiteAdapter type error breaks build #1664

bdrtsky opened this issue Aug 15, 2024 · 7 comments
Labels
bug Something ain't right...

Comments

@bdrtsky
Copy link

bdrtsky commented Aug 15, 2024

Package

​@lucia-auth/session-drizzle

Describe the bug

Not sure which exactly package started to cause the issue, since I had none before, but after I removed lock file, the error appeared:

image
const adapter = new DrizzleSQLiteAdapter(db, session, user) // here's on session 

---

import { drizzle } from "drizzle-orm/libsql"
import { createClient } from "@libsql/client"
import * as schema from "@/lib/db/schema"

export const client = createClient({
  url: process.env.TURSO_CONNECTION_URL!,
  authToken: process.env.TURSO_AUTH_TOKEN!
})

export const db = drizzle(client, {
  schema
})

---

export const session = sqliteTable("session", {
  id: text("id").notNull().primaryKey(),
  userId: text("user_id")
    .notNull()
    .references(() => user.id, {
      onDelete: "cascade"
    }),
  expiresAt: integer("expires_at").notNull(),
  authenticated: integer("authenticated", { mode: "boolean" })
})
Argument of type 'SQLiteTableWithColumns<{ name: "session"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "session"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [...]; baseColumn: never; }, object>; userId: SQLiteColumn<...>; ...' is not assignable to parameter of type 'SQLiteSessionTable'.
  Type 'SQLiteTableWithColumns<{ name: "session"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "session"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [...]; baseColumn: never; }, object>; userId: SQLiteColumn<...>; ...' is not assignable to type 'SQLiteTable<{ dialect: any; columns: { id: SQLiteColumn<{ dataType: any; notNull: true; enumValues: any; tableName: any; columnType: any; data: string; driverParam: any; hasDefault: false; name: any; isPrimaryKey: any; isAutoincrement: any; hasRuntimeDefault: any; generated: any; }, object>; expiresAt: SQLiteColumn<...'.
    The types of '_.config.columns.id' are incompatible between these types.
      Type 'SQLiteColumn<{ name: "id"; tableName: "session"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, object>' is not assignable to type 'SQLiteColumn<{ dataType: any; notNull: true; enumValues: any; tableName: any; columnType: any; data: string; driverParam: any; hasDefault: false; name: any; isPrimaryKey: any; isAutoincrement: any; hasRuntimeDefault: any; generated: any; }, object>'.
        Type '{ name: "id"; tableName: "session"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }' is missing the following properties from type '{ dataType: any; notNull: true; enumValues: any; tableName: any; columnType: any; data: string; driverParam: any; hasDefault: false; name: any; isPrimaryKey: any; isAutoincrement: any; hasRuntimeDefault: any; generated: any; }': isPrimaryKey, isAutoincrement, hasRuntimeDefault, generatedts(2345)

I have no idea what is happening here, and how to fix it. Tried to lock older versions, still error.

Using next, drizzle, turso/libsql

@bdrtsky bdrtsky added the bug Something ain't right... label Aug 15, 2024
@pilcrowonpaper
Copy link
Member

This is probably because you're using an older version of Drizzle, and that's unfortunately what happens when we built stuff on top off pre-1.0 libraries. It's only a type issue right?

@bdrtsky
Copy link
Author

bdrtsky commented Aug 15, 2024

@pilcrowonpaper here I managed to find my older lock file version (it wasn't on git, duh) and reinstalled deps, now it works. Drizzle version changed from 0.31.2 to 0.31.4. Not sure if it was causing the issue (didn't found anything breaking in their Changelog). here's a diff

dependencies:
- @lucia-auth/adapter-drizzle 1.1.0
+ @lucia-auth/adapter-drizzle 1.0.7
- arctic 1.9.2
+ arctic 1.9.1
- drizzle-orm 0.31.4
+ drizzle-orm 0.31.2
- posthog-js 1.155.4
+ posthog-js 1.139.5
- posthog-node 4.1.0
+ posthog-node 4.0.1
- react 18.3.1
+ react 18.2.0
- react-dom 18.3.1
+ react-dom 18.2.0
- resend 3.5.0
+ resend 3.4.0

devDependencies:
- @types/node 20.14.15
+ @types/node 20.12.2
- @types/react 18.3.3
+ @types/react 18.2.73
- @types/react-dom 18.3.0
+ @types/react-dom 18.2.23
- autoprefixer 10.4.20
+ autoprefixer 10.4.19
- clsx 2.1.1
+ clsx 2.1.0
- esbuild-register 3.6.0
+ esbuild-register 3.5.0
- postcss 8.4.41
+ postcss 8.4.38
- tailwindcss 3.4.10
+ tailwindcss 3.4.3
- typescript 5.5.4
+ typescript 5.4.3

@bdrtsky bdrtsky closed this as completed Aug 16, 2024
@redbaron76
Copy link

redbaron76 commented Aug 26, 2024

Same problem here after upgrading @lucia-auth/adapter-drizzle" from ^1.0.7 to ^1.1.0. All others packages keep the same version, Drizzle included.

Downgrading back to ^1.0.7 fixes the type error for session table.

@bdrtsky bdrtsky reopened this Aug 26, 2024
@bdrtsky
Copy link
Author

bdrtsky commented Aug 26, 2024

I should probably reopen this, so @pilcrowonpaper could decide on closing by himself.

@iekilinc
Copy link

Probably related as downgrading from 1.1.0 to 1.0.7 also fixes this for the Postgres Drizzle adapter: #1462 (comment). It seems like these extra keys in the type definitions of the columns of *SessionTable and *UserTable are the cause of the TypeScript error:

isPrimaryKey: any;
isAutoincrement: any;
hasRuntimeDefault: any;
generated: any;

@richardvanbergen
Copy link

This is the base type for columns in

// drizzle pg-core types

export declare abstract class PgColumn<T extends ColumnBaseConfig<ColumnDataType, string> = ColumnBaseConfig<ColumnDataType, string>, TRuntimeConfig extends object = {}, TTypeConfig extends object = {}> extends Column<T, TRuntimeConfig, TTypeConfig & {
    dialect: 'pg';
}> {
    readonly table: PgTable;
    static readonly [entityKind]: string;
    constructor(table: PgTable, config: ColumnBuilderRuntimeConfig<T['data'], TRuntimeConfig>);
}

// drizzle types

export declare const entityKind: unique symbol;

export interface ColumnBuilderBaseConfig<TDataType extends ColumnDataType, TColumnType extends string> {
    name: string;
    dataType: TDataType;
    columnType: TColumnType;
    data: unknown;
    driverParam: unknown;
    enumValues: string[] | undefined;
}

export interface ColumnBaseConfig<TDataType extends ColumnDataType, TColumnType extends string> extends ColumnBuilderBaseConfig<TDataType, TColumnType> {
    tableName: string;
    notNull: boolean;
    hasDefault: boolean;
}

export declare abstract class Column<T extends ColumnBaseConfig<ColumnDataType, string> = ColumnBaseConfig<ColumnDataType, string>, TRuntimeConfig extends object = object, TTypeConfig extends object = object> implements DriverValueMapper<T['data'], T['driverParam']>, SQLWrapper {
    readonly table: Table;
    static readonly [entityKind]: string;
    readonly _: ColumnTypeConfig<T, TTypeConfig>;
    readonly name: string;
    readonly primary: boolean;
    readonly notNull: boolean;
    readonly default: T['data'] | SQL | undefined;
    readonly defaultFn: (() => T['data'] | SQL) | undefined;
    readonly onUpdateFn: (() => T['data'] | SQL) | undefined;
    readonly hasDefault: boolean;
    readonly isUnique: boolean;
    readonly uniqueName: string | undefined;
    readonly uniqueType: string | undefined;
    readonly dataType: T['dataType'];
    readonly columnType: T['columnType'];
    readonly enumValues: T['enumValues'];
    protected config: ColumnRuntimeConfig<T['data'], TRuntimeConfig>;
    constructor(table: Table, config: ColumnRuntimeConfig<T['data'], TRuntimeConfig>);
    abstract getSQLType(): string;
    mapFromDriverValue(value: unknown): unknown;
    mapToDriverValue(value: unknown): unknown;
}

And the type definition for the adapter is

PgColumn<{
  dataType: any;
  notNull: true;
  enumValues: any;
  tableName: any;
  columnType: any;
  data: string;
  driverParam: any;
  hasDefault: false;
  name: any;
  isPrimaryKey: any;
  isAutoincrement: any;
  hasRuntimeDefault: any;
  generated: any;
}, object>;

So yep it's just some extra fields that don't exist on T which should extend ColumnBaseConfig and ColumnBuilderBaseConfig.

Looking at the constraints in @lucia-auth/adapter-drizzle it's specifying "drizzle-orm": ">= 0.29 <1" and my version is at 0.31.2. I'm guessing one of the 0.3x.x releases changed they types around a bit.

@jxh0414com
Copy link

jxh0414com commented Sep 30, 2024

  id: text("id").primaryKey(),
  userId: text("user_id")
    .notNull()
    .references(() => user.id, {
      onDelete: "cascade"
    }),
  expiresAt: integer("expires_at").notNull(),
})

i fixed this by removing notNull() from id, (with latest drizzle-orm and latest adapter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something ain't right...
Projects
None yet
Development

No branches or pull requests

6 participants