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(server, client): replace Node.js-dependent modules for better compatibility #125

Merged
merged 4 commits into from
Feb 7, 2025
Merged
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
12 changes: 6 additions & 6 deletions apps/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"fumadocs-twoslash": "^2.0.1",
"fumadocs-ui": "14.4.0",
"geist": "^1.3.1",
"next": "15.0.3",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"next": "15.1.4",
"react": "19.0.0",
"react-dom": "19.0.0"
},
"devDependencies": {
"@orpc/client": "workspace:*",
Expand All @@ -29,18 +29,18 @@
"@orpc/vue-colada": "workspace:*",
"@orpc/vue-query": "workspace:*",
"@orpc/zod": "workspace:*",
"@tanstack/react-query": "^5.62.7",
"@tanstack/react-query": "^5.63.0",
"@tanstack/vue-query": "^5.62.7",
"@types/express": "^5.0.0",
"@types/mdx": "^2.0.13",
"@types/node": "^22.9.0",
"@types/node": "^22.10.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"autoprefixer": "^10.4.20",
"express": "^4.21.1",
"postcss": "^8.4.48",
"tailwindcss": "^3.4.14",
"typescript": "5.7.2",
"typescript": "5.7.3",
"zod": "^3.24.1"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@eslint-react/eslint-plugin": "^1.16.2",
"@testing-library/jest-dom": "^6.6.2",
"@testing-library/react": "^16.0.1",
"@types/node": "^22.9.0",
"@types/node": "^22.10.0",
"@vitest/coverage-v8": "^3.0.4",
"eslint": "^9.15.0",
"eslint-plugin-format": "^0.1.2",
Expand All @@ -40,7 +40,7 @@
"lint-staged": "^15.2.10",
"simple-git-hooks": "^2.11.1",
"tsup": "^8.3.0",
"typescript": "5.7.2",
"typescript": "5.7.3",
"vitest": "^3.0.4"
},
"simple-git-hooks": {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@orpc/contract": "workspace:*",
"@orpc/server": "workspace:*",
"@orpc/shared": "workspace:*",
"content-disposition": "^0.5.4"
"@tinyhttp/content-disposition": "^2.2.2"
},
"devDependencies": {
"@orpc/openapi": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/adapters/fetch/orpc-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ORPCError } from '@orpc/contract'
import { fetchReToStandardBody } from '@orpc/server/fetch'
import { RPCSerializer } from '@orpc/server/standard'
import { isPlainObject, trim } from '@orpc/shared'
import cd from 'content-disposition'
import { contentDisposition } from '@tinyhttp/content-disposition'

export interface RPCLinkOptions<TClientContext> {
/**
Expand Down Expand Up @@ -74,7 +74,7 @@ export class RPCLink<TClientContext> implements ClientLink<TClientContext> {
const encoded = await this.encode(path, input, options)

if (encoded.body instanceof Blob && !encoded.headers.has('content-disposition')) {
encoded.headers.set('content-disposition', cd(encoded.body instanceof File ? encoded.body.name : 'blob'))
encoded.headers.set('content-disposition', contentDisposition(encoded.body instanceof File ? encoded.body.name : 'blob'))
}

const response = await this.fetch(encoded.url, {
Expand Down
4 changes: 2 additions & 2 deletions packages/contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
},
"dependencies": {
"@orpc/shared": "workspace:*",
"@standard-schema/spec": "1.0.0-rc.0"
"@standard-schema/spec": "1.0.0"
},
"devDependencies": {
"arktype": "2.0.0-rc.26",
"valibot": "1.0.0-beta.9",
"zod": "3.24.1"
"zod": "^3.24.1"
}
}
3 changes: 0 additions & 3 deletions packages/openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@
"@orpc/contract": "workspace:*",
"@orpc/server": "workspace:*",
"@orpc/shared": "workspace:*",
"@standard-schema/spec": "1.0.0-beta.4",
"@types/content-disposition": "^0.5.8",
"content-disposition": "^0.5.4",
"escape-string-regexp": "^5.0.0",
"fast-content-type-parse": "^2.0.0",
"json-schema-typed": "^8.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"dependencies": {
"@orpc/contract": "workspace:*",
"@orpc/shared": "workspace:*",
"content-disposition": "^0.5.4"
"@tinyhttp/content-disposition": "^2.2.2"
},
"devDependencies": {
"light-my-request": "^6.5.1"
Expand Down
8 changes: 4 additions & 4 deletions packages/server/src/adapters/fetch/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StandardBody, StandardHeaders, StandardRequest, StandardResponse } from '../standard'
import { once } from '@orpc/shared'
import cd from 'content-disposition'
import { contentDisposition, parse as parseContentDisposition } from '@tinyhttp/content-disposition'

function fetchHeadersToStandardHeaders(headers: Headers): StandardHeaders {
const standardHeaders: StandardHeaders = {}
Expand All @@ -26,9 +26,9 @@ export async function fetchReToStandardBody(re: Request | Response): Promise<Sta
}

const contentDisposition = re.headers.get('content-disposition')
const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : undefined
const fileName = contentDisposition ? parseContentDisposition(contentDisposition).parameters.filename : undefined

if (fileName) {
if (typeof fileName === 'string') {
const blob = await re.blob()
return new File([blob], fileName, {
type: blob.type,
Expand Down Expand Up @@ -102,7 +102,7 @@ function standardResponseToFetchHeaders(response: StandardResponse): Headers {
}

if (response.body instanceof Blob && !fetchHeaders.has('content-disposition')) {
fetchHeaders.set('content-disposition', cd(response.body instanceof File ? response.body.name : 'blob'))
fetchHeaders.set('content-disposition', contentDisposition(response.body instanceof File ? response.body.name : 'blob'))
}
else if (
!(response.body instanceof Blob)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/adapters/hono/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function createMiddleware<T extends Context>(handler: FetchHandler<T>, ..
const { matched, response } = await handler.handle(request, { ...options, context })

if (matched) {
return c.body(response.body, response)
return c.newResponse(response.body, response)
}

await next()
Expand Down
8 changes: 4 additions & 4 deletions packages/server/src/adapters/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { NodeHttpRequest, NodeHttpResponse } from './types'
import { Buffer, File } from 'node:buffer'
import { Readable } from 'node:stream'
import { once } from '@orpc/shared'
import cd from 'content-disposition'
import { contentDisposition, parse as parseContentDisposition } from '@tinyhttp/content-disposition'

export function nodeHttpToStandardRequest(
req: NodeHttpRequest,
Expand Down Expand Up @@ -57,7 +57,7 @@ export function nodeHttpResponseSendStandardResponse(
}

if (!standardResponse.headers['content-disposition'] && standardResponse.body instanceof Blob) {
resHeaders['content-disposition'] = cd(standardResponse.body instanceof File ? standardResponse.body.name : 'blob')
resHeaders['content-disposition'] = contentDisposition(standardResponse.body instanceof File ? standardResponse.body.name : 'blob')
}

res.writeHead(standardResponse.status, resHeaders)
Expand Down Expand Up @@ -113,10 +113,10 @@ async function nodeHttpRequestToStandardBody(req: NodeHttpRequest): Promise<Stan
}

const contentDisposition = req.headers['content-disposition']
const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : undefined
const fileName = contentDisposition ? parseContentDisposition(contentDisposition).parameters.filename : undefined
const contentType = req.headers['content-type']

if (fileName) {
if (typeof fileName === 'string') {
return await streamToFile(req, fileName, contentType || 'application/octet-stream') as any // Conflict between types=node and lib=dom so we need to cast it
}

Expand Down
1 change: 0 additions & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"type:check": "tsc -b"
},
"dependencies": {
"@standard-schema/spec": "1.0.0-beta.4",
"is-what": "^5.0.2",
"radash": "^12.1.0",
"type-fest": "^4.26.1"
Expand Down
1 change: 1 addition & 0 deletions packages/zod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@orpc/server": "workspace:*"
},
"dependencies": {
"@standard-schema/spec": "^1.0.0",
"json-schema-typed": "^8.0.1",
"wildcard-match": "^5.1.3",
"zod": "^3.24.1"
Expand Down
4 changes: 2 additions & 2 deletions playgrounds/contract-openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"zod": "^3.24.1"
},
"devDependencies": {
"@types/node": "^22.9.0",
"@types/node": "^22.10.0",
"tsx": "^4.19.2",
"typescript": "^5.6.3"
"typescript": "5.7.3"
}
}
4 changes: 2 additions & 2 deletions playgrounds/expressjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"devDependencies": {
"@types/express": "^5.0.0",
"@types/node": "^22.9.0",
"@types/node": "^22.10.0",
"tsx": "^4.19.2",
"typescript": "^5.6.3"
"typescript": "5.7.3"
}
}
2 changes: 1 addition & 1 deletion playgrounds/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"@types/node": "^22.10.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"typescript": "^5.7.2"
"typescript": "5.7.3"
}
}
4 changes: 2 additions & 2 deletions playgrounds/openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"zod": "^3.24.1"
},
"devDependencies": {
"@types/node": "^22.9.0",
"@types/node": "^22.10.0",
"tsx": "^4.19.2",
"typescript": "^5.6.3"
"typescript": "5.7.3"
}
}
Loading