effect-cf 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +36 -46
- package/dist/index.d.mts +353 -28
- package/dist/index.mjs +333 -6
- package/package.json +1 -1
- package/src/DurableObject.ts +26 -2
- package/src/DurableObjectAlarm.ts +832 -0
- package/src/Worker.ts +11 -45
- package/src/WorkerDefinition.ts +4 -9
- package/src/index.ts +1 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cause, Config, ConfigProvider, Context, Effect, Layer, Option, Schema, Scope } from "effect";
|
|
1
|
+
import { Cause, Config, ConfigProvider, Context, DateTime, Duration, Effect, Layer, Option, Schema, Scope } from "effect";
|
|
2
2
|
import { DurableObject, RpcStub, RpcTarget, WorkerEntrypoint } from "cloudflare:workers";
|
|
3
3
|
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
4
4
|
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
|
|
@@ -440,7 +440,7 @@ declare class DurableObjectState extends DurableObjectState_base {}
|
|
|
440
440
|
*/
|
|
441
441
|
declare const fromDurableObjectState: (state: globalThis.DurableObjectState) => DurableObjectStateService;
|
|
442
442
|
declare namespace DurableObjectDefinition_d_exports {
|
|
443
|
-
export { Api$3 as Api, Definition$3 as Definition, DurableObject$1 as DurableObject, HandlerEffect$3 as HandlerEffect, Handlers$3 as Handlers, NamespaceService, Options$3 as Options, ReservedMethodName$4 as ReservedMethodName, ServerApi$4 as ServerApi, Tag$
|
|
443
|
+
export { Api$3 as Api, Definition$3 as Definition, DurableObject$1 as DurableObject, HandlerEffect$3 as HandlerEffect, Handlers$3 as Handlers, NamespaceService, Options$3 as Options, ReservedMethodName$4 as ReservedMethodName, ServerApi$4 as ServerApi, Tag$4 as Tag, implement$3 as implement, make$4 as make, method$3 as method };
|
|
444
444
|
}
|
|
445
445
|
/**
|
|
446
446
|
* RPC contract for a Durable Object class.
|
|
@@ -533,7 +533,7 @@ declare const make$4: <Id extends string, const MethodsShape extends Methods>(id
|
|
|
533
533
|
readonly scopedCall: <Method extends (([Api$3<Definition$3<Id, MethodsShape>>] extends [never] ? Definition$3<Id, MethodsShape> extends infer T ? T extends Definition$3<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$4<T> : never : never : never : Api$3<Definition$3<Id, MethodsShape>>) extends infer T_2 ? { [Key in keyof T_2]-?: Key extends string ? T_2[Key] extends ((...args: any[]) => Promise<unknown>) ? Key : never : never } : never)[keyof ([Api$3<Definition$3<Id, MethodsShape>>] extends [never] ? Definition$3<Id, MethodsShape> extends infer T ? T extends Definition$3<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$4<T> : never : never : never : Api$3<Definition$3<Id, MethodsShape>>)]>(stub: DurableObjectStubClient<[Api$3<Definition$3<Id, MethodsShape>>] extends [never] ? Definition$3<Id, MethodsShape> extends infer T ? T extends Definition$3<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$4<T> : never : never : never : Api$3<Definition$3<Id, MethodsShape>>>, method: Method, ...args: AsyncMethodArgs<[Api$3<Definition$3<Id, MethodsShape>>] extends [never] ? Definition$3<Id, MethodsShape> extends infer T ? T extends Definition$3<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$4<T> : never : never : never : Api$3<Definition$3<Id, MethodsShape>>, Method>) => Effect.Effect<Awaited<Result<AsyncMethodSuccess<[Api$3<Definition$3<Id, MethodsShape>>] extends [never] ? Definition$3<Id, MethodsShape> extends infer T ? T extends Definition$3<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$4<T> : never : never : never : Api$3<Definition$3<Id, MethodsShape>>, Method>>>, unknown, _$effect_Scope0.Scope>;
|
|
534
534
|
};
|
|
535
535
|
};
|
|
536
|
-
declare const Tag$
|
|
536
|
+
declare const Tag$4: <_Self>() => <Id extends string, const MethodsShape extends Methods>(id: Id, methods: MethodsShape & NoReservedMethods<MethodsShape, ReservedMethodName$4>) => (abstract new () => object) & (Definition$3<Id, MethodsShape> & {
|
|
537
537
|
make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options: Options$3<ROut, Definition$3<Id, MethodsShape>>) => DurableObjectClass<BoundaryHandlers$1<ROut, Definition$3<Id, MethodsShape>>, ROut>;
|
|
538
538
|
Namespace: <Self>() => <BindingId extends string>(bindingId: BindingId, binding: Omit<DurableObjectNamespaceBindingDefinition<Definition$3<Id, MethodsShape>>, "definition">) => _$effect_Context0.ServiceClass<Self, BindingId, DurableObjectNamespaceClient<[Api$3<Definition$3<Id, MethodsShape>>] extends [never] ? Definition$3<Id, MethodsShape> extends infer T ? T extends Definition$3<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$4<T> : never : never : never : Api$3<Definition$3<Id, MethodsShape>>>> & {
|
|
539
539
|
"effect-cf/Binding": "effect-cf/Binding";
|
|
@@ -771,7 +771,7 @@ declare const Service$2: <Self, Api extends object = never>() => <Id extends str
|
|
|
771
771
|
readonly scopedCall: <Method extends StubMethodKey<ApiOrDefinition$1<Api, Definition>>>(stub: DurableObjectStubClient<ApiOrDefinition$1<Api, Definition>>, method: Method, ...args: StubMethodArgs<ApiOrDefinition$1<Api, Definition>, Method>) => Effect.Effect<Awaited<Result<AsyncMethodSuccess<ApiOrDefinition$1<Api, Definition>, Method>>>, unknown, _$effect_Scope0.Scope>;
|
|
772
772
|
};
|
|
773
773
|
declare namespace WorkerDefinition_d_exports {
|
|
774
|
-
export { Api$2 as Api, BindingService, Definition$2 as Definition, HandlerEffect$2 as HandlerEffect, Handlers$2 as Handlers, Options$2 as Options, ReservedMethodName$2 as ReservedMethodName, ServerApi$3 as ServerApi, Tag$
|
|
774
|
+
export { Api$2 as Api, BindingService, Definition$2 as Definition, HandlerEffect$2 as HandlerEffect, Handlers$2 as Handlers, Options$2 as Options, ReservedMethodName$2 as ReservedMethodName, ServerApi$3 as ServerApi, Tag$3 as Tag, Worker, implement$2 as implement, make$3 as make, method$2 as method };
|
|
775
775
|
}
|
|
776
776
|
/**
|
|
777
777
|
* RPC contract for a Worker service.
|
|
@@ -807,7 +807,7 @@ type BoundaryHandlers<ROut, Self extends Definition$2.Any> = { readonly [Key in
|
|
|
807
807
|
/**
|
|
808
808
|
* Worker constructor options for a specific RPC definition.
|
|
809
809
|
*/
|
|
810
|
-
interface Options$2<ROut, Self extends Definition$2.Any
|
|
810
|
+
interface Options$2<ROut, Self extends Definition$2.Any> extends Omit<WorkerOptions<ROut, Handlers$2<ROut, Self>>, "rpc"> {
|
|
811
811
|
readonly rpc: Handlers$2<ROut, Self>;
|
|
812
812
|
}
|
|
813
813
|
/**
|
|
@@ -815,7 +815,7 @@ interface Options$2<ROut, Self extends Definition$2.Any, RRequest = never, Reque
|
|
|
815
815
|
*/
|
|
816
816
|
declare const method$2: typeof method$4;
|
|
817
817
|
declare const make$3: <Id extends string, const MethodsShape extends Methods>(id: Id, methods: MethodsShape & NoReservedMethods<MethodsShape, ReservedMethodName$2>) => Definition$2<Id, MethodsShape> & {
|
|
818
|
-
make: <ROut, LayerError
|
|
818
|
+
make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: Options$2<ROut, Definition$2<Id, MethodsShape>>) => WorkerClass<BoundaryHandlers<ROut, Definition$2<Id, MethodsShape>>, ROut>;
|
|
819
819
|
Binding: <Self>() => <BindingId extends string>(bindingId: BindingId, binding: Omit<ServiceBindingDefinition<Definition$2<Id, MethodsShape>>, "definition">) => _$effect_Context0.ServiceClass<Self, BindingId, ServiceBindingClient<[Api$2<Definition$2<Id, MethodsShape>>] extends [never] ? Definition$2<Id, MethodsShape> extends infer T ? T extends Definition$2<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$3<T> : never : never : never : Api$2<Definition$2<Id, MethodsShape>>>> & {
|
|
820
820
|
"effect-cf/Binding": "effect-cf/Binding";
|
|
821
821
|
binding: string;
|
|
@@ -841,8 +841,8 @@ declare const make$3: <Id extends string, const MethodsShape extends Methods>(id
|
|
|
841
841
|
readonly scopedCall: <Method extends (([Api$2<Definition$2<Id, MethodsShape>>] extends [never] ? Definition$2<Id, MethodsShape> extends infer T ? T extends Definition$2<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$3<T> : never : never : never : Api$2<Definition$2<Id, MethodsShape>>) extends infer T_2 ? { [Key in keyof T_2]-?: Key extends string ? T_2[Key] extends ((...args: any[]) => Promise<unknown>) ? Key : never : never } : never)[keyof ([Api$2<Definition$2<Id, MethodsShape>>] extends [never] ? Definition$2<Id, MethodsShape> extends infer T ? T extends Definition$2<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$3<T> : never : never : never : Api$2<Definition$2<Id, MethodsShape>>)]>(method: Method, ...args: AsyncMethodArgs<[Api$2<Definition$2<Id, MethodsShape>>] extends [never] ? Definition$2<Id, MethodsShape> extends infer T ? T extends Definition$2<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$3<T> : never : never : never : Api$2<Definition$2<Id, MethodsShape>>, Method>) => Effect.Effect<Awaited<Result<AsyncMethodSuccess<[Api$2<Definition$2<Id, MethodsShape>>] extends [never] ? Definition$2<Id, MethodsShape> extends infer T ? T extends Definition$2<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$3<T> : never : never : never : Api$2<Definition$2<Id, MethodsShape>>, Method>>>, unknown, BindingService<BindingId, Definition$2<Id, MethodsShape>> | _$effect_Scope0.Scope>;
|
|
842
842
|
};
|
|
843
843
|
};
|
|
844
|
-
declare const Tag$
|
|
845
|
-
make: <ROut, LayerError
|
|
844
|
+
declare const Tag$3: <_Self>() => <Id extends string, const MethodsShape extends Methods>(id: Id, methods: MethodsShape & NoReservedMethods<MethodsShape, ReservedMethodName$2>) => (abstract new () => object) & (Definition$2<Id, MethodsShape> & {
|
|
845
|
+
make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: Options$2<ROut, Definition$2<Id, MethodsShape>>) => WorkerClass<BoundaryHandlers<ROut, Definition$2<Id, MethodsShape>>, ROut>;
|
|
846
846
|
Binding: <Self>() => <BindingId extends string>(bindingId: BindingId, binding: Omit<ServiceBindingDefinition<Definition$2<Id, MethodsShape>>, "definition">) => _$effect_Context0.ServiceClass<Self, BindingId, ServiceBindingClient<[Api$2<Definition$2<Id, MethodsShape>>] extends [never] ? Definition$2<Id, MethodsShape> extends infer T ? T extends Definition$2<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$3<T> : never : never : never : Api$2<Definition$2<Id, MethodsShape>>>> & {
|
|
847
847
|
"effect-cf/Binding": "effect-cf/Binding";
|
|
848
848
|
binding: string;
|
|
@@ -869,7 +869,7 @@ declare const Tag$2: <_Self>() => <Id extends string, const MethodsShape extends
|
|
|
869
869
|
};
|
|
870
870
|
});
|
|
871
871
|
declare const Worker: <_Self>() => <Id extends string, const MethodsShape extends Methods>(id: Id, methods: MethodsShape & NoReservedMethods<MethodsShape, ReservedMethodName$2>) => (abstract new () => object) & (Definition$2<Id, MethodsShape> & {
|
|
872
|
-
make: <ROut, LayerError
|
|
872
|
+
make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: Options$2<ROut, Definition$2<Id, MethodsShape>>) => WorkerClass<BoundaryHandlers<ROut, Definition$2<Id, MethodsShape>>, ROut>;
|
|
873
873
|
Binding: <Self>() => <BindingId extends string>(bindingId: BindingId, binding: Omit<ServiceBindingDefinition<Definition$2<Id, MethodsShape>>, "definition">) => _$effect_Context0.ServiceClass<Self, BindingId, ServiceBindingClient<[Api$2<Definition$2<Id, MethodsShape>>] extends [never] ? Definition$2<Id, MethodsShape> extends infer T ? T extends Definition$2<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$3<T> : never : never : never : Api$2<Definition$2<Id, MethodsShape>>>> & {
|
|
874
874
|
"effect-cf/Binding": "effect-cf/Binding";
|
|
875
875
|
binding: string;
|
|
@@ -994,7 +994,7 @@ declare const Service$1: <Self, Api extends object = never>() => <Id extends str
|
|
|
994
994
|
readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: ServiceMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Awaited<Result<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>>, unknown, Self | _$effect_Scope0.Scope>;
|
|
995
995
|
};
|
|
996
996
|
declare namespace Worker_d_exports {
|
|
997
|
-
export { Api$1 as Api, Definition$1 as Definition, ExecutionContext, FetchHandler, FetchWorkerOptions, HandlerEffect$1 as HandlerEffect, Handlers$1 as Handlers, NativeRequest, Options$1 as Options, ReservedMethodName, RpcHandlers$1 as RpcHandlers, ServerApi$2 as ServerApi, Tag$
|
|
997
|
+
export { Api$1 as Api, Definition$1 as Definition, ExecutionContext, FetchHandler, FetchWorkerOptions, HandlerEffect$1 as HandlerEffect, Handlers$1 as Handlers, NativeRequest, Options$1 as Options, ReservedMethodName, RpcHandlers$1 as RpcHandlers, ServerApi$2 as ServerApi, Tag$2 as Tag, WorkerClass, WorkerContext, WorkerContextService, WorkerContextWaitUntilOptions, WorkerFetchSuccess, WorkerHandler, WorkerOptions, WorkerRpc, WorkerRpcHandler, WorkerRpcShape, implement$1 as implement, isWebSocketUpgrade, make$2 as make, makeFetchHandler, method$1 as method, renderHttpResponse };
|
|
998
998
|
}
|
|
999
999
|
declare const ExecutionContext_base: Context.ServiceClass<ExecutionContext, "effect-cf/ExecutionContext", globalThis.ExecutionContext<unknown>>;
|
|
1000
1000
|
declare class ExecutionContext extends ExecutionContext_base {}
|
|
@@ -1021,18 +1021,11 @@ type WorkerRpcHandler<ROut, A = unknown> = Effect.Effect<A, unknown, WorkerRpcCo
|
|
|
1021
1021
|
type WorkerRpc<ROut> = Record<string, (...args: Array<any>) => WorkerRpcHandler<ROut>>;
|
|
1022
1022
|
type WorkerRpcShape<Rpc extends WorkerRpc<ROut>, ROut> = { readonly [Key in keyof Rpc]: Rpc[Key] extends ((...args: infer Args) => Effect.Effect<infer A, unknown, WorkerRpcContext<ROut>>) ? (...args: Args) => Promise<A> : never };
|
|
1023
1023
|
type RpcHandlers$1<ROut, Api> = { readonly [Key in keyof Api as Key extends keyof WorkerEntrypoint ? never : Key extends string ? Key extends ReservedMethodName ? never : [Api[Key]] extends [never] ? never : Api[Key] extends ((...args: Array<any>) => Promise<unknown>) ? Key : never : never]: Api[Key] extends ((...args: infer Args) => Promise<infer A>) ? (...args: Args) => WorkerRpcHandler<ROut, A> : never };
|
|
1024
|
-
interface WorkerOptions<ROut, Rpc extends WorkerRpc<ROut
|
|
1025
|
-
readonly fetch?: Effect.Effect<WorkerFetchSuccess, unknown, WorkerFetchContext<ROut
|
|
1026
|
-
/**
|
|
1027
|
-
* Per-request services provided while evaluating the fetch handler.
|
|
1028
|
-
*
|
|
1029
|
-
* This scope closes when the handler produces a `Response`; it is not kept
|
|
1030
|
-
* open until a streaming response body is consumed by the platform.
|
|
1031
|
-
*/
|
|
1032
|
-
readonly requestLayer?: Layer.Layer<RRequest, RequestLayerError, WorkerFetchContext<ROut>>;
|
|
1024
|
+
interface WorkerOptions<ROut, Rpc extends WorkerRpc<ROut>> {
|
|
1025
|
+
readonly fetch?: Effect.Effect<WorkerFetchSuccess, unknown, WorkerFetchContext<ROut>>;
|
|
1033
1026
|
readonly rpc?: Rpc;
|
|
1034
1027
|
}
|
|
1035
|
-
type FetchWorkerOptions<ROut
|
|
1028
|
+
type FetchWorkerOptions<ROut> = Omit<WorkerOptions<ROut, Record<never, never>>, "rpc"> & {
|
|
1036
1029
|
readonly rpc?: never;
|
|
1037
1030
|
};
|
|
1038
1031
|
type WorkerClass<Rpc extends WorkerRpc<ROut>, ROut> = new (ctx: globalThis.ExecutionContext, env: WorkerEnv) => WorkerEntrypoint<WorkerEnv> & {
|
|
@@ -1042,10 +1035,10 @@ interface FetchHandler<Env extends WorkerEnv = WorkerEnv> {
|
|
|
1042
1035
|
readonly fetch: (request: Request, env: Env, ctx: globalThis.ExecutionContext) => Promise<Response>;
|
|
1043
1036
|
}
|
|
1044
1037
|
declare const renderHttpResponse: <A extends HttpServerResponse.HttpServerResponse, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<Response, E, R>;
|
|
1045
|
-
declare const make$2: <ROut, LayerError, const Rpc extends WorkerRpc<ROut> = Record<never, never
|
|
1046
|
-
declare const makeFetchHandler: <ROut, LayerError,
|
|
1047
|
-
declare const Tag$
|
|
1048
|
-
make: <ROut, LayerError
|
|
1038
|
+
declare const make$2: <ROut, LayerError, const Rpc extends WorkerRpc<ROut> = Record<never, never>>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: WorkerOptions<ROut, Rpc>) => WorkerClass<Rpc, ROut>;
|
|
1039
|
+
declare const makeFetchHandler: <ROut, LayerError, Env extends WorkerEnv = WorkerEnv>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: FetchWorkerOptions<ROut>) => FetchHandler<Env>;
|
|
1040
|
+
declare const Tag$2: <_Self>() => <Id extends string, const MethodsShape extends Methods>(id: Id, methods: MethodsShape & NoReservedMethods<MethodsShape, ReservedMethodName$2>) => (abstract new () => object) & (Definition$2<Id, MethodsShape> & {
|
|
1041
|
+
make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: Options$2<ROut, Definition$2<Id, MethodsShape>>) => WorkerClass<{ readonly [Key in keyof MethodsShape]: (...args: Array<unknown>) => WorkerRpcHandler<ROut, _$effect_Schema0.Codec.Encoded<MethodsShape[Key]["success"]>> }, ROut>;
|
|
1049
1042
|
Binding: <Self>() => <BindingId extends string>(bindingId: BindingId, binding: Omit<ServiceBindingDefinition<Definition$2<Id, MethodsShape>>, "definition">) => Context.ServiceClass<Self, BindingId, ServiceBindingClient<[Api$2<Definition$2<Id, MethodsShape>>] extends [never] ? Definition$2<Id, MethodsShape> extends infer T ? T extends Definition$2<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$3<T> : never : never : never : Api$2<Definition$2<Id, MethodsShape>>>> & {
|
|
1050
1043
|
"effect-cf/Binding": "effect-cf/Binding";
|
|
1051
1044
|
binding: string;
|
|
@@ -1080,10 +1073,10 @@ declare namespace Definition$1 {
|
|
|
1080
1073
|
type ServerApi$2<Self extends Definition$2.Any> = ServerApi$3<Self>;
|
|
1081
1074
|
type Api$1<Self extends Definition$2.Any> = Api$2<Self>;
|
|
1082
1075
|
type Handlers$1<ROut, Self extends Definition$2.Any> = Handlers$2<ROut, Self>;
|
|
1083
|
-
type Options$1<ROut, Self extends Definition$2.Any
|
|
1076
|
+
type Options$1<ROut, Self extends Definition$2.Any> = Options$2<ROut, Self>;
|
|
1084
1077
|
type HandlerEffect$1<ROut, Self extends Definition$2.Any, Key extends keyof Self["methods"]> = HandlerEffect$2<ROut, Self, Key>;
|
|
1085
1078
|
declare namespace DurableObject_d_exports {
|
|
1086
|
-
export { Api, Definition, DurableObjectClass, DurableObjectHandler, DurableObjectOptions, DurableObjectRpc, DurableObjectRpcShape, HandlerEffect, Handlers, Options, RpcHandlers, ServerApi$1 as ServerApi, Tag, implement, make$1 as make, method };
|
|
1079
|
+
export { Api, Definition, DurableObjectClass, DurableObjectHandler, DurableObjectOptions, DurableObjectRpc, DurableObjectRpcShape, HandlerEffect, Handlers, Options, RpcHandlers, ServerApi$1 as ServerApi, Tag$1 as Tag, implement, make$1 as make, method };
|
|
1087
1080
|
}
|
|
1088
1081
|
type RuntimeContext<ROut> = DurableObjectState | WorkerEnvironment | ROut;
|
|
1089
1082
|
type HandlerContext<ROut> = RuntimeContext<ROut> | Scope.Scope;
|
|
@@ -1106,6 +1099,14 @@ interface DurableObjectOptions<ROut, Rpc extends DurableObjectRpc<ROut>> {
|
|
|
1106
1099
|
readonly rpc?: Rpc;
|
|
1107
1100
|
/** Optional fetch handler for HTTP/WebSocket requests. */
|
|
1108
1101
|
readonly fetch?: Effect.Effect<Response, unknown, FetchContext<ROut>>;
|
|
1102
|
+
/**
|
|
1103
|
+
* Optional logical alarm processing effect.
|
|
1104
|
+
*
|
|
1105
|
+
* This runs before `alarm` and should be built with helpers such as
|
|
1106
|
+
* `DurableObjectAlarm.processDue(...)` so the reusable scheduler stays inside
|
|
1107
|
+
* the Durable Object's single managed runtime boundary.
|
|
1108
|
+
*/
|
|
1109
|
+
readonly alarms?: Effect.Effect<unknown, unknown, HandlerContext<ROut>>;
|
|
1109
1110
|
readonly alarm?: (alarmInfo?: globalThis.AlarmInvocationInfo) => Effect.Effect<void, unknown, HandlerContext<ROut>>;
|
|
1110
1111
|
readonly webSocketMessage?: (socket: WebSocket, message: string | ArrayBuffer) => Effect.Effect<void, unknown, HandlerContext<ROut>>;
|
|
1111
1112
|
readonly webSocketClose?: (socket: WebSocket, code: number, reason: string, wasClean: boolean) => Effect.Effect<void, unknown, HandlerContext<ROut>>;
|
|
@@ -1119,7 +1120,7 @@ type DurableObjectClass<Rpc extends DurableObjectRpc<ROut>, ROut> = new (state:
|
|
|
1119
1120
|
* Creates a Durable Object class backed by a single managed Effect runtime.
|
|
1120
1121
|
*/
|
|
1121
1122
|
declare const make$1: <ROut, LayerError, const Rpc extends DurableObjectRpc<ROut> = Record<never, never>>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options?: DurableObjectOptions<ROut, Rpc>) => DurableObjectClass<Rpc, ROut>;
|
|
1122
|
-
declare const Tag: <_Self>() => <Id extends string, const MethodsShape extends Methods>(id: Id, methods: MethodsShape & NoReservedMethods<MethodsShape, ReservedMethodName$4>) => (abstract new () => object) & (Definition$3<Id, MethodsShape> & {
|
|
1123
|
+
declare const Tag$1: <_Self>() => <Id extends string, const MethodsShape extends Methods>(id: Id, methods: MethodsShape & NoReservedMethods<MethodsShape, ReservedMethodName$4>) => (abstract new () => object) & (Definition$3<Id, MethodsShape> & {
|
|
1123
1124
|
make: <ROut, LayerError>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options: Options$3<ROut, Definition$3<Id, MethodsShape>>) => DurableObjectClass<{ readonly [Key in keyof MethodsShape]: (...args: Array<unknown>) => DurableObjectHandler<ROut, _$effect_Schema0.Codec.Encoded<MethodsShape[Key]["success"]>> }, ROut>;
|
|
1124
1125
|
Namespace: <Self>() => <BindingId extends string>(bindingId: BindingId, binding: Omit<DurableObjectNamespaceBindingDefinition<Definition$3<Id, MethodsShape>>, "definition">) => _$effect_Context0.ServiceClass<Self, BindingId, DurableObjectNamespaceClient<[Api$3<Definition$3<Id, MethodsShape>>] extends [never] ? Definition$3<Id, MethodsShape> extends infer T ? T extends Definition$3<Id, MethodsShape> ? T extends Definition$4.Any ? ServerApi$4<T> : never : never : never : Api$3<Definition$3<Id, MethodsShape>>>> & {
|
|
1125
1126
|
"effect-cf/Binding": "effect-cf/Binding";
|
|
@@ -1183,6 +1184,330 @@ type Api<Self extends Definition$3.Any> = Api$3<Self>;
|
|
|
1183
1184
|
type Handlers<ROut, Self extends Definition$3.Any> = Handlers$3<ROut, Self>;
|
|
1184
1185
|
type Options<ROut, Self extends Definition$3.Any> = Options$3<ROut, Self>;
|
|
1185
1186
|
type HandlerEffect<ROut, Self extends Definition$3.Any, Key extends keyof Self["methods"]> = HandlerEffect$3<ROut, Self, Key>;
|
|
1187
|
+
declare namespace DurableObjectAlarm_d_exports {
|
|
1188
|
+
export { AlarmDefinitionConfig, AlarmDefinitionEntry, AlarmDefinitionPayload, AlarmDefinitions, AlarmFailurePolicy, AlarmPayload, AlarmPayloadSchema, AlarmRef, AlarmRetryPolicy, AlarmScheduler, DefinedAlarmEvent, DefinedAlarmHandlers, DurableObjectAlarm, DurableObjectAlarmError, DurableObjectAlarmEvent, InvalidAlarmPayloadError, InvalidAlarmRefError, InvalidProcessDueAlarmsOptionsError, InvalidRepeatEveryError, ProcessDueAlarmsFailure, ProcessDueAlarmsFailureAction, ProcessDueAlarmsHandler, ProcessDueAlarmsMode, ProcessDueAlarmsOptions, ProcessDueAlarmsResult, ScheduleAlarmInput, StoredAlarmDecodeError, define, process, processDue };
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* JSON-serializable alarm payload stored with each scheduled alarm.
|
|
1192
|
+
*
|
|
1193
|
+
* Payloads are intentionally opaque to `DurableObjectAlarm`. Consumers should use
|
|
1194
|
+
* stable `tag` values to route due alarms and then decode the payload for that
|
|
1195
|
+
* tag in their own domain layer.
|
|
1196
|
+
*/
|
|
1197
|
+
type AlarmPayload = Schema.Json;
|
|
1198
|
+
declare const InvalidAlarmRefError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
1199
|
+
readonly _tag: "InvalidAlarmRefError";
|
|
1200
|
+
} & Readonly<A>;
|
|
1201
|
+
declare class InvalidAlarmRefError extends InvalidAlarmRefError_base<{
|
|
1202
|
+
readonly cause: unknown;
|
|
1203
|
+
}> {}
|
|
1204
|
+
declare const InvalidAlarmPayloadError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
1205
|
+
readonly _tag: "InvalidAlarmPayloadError";
|
|
1206
|
+
} & Readonly<A>;
|
|
1207
|
+
declare class InvalidAlarmPayloadError extends InvalidAlarmPayloadError_base<{
|
|
1208
|
+
readonly cause: unknown;
|
|
1209
|
+
}> {}
|
|
1210
|
+
declare const InvalidRepeatEveryError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
1211
|
+
readonly _tag: "InvalidRepeatEveryError";
|
|
1212
|
+
} & Readonly<A>;
|
|
1213
|
+
declare class InvalidRepeatEveryError extends InvalidRepeatEveryError_base<{
|
|
1214
|
+
readonly cause: unknown;
|
|
1215
|
+
}> {}
|
|
1216
|
+
declare const InvalidProcessDueAlarmsOptionsError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
1217
|
+
readonly _tag: "InvalidProcessDueAlarmsOptionsError";
|
|
1218
|
+
} & Readonly<A>;
|
|
1219
|
+
declare class InvalidProcessDueAlarmsOptionsError extends InvalidProcessDueAlarmsOptionsError_base<{
|
|
1220
|
+
readonly cause: unknown;
|
|
1221
|
+
}> {}
|
|
1222
|
+
declare const StoredAlarmDecodeError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
1223
|
+
readonly _tag: "StoredAlarmDecodeError";
|
|
1224
|
+
} & Readonly<A>;
|
|
1225
|
+
declare class StoredAlarmDecodeError extends StoredAlarmDecodeError_base<{
|
|
1226
|
+
readonly cause: unknown;
|
|
1227
|
+
readonly storageId: string;
|
|
1228
|
+
}> {}
|
|
1229
|
+
type DurableObjectAlarmError = InvalidAlarmPayloadError | InvalidAlarmRefError | InvalidProcessDueAlarmsOptionsError | InvalidRepeatEveryError | StorageOperationError | StoredAlarmDecodeError;
|
|
1230
|
+
/**
|
|
1231
|
+
* Events handled by `processDueAlarms`.
|
|
1232
|
+
*
|
|
1233
|
+
* `AlarmDue` represents one durable alarm whose scheduled time is now due. The
|
|
1234
|
+
* `tag` is the consumer-owned routing key, while `id` is the stable alarm id
|
|
1235
|
+
* within that tag.
|
|
1236
|
+
*
|
|
1237
|
+
* `scheduledAt` is the logical due-after timestamp from durable storage. It is
|
|
1238
|
+
* not expected to match the current Durable Object alarm invocation time,
|
|
1239
|
+
* especially during retries. Retries re-scan durable rows with `run_at <= now`
|
|
1240
|
+
* and identify logical events by `{ tag, id }`.
|
|
1241
|
+
*
|
|
1242
|
+
* @example Handling events by tag
|
|
1243
|
+
* ```ts
|
|
1244
|
+
* yield* durableObjectAlarm.processDueAlarms((event) =>
|
|
1245
|
+
* event.tag === "heartbeat"
|
|
1246
|
+
* ? heartbeatManager.handleAlarmEvent(event).pipe(Effect.asVoid)
|
|
1247
|
+
* : Effect.void
|
|
1248
|
+
* );
|
|
1249
|
+
* ```
|
|
1250
|
+
*/
|
|
1251
|
+
declare const DurableObjectAlarmEvent: Schema.TaggedUnion<{
|
|
1252
|
+
readonly AlarmDue: Schema.TaggedStruct<"AlarmDue", {
|
|
1253
|
+
readonly id: Schema.NonEmptyString;
|
|
1254
|
+
readonly payload: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
1255
|
+
readonly scheduledAt: Schema.DateTimeUtc;
|
|
1256
|
+
readonly tag: Schema.NonEmptyString;
|
|
1257
|
+
}>;
|
|
1258
|
+
}>;
|
|
1259
|
+
type DurableObjectAlarmEvent = typeof DurableObjectAlarmEvent.Type;
|
|
1260
|
+
/**
|
|
1261
|
+
* Stable reference for a scheduled alarm.
|
|
1262
|
+
*
|
|
1263
|
+
* The pair of `tag` and `id` is the durable identity. Scheduling another alarm
|
|
1264
|
+
* with the same pair replaces the previous alarm, and cancellation uses the
|
|
1265
|
+
* same pair.
|
|
1266
|
+
*
|
|
1267
|
+
* @example Cancel an alarm
|
|
1268
|
+
* ```ts
|
|
1269
|
+
* yield* durableObjectAlarm.cancelAlarm({
|
|
1270
|
+
* tag: "connection-reconnect-grace",
|
|
1271
|
+
* id: "reconnect-grace-check",
|
|
1272
|
+
* });
|
|
1273
|
+
* ```
|
|
1274
|
+
*/
|
|
1275
|
+
type AlarmRef<Tag extends string = string> = {
|
|
1276
|
+
readonly id: string;
|
|
1277
|
+
readonly tag: Tag;
|
|
1278
|
+
};
|
|
1279
|
+
/**
|
|
1280
|
+
* Input for scheduling or replacing an alarm.
|
|
1281
|
+
*
|
|
1282
|
+
* `runAt` is the absolute first fire time. `repeatEvery` can be any Effect
|
|
1283
|
+
* `Duration.Input`, including strings like `"5 seconds"`, numbers interpreted
|
|
1284
|
+
* as milliseconds, or `Duration` values.
|
|
1285
|
+
*
|
|
1286
|
+
* @example One-shot alarm
|
|
1287
|
+
* ```ts
|
|
1288
|
+
* const now = yield* DateTime.now;
|
|
1289
|
+
*
|
|
1290
|
+
* yield* durableObjectAlarm.scheduleAlarm({
|
|
1291
|
+
* tag: "connection-reconnect-grace",
|
|
1292
|
+
* id: "reconnect-grace-check",
|
|
1293
|
+
* runAt: DateTime.add(now, { seconds: 15 }),
|
|
1294
|
+
* payload: { reason: "socket-closed" },
|
|
1295
|
+
* });
|
|
1296
|
+
* ```
|
|
1297
|
+
*
|
|
1298
|
+
* @example Repeating alarm
|
|
1299
|
+
* ```ts
|
|
1300
|
+
* const now = yield* DateTime.now;
|
|
1301
|
+
*
|
|
1302
|
+
* yield* durableObjectAlarm.scheduleAlarm({
|
|
1303
|
+
* tag: "heartbeat",
|
|
1304
|
+
* id: "heartbeat-check",
|
|
1305
|
+
* runAt: DateTime.add(now, { seconds: 5 }),
|
|
1306
|
+
* repeatEvery: "5 seconds",
|
|
1307
|
+
* payload: null,
|
|
1308
|
+
* });
|
|
1309
|
+
* ```
|
|
1310
|
+
*/
|
|
1311
|
+
type ScheduleAlarmInput<Tag extends string = string> = AlarmRef<Tag> & {
|
|
1312
|
+
readonly payload: AlarmPayload;
|
|
1313
|
+
readonly repeatEvery?: Duration.Input;
|
|
1314
|
+
readonly runAt: DateTime.Utc;
|
|
1315
|
+
};
|
|
1316
|
+
type ProcessDueAlarmsMode = "isolated" | "ordered";
|
|
1317
|
+
interface ProcessDueAlarmsFailure {
|
|
1318
|
+
readonly cause: unknown;
|
|
1319
|
+
readonly event?: DurableObjectAlarmEvent;
|
|
1320
|
+
readonly id: string;
|
|
1321
|
+
readonly storageId: string;
|
|
1322
|
+
readonly tag: string;
|
|
1323
|
+
}
|
|
1324
|
+
interface ProcessDueAlarmsResult {
|
|
1325
|
+
readonly failed: readonly ProcessDueAlarmsFailure[];
|
|
1326
|
+
readonly handled: readonly DurableObjectAlarmEvent[];
|
|
1327
|
+
}
|
|
1328
|
+
type ProcessDueAlarmsFailureAction = "ordered" | "retry" | "skip-and-advance-repeat" | {
|
|
1329
|
+
readonly mode: "ordered";
|
|
1330
|
+
} | {
|
|
1331
|
+
readonly mode: "retry";
|
|
1332
|
+
readonly retryFailedAfter?: Duration.Input;
|
|
1333
|
+
} | {
|
|
1334
|
+
readonly mode: "skip-and-advance-repeat";
|
|
1335
|
+
};
|
|
1336
|
+
interface ProcessDueAlarmsOptions<OnFailureR = never, OnFailureE = never> {
|
|
1337
|
+
/** Maximum due rows to load and process in one invocation. Defaults to 100. */
|
|
1338
|
+
readonly limit?: number;
|
|
1339
|
+
/**
|
|
1340
|
+
* Failure isolation mode. Defaults to `isolated` so one poison logical alarm
|
|
1341
|
+
* does not block unrelated maintenance work.
|
|
1342
|
+
*/
|
|
1343
|
+
readonly mode?: ProcessDueAlarmsMode;
|
|
1344
|
+
/**
|
|
1345
|
+
* Callback for logical handler/decode failures. Return a failure action to
|
|
1346
|
+
* override the global failure behavior for this row.
|
|
1347
|
+
*/
|
|
1348
|
+
readonly onFailure?: (failure: ProcessDueAlarmsFailure) => Effect.Effect<ProcessDueAlarmsFailureAction | void, OnFailureE, OnFailureR>;
|
|
1349
|
+
/**
|
|
1350
|
+
* Delay before retrying a failed logical row in isolated mode. Defaults to 30
|
|
1351
|
+
* seconds. Ignored by ordered mode unless supplied explicitly.
|
|
1352
|
+
*
|
|
1353
|
+
* Retrying updates only the selected occurrence, so replacements scheduled by
|
|
1354
|
+
* a long-running handler are not clobbered by failure handling.
|
|
1355
|
+
*/
|
|
1356
|
+
readonly retryFailedAfter?: Duration.Input;
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Handler invoked for each due alarm before that alarm is acknowledged.
|
|
1360
|
+
*
|
|
1361
|
+
* If the handler fails, `DurableObjectAlarm` leaves the row due and fails the alarm
|
|
1362
|
+
* processing effect. Cloudflare can then retry the Durable Object alarm handler,
|
|
1363
|
+
* and the scheduler will find the same logical row again because `run_at` is
|
|
1364
|
+
* still less than or equal to the retry time.
|
|
1365
|
+
*/
|
|
1366
|
+
type ProcessDueAlarmsHandler<R = never, E = never> = (event: DurableObjectAlarmEvent) => Effect.Effect<void, E, R>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Durable alarm scheduler API.
|
|
1369
|
+
*
|
|
1370
|
+
* This service only owns scheduling semantics. It does not publish, subscribe,
|
|
1371
|
+
* or dispatch events to consumers. Durable Object alarm handlers should pass a
|
|
1372
|
+
* domain handler to `processDueAlarms`; rows are acknowledged only after that
|
|
1373
|
+
* handler succeeds.
|
|
1374
|
+
*
|
|
1375
|
+
* This service must be the only code path that owns `storage.setAlarm()` inside
|
|
1376
|
+
* a Durable Object instance. Cloudflare exposes one platform alarm timestamp per
|
|
1377
|
+
* object, so another scheduler in the same object can clobber this service's
|
|
1378
|
+
* reconciled alarm timestamp.
|
|
1379
|
+
*
|
|
1380
|
+
* @example Durable Object alarm handler
|
|
1381
|
+
* ```ts
|
|
1382
|
+
* const onAlarm = Effect.gen(function* () {
|
|
1383
|
+
* const durableObjectAlarm = yield* DurableObjectAlarm;
|
|
1384
|
+
*
|
|
1385
|
+
* yield* durableObjectAlarm.processDueAlarms((event) =>
|
|
1386
|
+
* Effect.gen(function* () {
|
|
1387
|
+
* if (event.tag === "heartbeat") {
|
|
1388
|
+
* yield* heartbeatManager.handleAlarmEvent(event);
|
|
1389
|
+
* return;
|
|
1390
|
+
* }
|
|
1391
|
+
*
|
|
1392
|
+
* if (event.tag === "connection-reconnect-grace") {
|
|
1393
|
+
* yield* connectionManager.expireReconnectGracePeriods();
|
|
1394
|
+
* }
|
|
1395
|
+
* })
|
|
1396
|
+
* );
|
|
1397
|
+
* });
|
|
1398
|
+
* ```
|
|
1399
|
+
*/
|
|
1400
|
+
type AlarmScheduler = {
|
|
1401
|
+
/**
|
|
1402
|
+
* Cancel a scheduled alarm by `{ tag, id }`.
|
|
1403
|
+
*
|
|
1404
|
+
* This is idempotent. Cancelling a missing alarm is a no-op. The underlying
|
|
1405
|
+
* Durable Object alarm is reconciled afterward.
|
|
1406
|
+
*/
|
|
1407
|
+
readonly cancelAlarm: (input: AlarmRef) => Effect.Effect<void, InvalidAlarmRefError | StorageOperationError>;
|
|
1408
|
+
/**
|
|
1409
|
+
* Process due alarms according to `Clock.currentTimeMillis`.
|
|
1410
|
+
*
|
|
1411
|
+
* Each row is acknowledged only after `handle` succeeds. One-shot alarms are
|
|
1412
|
+
* then deleted. Repeating alarms are rescheduled to `acknowledgedAt +
|
|
1413
|
+
* repeatEvery`, which intentionally behaves as delay-after-success rather
|
|
1414
|
+
* than fixed-cadence catch-up. Acknowledgements are conditional on the stored
|
|
1415
|
+
* row still matching the selected occurrence, so a handler that reschedules
|
|
1416
|
+
* the same `{ tag, id }` will not have its replacement clobbered by the old
|
|
1417
|
+
* acknowledgement.
|
|
1418
|
+
*
|
|
1419
|
+
* Processing is ordered by `runAt` and stable alarm id. By default, logical
|
|
1420
|
+
* handler/decode failures are isolated to the failing row: the row is retried
|
|
1421
|
+
* after `retryFailedAfter`, later due rows still run, and the result reports
|
|
1422
|
+
* both handled and failed rows. Use `mode: "ordered"` when a workflow
|
|
1423
|
+
* intentionally requires strict head-of-line blocking.
|
|
1424
|
+
*
|
|
1425
|
+
* Handlers must still be idempotent: Cloudflare alarms are at-least-once, and
|
|
1426
|
+
* if a handler succeeds but the acknowledgement write fails, the logical event
|
|
1427
|
+
* can be delivered again.
|
|
1428
|
+
*/
|
|
1429
|
+
readonly processDueAlarms: <R = never, E = never, OnFailureR = never, OnFailureE = never>(handle: ProcessDueAlarmsHandler<R, E>, options?: ProcessDueAlarmsOptions<OnFailureR, OnFailureE>) => Effect.Effect<ProcessDueAlarmsResult, E | OnFailureE | DurableObjectAlarmError, R | OnFailureR>;
|
|
1430
|
+
/**
|
|
1431
|
+
* Schedule or replace an alarm by `{ tag, id }`.
|
|
1432
|
+
*
|
|
1433
|
+
* The durable row write and underlying platform alarm reconciliation are run
|
|
1434
|
+
* in one Durable Object storage transaction, so a failed `setAlarm` rolls back
|
|
1435
|
+
* the logical schedule instead of leaving a stored-but-unarmed alarm.
|
|
1436
|
+
*/
|
|
1437
|
+
readonly scheduleAlarm: (input: ScheduleAlarmInput) => Effect.Effect<void, InvalidAlarmPayloadError | InvalidAlarmRefError | InvalidRepeatEveryError | StorageOperationError>;
|
|
1438
|
+
};
|
|
1439
|
+
declare const processDue: <R = never, E = never, OnFailureR = never, OnFailureE = never>(handle: ProcessDueAlarmsHandler<R, E>, options?: ProcessDueAlarmsOptions<OnFailureR, OnFailureE>) => Effect.Effect<ProcessDueAlarmsResult, E | OnFailureE | DurableObjectAlarmError, OnFailureR | R | DurableObjectAlarm>;
|
|
1440
|
+
declare const process: <R = never, E = never, OnFailureR = never, OnFailureE = never>(handle: ProcessDueAlarmsHandler<R, E>, options?: ProcessDueAlarmsOptions<OnFailureR, OnFailureE>) => Effect.Effect<ProcessDueAlarmsResult, E | OnFailureE | DurableObjectAlarmError, OnFailureR | R | DurableObjectAlarm>;
|
|
1441
|
+
type AlarmPayloadSchema = Schema.Codec<any, any, never, never>;
|
|
1442
|
+
type AlarmFailurePolicy = "ordered" | "retry" | "skip-and-advance-repeat";
|
|
1443
|
+
interface AlarmRetryPolicy {
|
|
1444
|
+
readonly initialDelay?: Duration.Input;
|
|
1445
|
+
}
|
|
1446
|
+
interface AlarmDefinitionConfig<Payload extends AlarmPayloadSchema = AlarmPayloadSchema> {
|
|
1447
|
+
readonly failure?: AlarmFailurePolicy;
|
|
1448
|
+
readonly payload: Payload;
|
|
1449
|
+
readonly retry?: AlarmRetryPolicy;
|
|
1450
|
+
}
|
|
1451
|
+
type AlarmDefinitionEntry = AlarmDefinitionConfig | AlarmPayloadSchema;
|
|
1452
|
+
type AlarmDefinitions = Readonly<Record<string, AlarmDefinitionEntry>>;
|
|
1453
|
+
type AlarmDefinitionSchema<Definition> = Definition extends AlarmDefinitionConfig<infer Payload> ? Payload : Definition;
|
|
1454
|
+
type AlarmDefinitionPayload<Definition> = AlarmDefinitionSchema<Definition> extends Schema.Codec<infer A, any, never, never> ? A : never;
|
|
1455
|
+
type DefinedAlarmEvent<Tag extends string, Payload> = Omit<DurableObjectAlarmEvent, "payload" | "tag"> & {
|
|
1456
|
+
readonly payload: Payload;
|
|
1457
|
+
readonly tag: Tag;
|
|
1458
|
+
};
|
|
1459
|
+
type DefinedAlarmHandlers<Definitions extends AlarmDefinitions, R = never, E = never> = { readonly [Tag in keyof Definitions & string]: (event: DefinedAlarmEvent<Tag, AlarmDefinitionPayload<Definitions[Tag]>>) => Effect.Effect<void, E, R> };
|
|
1460
|
+
declare const define: <const Definitions extends AlarmDefinitions>(definitions: Definitions) => {
|
|
1461
|
+
handlers: <R = never, E = never>(handlers: DefinedAlarmHandlers<Definitions, R, E>, options?: ProcessDueAlarmsOptions<R, E>) => Effect.Effect<ProcessDueAlarmsResult, E | DurableObjectAlarmError, R | DurableObjectAlarm>;
|
|
1462
|
+
};
|
|
1463
|
+
declare const DurableObjectAlarm_base: Context.ServiceClass<DurableObjectAlarm, "effect-cf/DurableObjectAlarm", AlarmScheduler>;
|
|
1464
|
+
/**
|
|
1465
|
+
* SQLite-backed Durable Object alarm scheduler.
|
|
1466
|
+
*
|
|
1467
|
+
* `DurableObjectAlarm` stores alarms in the current Durable Object's SQLite storage
|
|
1468
|
+
* and keeps the platform alarm set to the earliest pending scheduled alarm. The
|
|
1469
|
+
* platform alarm timestamp is only a wake-up hint; logical event identity comes
|
|
1470
|
+
* from persisted `{ tag, id }` rows.
|
|
1471
|
+
*
|
|
1472
|
+
* Retry safety depends on acknowledgement ordering. `processDueAlarms` runs the
|
|
1473
|
+
* caller's handler first and only then conditionally deletes or advances the
|
|
1474
|
+
* same selected row. By default, handler failures are isolated: the failed row
|
|
1475
|
+
* is retried after a delay, later due rows continue, and the platform alarm is
|
|
1476
|
+
* reconciled once at the end. Use `mode: "ordered"` for strict workflows where
|
|
1477
|
+
* one failed logical alarm should block later due alarms.
|
|
1478
|
+
*
|
|
1479
|
+
* Provide `DurableObjectAlarm.layer` anywhere `DurableObjectState` is available.
|
|
1480
|
+
*
|
|
1481
|
+
* @example Providing the service
|
|
1482
|
+
* ```ts
|
|
1483
|
+
* const program = Effect.gen(function* () {
|
|
1484
|
+
* const durableObjectAlarm = yield* DurableObjectAlarm;
|
|
1485
|
+
* const now = yield* DateTime.now;
|
|
1486
|
+
*
|
|
1487
|
+
* yield* durableObjectAlarm.scheduleAlarm({
|
|
1488
|
+
* tag: "heartbeat",
|
|
1489
|
+
* id: "heartbeat-check",
|
|
1490
|
+
* runAt: DateTime.add(now, { seconds: 5 }),
|
|
1491
|
+
* repeatEvery: Duration.seconds(5),
|
|
1492
|
+
* payload: null,
|
|
1493
|
+
* });
|
|
1494
|
+
* }).pipe(Effect.provide(DurableObjectAlarm.layer));
|
|
1495
|
+
* ```
|
|
1496
|
+
*
|
|
1497
|
+
* @example Processing due alarms
|
|
1498
|
+
* ```ts
|
|
1499
|
+
* const handledEvents = yield* durableObjectAlarm.processDueAlarms((event) =>
|
|
1500
|
+
* Effect.gen(function* () {
|
|
1501
|
+
* if (event.tag === "heartbeat") {
|
|
1502
|
+
* yield* heartbeatManager.handleAlarmEvent(event);
|
|
1503
|
+
* }
|
|
1504
|
+
* })
|
|
1505
|
+
* );
|
|
1506
|
+
* ```
|
|
1507
|
+
*/
|
|
1508
|
+
declare class DurableObjectAlarm extends DurableObjectAlarm_base {
|
|
1509
|
+
static readonly layer: Layer.Layer<DurableObjectAlarm, never, DurableObjectState>;
|
|
1510
|
+
}
|
|
1186
1511
|
declare namespace DurableObjectRpcWebSocket_d_exports {
|
|
1187
1512
|
export { DurableObjectRpcWebSocket, DurableObjectRpcWebSocketService, LayerOptions, NativeWebSocketMessage, layer };
|
|
1188
1513
|
}
|
|
@@ -1384,4 +1709,4 @@ declare const Service: <Self>() => <Id extends string, Key, Value, EncodedValue>
|
|
|
1384
1709
|
unsafeRaw: () => Effect.Effect<KVNamespace<string>, never, Self>;
|
|
1385
1710
|
};
|
|
1386
1711
|
//#endregion
|
|
1387
|
-
export { Binding_d_exports as Binding, DurableObject_d_exports as DurableObject, DurableObjectDefinition_d_exports as DurableObjectDefinition, DurableObjectNamespace_d_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_d_exports as DurableObjectRpcWebSocket, DurableObjectState_d_exports as DurableObjectState, DurableObjectStorage_d_exports as DurableObjectStorage, DurableObjectWebSocket_d_exports as DurableObjectWebSocket, Kv_d_exports as Kv, Rpc_d_exports as Rpc, RpcDefinition_d_exports as RpcDefinition, ServiceBinding_d_exports as ServiceBinding, Worker_d_exports as Worker, WorkerConfig, WorkerDefinition_d_exports as WorkerDefinition, type WorkerEnv, WorkerEnvironment };
|
|
1712
|
+
export { Binding_d_exports as Binding, DurableObject_d_exports as DurableObject, DurableObjectAlarm_d_exports as DurableObjectAlarm, DurableObjectDefinition_d_exports as DurableObjectDefinition, DurableObjectNamespace_d_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_d_exports as DurableObjectRpcWebSocket, DurableObjectState_d_exports as DurableObjectState, DurableObjectStorage_d_exports as DurableObjectStorage, DurableObjectWebSocket_d_exports as DurableObjectWebSocket, Kv_d_exports as Kv, Rpc_d_exports as Rpc, RpcDefinition_d_exports as RpcDefinition, ServiceBinding_d_exports as ServiceBinding, Worker_d_exports as Worker, WorkerConfig, WorkerDefinition_d_exports as WorkerDefinition, type WorkerEnv, WorkerEnvironment };
|