Skip to content

Commit

Permalink
feat: use NodeNext module resolution (#9953)
Browse files Browse the repository at this point in the history
Co-authored-by: Nico Domino <yo@ndo.dev>
  • Loading branch information
balazsorban44 and ndom91 authored Jun 1, 2024
1 parent 0b321a0 commit 577b7f9
Show file tree
Hide file tree
Showing 17 changed files with 324 additions and 290 deletions.
2 changes: 1 addition & 1 deletion packages/adapter-d1/src/migrations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { D1Database } from "."
import type { D1Database } from "./index.js"

export const upSQLStatements = [
`CREATE TABLE IF NOT EXISTS "accounts" (
Expand Down
48 changes: 30 additions & 18 deletions packages/adapter-dgraph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@
*
* @module @auth/dgraph-adapter
*/
import { client as dgraphClient } from "./lib/client"
import { client as dgraphClient } from "./lib/client.js"
import { isDate, type Adapter } from "@auth/core/adapters"
import type { DgraphClientParams } from "./lib/client"
import * as defaultFragments from "./lib/graphql/fragments"
import type { DgraphClientParams } from "./lib/client.js"
import * as defaultFragments from "./lib/graphql/fragments.js"
import {
AdapterAccount,
AdapterSession,
AdapterUser,
VerificationToken,
} from "@auth/core/adapters"

export type { DgraphClientParams, DgraphClientError } from "./lib/client"
export type { DgraphClientParams, DgraphClientError } from "./lib/client.js"

/** This is the interface of the Dgraph adapter options. */
export interface DgraphAdapterOptions {
Expand All @@ -46,7 +52,7 @@ export function DgraphAdapter(

const fragments = { ...defaultFragments, ...options?.fragments }
return {
async createUser(input) {
async createUser(input: AdapterUser) {
const result = await c.run<{ user: any[] }>(
/* GraphQL */ `
mutation ($input: [AddUserInput!]!) {
Expand All @@ -63,7 +69,7 @@ export function DgraphAdapter(

return format.from<any>(result?.user[0])
},
async getUser(id) {
async getUser(id: string) {
const result = await c.run<any>(
/* GraphQL */ `
query ($id: ID!) {
Expand All @@ -78,7 +84,7 @@ export function DgraphAdapter(

return format.from<any>(result)
},
async getUserByEmail(email) {
async getUserByEmail(email: string) {
const [user] = await c.run<any>(
/* GraphQL */ `
query ($email: String = "") {
Expand All @@ -92,7 +98,10 @@ export function DgraphAdapter(
)
return format.from<any>(user)
},
async getUserByAccount(provider_providerAccountId) {
async getUserByAccount(provider_providerAccountId: {
provider: string
providerAccountId: string
}) {
const [account] = await c.run<any>(
/* GraphQL */ `
query ($providerAccountId: String = "", $provider: String = "") {
Expand All @@ -116,7 +125,7 @@ export function DgraphAdapter(
)
return format.from<any>(account?.user)
},
async updateUser({ id, ...input }) {
async updateUser({ id, ...input }: { id: string }) {
const result = await c.run<any>(
/* GraphQL */ `
mutation ($id: [ID!] = "", $input: UserPatch) {
Expand All @@ -132,7 +141,7 @@ export function DgraphAdapter(
)
return format.from<any>(result.user[0])
},
async deleteUser(id) {
async deleteUser(id: string) {
const result = await c.run<any>(
/* GraphQL */ `
mutation ($id: [ID!] = "") {
Expand Down Expand Up @@ -174,7 +183,7 @@ export function DgraphAdapter(
return deletedUser
},

async linkAccount(data) {
async linkAccount(data: AdapterAccount) {
const { userId, ...input } = data
await c.run<any>(
/* GraphQL */ `
Expand All @@ -191,7 +200,10 @@ export function DgraphAdapter(
)
return data
},
async unlinkAccount(provider_providerAccountId) {
async unlinkAccount(provider_providerAccountId: {
provider: string
providerAccountId: string
}) {
await c.run<any>(
/* GraphQL */ `
mutation ($providerAccountId: String = "", $provider: String = "") {
Expand All @@ -211,7 +223,7 @@ export function DgraphAdapter(
)
},

async getSessionAndUser(sessionToken) {
async getSessionAndUser(sessionToken: string) {
const [sessionAndUser] = await c.run<any>(
/* GraphQL */ `
query ($sessionToken: String = "") {
Expand All @@ -236,7 +248,7 @@ export function DgraphAdapter(
session: { ...format.from<any>(session), userId: user.id },
}
},
async createSession(data) {
async createSession(data: AdapterSession) {
const { userId, ...input } = data

await c.run<any>(
Expand All @@ -255,7 +267,7 @@ export function DgraphAdapter(

return data as any
},
async updateSession({ sessionToken, ...input }) {
async updateSession({ sessionToken, ...input }: { sessionToken: string }) {
const result = await c.run<any>(
/* GraphQL */ `
mutation ($input: SessionPatch = {}, $sessionToken: String) {
Expand Down Expand Up @@ -283,7 +295,7 @@ export function DgraphAdapter(

return { ...session, userId: session.user.id }
},
async deleteSession(sessionToken) {
async deleteSession(sessionToken: string) {
await c.run<any>(
/* GraphQL */ `
mutation ($sessionToken: String = "") {
Expand All @@ -296,7 +308,7 @@ export function DgraphAdapter(
)
},

async createVerificationToken(input) {
async createVerificationToken(input: VerificationToken) {
const result = await c.run<any>(
/* GraphQL */ `
mutation ($input: [AddVerificationTokenInput!]!) {
Expand All @@ -310,7 +322,7 @@ export function DgraphAdapter(
return format.from<any>(result)
},

async useVerificationToken(params) {
async useVerificationToken(params: { identifier: string; token: string }) {
const result = await c.run<any>(
/* GraphQL */ `
mutation ($token: String = "", $identifier: String = "") {
Expand Down
4 changes: 1 addition & 3 deletions packages/adapter-drizzle/src/lib/mysql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InferInsertModel, and, eq, getTableColumns } from "drizzle-orm"
import { and, eq, getTableColumns } from "drizzle-orm"
import {
MySqlColumn,
MySqlDatabase,
Expand All @@ -8,10 +8,8 @@ import {
primaryKey,
timestamp,
varchar,
index,
QueryResultHKT,
PreparedQueryHKTBase,
TableConfig,
MySqlTableWithColumns,
} from "drizzle-orm/mysql-core"

Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-xata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
"@auth/core": "workspace:*"
},
"peerDependencies": {
"@xata.io/client": ">=0.13.0"
"@xata.io/client": ">=0.28.0"
},
"devDependencies": {
"@xata.io/client": "^0.13.0"
"@xata.io/client": "^0.28.0"
}
}
2 changes: 1 addition & 1 deletion packages/adapter-xata/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/

import type { Adapter } from "@auth/core/adapters"
import type { XataClient } from "./xata"
import type { XataClient } from "./xata.js"

export function XataAdapter(client: XataClient): Adapter {
return {
Expand Down
171 changes: 157 additions & 14 deletions packages/adapter-xata/src/xata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BaseClientOptions,
XataRecord,
ClientConstructor,
type BaseSchema,
} from "@xata.io/client"

export interface NextauthUser {
Expand Down Expand Up @@ -67,27 +68,169 @@ export interface NextauthSession {
export type NextauthSessionRecord = NextauthSession & XataRecord

export type DatabaseSchema = {
nextauth_users: NextauthUser
nextauth_accounts: NextauthAccount
nextauth_verificationTokens: NextauthVerificationToken
nextauth_users_accounts: NextauthUsersAccount
nextauth_users_sessions: NextauthUsersSession
nextauth_sessions: NextauthSession
nextauth_users: NextauthUserRecord
nextauth_accounts: NextauthAccountRecord
nextauth_verificationTokens: NextauthVerificationTokenRecord
nextauth_users_accounts: NextauthUsersAccountRecord
nextauth_users_sessions: NextauthUsersSessionRecord
nextauth_sessions: NextauthSessionRecord
}

const tables = [
"nextauth_users",
"nextauth_accounts",
"nextauth_verificationTokens",
"nextauth_users_accounts",
"nextauth_users_sessions",
"nextauth_sessions",
const schemas: BaseSchema[] = [
{
name: "nextauth_users",
columns: [
{
name: "email",
type: "email",
},
{
name: "emailVerified",
type: "datetime",
},
{
name: "name",
type: "string",
},
{
name: "image",
type: "string",
},
],
},
{
name: "nextauth_accounts",
columns: [
{
name: "user",
type: "link",
link: {
table: "nextauth_users",
},
},
{
name: "type",
type: "string",
},
{
name: "provider",
type: "string",
},
{
name: "providerAccountId",
type: "string",
},
{
name: "refresh_token",
type: "string",
},
{
name: "access_token",
type: "string",
},
{
name: "expires_at",
type: "int",
},
{
name: "token_type",
type: "string",
},
{
name: "scope",
type: "string",
},
{
name: "id_token",
type: "text",
},
{
name: "session_state",
type: "string",
},
],
},
{
name: "nextauth_verificationTokens",
columns: [
{
name: "identifier",
type: "string",
},
{
name: "token",
type: "string",
},
{
name: "expires",
type: "datetime",
},
],
},
{
name: "nextauth_users_accounts",
columns: [
{
name: "user",
type: "link",
link: {
table: "nextauth_users",
},
},
{
name: "account",
type: "link",
link: {
table: "nextauth_accounts",
},
},
],
},
{
name: "nextauth_users_sessions",
columns: [
{
name: "user",
type: "link",
link: {
table: "nextauth_users",
},
},
{
name: "session",
type: "link",
link: {
table: "nextauth_sessions",
},
},
],
},
{
name: "nextauth_sessions",
columns: [
{
name: "sessionToken",
type: "string",
},
{
name: "expires",
type: "datetime",
},
{
name: "user",
type: "link",
link: {
table: "nextauth_users",
},
},
],
},
]

const DatabaseClient = buildClient() as ClientConstructor<any>

export class XataClient extends DatabaseClient<DatabaseSchema> {
constructor(options?: BaseClientOptions) {
super({ databaseURL: "", ...options }, tables)
super({ databaseURL: "", ...options }, schemas)
}
}
Loading

0 comments on commit 577b7f9

Please sign in to comment.