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/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
|
|
3
|
+
Effect-native Cloudflare primitives for Workers, Durable Objects, bindings, KV, and Durable Object storage.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`effect-cf` currently targets Effect 4 beta.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add effect-cf "effect@^4.0.0-beta.65"
|
|
15
|
+
```
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
```bash
|
|
18
|
+
npm install effect-cf "effect@^4.0.0-beta.65"
|
|
19
|
+
```
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
## Goal
|
|
20
22
|
|
|
21
|
-
- `
|
|
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
|
-
|
|
25
|
+
Runtime creation belongs at Cloudflare entrypoints, not inside binding helpers.
|
|
26
26
|
|
|
27
|
-
##
|
|
27
|
+
## Exports
|
|
28
28
|
|
|
29
|
-
- `Worker` -
|
|
30
|
-
- `DurableObject` - Durable Object
|
|
31
|
-
- `
|
|
32
|
-
- `
|
|
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
|
|
38
|
-
- `
|
|
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
|
-
##
|
|
37
|
+
## Worker Example
|
|
47
38
|
|
|
48
39
|
```ts
|
|
49
|
-
|
|
40
|
+
import { HttpServerResponse } from "effect";
|
|
41
|
+
import { Worker } from "effect-cf";
|
|
50
42
|
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
72
|
+
Define Wrangler bindings and migrations in the consuming application.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT
|