-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 127afb0
Showing
11 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
[0m[2m[35m$[0m [2m[1mbun test[0m | ||
[0m[1mbun test [0m[2mv1.1.38 (bf2f153f)[0m | ||
[0m | ||
src/index.test.ts: | ||
[0m[32m✓[0m[0m[1m swipe saves data to database[0m [0m[2m[1.78ms[0m[2m][0m | ||
|
||
[0m[32m 1 pass[0m | ||
[0m[2m 0 fail[0m | ||
2 expect() calls | ||
Ran 1 tests across 1 files. [0m[2m[[1m20.00ms[0m[2m][0m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
To install dependencies: | ||
```sh | ||
bun install | ||
``` | ||
|
||
To run: | ||
```sh | ||
bun run dev | ||
``` | ||
|
||
open http://localhost:3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", | ||
"vcs": { | ||
"enabled": false, | ||
"clientKind": "git", | ||
"useIgnoreFile": false | ||
}, | ||
"files": { | ||
"ignoreUnknown": false, | ||
"ignore": [] | ||
}, | ||
"formatter": { | ||
"enabled": true, | ||
"indentStyle": "space" | ||
}, | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true, | ||
"complexity": { | ||
"noForEach": "off" | ||
}, | ||
"correctness": { | ||
"noUnusedVariables": "error", | ||
"noUnusedImports": "error" | ||
} | ||
} | ||
}, | ||
"javascript": { | ||
"formatter": { | ||
"quoteStyle": "single" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "server", | ||
"scripts": { | ||
"dev": "bun run --hot src/index.ts", | ||
"lint": "bunx biome check --write .", | ||
"test": "bun test", | ||
"types": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@trpc/server": "^11.0.0-rc.660", | ||
"hono": "^4.6.13", | ||
"uuid": "^11.0.3", | ||
"zod": "^3.23.8" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.9.4", | ||
"@hono/trpc-server": "0.3.4", | ||
"@types/bun": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Context as HonoContext } from 'hono'; | ||
import { setCookie } from 'hono/cookie'; | ||
import type { BlankEnv, BlankInput } from 'hono/types'; | ||
|
||
export async function createContext( | ||
c?: HonoContext<BlankEnv, '/trpc/*', BlankInput>, | ||
) { | ||
return { | ||
c, | ||
setUserIdCookie: (userId: string) => { | ||
if (c === undefined) { | ||
return; | ||
} | ||
setCookie(c, 'userId', userId, {}); | ||
}, | ||
}; | ||
} | ||
|
||
export type Context = Awaited<ReturnType<typeof createContext>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expect, test } from 'bun:test'; | ||
import { createContext } from './context'; | ||
import { createCaller } from './router'; | ||
import { updateSchema } from './schemas'; | ||
|
||
test('swipe saves data to database', async () => { | ||
const ctx = await createContext(); | ||
const caller = createCaller(ctx); | ||
|
||
const data = await caller.get(); | ||
|
||
const result = updateSchema.safeParse(data); | ||
|
||
expect(result.data?.status).toBe('active'); | ||
expect(result.data?.id).toBe(4); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'; | ||
import { Hono } from 'hono'; | ||
import { createContext } from './context'; | ||
import { appRouter } from './router'; | ||
|
||
const app = new Hono(); | ||
|
||
app.all('/trpc/*', async (c) => { | ||
return await fetchRequestHandler({ | ||
endpoint: '/trpc', | ||
req: c.req.raw, | ||
router: appRouter, | ||
createContext: () => createContext(c), | ||
}); | ||
}); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { initTRPC } from '@trpc/server'; | ||
import type { Context } from './context'; | ||
import { updateSchema } from './schemas'; | ||
|
||
const t = initTRPC.context<Context>().create(); | ||
|
||
const publicProcedure = t.procedure; | ||
const router = t.router; | ||
export const createCallerFactory = t.createCallerFactory; | ||
|
||
export const appRouter = router({ | ||
update: publicProcedure.input(updateSchema).mutation(() => { | ||
}), | ||
get: publicProcedure.query(() => { | ||
return { | ||
id: 4, | ||
status: 'active' | ||
} | ||
}), | ||
}); | ||
|
||
export const createCaller = createCallerFactory(appRouter); | ||
export type AppRouter = typeof appRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { z } from 'zod'; | ||
import { status } from './types'; | ||
|
||
export const updateSchema = z.object({ | ||
id: z.number(), | ||
status: z.enum(status), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const status = ['active'] as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"jsx": "react-jsx", | ||
"jsxImportSource": "hono/jsx" | ||
} | ||
} |