effect-cf 0.50.0 → 0.51.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.
@@ -9,8 +9,6 @@ import * as Option from "effect/Option";
9
9
  import * as Result from "effect/Result";
10
10
  import * as Cause from "effect/Cause";
11
11
  import * as Exit from "effect/Exit";
12
- import * as Clock from "effect/Clock";
13
- import * as Duration from "effect/Duration";
14
12
  import * as Fiber from "effect/Fiber";
15
13
  //#region src/DurableObjectStorage.ts
16
14
  var DurableObjectStorage_exports = /* @__PURE__ */ __exportAll({
@@ -34,11 +32,6 @@ const tryStoragePromise = (operation, evaluate) => Effect.tryPromise({
34
32
  try: evaluate,
35
33
  catch: (cause) => storageError(operation, cause)
36
34
  });
37
- const setAlarmAfter = Effect.fn("DurableObjectStorage.setAlarmAfter")(function* (operation, setAlarm, delay, options) {
38
- const now = yield* Clock.currentTimeMillis;
39
- const delayMillis = Math.ceil(Duration.toMillis(delay));
40
- yield* tryStoragePromise(operation, () => setAlarm(now + delayMillis, options));
41
- });
42
35
  const fromSqlCursor = (cursor) => ({
43
36
  next: () => tryStorageSync("sql.next", () => cursor.next()),
44
37
  toArray: () => tryStorageSync("sql.toArray", () => cursor.toArray()),
@@ -98,10 +91,7 @@ const fromDurableObjectTransaction = (txn) => ({
98
91
  put: (keyOrEntries, valueOrOptions, maybeOptions) => tryStoragePromise("transaction.put", () => Predicate.isString(keyOrEntries) ? txn.put(keyOrEntries, valueOrOptions, maybeOptions) : txn.put(keyOrEntries, valueOrOptions)),
99
92
  delete: (keyOrKeys, options) => Array.isArray(keyOrKeys) ? tryStoragePromise("transaction.delete", () => txn.delete(keyOrKeys, options)) : tryStoragePromise("transaction.delete", () => txn.delete(keyOrKeys, options)),
100
93
  rollback: () => tryStorageSync("transaction.rollback", () => txn.rollback()),
101
- getAlarm: (options) => tryStoragePromise("transaction.getAlarm", () => txn.getAlarm(options)),
102
- setAlarm: (scheduledTime, options) => tryStoragePromise("transaction.setAlarm", () => txn.setAlarm(scheduledTime, options)),
103
- setAlarmAfter: (delay, options) => setAlarmAfter("transaction.setAlarm", (scheduledTime, options) => txn.setAlarm(scheduledTime, options), delay, options),
104
- deleteAlarm: (options) => tryStoragePromise("transaction.deleteAlarm", () => txn.deleteAlarm(options))
94
+ getAlarm: (options) => tryStoragePromise("transaction.getAlarm", () => txn.getAlarm(options))
105
95
  });
106
96
  const fromDurableObjectStorage = (storage) => ({
107
97
  get: (key, options) => tryStoragePromise("get", () => storage.get(key, options)),
@@ -109,9 +99,6 @@ const fromDurableObjectStorage = (storage) => ({
109
99
  delete: (key, options) => tryStoragePromise("delete", () => storage.delete(key, options)),
110
100
  deleteAll: (options) => tryStoragePromise("deleteAll", () => storage.deleteAll(options)),
111
101
  getAlarm: (options) => tryStoragePromise("getAlarm", () => storage.getAlarm(options)),
112
- setAlarm: (scheduledTime, options) => tryStoragePromise("setAlarm", () => storage.setAlarm(scheduledTime, options)),
113
- setAlarmAfter: (delay, options) => setAlarmAfter("setAlarm", (scheduledTime, options) => storage.setAlarm(scheduledTime, options), delay, options),
114
- deleteAlarm: (options) => tryStoragePromise("deleteAlarm", () => storage.deleteAlarm(options)),
115
102
  transactionSync: (closure) => Effect.context().pipe(Effect.flatMap((context) => Effect.suspend(() => {
116
103
  let aborted;
117
104
  let escapedFiber;
@@ -3,8 +3,16 @@ import * as Effect from "effect/Effect";
3
3
  import * as S from "effect/Schema";
4
4
  import * as Option from "effect/Option";
5
5
  declare namespace DurableObjectWebSocket_d_exports {
6
- export { AcceptUpgradeOptions, AcceptedUpgrade, AttachmentInvalidPolicy, AttachmentRehydrateOptions, DurableWebSocket, DurableWebSocketAttachment, DurableWebSocketAttachmentError, DurableWebSocketCloseError, DurableWebSocketHandlers, DurableWebSocketSendData, DurableWebSocketSendError, RehydratedDurableWebSocket, acceptUpgrade, attachment, fromWebSocket, handlers };
6
+ export { AcceptUpgradeOptions, AcceptedUpgrade, AttachmentInvalidPolicy, AttachmentRehydrateOptions, DEFAULT_KEEPALIVE_REQUEST, DEFAULT_KEEPALIVE_RESPONSE, DurableWebSocket, DurableWebSocketAttachment, DurableWebSocketAttachmentError, DurableWebSocketCloseError, DurableWebSocketHandlers, DurableWebSocketSendData, DurableWebSocketSendError, RehydratedDurableWebSocket, acceptUpgrade, attachment, fromWebSocket, handlers, installKeepalive };
7
7
  }
8
+ declare const DEFAULT_KEEPALIVE_REQUEST = "effect-cf:ping";
9
+ declare const DEFAULT_KEEPALIVE_RESPONSE = "effect-cf:pong";
10
+ /**
11
+ * Registers exact text keepalives with Cloudflare so they never invoke the object.
12
+ * The pair applies to all hibernating sockets on this object; install in its constructor.
13
+ * Clients send the request text and consume the response outside their application protocol.
14
+ */
15
+ declare const installKeepalive: (request?: any, response?: any) => Effect.Effect<undefined, never, DurableObjectState>;
8
16
  type DurableWebSocketSendData = string | ArrayBuffer | ArrayBufferView;
9
17
  declare const DurableWebSocketSendError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
10
18
  readonly _tag: "DurableWebSocketSendError";
@@ -80,4 +88,4 @@ declare const handlers: <R = never, E = unknown>(options: DurableWebSocketHandle
80
88
  webSocketError: ((socket: DurableWebSocket, cause: unknown) => Effect.Effect<void, E, R>) | undefined;
81
89
  };
82
90
  //#endregion
83
- export { AcceptUpgradeOptions, AcceptedUpgrade, AttachmentInvalidPolicy, AttachmentRehydrateOptions, DurableObjectWebSocket_d_exports, DurableWebSocket, DurableWebSocketAttachment, DurableWebSocketAttachmentError, DurableWebSocketCloseError, DurableWebSocketHandlers, DurableWebSocketSendData, DurableWebSocketSendError, RehydratedDurableWebSocket, acceptUpgrade, attachment, fromWebSocket, handlers };
91
+ export { AcceptUpgradeOptions, AcceptedUpgrade, AttachmentInvalidPolicy, AttachmentRehydrateOptions, DEFAULT_KEEPALIVE_REQUEST, DEFAULT_KEEPALIVE_RESPONSE, DurableObjectWebSocket_d_exports, DurableWebSocket, DurableWebSocketAttachment, DurableWebSocketAttachmentError, DurableWebSocketCloseError, DurableWebSocketHandlers, DurableWebSocketSendData, DurableWebSocketSendError, RehydratedDurableWebSocket, acceptUpgrade, attachment, fromWebSocket, handlers, installKeepalive };
@@ -8,13 +8,29 @@ import * as Option from "effect/Option";
8
8
  import * as Result from "effect/Result";
9
9
  //#region src/DurableObjectWebSocket.ts
10
10
  var DurableObjectWebSocket_exports = /* @__PURE__ */ __exportAll({
11
+ DEFAULT_KEEPALIVE_REQUEST: () => DEFAULT_KEEPALIVE_REQUEST,
12
+ DEFAULT_KEEPALIVE_RESPONSE: () => DEFAULT_KEEPALIVE_RESPONSE,
11
13
  DurableWebSocketAttachmentError: () => DurableWebSocketAttachmentError,
12
14
  DurableWebSocketCloseError: () => DurableWebSocketCloseError,
13
15
  DurableWebSocketSendError: () => DurableWebSocketSendError,
14
16
  acceptUpgrade: () => acceptUpgrade,
15
17
  attachment: () => attachment,
16
18
  fromWebSocket: () => fromWebSocket,
17
- handlers: () => handlers
19
+ handlers: () => handlers,
20
+ installKeepalive: () => installKeepalive
21
+ });
22
+ const DEFAULT_KEEPALIVE_REQUEST = "effect-cf:ping";
23
+ const DEFAULT_KEEPALIVE_RESPONSE = "effect-cf:pong";
24
+ /**
25
+ * Registers exact text keepalives with Cloudflare so they never invoke the object.
26
+ * The pair applies to all hibernating sockets on this object; install in its constructor.
27
+ * Clients send the request text and consume the response outside their application protocol.
28
+ */
29
+ const installKeepalive = Effect.fn("DurableObjectWebSocket.installKeepalive")(function* (request = DEFAULT_KEEPALIVE_REQUEST, response = DEFAULT_KEEPALIVE_RESPONSE) {
30
+ const state = yield* DurableObjectState;
31
+ const configured = yield* state.getWebSocketAutoResponse;
32
+ if (configured !== null && (configured.request !== request || configured.response !== response)) return yield* Effect.die(/* @__PURE__ */ new Error("Durable Object already has a different keepalive protocol"));
33
+ yield* state.setWebSocketAutoResponse(new WebSocketRequestResponsePair(request, response));
18
34
  });
19
35
  var DurableWebSocketSendError = class extends Data.TaggedError("DurableWebSocketSendError") {
20
36
  get message() {
@@ -117,4 +133,4 @@ const handlers = (options) => ({
117
133
  webSocketError: options.error
118
134
  });
119
135
  //#endregion
120
- export { DurableObjectWebSocket_exports, DurableWebSocketAttachmentError, DurableWebSocketCloseError, DurableWebSocketSendError, acceptUpgrade, attachment, fromWebSocket, handlers };
136
+ export { DEFAULT_KEEPALIVE_REQUEST, DEFAULT_KEEPALIVE_RESPONSE, DurableObjectWebSocket_exports, DurableWebSocketAttachmentError, DurableWebSocketCloseError, DurableWebSocketSendError, acceptUpgrade, attachment, fromWebSocket, handlers, installKeepalive };
@@ -5,9 +5,9 @@ import * as Schema from "effect/Schema";
5
5
  import * as Option from "effect/Option";
6
6
  import * as Cause from "effect/Cause";
7
7
  import * as Exit from "effect/Exit";
8
- import * as Clock from "effect/Clock";
9
8
  import * as Tracer from "effect/Tracer";
10
9
  import * as References from "effect/References";
10
+ import * as Clock from "effect/Clock";
11
11
  //#region src/RpcTracing.ts
12
12
  var RpcTracing_exports = /* @__PURE__ */ __exportAll({
13
13
  RpcTraceContext: () => RpcTraceContext,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-cf",
3
- "version": "0.50.0",
3
+ "version": "0.51.0",
4
4
  "description": "Effect-native primitives for Cloudflare Workers and bindings.",
5
5
  "license": "MIT",
6
6
  "repository": {