Skip to content

Commit 86afc82

Browse files
committed
fix typescript and eslint, remove better-sqlite3
1 parent 9b2e753 commit 86afc82

13 files changed

Lines changed: 86 additions & 50 deletions

File tree

app/entry.server.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,12 @@ export function handleError(
208208
}
209209
if (error instanceof Error) {
210210
console.error(chalk.red(error.stack))
211-
Sentry.captureRemixServerException(error, 'remix.server', request, true)
211+
void Sentry.captureRemixServerException(
212+
error,
213+
'remix.server',
214+
request,
215+
true,
216+
)
212217
} else {
213218
console.error(chalk.red(error))
214219
Sentry.captureException(error)

app/root.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ import * as React from 'react'
2727
import { useSpinDelay } from 'spin-delay'
2828
import { type KCDHandle } from '#app/types.ts'
2929
import { getInstanceInfo } from '#app/utils/cjs/litefs-js.server.js'
30-
import { useCapturedRouteError } from '#app/utils/misc.tsx'
30+
import {
31+
useCapturedRouteError,
32+
getDisplayUrl,
33+
getDomainUrl,
34+
getUrl,
35+
parseDate,
36+
removeTrailingSlash,
37+
typedBoolean,
38+
} from '#app/utils/misc.tsx'
3139
import { ArrowLink } from './components/arrow-button.tsx'
3240
import { ErrorPage, FourHundred } from './components/errors.tsx'
3341
import { Footer } from './components/footer.tsx'
@@ -51,14 +59,6 @@ import { ClientHintCheck, getHints } from './utils/client-hints.tsx'
5159
import { getClientSession } from './utils/client.server.ts'
5260
import { getEnv } from './utils/env.server.ts'
5361
import { getLoginInfoSession } from './utils/login.server.ts'
54-
import {
55-
getDisplayUrl,
56-
getDomainUrl,
57-
getUrl,
58-
parseDate,
59-
removeTrailingSlash,
60-
typedBoolean,
61-
} from './utils/misc.tsx'
6262
import { useNonce } from './utils/nonce-provider.ts'
6363
import { getSocialMetas } from './utils/seo.ts'
6464
import { getSession } from './utils/session.server.ts'

app/utils/cache.server.ts

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import fs from 'fs'
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import { DatabaseSync } from 'node:sqlite'
24
import {
35
type Cache,
46
cachified as baseCachified,
@@ -9,7 +11,6 @@ import {
911
totalTtl,
1012
} from '@epic-web/cachified'
1113
import { remember } from '@epic-web/remember'
12-
import Database, { type default as BetterSqlite3 } from 'better-sqlite3'
1314
import { getInstanceInfo, getInstanceInfoSync } from 'litefs-js'
1415
import { LRUCache } from 'lru-cache'
1516
import { updatePrimaryCacheValue } from '#app/routes/resources+/cache.sqlite.ts'
@@ -21,8 +22,10 @@ const CACHE_DATABASE_PATH = getRequiredServerEnvVar('CACHE_DATABASE_PATH')
2122

2223
const cacheDb = remember('cacheDb', createDatabase)
2324

24-
function createDatabase(tryAgain = true): BetterSqlite3.Database {
25-
const db = new Database(CACHE_DATABASE_PATH)
25+
function createDatabase(tryAgain = true): DatabaseSync {
26+
const parentDir = path.dirname(CACHE_DATABASE_PATH)
27+
fs.mkdirSync(parentDir, { recursive: true })
28+
const db = new DatabaseSync(CACHE_DATABASE_PATH)
2629
const { currentIsPrimary } = getInstanceInfoSync()
2730
if (!currentIsPrimary) return db
2831

@@ -69,32 +72,57 @@ export const lruCache = {
6972
},
7073
} satisfies Cache
7174

75+
const isBuffer = (obj: unknown): obj is Buffer =>
76+
Buffer.isBuffer(obj) || obj instanceof Uint8Array
77+
78+
function bufferReplacer(_key: string, value: unknown) {
79+
if (isBuffer(value)) {
80+
return {
81+
__isBuffer: true,
82+
data: value.toString('base64'),
83+
}
84+
}
85+
return value
86+
}
87+
88+
function bufferReviver(_key: string, value: unknown) {
89+
if (
90+
value &&
91+
typeof value === 'object' &&
92+
'__isBuffer' in value &&
93+
(value as any).data
94+
) {
95+
return Buffer.from((value as any).data, 'base64')
96+
}
97+
return value
98+
}
99+
72100
const preparedGet = cacheDb.prepare(
73101
'SELECT value, metadata FROM cache WHERE key = ?',
74102
)
75103
const preparedSet = cacheDb.prepare(
76-
'INSERT OR REPLACE INTO cache (key, value, metadata) VALUES (@key, @value, @metadata)',
104+
'INSERT OR REPLACE INTO cache (key, value, metadata) VALUES (?, ?, ?)',
77105
)
78106
const preparedDelete = cacheDb.prepare('DELETE FROM cache WHERE key = ?')
79107

80108
export const cache: CachifiedCache = {
81109
name: 'SQLite cache',
82110
get(key) {
83-
const result = preparedGet.get(key) as any // TODO: fix this with zod or something
111+
const result = preparedGet.get(key) as any
84112
if (!result) return null
85113
return {
86114
metadata: JSON.parse(result.metadata),
87-
value: JSON.parse(result.value),
115+
value: JSON.parse(result.value, bufferReviver),
88116
}
89117
},
90118
async set(key, entry) {
91119
const { currentIsPrimary, primaryInstance } = await getInstanceInfo()
92120
if (currentIsPrimary) {
93-
preparedSet.run({
121+
preparedSet.run(
94122
key,
95-
value: JSON.stringify(entry.value),
96-
metadata: JSON.stringify(entry.metadata),
97-
})
123+
JSON.stringify(entry.value, bufferReplacer),
124+
JSON.stringify(entry.metadata),
125+
)
98126
} else {
99127
// fire-and-forget cache update
100128
void updatePrimaryCacheValue!({

app/utils/compile-mdx.server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ const cloudinaryUrlRegex =
8080

8181
function optimizeCloudinaryImages() {
8282
return async function transformer(tree: H.Root) {
83-
// @ts-expect-error ugh
8483
visit(
8584
tree,
8685
'mdxJsxFlowElement',

app/utils/github.server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ async function downloadFileBySha(sha: string) {
132132
repo: 'kentcdodds.com',
133133
file_sha: sha,
134134
})
135-
// lol
136-
const encoding = data.encoding as Parameters<typeof Buffer.from>['1']
135+
const encoding = data.encoding as any
137136
return Buffer.from(data.content, encoding).toString()
138137
}
139138

@@ -149,7 +148,7 @@ async function downloadFile(path: string) {
149148
})
150149

151150
if ('content' in data && 'encoding' in data) {
152-
const encoding = data.encoding as Parameters<typeof Buffer.from>['1']
151+
const encoding = data.encoding as any
153152
return Buffer.from(data.content, encoding).toString()
154153
}
155154

app/utils/session.server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { type AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js'
21
import { type User } from '@prisma/client'
32
import { createCookieSessionStorage, redirect } from '@remix-run/node'
43
import { z } from 'zod'

app/utils/simplecast.server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ async function parseSummaryMarkdown(
378378
homeworkHTMLs.push(
379379
listItem.children
380380
.map((c) => {
381-
// @ts-expect-error not sure...
382381
const hastC = mdastToHast(c)
383382

384383
if (!hastC) {

content/blog/how-to-test-custom-react-hooks/__tests__/use-undo.helper.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('allows you to undo and redo', () => {
1919
expect(undoData.canUndo).toBe(false)
2020
expect(undoData.canRedo).toBe(false)
2121
expect(undoData.past).toEqual([])
22-
expect(undoData.present).toEqual('one')
22+
expect(undoData.present).toBe('one')
2323
expect(undoData.future).toEqual([])
2424

2525
// add second value
@@ -31,7 +31,7 @@ test('allows you to undo and redo', () => {
3131
expect(undoData.canUndo).toBe(true)
3232
expect(undoData.canRedo).toBe(false)
3333
expect(undoData.past).toEqual(['one'])
34-
expect(undoData.present).toEqual('two')
34+
expect(undoData.present).toBe('two')
3535
expect(undoData.future).toEqual([])
3636

3737
// add third value
@@ -43,7 +43,7 @@ test('allows you to undo and redo', () => {
4343
expect(undoData.canUndo).toBe(true)
4444
expect(undoData.canRedo).toBe(false)
4545
expect(undoData.past).toEqual(['one', 'two'])
46-
expect(undoData.present).toEqual('three')
46+
expect(undoData.present).toBe('three')
4747
expect(undoData.future).toEqual([])
4848

4949
// undo
@@ -55,7 +55,7 @@ test('allows you to undo and redo', () => {
5555
expect(undoData.canUndo).toBe(true)
5656
expect(undoData.canRedo).toBe(true)
5757
expect(undoData.past).toEqual(['one'])
58-
expect(undoData.present).toEqual('two')
58+
expect(undoData.present).toBe('two')
5959
expect(undoData.future).toEqual(['three'])
6060

6161
// undo again
@@ -67,7 +67,7 @@ test('allows you to undo and redo', () => {
6767
expect(undoData.canUndo).toBe(false)
6868
expect(undoData.canRedo).toBe(true)
6969
expect(undoData.past).toEqual([])
70-
expect(undoData.present).toEqual('one')
70+
expect(undoData.present).toBe('one')
7171
expect(undoData.future).toEqual(['two', 'three'])
7272

7373
// redo
@@ -79,7 +79,7 @@ test('allows you to undo and redo', () => {
7979
expect(undoData.canUndo).toBe(true)
8080
expect(undoData.canRedo).toBe(true)
8181
expect(undoData.past).toEqual(['one'])
82-
expect(undoData.present).toEqual('two')
82+
expect(undoData.present).toBe('two')
8383
expect(undoData.future).toEqual(['three'])
8484

8585
// add fourth value
@@ -91,7 +91,7 @@ test('allows you to undo and redo', () => {
9191
expect(undoData.canUndo).toBe(true)
9292
expect(undoData.canRedo).toBe(false)
9393
expect(undoData.past).toEqual(['one', 'two'])
94-
expect(undoData.present).toEqual('four')
94+
expect(undoData.present).toBe('four')
9595
expect(undoData.future).toEqual([])
9696
})
9797

content/blog/how-to-test-custom-react-hooks/__tests__/use-undo.rthl.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test('allows you to undo and redo', () => {
99
expect(result.current.canUndo).toBe(false)
1010
expect(result.current.canRedo).toBe(false)
1111
expect(result.current.past).toEqual([])
12-
expect(result.current.present).toEqual('one')
12+
expect(result.current.present).toBe('one')
1313
expect(result.current.future).toEqual([])
1414

1515
// add second value
@@ -21,7 +21,7 @@ test('allows you to undo and redo', () => {
2121
expect(result.current.canUndo).toBe(true)
2222
expect(result.current.canRedo).toBe(false)
2323
expect(result.current.past).toEqual(['one'])
24-
expect(result.current.present).toEqual('two')
24+
expect(result.current.present).toBe('two')
2525
expect(result.current.future).toEqual([])
2626

2727
// add third value
@@ -33,7 +33,7 @@ test('allows you to undo and redo', () => {
3333
expect(result.current.canUndo).toBe(true)
3434
expect(result.current.canRedo).toBe(false)
3535
expect(result.current.past).toEqual(['one', 'two'])
36-
expect(result.current.present).toEqual('three')
36+
expect(result.current.present).toBe('three')
3737
expect(result.current.future).toEqual([])
3838

3939
// undo
@@ -45,7 +45,7 @@ test('allows you to undo and redo', () => {
4545
expect(result.current.canUndo).toBe(true)
4646
expect(result.current.canRedo).toBe(true)
4747
expect(result.current.past).toEqual(['one'])
48-
expect(result.current.present).toEqual('two')
48+
expect(result.current.present).toBe('two')
4949
expect(result.current.future).toEqual(['three'])
5050

5151
// undo again
@@ -57,7 +57,7 @@ test('allows you to undo and redo', () => {
5757
expect(result.current.canUndo).toBe(false)
5858
expect(result.current.canRedo).toBe(true)
5959
expect(result.current.past).toEqual([])
60-
expect(result.current.present).toEqual('one')
60+
expect(result.current.present).toBe('one')
6161
expect(result.current.future).toEqual(['two', 'three'])
6262

6363
// redo
@@ -69,7 +69,7 @@ test('allows you to undo and redo', () => {
6969
expect(result.current.canUndo).toBe(true)
7070
expect(result.current.canRedo).toBe(true)
7171
expect(result.current.past).toEqual(['one'])
72-
expect(result.current.present).toEqual('two')
72+
expect(result.current.present).toBe('two')
7373
expect(result.current.future).toEqual(['three'])
7474

7575
// add fourth value
@@ -81,7 +81,7 @@ test('allows you to undo and redo', () => {
8181
expect(result.current.canUndo).toBe(true)
8282
expect(result.current.canRedo).toBe(false)
8383
expect(result.current.past).toEqual(['one', 'two'])
84-
expect(result.current.present).toEqual('four')
84+
expect(result.current.present).toBe('four')
8585
expect(result.current.future).toEqual([])
8686
})
8787

eslint.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { config as defaultConfig } from '@epic-web/config/eslint'
22

3-
/** @type {import("eslint").Linter.Config} */
4-
export default [...defaultConfig]
3+
/** @type {import("eslint").Linter.Config[]} */
4+
export default [
5+
{
6+
ignores: ['./oauth'],
7+
},
8+
...defaultConfig,
9+
]

0 commit comments

Comments
 (0)