Skip to content

Commit

Permalink
fix HttpPlatform dependency cycle (#3566)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Sep 7, 2024
1 parent 90ac8f6 commit 2f96465
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/platform/src/HttpApiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ export const httpApp: Effect.Effect<
* @since 1.0.0
* @category constructors
* @example
* import type { HttpApi } from "@effect/platform"
* import { HttpApi } from "@effect/platform"
* import { Etag, HttpApiBuilder, HttpMiddleware, HttpPlatform } from "@effect/platform"
* import { NodeContext } from "@effect/platform-node"
* import { Layer, ManagedRuntime } from "effect"
*
* declare const ApiLive: Layer.Layer<HttpApi.HttpApi.Service>
* const ApiLive = HttpApiBuilder.api(HttpApi.empty)
*
* const runtime = ManagedRuntime.make(
* Layer.mergeAll(
Expand Down
9 changes: 6 additions & 3 deletions packages/platform/src/internal/httpServerResponse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ParseOptions } from "@effect/schema/AST"
import type * as Schema from "@effect/schema/Schema"
import * as Context from "effect/Context"
import * as Effect from "effect/Effect"
import * as Effectable from "effect/Effectable"
import { dual } from "effect/Function"
Expand All @@ -11,7 +12,7 @@ import type * as PlatformError from "../Error.js"
import type * as FileSystem from "../FileSystem.js"
import * as Headers from "../Headers.js"
import type * as Body from "../HttpBody.js"
import * as Platform from "../HttpPlatform.js"
import type * as Platform from "../HttpPlatform.js"
import type * as Respondable from "../HttpServerRespondable.js"
import type * as ServerResponse from "../HttpServerResponse.js"
import * as Template from "../Template.js"
Expand Down Expand Up @@ -214,13 +215,15 @@ export const schemaJson = <A, I, R>(
))
}

const httpPlatform = Context.GenericTag<Platform.HttpPlatform>("@effect/platform/HttpPlatform")

/** @internal */
export const file = (
path: string,
options?: (ServerResponse.Options & FileSystem.StreamOptions) | undefined
): Effect.Effect<ServerResponse.HttpServerResponse, PlatformError.PlatformError, Platform.HttpPlatform> =>
Effect.flatMap(
Platform.HttpPlatform,
httpPlatform,
(platform) => platform.fileResponse(path, options)
)

Expand All @@ -230,7 +233,7 @@ export const fileWeb = (
options?: (ServerResponse.Options.WithContent & FileSystem.StreamOptions) | undefined
): Effect.Effect<ServerResponse.HttpServerResponse, never, Platform.HttpPlatform> =>
Effect.flatMap(
Platform.HttpPlatform,
httpPlatform,
(platform) => platform.fileWebResponse(file, options)
)

Expand Down

0 comments on commit 2f96465

Please sign in to comment.