Skip to content

Commit

Permalink
move http search params apis to ServerRequest module (#2669)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Apr 30, 2024
1 parent ebd8656 commit 9deab0a
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 155 deletions.
19 changes: 19 additions & 0 deletions .changeset/few-lamps-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"@effect/platform": minor
---

move http search params apis to ServerRequest module

If you want to access the search params for a request, you can now use the `Http.request.ParsedSearchParams` tag.

```ts
import * as Http from "@effect/platform/HttpServer"
import { Effect } from "effect"

Effect.gen(function* () {
const searchParams = yield* Http.request.ParsedSearchParams
console.log(searchParams)
})
```

The schema method has also been moved to the `ServerRequest` module. It is now available as `Http.request.schemaSearchParams`.
2 changes: 1 addition & 1 deletion packages/platform-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@
}
},
"dependencies": {
"multipasta": "^0.2.0"
"multipasta": "^0.2.1"
}
}
2 changes: 1 addition & 1 deletion packages/platform-node-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"dependencies": {
"@parcel/watcher": "^2.4.1",
"multipasta": "^0.2.0"
"multipasta": "^0.2.1"
},
"peerDependencies": {
"@effect/platform": "workspace:^",
Expand Down
4 changes: 2 additions & 2 deletions packages/platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
"coverage": "vitest --coverage"
},
"dependencies": {
"find-my-way-ts": "^0.1.1",
"find-my-way-ts": "^0.1.2",
"isows": "^1.0.4",
"multipasta": "^0.2.0",
"multipasta": "^0.2.1",
"path-browserify": "^1.0.1"
},
"peerDependencies": {
Expand Down
4 changes: 1 addition & 3 deletions packages/platform/src/Http/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ export const toWebHandlerRuntime = <R>(runtime: Runtime.Runtime<R>) => {
const req = ServerRequest.fromWeb(request)
;(req as any)[resolveSymbol] = resolve
;(req as any)[rejectSymbol] = reject
const fiber = run(
Effect.provideService(handled, ServerRequest.ServerRequest, req)
)
const fiber = run(Effect.provideService(handled, ServerRequest.ServerRequest, req))
request.signal.addEventListener("abort", () => {
fiber.unsafeInterruptAsFork(ServerError.clientAbortFiberId)
})
Expand Down
11 changes: 11 additions & 0 deletions packages/platform/src/Http/Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,14 @@ export const withTracerDisabledForUrls: {
* @category constructors
*/
export const xForwardedHeaders: <R, E>(httpApp: App.Default<E, R>) => App.Default<E, R> = internal.xForwardedHeaders

/**
* @since 1.0.0
* @category constructors
*/
export const searchParamsParser: <E, R>(
httpApp: App.Default<E, R>
) => App.Default<
E,
Exclude<R, ServerRequest.ParsedSearchParams>
> = internal.searchParamsParser
Loading

0 comments on commit 9deab0a

Please sign in to comment.