Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
unnoq committed Jan 30, 2025
1 parent 76fc5ca commit 1a69163
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
3 changes: 1 addition & 2 deletions packages/server/src/adapters/fetch/orpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ export class RPCHandler<T extends Context> implements FetchHandler<T> {
catch (e) {
const error = e instanceof ORPCError
? e
: new ORPCError({
code: 'INTERNAL_SERVER_ERROR',
: new ORPCError('INTERNAL_SERVER_ERROR', {
message: 'Internal server error',
cause: e,
})
Expand Down
5 changes: 2 additions & 3 deletions packages/server/src/adapters/fetch/orpc-payload-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ export class ORPCPayloadCodec {

const json = await re.json()

return SuperJSON.deserialize(json)
return SuperJSON.deserialize(json as any)
}
catch (e) {
throw new ORPCError({
code: 'BAD_REQUEST',
throw new ORPCError('BAD_REQUEST', {
message: 'Cannot parse request/response. Please check the request/response body and Content-Type header.',
cause: e,
})
Expand Down
9 changes: 5 additions & 4 deletions packages/server/src/adapters/fetch/orpc-procedure-matcher.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { ANY_PROCEDURE } from '../../procedure'
import type { AnyProcedure } from '../../procedure'
import type { AnyRouter } from '../../router'
import { trim } from '@orpc/shared'
import { unlazy } from '../../lazy'
import { isProcedure } from '../../procedure'
import { type ANY_ROUTER, getRouterChild } from '../../router'
import { getRouterChild } from '../../router'

export class ORPCProcedureMatcher {
constructor(
private readonly router: ANY_ROUTER,
private readonly router: AnyRouter,
) { }

async match(pathname: string): Promise<{ path: string[], procedure: ANY_PROCEDURE } | undefined> {
async match(pathname: string): Promise<{ path: string[], procedure: AnyProcedure } | undefined> {
const path = trim(pathname, '/').split('/').map(decodeURIComponent)

const match = getRouterChild(this.router, ...path)
Expand Down
7 changes: 3 additions & 4 deletions packages/server/src/lazy.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ping } from '../tests/shared'
import { getLazyMeta, isLazy, lazy, unlazy } from './lazy'
import { isLazy, lazy, unlazy } from './lazy'

it('lazy & isLazy & unlazy & getLazyMeta', () => {
const lazied = lazy(() => Promise.resolve({ default: ping }), { prefix: '/test' })
it('lazy & isLazy & unlazy ', () => {
const lazied = lazy(() => Promise.resolve({ default: ping }))
expect(lazied).toSatisfy(isLazy)
expect(unlazy(lazied)).resolves.toEqual({ default: ping })
expect(getLazyMeta(lazied)).toEqual({ prefix: '/test' })

expect({}).not.toSatisfy(isLazy)
expect(true).not.toSatisfy(isLazy)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/procedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface ProcedureDef<
TErrorMap extends ErrorMap,
TMeta extends Meta,
> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
__initialContext?(type: TInitialContext): any
__initialContext?(type: TInitialContext): unknown
middlewares: AnyMiddleware[]
inputValidationIndex: number
outputValidationIndex: number
Expand Down

0 comments on commit 1a69163

Please sign in to comment.