Skip to content

Commit

Permalink
revert type declaration change
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper committed Dec 26, 2023
1 parent f7be3c7 commit 0038982
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 142 deletions.
9 changes: 0 additions & 9 deletions packages/adapter-drizzle/tests/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,3 @@ await connection.execute("DROP TABLE IF EXISTS user_session");
await connection.execute("DROP TABLE IF EXISTS test_user");

process.exit();

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}
9 changes: 0 additions & 9 deletions packages/adapter-drizzle/tests/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,3 @@ await pool.query("DROP TABLE public.session");
await pool.query("DROP TABLE public.user");

process.exit();

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}
9 changes: 0 additions & 9 deletions packages/adapter-drizzle/tests/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,3 @@ const db = drizzle(sqliteDB);
const adapter = new DrizzleSQLiteAdapter(db, sessionTable, userTable);

await testAdapter(adapter);

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}
8 changes: 4 additions & 4 deletions packages/adapter-mongodb/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type {
Adapter,
DatabaseSession,
DatabaseSessionAttributes,
RegisteredDatabaseSessionAttributes,
DatabaseUser,
DatabaseUserAttributes
RegisteredDatabaseUserAttributes
} from "lucia";
import { Collection } from "mongodb";

interface UserDoc extends DatabaseUserAttributes {
interface UserDoc extends RegisteredDatabaseUserAttributes {
_id: string;
__v?: any;
}

interface SessionDoc extends DatabaseSessionAttributes {
interface SessionDoc extends RegisteredDatabaseSessionAttributes {
_id: string;
__v?: any;
user_id: string;
Expand Down
8 changes: 4 additions & 4 deletions packages/adapter-mysql/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {
Adapter,
DatabaseSession,
DatabaseSessionAttributes,
RegisteredDatabaseSessionAttributes,
DatabaseUser,
DatabaseUserAttributes
RegisteredDatabaseUserAttributes
} from "lucia";

export class MySQLAdapter implements Adapter {
Expand Down Expand Up @@ -106,13 +106,13 @@ export interface Controller {
getAll<T>(sql: string, args: any[]): Promise<T[]>;
}

interface SessionSchema extends DatabaseSessionAttributes {
interface SessionSchema extends RegisteredDatabaseSessionAttributes {
id: string;
user_id: string;
expires_at: Date | string;
}

interface UserSchema extends DatabaseUserAttributes {
interface UserSchema extends RegisteredDatabaseUserAttributes {
id: string;
}

Expand Down
9 changes: 0 additions & 9 deletions packages/adapter-mysql/tests/mysql2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,3 @@ await connection.execute("DROP TABLE IF EXISTS user_session");
await connection.execute("DROP TABLE IF EXISTS test_user");

process.exit();

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}
9 changes: 0 additions & 9 deletions packages/adapter-mysql/tests/planetscale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,3 @@ await connection.execute("DROP TABLE IF EXISTS user_session");
await connection.execute("DROP TABLE IF EXISTS test_user");

process.exit();

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}
8 changes: 4 additions & 4 deletions packages/adapter-postgresql/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {
Adapter,
DatabaseSession,
DatabaseSessionAttributes,
RegisteredDatabaseSessionAttributes,
DatabaseUser,
DatabaseUserAttributes
RegisteredDatabaseUserAttributes
} from "lucia";

export class PostgreSQLAdapter implements Adapter {
Expand Down Expand Up @@ -109,13 +109,13 @@ export interface Controller {
getAll<T extends {}>(sql: string, args: any[]): Promise<T[]>;
}

interface SessionSchema extends DatabaseSessionAttributes {
interface SessionSchema extends RegisteredDatabaseSessionAttributes {
id: string;
user_id: string;
expires_at: Date;
}

interface UserSchema extends DatabaseUserAttributes {
interface UserSchema extends RegisteredDatabaseUserAttributes {
id: string;
}

Expand Down
9 changes: 0 additions & 9 deletions packages/adapter-postgresql/tests/node-postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,3 @@ await pool.query("DROP TABLE public.session");
await pool.query("DROP TABLE public.user");

process.exit();

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}
9 changes: 0 additions & 9 deletions packages/adapter-postgresql/tests/postgresjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,3 @@ await sql`DROP TABLE public.session`;
await sql`DROP TABLE public.user`;

process.exit();

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}
8 changes: 4 additions & 4 deletions packages/adapter-prisma/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {
Adapter,
DatabaseSession,
DatabaseSessionAttributes,
RegisteredDatabaseSessionAttributes,
DatabaseUser,
DatabaseUserAttributes
RegisteredDatabaseUserAttributes
} from "lucia";

export class PrismaAdapter<_PrismaClient extends PrismaClient> implements Adapter {
Expand Down Expand Up @@ -112,11 +112,11 @@ interface PrismaClient {
$transaction: any;
}

interface UserSchema extends DatabaseUserAttributes {
interface UserSchema extends RegisteredDatabaseUserAttributes {
id: string;
}

interface SessionSchema extends DatabaseSessionAttributes {
interface SessionSchema extends RegisteredDatabaseSessionAttributes {
id: string;
userId: string;
expiresAt: Date;
Expand Down
8 changes: 4 additions & 4 deletions packages/adapter-sqlite/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {
Adapter,
DatabaseSession,
DatabaseSessionAttributes,
RegisteredDatabaseSessionAttributes,
DatabaseUser,
DatabaseUserAttributes
RegisteredDatabaseUserAttributes
} from "lucia";

export class SQLiteAdapter implements Adapter {
Expand Down Expand Up @@ -106,13 +106,13 @@ export interface Controller {
getAll<T>(sql: string, args: any[]): Promise<T[]>;
}

interface SessionSchema extends DatabaseSessionAttributes {
interface SessionSchema extends RegisteredDatabaseSessionAttributes {
id: string;
user_id: string;
expires_at: number;
}

interface UserSchema extends DatabaseUserAttributes {
interface UserSchema extends RegisteredDatabaseUserAttributes {
id: string;
}

Expand Down
9 changes: 0 additions & 9 deletions packages/adapter-sqlite/tests/better-sqlite3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,3 @@ const adapter = new BetterSqlite3Adapter(db, {
});

await testAdapter(adapter);

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}
9 changes: 0 additions & 9 deletions packages/adapter-sqlite/tests/bun-sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,3 @@ const adapter = new BunSQLiteAdapter(db, {
});

await testAdapter(adapter);

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}
9 changes: 0 additions & 9 deletions packages/adapter-sqlite/tests/d1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,3 @@ const adapter = new D1Adapter(d1, {
});

await testAdapter(adapter);

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}
9 changes: 0 additions & 9 deletions packages/adapter-sqlite/tests/libsql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,3 @@ try {
} finally {
await fs.rm("test/libsql/test.db");
}

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}
9 changes: 0 additions & 9 deletions packages/adapter-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import { Adapter, DatabaseSession, DatabaseUser } from "lucia";
import { generateRandomString, alphabet } from "oslo/random";
import assert from "node:assert/strict";

declare module "lucia" {
interface DatabaseUserAttributes {
username: string;
}
interface DatabaseSessionAttributes {
country: string;
}
}

export const databaseUser: DatabaseUser = {
id: generateRandomString(15, alphabet("0-9", "a-z")),
attributes: {
Expand Down
18 changes: 11 additions & 7 deletions packages/lucia/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { CookieController } from "oslo/cookie";
import type { Cookie } from "oslo/cookie";
import type { Adapter } from "./database.js";
import type {
DatabaseSessionAttributes,
DatabaseUserAttributes,
RegisteredDatabaseSessionAttributes,
RegisteredDatabaseUserAttributes,
RegisteredLucia
} from "./index.js";
import { CookieAttributes } from "oslo/cookie";
Expand Down Expand Up @@ -39,10 +39,12 @@ export class Lucia<
private sessionCookieController: CookieController;

private getSessionAttributes: (
databaseSessionAttributes: DatabaseSessionAttributes
databaseSessionAttributes: RegisteredDatabaseSessionAttributes
) => _SessionAttributes;

private getUserAttributes: (databaseUserAttributes: DatabaseUserAttributes) => _UserAttributes;
private getUserAttributes: (
databaseUserAttributes: RegisteredDatabaseUserAttributes
) => _UserAttributes;

public readonly sessionCookieName: string;

Expand All @@ -52,9 +54,11 @@ export class Lucia<
sessionExpiresIn?: TimeSpan;
sessionCookie?: SessionCookieOptions;
getSessionAttributes?: (
databaseSessionAttributes: DatabaseSessionAttributes
databaseSessionAttributes: RegisteredDatabaseSessionAttributes
) => _SessionAttributes;
getUserAttributes?: (databaseUserAttributes: DatabaseUserAttributes) => _UserAttributes;
getUserAttributes?: (
databaseUserAttributes: RegisteredDatabaseUserAttributes
) => _UserAttributes;
}
) {
this.adapter = adapter;
Expand Down Expand Up @@ -151,7 +155,7 @@ export class Lucia<

public async createSession(
userId: string,
attributes: DatabaseSessionAttributes,
attributes: RegisteredDatabaseSessionAttributes,
options?: {
sessionId?: string;
}
Expand Down
9 changes: 6 additions & 3 deletions packages/lucia/src/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { DatabaseSessionAttributes, DatabaseUserAttributes } from "./index.js";
import type {
RegisteredDatabaseSessionAttributes,
RegisteredDatabaseUserAttributes
} from "./index.js";

export interface Adapter {
getSessionAndUser(
Expand All @@ -13,12 +16,12 @@ export interface Adapter {

export interface DatabaseUser {
id: string;
attributes: DatabaseUserAttributes;
attributes: RegisteredDatabaseUserAttributes;
}

export interface DatabaseSession {
userId: string;
expiresAt: Date;
id: string;
attributes: DatabaseSessionAttributes;
attributes: RegisteredDatabaseSessionAttributes;
}
16 changes: 12 additions & 4 deletions packages/lucia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ export type { CookieAttributes } from "oslo/cookie";

import type { Lucia } from "./core.js";

export interface DatabaseUserAttributes {}
export interface DatabaseSessionAttributes {}

export interface Register {}

export type RegisteredLucia = Register extends {
// need to infer to "copy" the generics of Lucia
Lucia: infer _Lucia;
}
? _Lucia extends Lucia<any, any>
? _Lucia
: Lucia
: Lucia;

export type RegisteredDatabaseUserAttributes = Register extends {
DatabaseUserAttributes: infer _DatabaseUserAttributes;
}
? _DatabaseUserAttributes
: {};

export type RegisteredDatabaseSessionAttributes = Register extends {
DatabaseSessionAttributes: infer _DatabaseSessionAttributes;
}
? _DatabaseSessionAttributes
: {};

0 comments on commit 0038982

Please sign in to comment.