Skip to content
This repository was archived by the owner on Jul 17, 2022. It is now read-only.

feat(typeorm-legacy): bring typeorm up-to-date #77

Merged
merged 7 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions packages/typeorm-legacy/.babelrc

This file was deleted.

9 changes: 9 additions & 0 deletions packages/typeorm-legacy/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// We aim to have the same support as Next.js
// https://nextjs.org/docs/getting-started#system-requirements
// https://nextjs.org/docs/basic-features/supported-browsers-features

module.exports = {
presets: [["@babel/preset-env", { targets: { node: "10.13" } }]],
plugins: ["@babel/plugin-transform-runtime"],
comments: false,
}
94 changes: 94 additions & 0 deletions packages/typeorm-legacy/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type { Profile, Session, User } from "next-auth"
import { ConnectionOptions, EntitySchema } from "typeorm"
import { Adapter } from "next-auth/adapters"

/**
* TODO: fix auto-type schema
*/
type Schema<T = any> = EntitySchema<T>["options"]

export class TypeORMUserModel implements User {
name?: string
email?: string
image?: string
emailVerified?: Date

constructor(
name?: string,
email?: string,
image?: string,
emailVerified?: Date
)
[x: string]: unknown
}

export class TypeORMSessionModel {
userId: number
expires: Date | string
sessionToken: string
accessToken: string

constructor(
userId: number,
expires: Date,
sessionToken?: string,
accessToken?: string
)
}

export class TypeORMVerificationRequestModel {
identifier: string
token: string
expires: Date
constructor(identifier: string, token: string, expires: Date)
}

export class TypeORMAccountModel {
compoundId: string
userId: number
providerType: string
providerId: string
providerAccountId: string
refreshToken?: string
accessToken?: string
accessTokenExpires?: Date

constructor(
userId: number,
providerId: string,
providerType: string,
providerAccountId: string,
refreshToken?: string,
accessToken?: string,
accessTokenExpires?: Date
)
}

export interface TypeORMAdapterModels {
Account: {
model: TypeORMAccountModel
schema: Schema<TypeORMAccountModel>
}
User: {
model: TypeORMUserModel
schema: Schema<TypeORMUserModel>
}
Session: {
model: TypeORMSessionModel
schema: Schema<TypeORMSessionModel>
}
VerificationRequest: {
model: TypeORMVerificationRequestModel
schema: Schema<TypeORMVerificationRequestModel>
}
}

export type TypeORMAdapter<
C = ConnectionOptions | string,
O = { models?: TypeORMAdapterModels },
U = User,
P = Profile,
S = Omit<Session, "expires"> & { expires: Date }
> = Adapter<C, O, U, P, S>

export { TypeORMAdapter as Adapter, TypeORMAdapterModels as Models }
3 changes: 2 additions & 1 deletion packages/typeorm-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"crypto-js": "^4.0.0",
"@babel/runtime": "^7.14.0",
"require_optional": "^1.0.1",
"typeorm": "^0.2.30"
},
"devDependencies": {
"@babel/cli": "^7.13.16",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "^7.13.15",
"assert": "^2.0.0",
"jest": "^26.6.3",
Expand Down
Loading