diff --git a/next-mate.code-workspace b/next-mate.code-workspace index 06777b5..baf0a5f 100644 --- a/next-mate.code-workspace +++ b/next-mate.code-workspace @@ -58,5 +58,8 @@ "./packages/next-prisma", ], "typescript.tsdk": "root/node_modules/typescript/lib", + "[prisma]": { + "editor.defaultFormatter": "Prisma.prisma", + }, }, } diff --git a/packages/next-auth/copyPrisma.js b/packages/next-auth/copyPrisma.js index a32ebee..bb03915 100644 --- a/packages/next-auth/copyPrisma.js +++ b/packages/next-auth/copyPrisma.js @@ -1,6 +1,6 @@ -import * as fs from 'fs'; -import * as path from 'path'; -import { promisify } from 'util'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import { promisify } from 'node:util'; const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); diff --git a/packages/next-auth/src/lucia/core.ts b/packages/next-auth/src/lucia/core.ts index 7940bde..f932a21 100644 --- a/packages/next-auth/src/lucia/core.ts +++ b/packages/next-auth/src/lucia/core.ts @@ -3,7 +3,7 @@ import { TimeSpan, createDate, isWithinExpirationDate } from 'oslo'; import type { Cookie, CookieAttributes } from 'oslo/cookie'; import { CookieController } from 'oslo/cookie'; - +import type { PasswordHashingAlgorithm } from './crypto.js'; import { generateIdFromEntropySize } from './crypto.js'; import type { Adapter, DatabaseAuth, DatabaseUser } from './database.js'; import type { @@ -12,8 +12,7 @@ import type { RegisteredDatabaseAuthAttributes, RegisteredLucia, UserId, - PasswordHashingAlgorithm, -} from './index.js'; +} from './type.js'; type SessionAttributes = RegisteredLucia extends Lucia diff --git a/packages/next-auth/src/lucia/crypto.ts b/packages/next-auth/src/lucia/crypto.ts index 4812171..7791249 100644 --- a/packages/next-auth/src/lucia/crypto.ts +++ b/packages/next-auth/src/lucia/crypto.ts @@ -48,33 +48,3 @@ export class Scrypt implements PasswordHashingAlgorithm { return constantTimeEqual(targetKey, decodeHex(key)); } } - -export class LegacyScrypt implements PasswordHashingAlgorithm { - async hash(password: string): Promise { - const salt = encodeHex(crypto.getRandomValues(new Uint8Array(16))); - const key = await generateScryptKey(password.normalize('NFKC'), salt); - return `s2:${salt}:${encodeHex(key)}`; - } - async verify(hash: string, password: string): Promise { - const parts = hash.split(':'); - if (parts.length === 2) { - const [salt, key] = parts; - const targetKey = await generateScryptKey( - password.normalize('NFKC'), - salt, - 8 - ); - return constantTimeEqual(targetKey, decodeHex(key)); - } - if (parts.length !== 3) return false; - const [version, salt, key] = parts; - if (version === 's2') { - const targetKey = await generateScryptKey( - password.normalize('NFKC'), - salt - ); - return constantTimeEqual(targetKey, decodeHex(key)); - } - return false; - } -} diff --git a/packages/next-auth/src/lucia/database.ts b/packages/next-auth/src/lucia/database.ts index c0bdbff..b02eac8 100644 --- a/packages/next-auth/src/lucia/database.ts +++ b/packages/next-auth/src/lucia/database.ts @@ -4,7 +4,7 @@ import type { RegisteredDatabaseUserAttributes, RegisteredDatabaseAuthAttributes, UserId, -} from './index.js'; +} from './type.js'; export interface Adapter { getSessionAndUser( diff --git a/packages/next-auth/src/lucia/index.ts b/packages/next-auth/src/lucia/index.ts index cace23c..da6e74b 100644 --- a/packages/next-auth/src/lucia/index.ts +++ b/packages/next-auth/src/lucia/index.ts @@ -1,12 +1,5 @@ -/* eslint-disable @typescript-eslint/ban-types */ -/* eslint-disable @typescript-eslint/no-explicit-any */ export { Lucia } from './core.js'; -export { - Scrypt, - LegacyScrypt, - generateId, - generateIdFromEntropySize, -} from './crypto.js'; +export { Scrypt, generateId, generateIdFromEntropySize } from './crypto.js'; export { TimeSpan } from 'oslo'; export { Cookie } from 'oslo/cookie'; export { verifyRequestOrigin } from 'oslo/request'; @@ -25,39 +18,4 @@ export type { } from './database.js'; export type { PasswordHashingAlgorithm } from './crypto.js'; export type { CookieAttributes } from 'oslo/cookie'; - -import type { Lucia } from './core.js'; - -export interface Register {} - -export type UserId = Register extends { - UserId: infer _UserId; -} - ? _UserId - : string; - -export type RegisteredLucia = Register extends { - Lucia: infer _Lucia; -} - ? _Lucia extends Lucia - ? _Lucia - : Lucia - : Lucia; - -export type RegisteredDatabaseUserAttributes = Register extends { - DatabaseUserAttributes: infer _DatabaseUserAttributes; -} - ? _DatabaseUserAttributes - : {}; - -export type RegisteredDatabaseSessionAttributes = Register extends { - DatabaseSessionAttributes: infer _DatabaseSessionAttributes; -} - ? _DatabaseSessionAttributes - : {}; - -export type RegisteredDatabaseAuthAttributes = Register extends { - DatabaseAuthAttributes: infer _DatabaseAuthAttributes; -} - ? _DatabaseAuthAttributes - : {}; +export * from './type.js'; diff --git a/packages/next-auth/src/lucia/type.ts b/packages/next-auth/src/lucia/type.ts new file mode 100644 index 0000000..3478628 --- /dev/null +++ b/packages/next-auth/src/lucia/type.ts @@ -0,0 +1,37 @@ +/* eslint-disable @typescript-eslint/ban-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import type { Lucia } from './core.js'; + +export interface Register {} + +export type UserId = Register extends { + UserId: infer _UserId; +} + ? _UserId + : string; + +export type RegisteredLucia = Register extends { + Lucia: infer _Lucia; +} + ? _Lucia extends Lucia + ? _Lucia + : Lucia + : Lucia; + +export type RegisteredDatabaseUserAttributes = Register extends { + DatabaseUserAttributes: infer _DatabaseUserAttributes; +} + ? _DatabaseUserAttributes + : {}; + +export type RegisteredDatabaseSessionAttributes = Register extends { + DatabaseSessionAttributes: infer _DatabaseSessionAttributes; +} + ? _DatabaseSessionAttributes + : {}; + +export type RegisteredDatabaseAuthAttributes = Register extends { + DatabaseAuthAttributes: infer _DatabaseAuthAttributes; +} + ? _DatabaseAuthAttributes + : {}; diff --git a/packages/next-prisma/package.json b/packages/next-prisma/package.json index 16b4e27..7ca74da 100644 --- a/packages/next-prisma/package.json +++ b/packages/next-prisma/package.json @@ -45,10 +45,7 @@ "@prisma/generator-helper": "5.13.0", "@prisma/internals": "5.13.0", "dotenv": "16.4.5", - "fs": "^0.0.1-security", - "glob": "^10.3.15", - "path": "^0.12.7", - "util": "^0.12.5" + "glob": "^10.3.15" }, "devDependencies": { "@armit/eslint-config-bases": "^0.1.5", diff --git a/packages/next-prisma/src/merge.ts b/packages/next-prisma/src/merge.ts index b37fdc7..7e36964 100644 --- a/packages/next-prisma/src/merge.ts +++ b/packages/next-prisma/src/merge.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import * as fs from 'fs'; -import * as path from 'path'; -import { promisify } from 'util'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import { promisify } from 'node:util'; import { type DMMF, type DataSource, diff --git a/packages/next-prisma/tests/__snapshots__/prisma-merge.spec.ts.snap b/packages/next-prisma/tests/__snapshots__/prisma-merge.spec.ts.snap new file mode 100644 index 0000000..c417037 --- /dev/null +++ b/packages/next-prisma/tests/__snapshots__/prisma-merge.spec.ts.snap @@ -0,0 +1,29 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`merge prisma 1`] = ` +"// *** GENERATED BY next-prisma :: DO NOT EDIT *** +model User { + id Int @unique + name String + content Int + desc String +} +model Post { + id String @unique + name String +}" +`; + +exports[`merge prisma cover 1`] = ` +"// *** GENERATED BY next-prisma :: DO NOT EDIT *** +model User { + id Int @unique + name Int + content String + desc String +} +model Post { + id String @unique + name String +}" +`; diff --git a/packages/next-prisma/tests/prisma-merge.spec.ts b/packages/next-prisma/tests/prisma-merge.spec.ts new file mode 100644 index 0000000..51b1193 --- /dev/null +++ b/packages/next-prisma/tests/prisma-merge.spec.ts @@ -0,0 +1,46 @@ +import * as fs from 'node:fs'; +import { promisify } from 'node:util'; + +import { prismaMerge } from '../src/index.js'; + +const readFile = promisify(fs.readFile); + +test('merge prisma', async () => { + const luciaPrismaContent = ` + model User { + id String @unique + name String + } +`; + + await prismaMerge({ + prePrismaModel: luciaPrismaContent, + input: ['tests/prisma/test1.prisma'], + output: 'tests/prisma/testMerge1.prisma', + }); + + const prismaContent = await readFile('tests/prisma/testMerge1.prisma', { + encoding: 'utf-8', + }); + expect(prismaContent).toMatchSnapshot(); +}); + +test('merge prisma cover', async () => { + const luciaPrismaContent = ` + model User { + id String @unique + name String + } + `; + + await prismaMerge({ + prePrismaModel: luciaPrismaContent, + input: ['tests/prisma/test1.prisma', 'tests/prisma/test2.prisma'], + output: 'tests/prisma/testMerge2.prisma', + }); + + const prismaContent = await readFile('tests/prisma/testMerge2.prisma', { + encoding: 'utf-8', + }); + expect(prismaContent).toMatchSnapshot(); +}); diff --git a/packages/next-prisma/tests/prisma/test1.prisma b/packages/next-prisma/tests/prisma/test1.prisma new file mode 100644 index 0000000..5179498 --- /dev/null +++ b/packages/next-prisma/tests/prisma/test1.prisma @@ -0,0 +1,10 @@ +model User { + id Int @unique + content Int + desc String +} + +model Post { + id String @unique + name String +} diff --git a/packages/next-prisma/tests/prisma/test2.prisma b/packages/next-prisma/tests/prisma/test2.prisma new file mode 100644 index 0000000..8ff70c2 --- /dev/null +++ b/packages/next-prisma/tests/prisma/test2.prisma @@ -0,0 +1,5 @@ +model User { + id Int @unique + name Int + content String +} diff --git a/packages/next-prisma/tests/prisma/testMerge1.prisma b/packages/next-prisma/tests/prisma/testMerge1.prisma new file mode 100644 index 0000000..8a1354b --- /dev/null +++ b/packages/next-prisma/tests/prisma/testMerge1.prisma @@ -0,0 +1,11 @@ +// *** GENERATED BY next-prisma :: DO NOT EDIT *** +model User { + id Int @unique + name String + content Int + desc String +} +model Post { + id String @unique + name String +} \ No newline at end of file diff --git a/packages/next-prisma/tests/prisma/testMerge2.prisma b/packages/next-prisma/tests/prisma/testMerge2.prisma new file mode 100644 index 0000000..069d3c8 --- /dev/null +++ b/packages/next-prisma/tests/prisma/testMerge2.prisma @@ -0,0 +1,11 @@ +// *** GENERATED BY next-prisma :: DO NOT EDIT *** +model User { + id Int @unique + name Int + content String + desc String +} +model Post { + id String @unique + name String +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 6bc650a..8bf8f6a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3703,15 +3703,12 @@ __metadata: dotenv: "npm:16.4.5" eslint: "npm:8.55.0" fastify: "npm:^4.27.0" - fs: "npm:^0.0.1-security" glob: "npm:^10.3.15" npm-run-all: "npm:4.1.5" - path: "npm:^0.12.7" prettier: "npm:3.2.5" rimraf: "npm:5.0.5" ts-node: "npm:10.9.2" typescript: "npm:5.4.5" - util: "npm:^0.12.5" vite: "npm:5.2.11" vite-tsconfig-paths: "npm:4.3.2" vitest: "npm:1.6.0" @@ -9904,13 +9901,6 @@ __metadata: languageName: node linkType: hard -"fs@npm:^0.0.1-security": - version: 0.0.1-security - resolution: "fs@npm:0.0.1-security" - checksum: 10c0/e0c0b585ec6f7483d63d067215d9d6bb2e0dba5912060d32554c8e566a0e22ee65e4c2a2b0567476efbbfb47682554b4711d69cab49950d01f227a3dfa7d671a - languageName: node - linkType: hard - "fsevents@npm:2.3.2": version: 2.3.2 resolution: "fsevents@npm:2.3.2" @@ -10890,13 +10880,6 @@ __metadata: languageName: node linkType: hard -"inherits@npm:2.0.3": - version: 2.0.3 - resolution: "inherits@npm:2.0.3" - checksum: 10c0/6e56402373149ea076a434072671f9982f5fad030c7662be0332122fe6c0fa490acb3cc1010d90b6eff8d640b1167d77674add52dfd1bb85d545cf29e80e73e7 - languageName: node - linkType: hard - "ini@npm:2.0.0": version: 2.0.0 resolution: "ini@npm:2.0.0" @@ -11053,16 +11036,6 @@ __metadata: languageName: node linkType: hard -"is-arguments@npm:^1.0.4": - version: 1.1.1 - resolution: "is-arguments@npm:1.1.1" - dependencies: - call-bind: "npm:^1.0.2" - has-tostringtag: "npm:^1.0.0" - checksum: 10c0/5ff1f341ee4475350adfc14b2328b38962564b7c2076be2f5bac7bd9b61779efba99b9f844a7b82ba7654adccf8e8eb19d1bb0cc6d1c1a085e498f6793d4328f - languageName: node - linkType: hard - "is-array-buffer@npm:^3.0.4": version: 3.0.4 resolution: "is-array-buffer@npm:3.0.4" @@ -11261,7 +11234,7 @@ __metadata: languageName: node linkType: hard -"is-generator-function@npm:^1.0.10, is-generator-function@npm:^1.0.7": +"is-generator-function@npm:^1.0.10": version: 1.0.10 resolution: "is-generator-function@npm:1.0.10" dependencies: @@ -11538,7 +11511,7 @@ __metadata: languageName: node linkType: hard -"is-typed-array@npm:^1.1.13, is-typed-array@npm:^1.1.3": +"is-typed-array@npm:^1.1.13": version: 1.1.13 resolution: "is-typed-array@npm:1.1.13" dependencies: @@ -14406,16 +14379,6 @@ __metadata: languageName: node linkType: hard -"path@npm:^0.12.7": - version: 0.12.7 - resolution: "path@npm:0.12.7" - dependencies: - process: "npm:^0.11.1" - util: "npm:^0.10.3" - checksum: 10c0/f795ce5438a988a590c7b6dfd450ec9baa1c391a8be4c2dea48baa6e0f5b199e56cd83b8c9ebf3991b81bea58236d2c32bdafe2c17a2e70c3a2e4c69891ade59 - languageName: node - linkType: hard - "pathe@npm:^1.1.0, pathe@npm:^1.1.1": version: 1.1.1 resolution: "pathe@npm:1.1.1" @@ -14829,7 +14792,7 @@ __metadata: languageName: node linkType: hard -"process@npm:^0.11.1, process@npm:^0.11.10": +"process@npm:^0.11.10": version: 0.11.10 resolution: "process@npm:0.11.10" checksum: 10c0/40c3ce4b7e6d4b8c3355479df77aeed46f81b279818ccdc500124e6a5ab882c0cc81ff7ea16384873a95a74c4570b01b120f287abbdd4c877931460eca6084b3 @@ -17848,28 +17811,6 @@ __metadata: languageName: node linkType: hard -"util@npm:^0.10.3": - version: 0.10.4 - resolution: "util@npm:0.10.4" - dependencies: - inherits: "npm:2.0.3" - checksum: 10c0/d29f6893e406b63b088ce9924da03201df89b31490d4d011f1c07a386ea4b3dbe907464c274023c237da470258e1805d806c7e4009a5974cd6b1d474b675852a - languageName: node - linkType: hard - -"util@npm:^0.12.5": - version: 0.12.5 - resolution: "util@npm:0.12.5" - dependencies: - inherits: "npm:^2.0.3" - is-arguments: "npm:^1.0.4" - is-generator-function: "npm:^1.0.7" - is-typed-array: "npm:^1.1.3" - which-typed-array: "npm:^1.1.2" - checksum: 10c0/c27054de2cea2229a66c09522d0fa1415fb12d861d08523a8846bf2e4cbf0079d4c3f725f09dcb87493549bcbf05f5798dce1688b53c6c17201a45759e7253f3 - languageName: node - linkType: hard - "v8-compile-cache-lib@npm:^3.0.1": version: 3.0.1 resolution: "v8-compile-cache-lib@npm:3.0.1" @@ -18233,7 +18174,7 @@ __metadata: languageName: node linkType: hard -"which-typed-array@npm:^1.1.14, which-typed-array@npm:^1.1.15, which-typed-array@npm:^1.1.2, which-typed-array@npm:^1.1.9": +"which-typed-array@npm:^1.1.14, which-typed-array@npm:^1.1.15, which-typed-array@npm:^1.1.9": version: 1.1.15 resolution: "which-typed-array@npm:1.1.15" dependencies: