| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Binding from "../Binding.ts"; |
| 3 | import { type RuntimeContext } from "../RuntimeContext.ts"; |
| 4 | import type { Function } from "./Function.ts"; |
| 5 | |
| 6 | export interface InvokeFunctionClient { |
| 7 | /** Public base URL; access control remains the application's responsibility. */ |
| 8 | url: Effect.Effect<string, never, RuntimeContext>; |
| 9 | /** Stream an HTTP response. Supply caller authorization explicitly; no account API key is attached. */ |
| 10 | fetch( |
| 11 | path?: string, |
| 12 | init?: RequestInit, |
| 13 | ): Effect.Effect<Response, InvokeFunctionError, RuntimeContext>; |
| 14 | } |
| 15 | |
| 16 | import * as Data from "effect/Data"; |
| 17 | export class InvokeFunctionError extends Data.TaggedError( |
| 18 | "InvokeFunctionError", |
| 19 | )<{ message: string }> {} |
| 20 | |
| 21 | /** |
| 22 | * Bind a public Function URL to any Alchemy runtime host. |
| 23 | * |
| 24 | * ### Invoke a Function |
| 25 | * **Example:** Forward explicit caller credentials |
| 26 | * ```typescript |
| 27 | * const invoke = yield* Neon.InvokeFunction(api); |
| 28 | * const response = yield* invoke.fetch("/private", { headers: { authorization: bearer } }); |
| 29 | * ``` |
| 30 | * |
| 31 | * @binding |
| 32 | * @product Function |
| 33 | */ |
| 34 | export interface InvokeFunction extends Binding.Service< |
| 35 | InvokeFunction, |
| 36 | "Neon.InvokeFunction", |
| 37 | (fn: Function) => Effect.Effect<InvokeFunctionClient> |
| 38 | > {} |
| 39 | export const InvokeFunction = Binding.Service<InvokeFunction>( |
| 40 | "Neon.InvokeFunction", |
| 41 | ); |