effect-cf 0.0.4 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-cf",
3
- "version": "0.0.4",
3
+ "version": "0.2.0",
4
4
  "description": "Effect-native primitives for Cloudflare Workers and bindings.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -9,6 +9,7 @@
9
9
  "directory": "packages/effect-cf"
10
10
  },
11
11
  "files": [
12
+ "CHANGELOG.md",
12
13
  "dist",
13
14
  "src"
14
15
  ],
@@ -38,7 +39,7 @@
38
39
  "@effect/vitest": "catalog:",
39
40
  "effect": "catalog:",
40
41
  "typescript": "^6.0.2",
41
- "vite-plus": "0.1.19",
42
+ "vite-plus": "0.1.20",
42
43
  "vitest": "catalog:"
43
44
  },
44
45
  "peerDependencies": {
@@ -72,6 +72,14 @@ export interface DurableObjectOptions<ROut, Rpc extends DurableObjectRpc<ROut>>
72
72
  readonly rpc?: Rpc;
73
73
  /** Optional fetch handler for HTTP/WebSocket requests. */
74
74
  readonly fetch?: Effect.Effect<Response, unknown, FetchContext<ROut>>;
75
+ /**
76
+ * Optional logical alarm processing effect.
77
+ *
78
+ * This runs before `alarm` and should be built with helpers such as
79
+ * `DurableObjectAlarm.processDue(...)` so the reusable scheduler stays inside
80
+ * the Durable Object's single managed runtime boundary.
81
+ */
82
+ readonly alarms?: Effect.Effect<unknown, unknown, HandlerContext<ROut>>;
75
83
  readonly alarm?: (
76
84
  alarmInfo?: globalThis.AlarmInvocationInfo,
77
85
  ) => Effect.Effect<void, unknown, HandlerContext<ROut>>;
@@ -141,8 +149,24 @@ export const make = <
141
149
  }
142
150
 
143
151
  alarm(alarmInfo?: globalThis.AlarmInvocationInfo): Promise<void> | void {
144
- if (options.alarm !== undefined) {
145
- return this[RunSymbol](options.alarm(alarmInfo));
152
+ const logicalAlarms = options.alarms?.pipe(Effect.asVoid);
153
+ const rawAlarm = options.alarm?.(alarmInfo);
154
+
155
+ if (logicalAlarms !== undefined && rawAlarm !== undefined) {
156
+ return this[RunSymbol](
157
+ Effect.gen(function* () {
158
+ yield* logicalAlarms;
159
+ yield* rawAlarm;
160
+ }),
161
+ );
162
+ }
163
+
164
+ if (logicalAlarms !== undefined) {
165
+ return this[RunSymbol](logicalAlarms);
166
+ }
167
+
168
+ if (rawAlarm !== undefined) {
169
+ return this[RunSymbol](rawAlarm);
146
170
  }
147
171
  }
148
172