1import * as Effect from "effect/Effect";
2import type { Scope } from "effect/Scope";
3import * as Binding from "../Binding.ts";
4import type { RuntimeContext } from "../RuntimeContext.ts";
5import type { CronEvent } from "./FunctionTriggerEvent.ts";
6
7export interface CronEventSourceProps {
8 /** Numeric five-field UTC cron expression. */ cron: string;
9 /** Enable future delivery. @default true */ enabled?: boolean;
10}
11export type CronEventSourceService = <R = never>(
12 name: string,
13 props: CronEventSourceProps,
14 handler: (event: CronEvent) => Effect.Effect<void, unknown, R>,
15) => Effect.Effect<void, never, Exclude<R, RuntimeContext | Scope>>;
16/**
17 * Register a typed POST handler and create its tracked FunctionTrigger automatically.
18 * Provide CronEventSourceHttp on the Function initialization Effect. Handler failures
19 * remain non-success HTTP responses; delivery is not a native `scheduled` event
20 * or an exactly-once guarantee. Local development does not run a cron scheduler.
21 *
22 * ### Register a Schedule
23 * **Example:** Process a scheduled occurrence
24 * ```typescript
25 * yield* Neon.CronEventSource("Nightly", { cron: "0 2 * * *" }, event => Effect.log(event.invocationId));
26 * ```
27 *
28 * @binding
29 * @product Function
30 */
31export interface CronEventSource extends Binding.Service<
32 CronEventSource,
33 "Neon.CronEventSource",
34 CronEventSourceService
35> {
36 <R = never>(
37 name: string,
38 props: CronEventSourceProps,
39 handler: (event: CronEvent) => Effect.Effect<void, unknown, R>,
40 ): Effect.Effect<
41 void,
42 never,
43 CronEventSource | Exclude<R, RuntimeContext | Scope>
44 >;
45}
46export const CronEventSource = Binding.Service<CronEventSource>(
47 "Neon.CronEventSource",
48);