Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: transaction context's state to derive correct type #82

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-sheep-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frog": patch
---

Fixes the `unknown` state type by passing type arguments to `transaction` route.
8 changes: 4 additions & 4 deletions src/routes/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import { getTransactionContext } from '../utils/getTransactionContext.js'
import { parsePath } from '../utils/parsePath.js'
import { requestToContext } from '../utils/requestToContext.js'

export function transaction<state, env extends Env>(
export function transaction<state, env extends Env, path extends string>(
this: FrogBase<state, env>,
path: string,
path: path,
handler: (
context: TransactionContext,
context: TransactionContext<path, state>,
) => HandlerResponse<TransactionResponse>,
options: RouteOptions = {},
) {
const { verify = this.verify } = options

this.hono.post(parsePath(path), async (c) => {
const transactionContext = getTransactionContext({
const transactionContext = getTransactionContext<path, state>({
context: await requestToContext(c.req, {
hub:
this.hub || (this.hubApiUrl ? { apiUrl: this.hubApiUrl } : undefined),
Expand Down
4 changes: 2 additions & 2 deletions src/utils/getTransactionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type GetTransactionContextParameters<state = unknown> = {
req: HonoRequest
}

export function getTransactionContext<state>(
export function getTransactionContext<path extends string, state>(
parameters: GetTransactionContextParameters<state>,
): TransactionContext<string, state> {
): TransactionContext<path, state> {
const { context, req } = parameters
const {
frameData,
Expand Down
Loading