effect-cf 0.50.0 → 0.52.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/CHANGELOG.md +20 -0
- package/README.md +2 -0
- package/dist/DurableObjectAlarm.d.mts +68 -15
- package/dist/DurableObjectAlarm.mjs +261 -110
- package/dist/DurableObjectContainer.d.mts +3 -1
- package/dist/DurableObjectContainer.mjs +4 -2
- package/dist/DurableObjectRpcWebSocket.d.mts +2 -2
- package/dist/DurableObjectRpcWebSocket.mjs +2 -6
- package/dist/DurableObjectStorage.d.mts +2 -9
- package/dist/DurableObjectStorage.mjs +1 -14
- package/dist/DurableObjectWebSocket.d.mts +10 -2
- package/dist/DurableObjectWebSocket.mjs +18 -2
- package/dist/RpcTracing.mjs +1 -1
- package/package.json +1 -1
- package/src/DurableObjectAlarm.ts +536 -202
- package/src/DurableObjectContainer.ts +12 -1
- package/src/DurableObjectRpcWebSocket.ts +4 -14
- package/src/DurableObjectStorage.ts +2 -59
- package/src/DurableObjectWebSocket.ts +24 -0
|
@@ -2,7 +2,6 @@ import * as Effect from "effect/Effect";
|
|
|
2
2
|
import * as S from "effect/Schema";
|
|
3
3
|
import * as Option from "effect/Option";
|
|
4
4
|
import * as Cause from "effect/Cause";
|
|
5
|
-
import * as Duration from "effect/Duration";
|
|
6
5
|
declare namespace DurableObjectStorage_d_exports {
|
|
7
6
|
export { DurableObjectStorage, DurableObjectTransaction, SchemaBackedSyncKvStorage, SqlCursor, SqlStorage, SqlStorageValue, StorageOperationError, SyncKvDefinition, SyncKvStorage, fromDurableObjectStorage };
|
|
8
7
|
}
|
|
@@ -69,23 +68,17 @@ interface DurableObjectTransaction {
|
|
|
69
68
|
delete(keys: Array<string>, options?: globalThis.DurableObjectPutOptions): StorageEffect<number>;
|
|
70
69
|
rollback(): StorageEffect<void>;
|
|
71
70
|
getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
|
|
72
|
-
setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
73
|
-
setAlarmAfter(delay: Duration.Input, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
74
|
-
deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
75
71
|
}
|
|
76
72
|
interface DurableObjectStorage {
|
|
77
73
|
get<T = unknown>(key: string, options?: globalThis.DurableObjectGetOptions): StorageEffect<T | undefined>;
|
|
78
74
|
put<T>(key: string, value: T, options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
79
75
|
delete(key: string, options?: globalThis.DurableObjectPutOptions): StorageEffect<boolean>;
|
|
80
76
|
/**
|
|
81
|
-
* Deletes all stored data
|
|
82
|
-
*
|
|
77
|
+
* Deletes all stored data, including logical schedules. Use the alarm scheduler
|
|
78
|
+
* to cancel individual alarms without deleting application data.
|
|
83
79
|
*/
|
|
84
80
|
deleteAll(options?: globalThis.DurableObjectPutOptions): StorageEffect<void>;
|
|
85
81
|
getAlarm(options?: globalThis.DurableObjectGetAlarmOptions): StorageEffect<number | null>;
|
|
86
|
-
setAlarm(scheduledTime: number | Date, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
87
|
-
setAlarmAfter(delay: Duration.Input, options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
88
|
-
deleteAlarm(options?: globalThis.DurableObjectSetAlarmOptions): StorageEffect<void>;
|
|
89
82
|
/**
|
|
90
83
|
* SQLite-backed Durable Object storage only.
|
|
91
84
|
*
|
|
@@ -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 };
|
package/dist/RpcTracing.mjs
CHANGED
|
@@ -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,
|