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/src/Worker.ts
CHANGED
|
@@ -167,27 +167,12 @@ export type RpcHandlers<ROut, Api> = {
|
|
|
167
167
|
: never;
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
-
export interface WorkerOptions<
|
|
171
|
-
ROut
|
|
172
|
-
Rpc extends WorkerRpc<ROut>,
|
|
173
|
-
RRequest = never,
|
|
174
|
-
RequestLayerError = never,
|
|
175
|
-
> {
|
|
176
|
-
readonly fetch?: Effect.Effect<WorkerFetchSuccess, unknown, WorkerFetchContext<ROut | RRequest>>;
|
|
177
|
-
/**
|
|
178
|
-
* Per-request services provided while evaluating the fetch handler.
|
|
179
|
-
*
|
|
180
|
-
* This scope closes when the handler produces a `Response`; it is not kept
|
|
181
|
-
* open until a streaming response body is consumed by the platform.
|
|
182
|
-
*/
|
|
183
|
-
readonly requestLayer?: Layer.Layer<RRequest, RequestLayerError, WorkerFetchContext<ROut>>;
|
|
170
|
+
export interface WorkerOptions<ROut, Rpc extends WorkerRpc<ROut>> {
|
|
171
|
+
readonly fetch?: Effect.Effect<WorkerFetchSuccess, unknown, WorkerFetchContext<ROut>>;
|
|
184
172
|
readonly rpc?: Rpc;
|
|
185
173
|
}
|
|
186
174
|
|
|
187
|
-
export type FetchWorkerOptions<ROut
|
|
188
|
-
WorkerOptions<ROut, Record<never, never>, RRequest, RequestLayerError>,
|
|
189
|
-
"rpc"
|
|
190
|
-
> & {
|
|
175
|
+
export type FetchWorkerOptions<ROut> = Omit<WorkerOptions<ROut, Record<never, never>>, "rpc"> & {
|
|
191
176
|
readonly rpc?: never;
|
|
192
177
|
};
|
|
193
178
|
|
|
@@ -226,15 +211,9 @@ const renderFetchSuccess = <E, R>(
|
|
|
226
211
|
),
|
|
227
212
|
);
|
|
228
213
|
|
|
229
|
-
export const make = <
|
|
230
|
-
ROut,
|
|
231
|
-
LayerError,
|
|
232
|
-
const Rpc extends WorkerRpc<ROut> = Record<never, never>,
|
|
233
|
-
RRequest = never,
|
|
234
|
-
RequestLayerError = never,
|
|
235
|
-
>(
|
|
214
|
+
export const make = <ROut, LayerError, const Rpc extends WorkerRpc<ROut> = Record<never, never>>(
|
|
236
215
|
layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>,
|
|
237
|
-
options: WorkerOptions<ROut, Rpc
|
|
216
|
+
options: WorkerOptions<ROut, Rpc>,
|
|
238
217
|
): WorkerClass<Rpc, ROut> => {
|
|
239
218
|
class EffectWorker extends CloudflareWorkerEntrypoint<WorkerEnv> {
|
|
240
219
|
readonly runtime: ManagedRuntime.ManagedRuntime<RuntimeContext<ROut>, LayerError>;
|
|
@@ -281,14 +260,9 @@ export const make = <
|
|
|
281
260
|
Layer.succeed(NativeRequest, request),
|
|
282
261
|
Layer.succeed(HttpServerRequest.HttpServerRequest, HttpServerRequest.fromWeb(request)),
|
|
283
262
|
);
|
|
284
|
-
const fetchEffect = renderFetchSuccess(fetchHandler);
|
|
285
|
-
const requestEffect =
|
|
286
|
-
options.requestLayer === undefined
|
|
287
|
-
? fetchEffect
|
|
288
|
-
: fetchEffect.pipe(Effect.provide(options.requestLayer));
|
|
289
263
|
|
|
290
264
|
return this[RunSymbol](
|
|
291
|
-
|
|
265
|
+
renderFetchSuccess(fetchHandler).pipe(Effect.provide(requestServices)) as Effect.Effect<
|
|
292
266
|
Response,
|
|
293
267
|
unknown,
|
|
294
268
|
RuntimeContext<ROut> | Scope.Scope
|
|
@@ -308,15 +282,9 @@ export const make = <
|
|
|
308
282
|
return Entrypoint.assumeEntrypointClass<WorkerClass<Rpc, ROut>>(EffectWorker);
|
|
309
283
|
};
|
|
310
284
|
|
|
311
|
-
export const makeFetchHandler = <
|
|
312
|
-
ROut,
|
|
313
|
-
LayerError,
|
|
314
|
-
RRequest = never,
|
|
315
|
-
RequestLayerError = never,
|
|
316
|
-
Env extends WorkerEnv = WorkerEnv,
|
|
317
|
-
>(
|
|
285
|
+
export const makeFetchHandler = <ROut, LayerError, Env extends WorkerEnv = WorkerEnv>(
|
|
318
286
|
layer: Layer.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>,
|
|
319
|
-
options: FetchWorkerOptions<ROut
|
|
287
|
+
options: FetchWorkerOptions<ROut>,
|
|
320
288
|
): FetchHandler<Env> => {
|
|
321
289
|
const WorkerClass = make(layer, options);
|
|
322
290
|
|
|
@@ -350,12 +318,10 @@ export type Handlers<
|
|
|
350
318
|
Self extends WorkerDefinition.Definition.Any,
|
|
351
319
|
> = WorkerDefinition.Handlers<ROut, Self>;
|
|
352
320
|
|
|
353
|
-
export type Options<
|
|
321
|
+
export type Options<ROut, Self extends WorkerDefinition.Definition.Any> = WorkerDefinition.Options<
|
|
354
322
|
ROut,
|
|
355
|
-
Self
|
|
356
|
-
|
|
357
|
-
RequestLayerError = never,
|
|
358
|
-
> = WorkerDefinition.Options<ROut, Self, RRequest, RequestLayerError>;
|
|
323
|
+
Self
|
|
324
|
+
>;
|
|
359
325
|
|
|
360
326
|
export type HandlerEffect<
|
|
361
327
|
ROut,
|
package/src/WorkerDefinition.ts
CHANGED
|
@@ -74,13 +74,8 @@ type BoundaryHandlers<ROut, Self extends Definition.Any> = {
|
|
|
74
74
|
/**
|
|
75
75
|
* Worker constructor options for a specific RPC definition.
|
|
76
76
|
*/
|
|
77
|
-
export interface Options<
|
|
78
|
-
ROut,
|
|
79
|
-
Self extends Definition.Any,
|
|
80
|
-
RRequest = never,
|
|
81
|
-
RequestLayerError = never,
|
|
82
|
-
> extends Omit<
|
|
83
|
-
WorkerEntrypoint.WorkerOptions<ROut, Handlers<ROut, Self>, RRequest, RequestLayerError>,
|
|
77
|
+
export interface Options<ROut, Self extends Definition.Any> extends Omit<
|
|
78
|
+
WorkerEntrypoint.WorkerOptions<ROut, Handlers<ROut, Self>>,
|
|
84
79
|
"rpc"
|
|
85
80
|
> {
|
|
86
81
|
readonly rpc: Handlers<ROut, Self>;
|
|
@@ -113,13 +108,13 @@ const makeDefinition = <Id extends string, const MethodsShape extends RpcDefinit
|
|
|
113
108
|
const definition: SelfDefinition = RpcDefinition.make(id, methods);
|
|
114
109
|
|
|
115
110
|
return Object.assign(definition, {
|
|
116
|
-
make: <ROut, LayerError
|
|
111
|
+
make: <ROut, LayerError>(
|
|
117
112
|
layer: Layer.Layer<
|
|
118
113
|
ROut,
|
|
119
114
|
LayerError,
|
|
120
115
|
WorkerEntrypoint.ExecutionContext | WorkerEntrypoint.WorkerContext | WorkerEnvironment
|
|
121
116
|
>,
|
|
122
|
-
options: Options<ROut, SelfDefinition
|
|
117
|
+
options: Options<ROut, SelfDefinition>,
|
|
123
118
|
) =>
|
|
124
119
|
WorkerEntrypoint.make(layer, {
|
|
125
120
|
...options,
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * as Binding from "./Binding";
|
|
2
2
|
export * as DurableObject from "./DurableObject";
|
|
3
|
+
export * as DurableObjectAlarm from "./DurableObjectAlarm";
|
|
3
4
|
export * as DurableObjectDefinition from "./DurableObjectDefinition";
|
|
4
5
|
export * as DurableObjectNamespace from "./DurableObjectNamespace";
|
|
5
6
|
export * as DurableObjectRpcWebSocket from "./DurableObjectRpcWebSocket";
|