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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dan van der Merwe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,70 +1,56 @@
1
1
  # effect-cf
2
2
 
3
- Effect-native primitives for Cloudflare Workers and bindings.
3
+ Effect-native Cloudflare primitives for Workers, Durable Objects, bindings, KV, and Durable Object storage.
4
4
 
5
- ## Design Goal
5
+ ## Install
6
6
 
7
- Cloudflare services should be described as `Context`, `Layer`, and `Effect` values and executed through package-owned Cloudflare entrypoint/runtime boundaries. Consumer code should stay in `Effect`; bindings and storage helpers wrap Promise-returning Cloudflare APIs so applications do not call `Effect.runPromise` or manually bridge Promises.
7
+ `effect-cf` currently targets Effect 4 beta.
8
8
 
9
- The low-level Worker entrypoint factory is exported as `Worker.make`. It returns a `WorkerEntrypoint` class with a `fetch` handler and optional typed RPC methods. Durable Object support starts with `DurableObject.make`, which routes Durable Object lifecycle methods and RPC handlers through one managed runtime for each Durable Object instance.
10
-
11
- Worker fetch handlers can return either web `Response` values or Effect `HttpServerResponse` values. `Worker.make` renders `HttpServerResponse` back to a web `Response` at the Cloudflare boundary, so application handlers can stay in Effect HTTP primitives.
12
-
13
- Use `requestLayer` on `Worker.make` for per-request services such as auth/session context, tenant metadata, request IDs, or request-local clients. The request layer scope is the handler evaluation scope: it closes when the handler produces a `Response`, not when a streaming response body is later consumed by the platform.
9
+ ```bash
10
+ bun add effect-cf "effect@^4.0.0-beta.65"
11
+ ```
14
12
 
15
- For modules that need an `ExportedHandler` object instead of a `WorkerEntrypoint` class, use `Worker.makeFetchHandler`. This helper is fetch-only and intentionally does not accept Worker RPC methods.
13
+ ```bash
14
+ pnpm add effect-cf "effect@^4.0.0-beta.65"
15
+ ```
16
16
 
17
- RPC contracts can be described as classes with `Worker.Tag` and `DurableObject.Tag`. Contract classes expose `.make(...)` for runtime entrypoint creation and `.Binding(...)` / `.Namespace(...)` for typed bindings. Bindings infer call types from the same code-owned contract classes. Definition-backed calls encode/decode arguments and success values with their Effect schemas at Worker and Durable Object boundaries.
17
+ ```bash
18
+ npm install effect-cf "effect@^4.0.0-beta.65"
19
+ ```
18
20
 
19
- Binding helpers expose two RPC paths:
21
+ ## Goal
20
22
 
21
- - `call(...)` awaits one RPC result inside `Effect`. Use it for ordinary structured-cloneable values.
22
- - `rpc(...)` returns Cloudflare's native RPC thenable/stub without awaiting it, preserving promise pipelining.
23
- - `scopedCall(...)` awaits the result and registers any `Symbol.dispose` disposer with the current Effect `Scope`.
23
+ Cloudflare APIs return promises and expose platform-specific bindings. `effect-cf` wraps those boundaries as `Context`, `Layer`, and `Effect` values so application code stays inside one managed Effect runtime.
24
24
 
25
- Client APIs use Cloudflare-style provider types, so object results expose pipelined property and method access. `ServerApi` remains available when a plain implementation-shaped `(...args) => Promise<A>` contract is needed.
25
+ Runtime creation belongs at Cloudflare entrypoints, not inside binding helpers.
26
26
 
27
- ## Current Exports
27
+ ## Exports
28
28
 
29
- - `Worker` - WorkerEntrypoint class factory, schema-backed RPC contract tags, and service binding helpers
30
- - `DurableObject` - Durable Object class factory, schema-backed RPC contract tags, and namespace helpers
31
- - `WorkerDefinition`, `DurableObjectDefinition` - compatibility exports for the lower-level definition modules
32
- - `DurableObjectNamespace` - typed Durable Object namespace binding helper
33
- - `DurableObjectState`, `DurableObjectStorage` - small Effect wrappers for Durable Object state, alarms, SQL, and embedded KV storage
34
- - `DurableObjectWebSocket` - Durable Object WebSocket upgrade helpers built on `WebSocketPair` and `acceptWebSocket`
35
- - `Binding` - low-level binding service helper
29
+ - `Worker` - Worker entrypoint factory, request services, and typed Worker bindings
30
+ - `DurableObject` - Durable Object entrypoint factory and typed namespace helpers
31
+ - `DurableObjectState` / `DurableObjectStorage` - Effect wrappers for state, alarms, SQL, and embedded KV
32
+ - `DurableObjectWebSocket` - WebSocket upgrade helpers for Durable Objects
36
33
  - `Kv` - typed KV namespace helper
37
- - `Rpc` - Cloudflare RPC type helpers, `RpcTarget` / `RpcStub` re-exports, and scoped disposal utilities
38
- - `ServiceBinding` - typed Worker-to-Worker service binding helper
39
- - `WorkerEnvironment` - request environment service
40
- - `WorkerConfig` - Effect `Config` helpers backed by Cloudflare worker `env`, including `layerWith` for custom env-to-config mapping
41
-
42
- ## RPC Values
43
-
44
- Definition-backed RPC methods are intended for schema-backed structured values. If a Cloudflare RPC method returns a lifecycle-managed RPC object or stub, expose that through a lower-level binding API instead of a `WorkerDefinition` / `DurableObjectDefinition` method so disposal remains explicit.
34
+ - `Rpc` - Cloudflare RPC type helpers and scoped disposal utilities
35
+ - `WorkerConfig` - Effect `Config` helpers backed by Cloudflare `env`
45
36
 
46
- ## Durable Object WebSocket Example
37
+ ## Worker Example
47
38
 
48
39
  ```ts
49
- const request = yield * Worker.NativeRequest;
40
+ import { HttpServerResponse } from "effect";
41
+ import { Worker } from "effect-cf";
50
42
 
51
- if (!Worker.isWebSocketUpgrade(request)) {
52
- return new Response("Expected WebSocket upgrade", { status: 426 });
53
- }
54
-
55
- const upgrade =
56
- yield *
57
- DurableObjectWebSocket.acceptUpgrade({
58
- tags: ["room:general"],
59
- attachment: { roomId: "general" },
60
- });
61
-
62
- return upgrade.response;
43
+ export default Worker.make({
44
+ fetch: () => HttpServerResponse.text("ok"),
45
+ });
63
46
  ```
64
47
 
65
48
  ## Durable Object Example
66
49
 
67
50
  ```ts
51
+ import { Effect, Layer, Schema as S } from "effect";
52
+ import { DurableObject, DurableObjectState } from "effect-cf";
53
+
68
54
  export class Counter extends DurableObject.Tag<Counter>()("Counter", {
69
55
  get: DurableObject.method({ success: S.Number }),
70
56
  }) {}
@@ -83,4 +69,8 @@ export const CounterDurableObject = Counter.make(Layer.empty, {
83
69
  });
84
70
  ```
85
71
 
86
- Define the Wrangler binding and SQLite migration in the application. This package intentionally does not replace `wrangler.jsonc`.
72
+ Define Wrangler bindings and migrations in the consuming application.
73
+
74
+ ## License
75
+
76
+ MIT