-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update dependencies and add more react tests
- Loading branch information
1 parent
841fbce
commit d669a8f
Showing
9 changed files
with
421 additions
and
103 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
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
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
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
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
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,62 @@ | ||
import { initTRPC } from '@trpc/server' | ||
import { observable } from '@trpc/server/observable' | ||
|
||
const t = initTRPC.create() | ||
|
||
export interface User { | ||
id: string | ||
name: string | ||
} | ||
|
||
const userList: User[] = [ | ||
{ | ||
id: '1', | ||
name: 'KATT', | ||
}, | ||
] | ||
|
||
const appRouter = t.router({ | ||
userById: t.procedure | ||
.input((val: unknown) => { | ||
if (typeof val === 'string') return val | ||
|
||
throw new Error(`Invalid input: ${typeof val}`) | ||
}) | ||
.query((req) => { | ||
const { input } = req | ||
|
||
const user = userList.find((u) => u.id === input) | ||
|
||
return user | ||
}), | ||
createUser: t.procedure | ||
.input((val: unknown) => { | ||
if (typeof val === 'string') return val | ||
|
||
throw new Error(`Invalid input: ${typeof val}`) | ||
}) | ||
.mutation((req) => { | ||
const { input } = req | ||
|
||
return { | ||
id: '2', | ||
name: input, | ||
} as User | ||
}), | ||
getUserUpdates: t.procedure | ||
.input((val: unknown) => { | ||
if (typeof val === 'string') return val | ||
|
||
throw new Error(`Invalid input: ${typeof val}`) | ||
}) | ||
.subscription(() => { | ||
return observable<User>((emit) => { | ||
emit.next({ id: '3', name: 'Marie' }) | ||
}) | ||
}), | ||
}) | ||
|
||
const nestedRouter = t.router({ deeply: { nested: appRouter } }) | ||
|
||
export type NestedAppRouter = typeof nestedRouter | ||
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,60 @@ | ||
import { initTRPC } from '@trpc/server' | ||
import { observable } from '@trpc/server/observable' | ||
import SuperJSON from 'superjson' | ||
|
||
const t = initTRPC.create({ transformer: SuperJSON }) | ||
|
||
export interface User { | ||
id: string | ||
name: string | ||
} | ||
|
||
const userList: User[] = [ | ||
{ | ||
id: '1', | ||
name: 'KATT', | ||
}, | ||
] | ||
|
||
const appRouter = t.router({ | ||
userById: t.procedure | ||
.input((val: unknown) => { | ||
if (typeof val === 'string') return val | ||
|
||
throw new Error(`Invalid input: ${typeof val}`) | ||
}) | ||
.query((req) => { | ||
const { input } = req | ||
|
||
const user = userList.find((u) => u.id === input) | ||
|
||
return user | ||
}), | ||
createUser: t.procedure | ||
.input((val: unknown) => { | ||
if (typeof val === 'string') return val | ||
|
||
throw new Error(`Invalid input: ${typeof val}`) | ||
}) | ||
.mutation((req) => { | ||
const { input } = req | ||
|
||
return { | ||
id: '2', | ||
name: input, | ||
} as User | ||
}), | ||
getUserUpdates: t.procedure | ||
.input((val: unknown) => { | ||
if (typeof val === 'string') return val | ||
|
||
throw new Error(`Invalid input: ${typeof val}`) | ||
}) | ||
.subscription(() => { | ||
return observable<User>((emit) => { | ||
emit.next({ id: '3', name: 'Marie' }) | ||
}) | ||
}), | ||
}) | ||
|
||
export type AppRouteWithSuperJson = typeof appRouter |
Oops, something went wrong.