Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
add Router.schemaSearchParams/schemaPathParams (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Dec 7, 2023
1 parent c019f1a commit 162aa91
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-onions-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform": patch
---

add Router.schemaSearchParams/schemaPathParams
26 changes: 26 additions & 0 deletions docs/platform/Http/Router.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Added in v1.0.0
- [RouteContext](#routecontext)
- [params](#params)
- [schemaParams](#schemaparams)
- [schemaPathParams](#schemapathparams)
- [schemaSearchParams](#schemasearchparams)
- [searchParams](#searchparams)
- [routing](#routing)
- [all](#all)
Expand Down Expand Up @@ -407,6 +409,30 @@ export declare const schemaParams: <I extends Readonly<Record<string, string>>,
Added in v1.0.0
## schemaPathParams
**Signature**
```ts
export declare const schemaPathParams: <I extends Readonly<Record<string, string>>, A>(
schema: Schema.Schema<I, A>
) => Effect.Effect<RouteContext, ParseResult.ParseError, A>
```
Added in v1.0.0
## schemaSearchParams
**Signature**
```ts
export declare const schemaSearchParams: <I extends Readonly<Record<string, string>>, A>(
schema: Schema.Schema<I, A>
) => Effect.Effect<RouteContext, ParseResult.ParseError, A>
```
Added in v1.0.0
## searchParams
**Signature**
Expand Down
16 changes: 16 additions & 0 deletions packages/platform/src/Http/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ export const schemaParams: <I extends Readonly<Record<string, string>>, A>(
schema: Schema.Schema<I, A>
) => Effect.Effect<RouteContext, ParseResult.ParseError, A> = internal.schemaParams

/**
* @since 1.0.0
* @category route context
*/
export const schemaPathParams: <I extends Readonly<Record<string, string>>, A>(
schema: Schema.Schema<I, A>
) => Effect.Effect<RouteContext, ParseResult.ParseError, A> = internal.schemaPathParams

/**
* @since 1.0.0
* @category route context
*/
export const schemaSearchParams: <I extends Readonly<Record<string, string>>, A>(
schema: Schema.Schema<I, A>
) => Effect.Effect<RouteContext, ParseResult.ParseError, A> = internal.schemaSearchParams

/**
* @since 1.0.0
* @category constructors
Expand Down
21 changes: 13 additions & 8 deletions packages/platform/src/internal/http/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ export const searchParams = Effect.map(RouteContext, (_) => _.searchParams)
/** @internal */
export const schemaParams = <I extends Readonly<Record<string, string>>, A>(schema: Schema.Schema<I, A>) => {
const parse = Schema.parse(schema)
return Effect.flatMap(
RouteContext,
(_) =>
parse({
..._.searchParams,
..._.params
})
)
return Effect.flatMap(RouteContext, (_) => parse({ ..._.searchParams, ..._.params }))
}

/** @internal */
export const schemaPathParams = <I extends Readonly<Record<string, string>>, A>(schema: Schema.Schema<I, A>) => {
const parse = Schema.parse(schema)
return Effect.flatMap(RouteContext, (_) => parse(_.params))
}

/** @internal */
export const schemaSearchParams = <I extends Readonly<Record<string, string>>, A>(schema: Schema.Schema<I, A>) => {
const parse = Schema.parse(schema)
return Effect.flatMap(RouteContext, (_) => parse(_.searchParams))
}

class RouterImpl<R, E> extends Effectable.StructuralClass<
Expand Down

0 comments on commit 162aa91

Please sign in to comment.