Skip to content

Commit 751c7ad

Browse files
committed
refactor(db): rename last db- prefixed files
1 parent 2a6b24d commit 751c7ad

20 files changed

+16
-17
lines changed

packages/db-react/src/use-db-reset.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { useMutation, useQueryClient } from '@tanstack/react-query'
22
import { db } from '@workspace/db/db'
3-
import { dbReset } from '@workspace/db/db-reset'
3+
import { reset } from '@workspace/db/reset'
44
import { toastSuccess } from '@workspace/ui/lib/toast-success'
55

66
export function useDbReset() {
77
const queryClient = useQueryClient()
88

99
return useMutation({
1010
mutationFn: async () => {
11-
await dbReset(db)
11+
await reset(db)
1212
queryClient.clear()
1313
toastSuccess('Database reset successfully')
1414
},

packages/db/src/database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Dexie, type Table } from 'dexie'
22
import type { Account } from './account/account.ts'
3-
import { dbPopulate } from './db-populate.ts'
43
import type { Network } from './network/network.ts'
4+
import { populate } from './populate.ts'
55
import type { Setting } from './setting/setting.ts'
66
import type { Wallet } from './wallet/wallet.ts'
77

@@ -25,7 +25,7 @@ export class Database extends Dexie {
2525
})
2626

2727
this.on('populate', async () => {
28-
await dbPopulate(this)
28+
await populate(this)
2929
})
3030
}
3131
}

packages/db/src/db-reset.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/db/src/get-default-networks.ts renamed to packages/db/src/populate-networks.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import type { Env } from '@workspace/env/env'
2-
32
import { env } from '@workspace/env/env'
43

54
import type { Network } from './network/network.ts'
65
import type { NetworkType } from './network/network-type.ts'
76

87
const networkEnvVars: (keyof Env)[] = ['networkDevnet', 'networkLocalnet', 'networkMainnet', 'networkTestnet']
98

10-
export function getDefaultNetworks(): Network[] {
9+
export function populateNetworks(): Network[] {
1110
const now = new Date()
1211
return networkEnvVars
1312
.map((key) => ({ endpoint: env(key), key }))

packages/db/src/db-populate.ts renamed to packages/db/src/populate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { env } from '@workspace/env/env'
22

33
import type { Database } from './database.ts'
44

5-
import { getDefaultNetworks } from './get-default-networks.ts'
5+
import { populateNetworks } from './populate-networks.ts'
66

7-
export async function dbPopulate(db: Database) {
7+
export async function populate(db: Database) {
88
const now = new Date()
9-
await db.networks.bulkAdd(getDefaultNetworks())
9+
await db.networks.bulkAdd(populateNetworks())
1010
await db.settings.bulkAdd([
1111
{ createdAt: now, id: crypto.randomUUID(), key: 'activeNetworkId', updatedAt: now, value: env('activeNetworkId') },
1212
{ createdAt: now, id: crypto.randomUUID(), key: 'apiEndpoint', updatedAt: now, value: env('apiEndpoint') },

packages/db/src/reset.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { Database } from './database.ts'
2+
3+
import { populate } from './populate.ts'
4+
5+
export async function reset(db: Database) {
6+
await Promise.all(db.tables.map((table) => table.clear()))
7+
await populate(db)
8+
}

0 commit comments

Comments
 (0)