| 1 | import { Function } from "@/Neon/Function"; |
| 2 | import { InvokeFunction } from "@/Neon/InvokeFunction"; |
| 3 | import { InvokeFunctionHttp } from "@/Neon/InvokeFunctionHttp"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 6 | import Constructor from "./function-constructor.ts"; |
| 7 | import { project } from "./function-form-resources.ts"; |
| 8 | export class LayerFunction extends Function<LayerFunction>()("LayerFunction") {} |
| 9 | export default LayerFunction.make( |
| 10 | Effect.gen(function* () { |
| 11 | return { project: yield* project, main: import.meta.url }; |
| 12 | }), |
| 13 | Effect.gen(function* () { |
| 14 | const invoke = yield* InvokeFunction(yield* Constructor); |
| 15 | return { |
| 16 | fetch: Effect.gen(function* () { |
| 17 | const response = yield* invoke.fetch().pipe(Effect.orDie); |
| 18 | const text = yield* Effect.tryPromise(() => response.text()).pipe( |
| 19 | Effect.orDie, |
| 20 | ); |
| 21 | return HttpServerResponse.text(`layer:${text}`); |
| 22 | }), |
| 23 | }; |
| 24 | }).pipe(Effect.provide(InvokeFunctionHttp)), |
| 25 | ); |