Skip to content

Commit 9445198

Browse files
committed
fix lint errors
1 parent dab556f commit 9445198

9 files changed

Lines changed: 59 additions & 49 deletions

File tree

playground/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default defineNuxtConfig({
22
modules: ['../src/module'],
3+
devtools: { enabled: true },
34
compatibilityDate: '2025-07-08',
45
nuxtUsers: {},
5-
devtools: { enabled: true },
66
})

src/runtime/server/api/login.post.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createError, defineEventHandler, readBody } from 'h3'
22
import { getConnector } from '../utils/db'
33
import { createDatabase } from 'db0'
44
import bcrypt from 'bcrypt'
5-
import type { ModuleOptions } from '../../../types'
5+
import type { ModuleOptions, User } from '../../../types'
66

77
export default defineEventHandler(async (event) => {
88
const body = await readBody(event)
@@ -22,7 +22,7 @@ export default defineEventHandler(async (event) => {
2222
const connector = await getConnector(connectorName)
2323
const db = createDatabase(connector(options.connector!.options))
2424

25-
const user = await db.sql`SELECT * FROM users WHERE email = ${email}` as any
25+
const user = await db.sql`SELECT * FROM users WHERE email = ${email}` as { rows: User[] }
2626

2727
if (user.rows.length === 0) {
2828
throw createError({

src/runtime/server/utils/create-user.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const defaultOptions: ModuleOptions = {
4242

4343
const createUserDefault = async () => {
4444
const args = process.argv.slice(2)
45-
45+
4646
if (args.length < 3) {
4747
console.error('[DB:Create User] Usage: yarn create:user <email> <name> <password>')
4848
console.error('[DB:Create User] Example: yarn create:user john@example.com "John Doe" mypassword')
@@ -56,7 +56,8 @@ const createUserDefault = async () => {
5656
try {
5757
await createUser({ email, name, password }, defaultOptions)
5858
process.exit(0)
59-
} catch (error) {
59+
}
60+
catch (error) {
6061
console.error('[DB:Create User] Error:', error)
6162
process.exit(1)
6263
}
@@ -65,4 +66,4 @@ const createUserDefault = async () => {
6566
// Run if this is the main module
6667
if (process.argv[1] && process.argv[1].endsWith('create-user.ts')) {
6768
createUserDefault()
68-
}
69+
}

src/runtime/server/utils/create-users-table.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export const createUsersTable = async (table: string, options: ModuleOptions) =>
2323
`
2424
console.log('[DB:Create Users Table] Users table created successfully!')
2525
console.log('[DB:Create Users Table] Fields: id, email, name, password, created_at, updated_at')
26-
} else {
26+
}
27+
else {
2728
console.log(`[DB:Create Users Table] Unknown table: ${table}`)
2829
throw new Error(`Unknown table: ${table}`)
2930
}
@@ -47,7 +48,8 @@ const migrateDefault = async () => {
4748
try {
4849
await createUsersTable('users', defaultOptions)
4950
process.exit(0)
50-
} catch (error) {
51+
}
52+
catch (error) {
5153
console.error('[DB:Create Users Table] Error:', error)
5254
process.exit(1)
5355
}
@@ -56,4 +58,4 @@ const migrateDefault = async () => {
5658
// Run if this is the main module
5759
if (process.argv[1] && process.argv[1].endsWith('create-users-table.ts')) {
5860
migrateDefault()
59-
}
61+
}

src/runtime/server/utils/db.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ const useDb = async (options: ModuleOptions) => {
2323

2424
export const checkUsersTableExists = async (options: ModuleOptions) => {
2525
const db = await useDb(options)
26-
26+
2727
try {
2828
// Try to query the users table - if it exists, this will succeed
2929
await db.sql`SELECT 1 FROM users LIMIT 1`
3030
return true
31-
} catch (error) {
31+
}
32+
catch {
3233
// If the table doesn't exist, the query will fail
3334
return false
3435
}
@@ -40,11 +41,12 @@ interface CountResult {
4041

4142
export const hasAnyUsers = async (options: ModuleOptions) => {
4243
const db = await useDb(options)
43-
44+
4445
try {
4546
const users = await db.sql`SELECT COUNT(*) as count FROM users` as CountResult
4647
return users.rows?.[0]?.count > 0
47-
} catch (error) {
48+
}
49+
catch {
4850
// If the table doesn't exist, there are no users
4951
return false
5052
}

test/cli.create-user.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
22
import { createDatabase } from 'db0'
3+
import type { Database } from 'db0'
34
import { createUsersTable } from '../src/runtime/server/utils/create-users-table'
45
import { createUser } from '../src/runtime/server/utils/create-user'
56
import type { ModuleOptions } from '../src/types'
6-
import fs from 'fs'
7+
import fs from 'node:fs'
78

89
describe('CLI: Create User', () => {
9-
let db: any
10+
let db: Database
1011
let testOptions: ModuleOptions
1112

1213
beforeEach(async () => {
@@ -23,7 +24,7 @@ describe('CLI: Create User', () => {
2324
// Create in-memory database and migrate
2425
const connector = await import('db0/connectors/better-sqlite3')
2526
db = createDatabase(connector.default(testOptions.connector!.options))
26-
27+
2728
// Create users table
2829
await createUsersTable('users', testOptions)
2930
})
@@ -33,7 +34,8 @@ describe('CLI: Create User', () => {
3334
try {
3435
fs.unlinkSync('./_create-user')
3536
fs.unlinkSync('./_create-user-different-connector')
36-
} catch (error) {
37+
}
38+
catch {
3739
// Ignore errors during cleanup
3840
}
3941
})
@@ -112,14 +114,14 @@ describe('CLI: Create User', () => {
112114

113115
expect(user.created_at).toBeDefined()
114116
expect(user.updated_at).toBeDefined()
115-
117+
116118
// Check that timestamps are valid dates
117119
const createdAt = new Date(user.created_at)
118120
const updatedAt = new Date(user.updated_at)
119121

120122
expect(createdAt.toString()).not.toBe('Invalid Date')
121123
expect(updatedAt.toString()).not.toBe('Invalid Date')
122-
124+
123125
// Check that timestamps are not null/undefined
124126
expect(user.created_at).not.toBeNull()
125127
expect(user.updated_at).not.toBeNull()
@@ -170,4 +172,4 @@ describe('CLI: Create User', () => {
170172
expect(user.email).toBe(userData.email)
171173
expect(user.name).toBe(userData.name)
172174
})
173-
})
175+
})

test/cli.create-users-table.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
22
import { createDatabase } from 'db0'
3+
import type { Database } from 'db0'
34
import { createUsersTable } from '../src/runtime/server/utils/create-users-table'
45
import type { ModuleOptions } from '../src/types'
5-
import fs from 'fs'
6+
import fs from 'node:fs'
67

78
describe('CLI: Create Users Table', () => {
8-
let db: any
9+
let db: Database
910
let testOptions: ModuleOptions
1011

1112
beforeEach(async () => {
@@ -29,7 +30,8 @@ describe('CLI: Create Users Table', () => {
2930
try {
3031
fs.unlinkSync('./_create-users-table')
3132
fs.unlinkSync('./_create-users-table-different-connector')
32-
} catch (error) {
33+
}
34+
catch {
3335
// Ignore errors during cleanup
3436
}
3537
})
@@ -185,4 +187,4 @@ describe('CLI: Create Users Table', () => {
185187
VALUES ('Invalid User', 'password')
186188
`).rejects.toThrow() // Missing email
187189
})
188-
})
190+
})

test/fixtures/login/app.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<template>
2-
<div>api-login fixture</div>
3-
</template>
4-
2+
<div>api-login fixture</div>
3+
</template>

test/utils.db.test.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
22
import { createDatabase } from 'db0'
3+
import type { Database } from 'db0'
34
import { getConnector, checkUsersTableExists, hasAnyUsers } from '../src/runtime/server/utils/db'
45
import { createUsersTable } from '../src/runtime/server/utils/create-users-table'
56
import type { ModuleOptions } from '../src/types'
6-
import fs from 'fs'
7+
import fs from 'node:fs'
78

89
describe('Utils: DB', () => {
9-
let db: any
10+
let db: Database
1011
let testOptions: ModuleOptions
1112

1213
beforeEach(async () => {
@@ -26,11 +27,12 @@ describe('Utils: DB', () => {
2627
})
2728

2829
afterEach(async () => {
29-
try {
30+
try {
3031
fs.unlinkSync('./_db-utils')
3132
fs.unlinkSync('./_db-utils-different')
3233
fs.unlinkSync('./_db-utils-has-users')
33-
} catch (error) {
34+
}
35+
catch {
3436
// Ignore errors during cleanup
3537
}
3638
})
@@ -68,7 +70,7 @@ describe('Utils: DB', () => {
6870
it('should return true when users table exists', async () => {
6971
// Create the users table first
7072
await createUsersTable('users', testOptions)
71-
73+
7274
const exists = await checkUsersTableExists(testOptions)
7375
expect(exists).toBe(true)
7476
})
@@ -89,7 +91,7 @@ describe('Utils: DB', () => {
8991

9092
// Create table in new database
9193
await createUsersTable('users', differentOptions)
92-
94+
9395
// Now table exists
9496
const existsAfter = await checkUsersTableExists(differentOptions)
9597
expect(existsAfter).toBe(true)
@@ -100,29 +102,29 @@ describe('Utils: DB', () => {
100102
it('should return false when no users exist', async () => {
101103
// Create table but don't add users
102104
await createUsersTable('users', testOptions)
103-
105+
104106
const hasUsers = await hasAnyUsers(testOptions)
105107
expect(hasUsers).toBe(false)
106108
})
107109

108110
it('should return true when users exist', async () => {
109111
// Create table and add a user
110112
await createUsersTable('users', testOptions)
111-
113+
112114
// Insert a test user
113115
await db.sql`
114116
INSERT INTO users (email, name, password, created_at, updated_at)
115117
VALUES ('test@example.com', 'Test User', 'hashedpassword', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
116118
`
117-
119+
118120
const hasUsers = await hasAnyUsers(testOptions)
119121
expect(hasUsers).toBe(true)
120122
})
121123

122124
it('should return true with multiple users', async () => {
123125
// Create table and add multiple users
124126
await createUsersTable('users', testOptions)
125-
127+
126128
// Insert multiple test users
127129
await db.sql`
128130
INSERT INTO users (email, name, password, created_at, updated_at)
@@ -132,7 +134,7 @@ describe('Utils: DB', () => {
132134
INSERT INTO users (email, name, password, created_at, updated_at)
133135
VALUES ('user2@example.com', 'User 2', 'pass2', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
134136
`
135-
137+
136138
const hasUsers = await hasAnyUsers(testOptions)
137139
expect(hasUsers).toBe(true)
138140
})
@@ -155,16 +157,16 @@ describe('Utils: DB', () => {
155157

156158
// Create table and add user in different database
157159
await createUsersTable('users', differentOptions)
158-
160+
159161
// Create a new database instance for the different options
160162
const connector = await import('db0/connectors/better-sqlite3')
161163
const differentDb = createDatabase(connector.default(differentOptions.connector!.options))
162-
164+
163165
await differentDb.sql`
164166
INSERT INTO users (email, name, password, created_at, updated_at)
165167
VALUES ('test@example.com', 'Test User', 'hashedpassword', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
166168
`
167-
169+
168170
const hasUsers = await hasAnyUsers(differentOptions)
169171
expect(hasUsers).toBe(true)
170172
})
@@ -178,7 +180,7 @@ describe('Utils: DB', () => {
178180

179181
// Step 2: Create table
180182
await createUsersTable('users', testOptions)
181-
183+
182184
// Step 3: Check table exists
183185
const tableExistsAfter = await checkUsersTableExists(testOptions)
184186
expect(tableExistsAfter).toBe(true)
@@ -192,7 +194,7 @@ describe('Utils: DB', () => {
192194
INSERT INTO users (email, name, password, created_at, updated_at)
193195
VALUES ('test@example.com', 'Test User', 'hashedpassword', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
194196
`
195-
197+
196198
// Step 6: Check user exists
197199
const hasUsersAfter = await hasAnyUsers(testOptions)
198200
expect(hasUsersAfter).toBe(true)
@@ -201,13 +203,13 @@ describe('Utils: DB', () => {
201203
it('should handle multiple database operations correctly', async () => {
202204
// Create table
203205
await createUsersTable('users', testOptions)
204-
206+
205207
// Verify table exists
206208
expect(await checkUsersTableExists(testOptions)).toBe(true)
207-
209+
208210
// Verify no users initially
209211
expect(await hasAnyUsers(testOptions)).toBe(false)
210-
212+
211213
// Add users
212214
await db.sql`
213215
INSERT INTO users (email, name, password, created_at, updated_at)
@@ -217,12 +219,12 @@ describe('Utils: DB', () => {
217219
INSERT INTO users (email, name, password, created_at, updated_at)
218220
VALUES ('user2@example.com', 'User 2', 'pass2', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
219221
`
220-
222+
221223
// Verify users exist
222224
expect(await hasAnyUsers(testOptions)).toBe(true)
223-
225+
224226
// Verify table still exists
225227
expect(await checkUsersTableExists(testOptions)).toBe(true)
226228
})
227229
})
228-
})
230+
})

0 commit comments

Comments
 (0)