effect-cf 0.39.0 → 0.40.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 +16 -0
- package/README.md +9 -1
- package/dist/ComputerWorkspace.d.mts +1 -1
- package/dist/ComputerWorkspace.mjs +2 -1
- package/dist/{DurableObjectState-CpgAmFqo.d.mts → DurableObjectState-DJ0K-zyd.d.mts} +1 -1
- package/dist/Mcp.d.mts +1 -1
- package/dist/Vitest.d.mts +2 -2
- package/dist/{Worker-Dl6_Pijl.d.mts → Worker-gV4mDqIs.d.mts} +15 -15
- package/dist/{WorkflowBinding-CvJT9hB5.d.mts → WorkflowBinding-DtVykUCz.d.mts} +1 -1
- package/dist/index.d.mts +224 -185
- package/dist/index.mjs +475 -435
- package/package.json +1 -1
- package/src/DurableObject.ts +129 -37
- package/src/DurableObjectAlarm.ts +175 -40
- package/src/DurableObjectDefinition.ts +19 -21
- package/src/DurableObjectNamespace.ts +6 -4
- package/src/DurableObjectStorage.ts +4 -5
- package/src/Images.ts +4 -8
- package/src/ServiceBinding.ts +6 -4
- package/src/Worker.ts +12 -10
package/dist/index.mjs
CHANGED
|
@@ -18,7 +18,7 @@ import { SqliteClient } from "@effect/sql-sqlite-do";
|
|
|
18
18
|
import { NonRetryableError } from "cloudflare:workflows";
|
|
19
19
|
//#region src/WorkersAi.ts
|
|
20
20
|
var WorkersAi_exports = /* @__PURE__ */ __exportAll({
|
|
21
|
-
Tag: () => Tag$
|
|
21
|
+
Tag: () => Tag$14,
|
|
22
22
|
WorkersAiOperationError: () => WorkersAiOperationError,
|
|
23
23
|
embeddingResponse: () => embeddingResponse,
|
|
24
24
|
isWorkersAiBinding: () => isWorkersAiBinding,
|
|
@@ -80,8 +80,8 @@ const makeClient$13 = (definition) => (ai) => {
|
|
|
80
80
|
};
|
|
81
81
|
};
|
|
82
82
|
const layer$17 = (tag, definition) => layer$18(tag, definition.binding, (value) => isWorkersAiBinding(value), makeClient$13(definition), { expected: expectedWorkersAiBinding });
|
|
83
|
-
const make$14 = (id) => Tag$
|
|
84
|
-
const Tag$
|
|
83
|
+
const make$14 = (id) => Tag$14()(id);
|
|
84
|
+
const Tag$14 = () => (id) => {
|
|
85
85
|
const tag = Context.Service()(id);
|
|
86
86
|
const makeLayer = (definition) => layer$17(tag, definition);
|
|
87
87
|
return Object.assign(tag, {
|
|
@@ -93,7 +93,7 @@ const Tag$13 = () => (id) => {
|
|
|
93
93
|
//#region src/AiGateway.ts
|
|
94
94
|
var AiGateway_exports = /* @__PURE__ */ __exportAll({
|
|
95
95
|
AiGatewayOperationError: () => AiGatewayOperationError,
|
|
96
|
-
Tag: () => Tag$
|
|
96
|
+
Tag: () => Tag$13,
|
|
97
97
|
isAiGatewayBinding: () => isAiGatewayBinding,
|
|
98
98
|
layer: () => layer$16,
|
|
99
99
|
make: () => make$13,
|
|
@@ -249,8 +249,8 @@ const makeHttpClient = (definition, request = fetch) => {
|
|
|
249
249
|
};
|
|
250
250
|
};
|
|
251
251
|
const layer$16 = (tag, definition) => layer$18(tag, definition.binding, isAiGatewayBinding, (ai) => makeClientFromAi(definition, ai), { expected: expectedAiGatewayBinding });
|
|
252
|
-
const make$13 = (id) => Tag$
|
|
253
|
-
const Tag$
|
|
252
|
+
const make$13 = (id) => Tag$13()(id);
|
|
253
|
+
const Tag$13 = () => (id) => {
|
|
254
254
|
const tag = Context.Service()(id);
|
|
255
255
|
const makeLayer = (definition) => layer$16(tag, definition);
|
|
256
256
|
return Object.assign(tag, {
|
|
@@ -267,7 +267,7 @@ var AnalyticsEngine_exports = /* @__PURE__ */ __exportAll({
|
|
|
267
267
|
AnalyticsEngineQueryError: () => AnalyticsEngineQueryError,
|
|
268
268
|
AnalyticsEngineWriteValidationError: () => AnalyticsEngineWriteValidationError,
|
|
269
269
|
QueryTag: () => QueryTag,
|
|
270
|
-
Tag: () => Tag$
|
|
270
|
+
Tag: () => Tag$12,
|
|
271
271
|
isAnalyticsEngineDataset: () => isAnalyticsEngineDataset,
|
|
272
272
|
layer: () => layer$15,
|
|
273
273
|
layerFetch: () => layerFetch,
|
|
@@ -288,7 +288,7 @@ const writeLimits = {
|
|
|
288
288
|
maxBlobs: 20,
|
|
289
289
|
maxDoubles: 20,
|
|
290
290
|
maxIndexes: 1,
|
|
291
|
-
maxBlobBytes:
|
|
291
|
+
maxBlobBytes: 16384,
|
|
292
292
|
maxIndexBytes: 96,
|
|
293
293
|
maxDataPointsPerInvocation: 250
|
|
294
294
|
};
|
|
@@ -493,9 +493,9 @@ const queryLayerConfig = (tag, config = queryConfig()) => Layer.effect(tag, Effe
|
|
|
493
493
|
}));
|
|
494
494
|
const layerFetchConfig = (tag, config = queryConfig()) => queryLayerConfig(tag, config).pipe(Layer.provide(FetchHttpClient.layer));
|
|
495
495
|
const layer$15 = (tag, definition) => layer$18(tag, definition.binding, isAnalyticsEngineDataset, makeClient$11(definition, definition.write), { expected: expectedAnalyticsEngineDataset });
|
|
496
|
-
const make$12 = (id) => Tag$
|
|
496
|
+
const make$12 = (id) => Tag$12()(id);
|
|
497
497
|
const makeQuery = (id) => QueryTag()(id);
|
|
498
|
-
const Tag$
|
|
498
|
+
const Tag$12 = () => (id) => {
|
|
499
499
|
const tag = Context.Service()(id);
|
|
500
500
|
const makeLayer = (definition) => layer$15(tag, definition);
|
|
501
501
|
return Object.assign(tag, {
|
|
@@ -521,7 +521,7 @@ const QueryTag = () => (id) => {
|
|
|
521
521
|
//#region src/BrowserRendering.ts
|
|
522
522
|
var BrowserRendering_exports = /* @__PURE__ */ __exportAll({
|
|
523
523
|
BrowserRenderingOperationError: () => BrowserRenderingOperationError,
|
|
524
|
-
Tag: () => Tag$
|
|
524
|
+
Tag: () => Tag$11,
|
|
525
525
|
isBrowserRenderingBinding: () => isBrowserRenderingBinding,
|
|
526
526
|
layer: () => layer$14,
|
|
527
527
|
make: () => make$11,
|
|
@@ -581,8 +581,8 @@ const makeClient$10 = (definition) => (binding) => ({
|
|
|
581
581
|
rawUnsafe: Effect.succeed(binding)
|
|
582
582
|
});
|
|
583
583
|
const layer$14 = (tag, definition) => layer$18(tag, definition.binding, isBrowserRenderingBinding, makeClient$10(definition), { expected: expectedBrowserRenderingBinding });
|
|
584
|
-
const make$11 = (id) => Tag$
|
|
585
|
-
const Tag$
|
|
584
|
+
const make$11 = (id) => Tag$11()(id);
|
|
585
|
+
const Tag$11 = () => (id) => {
|
|
586
586
|
const tag = Context.Service()(id);
|
|
587
587
|
const makeLayer = (definition) => layer$14(tag, definition);
|
|
588
588
|
return Object.assign(tag, {
|
|
@@ -807,7 +807,7 @@ var ContainerNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
|
807
807
|
ContainerNamespace: () => ContainerNamespace,
|
|
808
808
|
ContainerOperationError: () => ContainerOperationError,
|
|
809
809
|
ContainerState: () => ContainerState,
|
|
810
|
-
Tag: () => Tag$
|
|
810
|
+
Tag: () => Tag$10,
|
|
811
811
|
isContainerNamespaceResource: () => isContainerNamespaceResource,
|
|
812
812
|
layer: () => layer$10,
|
|
813
813
|
make: () => make$10,
|
|
@@ -924,8 +924,8 @@ const makeClient$8 = (definition) => (namespace) => {
|
|
|
924
924
|
};
|
|
925
925
|
};
|
|
926
926
|
const layer$10 = (tag, definition) => layer$18(tag, definition.binding, (value) => isContainerNamespaceResource(value), makeClient$8(definition), { expected: expectedContainerNamespace });
|
|
927
|
-
const make$10 = (id) => Tag$
|
|
928
|
-
const Tag$
|
|
927
|
+
const make$10 = (id) => Tag$10()(id);
|
|
928
|
+
const Tag$10 = () => (id) => {
|
|
929
929
|
const tag = Context.Service()(`effect-cf/Container/${id}`);
|
|
930
930
|
const makeLayer = (definition) => layer$10(tag, definition);
|
|
931
931
|
const getByName = Effect.fnUntraced(function* (name, options) {
|
|
@@ -956,7 +956,7 @@ const Tag$9 = () => (id) => {
|
|
|
956
956
|
rawUnsafe
|
|
957
957
|
});
|
|
958
958
|
};
|
|
959
|
-
const ContainerNamespace = Tag$
|
|
959
|
+
const ContainerNamespace = Tag$10;
|
|
960
960
|
//#endregion
|
|
961
961
|
//#region src/D1.ts
|
|
962
962
|
var D1_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -983,412 +983,100 @@ const Service = () => (id, definition) => {
|
|
|
983
983
|
});
|
|
984
984
|
};
|
|
985
985
|
//#endregion
|
|
986
|
-
//#region src/
|
|
987
|
-
var
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
986
|
+
//#region src/DurableObjectAlarm.ts
|
|
987
|
+
var DurableObjectAlarm_exports = /* @__PURE__ */ __exportAll({
|
|
988
|
+
DurableObjectAlarm: () => DurableObjectAlarm,
|
|
989
|
+
DurableObjectAlarmEvent: () => DurableObjectAlarmEvent,
|
|
990
|
+
InvalidAlarmPayloadError: () => InvalidAlarmPayloadError,
|
|
991
|
+
InvalidAlarmRefError: () => InvalidAlarmRefError,
|
|
992
|
+
InvalidProcessDueAlarmsOptionsError: () => InvalidProcessDueAlarmsOptionsError,
|
|
993
|
+
InvalidRepeatEveryError: () => InvalidRepeatEveryError,
|
|
994
|
+
StoredAlarmDecodeError: () => StoredAlarmDecodeError,
|
|
995
|
+
Tag: () => Tag$9,
|
|
996
|
+
define: () => define,
|
|
997
|
+
processDue: () => processDue
|
|
994
998
|
});
|
|
995
|
-
const
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
999
|
+
const INIT_TABLE_SQL = `
|
|
1000
|
+
CREATE TABLE IF NOT EXISTS effect_cf_scheduled_alarms (
|
|
1001
|
+
storage_id TEXT PRIMARY KEY,
|
|
1002
|
+
alarm_id TEXT NOT NULL,
|
|
1003
|
+
tag TEXT NOT NULL,
|
|
1004
|
+
run_at INTEGER NOT NULL,
|
|
1005
|
+
repeat_every_ms INTEGER,
|
|
1006
|
+
payload TEXT NOT NULL
|
|
1007
|
+
);
|
|
1008
|
+
CREATE INDEX IF NOT EXISTS idx_effect_cf_scheduled_alarms_run_at_storage_id
|
|
1009
|
+
ON effect_cf_scheduled_alarms (run_at, storage_id);
|
|
1010
|
+
`;
|
|
1011
|
+
const DEFAULT_PROCESS_DUE_ALARMS_LIMIT = 100;
|
|
1012
|
+
const DEFAULT_PROCESS_DUE_ALARMS_FAILURE_RESCHEDULE_AFTER = "30 seconds";
|
|
1013
|
+
const getScheduledEventId = (input) => `effect-cf-alarm:${encodeURIComponent(input.tag)}:${encodeURIComponent(input.id)}`;
|
|
1014
|
+
var InvalidAlarmRefError = class extends Data.TaggedError("InvalidAlarmRefError") {
|
|
1000
1015
|
get message() {
|
|
1001
|
-
return `Durable Object
|
|
1016
|
+
return `Invalid Durable Object alarm ref: ${causeMessage(this.cause)}`;
|
|
1002
1017
|
}
|
|
1003
1018
|
};
|
|
1004
|
-
|
|
1005
|
-
* Failure raised when forwarding a request to a Durable Object stub.
|
|
1006
|
-
*/
|
|
1007
|
-
var DurableObjectFetchError = class extends Data.TaggedError("DurableObjectFetchError") {
|
|
1019
|
+
var InvalidAlarmPayloadError = class extends Data.TaggedError("InvalidAlarmPayloadError") {
|
|
1008
1020
|
get message() {
|
|
1009
|
-
return `Durable Object
|
|
1021
|
+
return `Invalid Durable Object alarm payload: ${causeMessage(this.cause)}`;
|
|
1010
1022
|
}
|
|
1011
1023
|
};
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
const newUniqueId = (options) => Effect.sync(() => namespace.newUniqueId(options));
|
|
1017
|
-
const idFromName = (name) => Effect.sync(() => namespace.idFromName(name));
|
|
1018
|
-
const idFromString = (id) => Effect.sync(() => namespace.idFromString(id));
|
|
1019
|
-
const get = (id, options) => Effect.sync(() => namespace.get(id, options));
|
|
1020
|
-
const getByName = (name, options) => Effect.sync(() => namespace.getByName(name, options));
|
|
1021
|
-
const jurisdiction = (value) => Effect.sync(() => namespace.jurisdiction(value));
|
|
1022
|
-
const fetch = (stub, input, init) => Effect.tryPromise({
|
|
1023
|
-
try: (signal) => {
|
|
1024
|
-
const callerSignal = init?.signal !== void 0 ? init.signal : input instanceof Request ? input.signal : void 0;
|
|
1025
|
-
return stub.fetch(input, {
|
|
1026
|
-
...init,
|
|
1027
|
-
signal: callerSignal === null || callerSignal === void 0 ? signal : AbortSignal.any([callerSignal, signal])
|
|
1028
|
-
});
|
|
1029
|
-
},
|
|
1030
|
-
catch: (cause) => new DurableObjectFetchError({
|
|
1031
|
-
binding: definition.binding,
|
|
1032
|
-
cause
|
|
1033
|
-
})
|
|
1034
|
-
});
|
|
1035
|
-
const rpc = Effect.fnUntraced(function* (stub, method, ...args) {
|
|
1036
|
-
const methodName = String(method);
|
|
1037
|
-
const encodedArgs = definition.definition === void 0 ? args : yield* encodeArgs(definition.definition, methodName, args).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1038
|
-
binding: definition.binding,
|
|
1039
|
-
method: methodName,
|
|
1040
|
-
cause
|
|
1041
|
-
})));
|
|
1042
|
-
return yield* invokeRpcMethod(stub, method, definition.rpcTracing ? yield* withRpcTraceContext(encodedArgs) : encodedArgs, (cause) => new DurableObjectRpcError({
|
|
1043
|
-
binding: definition.binding,
|
|
1044
|
-
method: methodName,
|
|
1045
|
-
cause
|
|
1046
|
-
}));
|
|
1047
|
-
});
|
|
1048
|
-
const decodeSuccess$1 = Effect.fnUntraced(function* (methodName, value) {
|
|
1049
|
-
if (definition.definition === void 0) return value;
|
|
1050
|
-
return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1051
|
-
binding: definition.binding,
|
|
1052
|
-
method: methodName,
|
|
1053
|
-
cause
|
|
1054
|
-
})));
|
|
1055
|
-
});
|
|
1056
|
-
const call = Effect.fnUntraced(function* (stub, method, ...args) {
|
|
1057
|
-
const methodName = String(method);
|
|
1058
|
-
const value = yield* resolve(yield* rpc(stub, method, ...args)).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1059
|
-
binding: definition.binding,
|
|
1060
|
-
method: methodName,
|
|
1061
|
-
cause
|
|
1062
|
-
})));
|
|
1063
|
-
return yield* decodeSuccess$1(methodName, value);
|
|
1064
|
-
}, (effect, ...args) => withRpcClientSpan(effect, definition.binding, String(args[1])));
|
|
1065
|
-
const scopedCall = Effect.fnUntraced(function* (stub, method, ...args) {
|
|
1066
|
-
const methodName = String(method);
|
|
1067
|
-
const value = yield* scoped(yield* rpc(stub, method, ...args)).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1068
|
-
binding: definition.binding,
|
|
1069
|
-
method: methodName,
|
|
1070
|
-
cause
|
|
1071
|
-
})));
|
|
1072
|
-
return yield* decodeSuccess$1(methodName, value);
|
|
1073
|
-
}, (effect, ...args) => withRpcClientSpan(effect, definition.binding, String(args[1])));
|
|
1074
|
-
const directMethods = makeDirectMethods(definition.definition, {
|
|
1075
|
-
call,
|
|
1076
|
-
fetch,
|
|
1077
|
-
get,
|
|
1078
|
-
getByName
|
|
1079
|
-
});
|
|
1080
|
-
return Object.assign(directMethods, {
|
|
1081
|
-
newUniqueId,
|
|
1082
|
-
idFromName,
|
|
1083
|
-
idFromString,
|
|
1084
|
-
get,
|
|
1085
|
-
getByName,
|
|
1086
|
-
jurisdiction,
|
|
1087
|
-
fetch,
|
|
1088
|
-
rpc,
|
|
1089
|
-
call,
|
|
1090
|
-
scopedCall,
|
|
1091
|
-
rawUnsafe: Effect.succeed(namespace)
|
|
1092
|
-
});
|
|
1093
|
-
};
|
|
1024
|
+
var InvalidRepeatEveryError = class extends Data.TaggedError("InvalidRepeatEveryError") {
|
|
1025
|
+
get message() {
|
|
1026
|
+
return `Invalid Durable Object alarm repeatEvery: ${causeMessage(this.cause)}`;
|
|
1027
|
+
}
|
|
1094
1028
|
};
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
if (rpcDefinition !== void 0) {
|
|
1099
|
-
for (const methodName of Object.keys(rpcDefinition.methods)) methods[methodName] = (stub, ...args) => helpers.call(stub, methodName, ...args);
|
|
1100
|
-
const makeClient = (getStub) => {
|
|
1101
|
-
const client = { fetch: (input, init) => Effect.gen(function* () {
|
|
1102
|
-
const stub = yield* getStub();
|
|
1103
|
-
return yield* helpers.fetch(stub, input, init);
|
|
1104
|
-
}) };
|
|
1105
|
-
for (const methodName of Object.keys(rpcDefinition.methods)) client[methodName] = (...args) => Effect.gen(function* () {
|
|
1106
|
-
const stub = yield* getStub();
|
|
1107
|
-
return yield* helpers.call(stub, methodName, ...args);
|
|
1108
|
-
});
|
|
1109
|
-
return client;
|
|
1110
|
-
};
|
|
1111
|
-
methods.byName = (name, options) => makeClient(() => helpers.getByName(name, options));
|
|
1112
|
-
methods.byId = (id, options) => makeClient(() => helpers.get(id, options));
|
|
1029
|
+
var InvalidProcessDueAlarmsOptionsError = class extends Data.TaggedError("InvalidProcessDueAlarmsOptionsError") {
|
|
1030
|
+
get message() {
|
|
1031
|
+
return `Invalid processDueAlarms options: ${causeMessage(this.cause)}`;
|
|
1113
1032
|
}
|
|
1114
|
-
return methods;
|
|
1115
1033
|
};
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
Tag: () => Tag$8,
|
|
1121
|
-
implement: () => implement$2,
|
|
1122
|
-
make: () => make$8,
|
|
1123
|
-
method: () => method
|
|
1124
|
-
});
|
|
1125
|
-
const reservedMethodNames$1 = /* @__PURE__ */ new Set([
|
|
1126
|
-
"constructor",
|
|
1127
|
-
"dup",
|
|
1128
|
-
"fetch",
|
|
1129
|
-
"alarm",
|
|
1130
|
-
"webSocketMessage",
|
|
1131
|
-
"webSocketClose",
|
|
1132
|
-
"webSocketError"
|
|
1133
|
-
]);
|
|
1134
|
-
function method(definition) {
|
|
1135
|
-
return method$1(definition);
|
|
1136
|
-
}
|
|
1137
|
-
const makeDefinition$2 = (id, methods) => {
|
|
1138
|
-
assertNoReservedMethods("Durable Object", methods, reservedMethodNames$1);
|
|
1139
|
-
const definition = make$15(id, methods);
|
|
1140
|
-
return Object.assign(definition, { make: (layer, options) => make$7(layer, {
|
|
1141
|
-
...options,
|
|
1142
|
-
rpc: wrapHandlers(definition, options.rpc)
|
|
1143
|
-
}) });
|
|
1034
|
+
var StoredAlarmDecodeError = class extends Data.TaggedError("StoredAlarmDecodeError") {
|
|
1035
|
+
get message() {
|
|
1036
|
+
return `Failed to decode stored alarm "${this.storageId}": ${causeMessage(this.cause)}`;
|
|
1037
|
+
}
|
|
1144
1038
|
};
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1039
|
+
const DurableObjectAlarmEvent = Schema.TaggedUnion({ AlarmDue: {
|
|
1040
|
+
id: Schema.NonEmptyString,
|
|
1041
|
+
payload: Schema.Json,
|
|
1042
|
+
/** Persisted due time, which can differ from the invocation time during retries. */
|
|
1043
|
+
scheduledAt: Schema.DateTimeUtc,
|
|
1044
|
+
tag: Schema.NonEmptyString
|
|
1045
|
+
} });
|
|
1046
|
+
const AlarmRefSchema = Schema.Struct({
|
|
1047
|
+
id: Schema.NonEmptyString,
|
|
1048
|
+
tag: Schema.NonEmptyString
|
|
1049
|
+
});
|
|
1050
|
+
const decodeAlarmRef = (input) => Schema.decodeUnknownEffect(AlarmRefSchema)(input).pipe(Effect.mapError((cause) => new InvalidAlarmRefError({ cause })));
|
|
1051
|
+
const StoredPayloadString = Schema.fromJsonString(Schema.Json);
|
|
1052
|
+
const decodeStoredPayload = (row) => Schema.decodeUnknownEffect(StoredPayloadString)(row.payload).pipe(Effect.mapError((cause) => new StoredAlarmDecodeError({
|
|
1053
|
+
cause,
|
|
1054
|
+
storageId: row.storage_id
|
|
1055
|
+
})));
|
|
1056
|
+
const encodeStoredPayload = (payload) => Schema.encodeEffect(StoredPayloadString)(payload).pipe(Effect.mapError((cause) => new InvalidAlarmPayloadError({ cause })));
|
|
1057
|
+
const ensureTable = (state) => state.storage.sql.exec(INIT_TABLE_SQL).pipe(Effect.asVoid);
|
|
1058
|
+
const toRepeatEveryMillis = (input) => {
|
|
1059
|
+
if (input === void 0) return Effect.succeed(null);
|
|
1060
|
+
return Effect.try({
|
|
1061
|
+
try: () => {
|
|
1062
|
+
const millis = Duration.toMillis(input);
|
|
1063
|
+
if (!Number.isFinite(millis) || millis <= 0) throw new Error("Alarm repeatEvery must be a positive finite duration");
|
|
1064
|
+
return Math.ceil(millis);
|
|
1065
|
+
},
|
|
1066
|
+
catch: (cause) => new InvalidRepeatEveryError({ cause })
|
|
1153
1067
|
});
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
});
|
|
1167
|
-
const getByName = Effect.fn("DurableObject.getByName")(function* (name, options) {
|
|
1168
|
-
return yield* (yield* tag).getByName(name, options);
|
|
1169
|
-
});
|
|
1170
|
-
const jurisdiction = Effect.fn("DurableObject.jurisdiction")(function* (value) {
|
|
1171
|
-
return yield* (yield* tag).jurisdiction(value);
|
|
1172
|
-
});
|
|
1173
|
-
const fetch = Effect.fn("DurableObject.fetch")(function* (stub, input, init) {
|
|
1174
|
-
return yield* (yield* tag).fetch(stub, input, init);
|
|
1175
|
-
});
|
|
1176
|
-
const rpc = Effect.fnUntraced(function* (stub, methodName, ...args) {
|
|
1177
|
-
const invokeRpc = (yield* tag).rpc;
|
|
1178
|
-
return yield* invokeRpc(stub, methodName, ...args);
|
|
1179
|
-
});
|
|
1180
|
-
const call = Effect.fnUntraced(function* (stub, methodName, ...args) {
|
|
1181
|
-
const invokeCall = (yield* tag).call;
|
|
1182
|
-
return yield* invokeCall(stub, methodName, ...args);
|
|
1183
|
-
});
|
|
1184
|
-
const scopedCall = Effect.fnUntraced(function* (stub, methodName, ...args) {
|
|
1185
|
-
const invokeScopedCall = (yield* tag).scopedCall;
|
|
1186
|
-
return yield* invokeScopedCall(stub, methodName, ...args);
|
|
1187
|
-
});
|
|
1188
|
-
const rawUnsafe = Effect.fnUntraced(function* () {
|
|
1189
|
-
return yield* (yield* tag).rawUnsafe;
|
|
1190
|
-
});
|
|
1191
|
-
const directMethods = makeDirectMethods(definition, {
|
|
1192
|
-
call,
|
|
1193
|
-
fetch,
|
|
1194
|
-
get,
|
|
1195
|
-
getByName
|
|
1196
|
-
});
|
|
1197
|
-
return Object.assign(tag, directMethods, {
|
|
1198
|
-
id: definition.id,
|
|
1199
|
-
methods: definition.methods,
|
|
1200
|
-
make: definition.make,
|
|
1201
|
-
layer,
|
|
1202
|
-
newUniqueId,
|
|
1203
|
-
idFromName,
|
|
1204
|
-
idFromString,
|
|
1205
|
-
get,
|
|
1206
|
-
getByName,
|
|
1207
|
-
jurisdiction,
|
|
1208
|
-
fetch,
|
|
1209
|
-
rpc,
|
|
1210
|
-
call,
|
|
1211
|
-
scopedCall,
|
|
1212
|
-
rawUnsafe
|
|
1213
|
-
});
|
|
1214
|
-
};
|
|
1215
|
-
const DurableObject$1 = Tag$8;
|
|
1216
|
-
const wrapHandlers = (definition, handlers) => {
|
|
1217
|
-
const wrapped = Object.create(Object.prototype);
|
|
1218
|
-
for (const key of Object.keys(definition.methods)) {
|
|
1219
|
-
const handler = handlers[key];
|
|
1220
|
-
wrapped[key] = (...args) => Effect.gen(function* () {
|
|
1221
|
-
const decodedArgs = yield* decodeArgs(definition, key, args);
|
|
1222
|
-
yield* recordDecodedArgs(decodedArgs);
|
|
1223
|
-
const value = yield* handler(...decodedArgs);
|
|
1224
|
-
return yield* encodeSuccess(definition, key, value);
|
|
1225
|
-
});
|
|
1226
|
-
}
|
|
1227
|
-
return wrapped;
|
|
1228
|
-
};
|
|
1229
|
-
/**
|
|
1230
|
-
* Helper for implementing handlers with the exact method shape of a definition.
|
|
1231
|
-
*/
|
|
1232
|
-
const implement$2 = (_definition, handlers) => handlers;
|
|
1233
|
-
//#endregion
|
|
1234
|
-
//#region src/DurableObject.ts
|
|
1235
|
-
var DurableObject_exports = /* @__PURE__ */ __exportAll({
|
|
1236
|
-
RunSymbol: () => RunSymbol,
|
|
1237
|
-
Tag: () => Tag$8,
|
|
1238
|
-
implement: () => implement$2,
|
|
1239
|
-
make: () => make$7,
|
|
1240
|
-
method: () => method
|
|
1241
|
-
});
|
|
1242
|
-
const reservedMethodNames = reservedMethodNames$2;
|
|
1243
|
-
/** Override to instrument the whole event, then call super[RunSymbol]. */
|
|
1244
|
-
const RunSymbol = Symbol.for("effect-cf/DurableObject/run");
|
|
1245
|
-
const scheduleTelemetryFlush = scheduleTelemetryFlush$1((flush) => Effect.flatMap(DurableObjectState, (state) => state.waitUntil(flush)));
|
|
1246
|
-
/**
|
|
1247
|
-
* Builds a Durable Object whose base `layer` lives for the in-memory instance.
|
|
1248
|
-
* Cloudflare does not expose an eviction or shutdown hook, so finalizers in
|
|
1249
|
-
* that layer are not guaranteed to run. Put resources that require timely
|
|
1250
|
-
* release in `eventLayer`, whose scope closes after each handled event.
|
|
1251
|
-
*/
|
|
1252
|
-
const make$7 = (layer, options = {}) => {
|
|
1253
|
-
class EffectDurableObject extends DurableObject {
|
|
1254
|
-
runtime;
|
|
1255
|
-
constructor(state, env) {
|
|
1256
|
-
super(state, env);
|
|
1257
|
-
this.runtime = makeEntrypointRuntime(layer, env, Layer.succeed(DurableObjectState, fromDurableObjectState(state)));
|
|
1258
|
-
const initialize = options.initialize;
|
|
1259
|
-
if (initialize !== void 0) state.waitUntil(this[RunSymbol](initialize, { eventLayer: false }));
|
|
1260
|
-
}
|
|
1261
|
-
[RunSymbol](effect, runOptions = {}) {
|
|
1262
|
-
const eventLayer = runOptions.eventLayer === false ? void 0 : options.eventLayer;
|
|
1263
|
-
const parent = runOptions.rpc?.parent;
|
|
1264
|
-
const parentSpan = parent === void 0 ? void 0 : Tracer.externalSpan(parent);
|
|
1265
|
-
if (eventLayer === void 0) return runEventPromise(this.runtime, effect, void 0, parentSpan);
|
|
1266
|
-
return runEventPromise(this.runtime, effect, eventLayer, parentSpan);
|
|
1267
|
-
}
|
|
1268
|
-
fetch(request) {
|
|
1269
|
-
const fetchHandler = options.fetch;
|
|
1270
|
-
if (fetchHandler === void 0) return Promise.resolve(new Response("Not Found", { status: 404 }));
|
|
1271
|
-
return this[RunSymbol](Effect.provideService(fetchHandler, NativeRequest, request), { event: "fetch" });
|
|
1272
|
-
}
|
|
1273
|
-
alarm(alarmInfo) {
|
|
1274
|
-
const logicalAlarms = options.alarms?.pipe(Effect.asVoid);
|
|
1275
|
-
const rawAlarm = options.alarm?.(alarmInfo);
|
|
1276
|
-
const alarmEffect = logicalAlarms !== void 0 && rawAlarm !== void 0 ? Effect.gen(function* () {
|
|
1277
|
-
yield* logicalAlarms;
|
|
1278
|
-
yield* rawAlarm;
|
|
1279
|
-
}) : logicalAlarms ?? rawAlarm;
|
|
1280
|
-
if (alarmEffect !== void 0) return this[RunSymbol](alarmEffect.pipe(Effect.onExit(() => scheduleTelemetryFlush)), { event: "alarm" });
|
|
1281
|
-
}
|
|
1282
|
-
webSocketMessage(socket, message) {
|
|
1283
|
-
if (options.webSocketMessage !== void 0) return this[RunSymbol](options.webSocketMessage(fromWebSocket(socket), message), { event: "webSocketMessage" });
|
|
1284
|
-
}
|
|
1285
|
-
webSocketClose(socket, code, reason, wasClean) {
|
|
1286
|
-
if (options.webSocketClose !== void 0) return this[RunSymbol](options.webSocketClose(fromWebSocket(socket), code, reason, wasClean), { event: "webSocketClose" });
|
|
1287
|
-
}
|
|
1288
|
-
webSocketError(socket, cause) {
|
|
1289
|
-
if (options.webSocketError !== void 0) return this[RunSymbol](options.webSocketError(fromWebSocket(socket), cause), { event: "webSocketError" });
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
defineEntrypointRpcMethods("Durable Object", EffectDurableObject.prototype, options.rpc, reservedMethodNames, (self, effect, rpc) => self[RunSymbol](effect, {
|
|
1293
|
-
event: "rpc",
|
|
1294
|
-
rpc
|
|
1295
|
-
}), () => scheduleTelemetryFlush, options.rpcTracing);
|
|
1296
|
-
return assumeEntrypointClass(EffectDurableObject);
|
|
1297
|
-
};
|
|
1298
|
-
//#endregion
|
|
1299
|
-
//#region src/DurableObjectAlarm.ts
|
|
1300
|
-
var DurableObjectAlarm_exports = /* @__PURE__ */ __exportAll({
|
|
1301
|
-
DurableObjectAlarm: () => DurableObjectAlarm,
|
|
1302
|
-
DurableObjectAlarmEvent: () => DurableObjectAlarmEvent,
|
|
1303
|
-
InvalidAlarmPayloadError: () => InvalidAlarmPayloadError,
|
|
1304
|
-
InvalidAlarmRefError: () => InvalidAlarmRefError,
|
|
1305
|
-
InvalidProcessDueAlarmsOptionsError: () => InvalidProcessDueAlarmsOptionsError,
|
|
1306
|
-
InvalidRepeatEveryError: () => InvalidRepeatEveryError,
|
|
1307
|
-
StoredAlarmDecodeError: () => StoredAlarmDecodeError,
|
|
1308
|
-
define: () => define,
|
|
1309
|
-
processDue: () => processDue
|
|
1310
|
-
});
|
|
1311
|
-
const INIT_TABLE_SQL = `
|
|
1312
|
-
CREATE TABLE IF NOT EXISTS effect_cf_scheduled_alarms (
|
|
1313
|
-
storage_id TEXT PRIMARY KEY,
|
|
1314
|
-
alarm_id TEXT NOT NULL,
|
|
1315
|
-
tag TEXT NOT NULL,
|
|
1316
|
-
run_at INTEGER NOT NULL,
|
|
1317
|
-
repeat_every_ms INTEGER,
|
|
1318
|
-
payload TEXT NOT NULL
|
|
1319
|
-
);
|
|
1320
|
-
CREATE INDEX IF NOT EXISTS idx_effect_cf_scheduled_alarms_run_at_storage_id
|
|
1321
|
-
ON effect_cf_scheduled_alarms (run_at, storage_id);
|
|
1322
|
-
`;
|
|
1323
|
-
const DEFAULT_PROCESS_DUE_ALARMS_LIMIT = 100;
|
|
1324
|
-
const DEFAULT_PROCESS_DUE_ALARMS_FAILURE_RESCHEDULE_AFTER = "30 seconds";
|
|
1325
|
-
const getScheduledEventId = (input) => `effect-cf-alarm:${encodeURIComponent(input.tag)}:${encodeURIComponent(input.id)}`;
|
|
1326
|
-
var InvalidAlarmRefError = class extends Data.TaggedError("InvalidAlarmRefError") {
|
|
1327
|
-
get message() {
|
|
1328
|
-
return `Invalid Durable Object alarm ref: ${causeMessage(this.cause)}`;
|
|
1329
|
-
}
|
|
1330
|
-
};
|
|
1331
|
-
var InvalidAlarmPayloadError = class extends Data.TaggedError("InvalidAlarmPayloadError") {
|
|
1332
|
-
get message() {
|
|
1333
|
-
return `Invalid Durable Object alarm payload: ${causeMessage(this.cause)}`;
|
|
1334
|
-
}
|
|
1335
|
-
};
|
|
1336
|
-
var InvalidRepeatEveryError = class extends Data.TaggedError("InvalidRepeatEveryError") {
|
|
1337
|
-
get message() {
|
|
1338
|
-
return `Invalid Durable Object alarm repeatEvery: ${causeMessage(this.cause)}`;
|
|
1339
|
-
}
|
|
1340
|
-
};
|
|
1341
|
-
var InvalidProcessDueAlarmsOptionsError = class extends Data.TaggedError("InvalidProcessDueAlarmsOptionsError") {
|
|
1342
|
-
get message() {
|
|
1343
|
-
return `Invalid processDueAlarms options: ${causeMessage(this.cause)}`;
|
|
1344
|
-
}
|
|
1345
|
-
};
|
|
1346
|
-
var StoredAlarmDecodeError = class extends Data.TaggedError("StoredAlarmDecodeError") {
|
|
1347
|
-
get message() {
|
|
1348
|
-
return `Failed to decode stored alarm "${this.storageId}": ${causeMessage(this.cause)}`;
|
|
1349
|
-
}
|
|
1350
|
-
};
|
|
1351
|
-
const DurableObjectAlarmEvent = Schema.TaggedUnion({ AlarmDue: {
|
|
1352
|
-
id: Schema.NonEmptyString,
|
|
1353
|
-
payload: Schema.Json,
|
|
1354
|
-
/** Persisted due time, which can differ from the invocation time during retries. */
|
|
1355
|
-
scheduledAt: Schema.DateTimeUtc,
|
|
1356
|
-
tag: Schema.NonEmptyString
|
|
1357
|
-
} });
|
|
1358
|
-
const AlarmRefSchema = Schema.Struct({
|
|
1359
|
-
id: Schema.NonEmptyString,
|
|
1360
|
-
tag: Schema.NonEmptyString
|
|
1361
|
-
});
|
|
1362
|
-
const decodeAlarmRef = (input) => Schema.decodeUnknownEffect(AlarmRefSchema)(input).pipe(Effect.mapError((cause) => new InvalidAlarmRefError({ cause })));
|
|
1363
|
-
const StoredPayloadString = Schema.fromJsonString(Schema.Json);
|
|
1364
|
-
const decodeStoredPayload = (row) => Schema.decodeUnknownEffect(StoredPayloadString)(row.payload).pipe(Effect.mapError((cause) => new StoredAlarmDecodeError({
|
|
1365
|
-
cause,
|
|
1366
|
-
storageId: row.storage_id
|
|
1367
|
-
})));
|
|
1368
|
-
const encodeStoredPayload = (payload) => Schema.encodeEffect(StoredPayloadString)(payload).pipe(Effect.mapError((cause) => new InvalidAlarmPayloadError({ cause })));
|
|
1369
|
-
const ensureTable = (state) => state.storage.sql.exec(INIT_TABLE_SQL).pipe(Effect.asVoid);
|
|
1370
|
-
const toRepeatEveryMillis = (input) => {
|
|
1371
|
-
if (input === void 0) return Effect.succeed(null);
|
|
1372
|
-
return Effect.try({
|
|
1373
|
-
try: () => {
|
|
1374
|
-
const millis = Duration.toMillis(input);
|
|
1375
|
-
if (!Number.isFinite(millis) || millis <= 0) throw new Error("Alarm repeatEvery must be a positive finite duration");
|
|
1376
|
-
return Math.ceil(millis);
|
|
1377
|
-
},
|
|
1378
|
-
catch: (cause) => new InvalidRepeatEveryError({ cause })
|
|
1379
|
-
});
|
|
1380
|
-
};
|
|
1381
|
-
const toAlarmDue = (row) => Effect.gen(function* () {
|
|
1382
|
-
if (!Number.isFinite(row.run_at)) return yield* Effect.fail(new StoredAlarmDecodeError({
|
|
1383
|
-
cause: /* @__PURE__ */ new Error("Stored alarm run_at must be a finite number"),
|
|
1384
|
-
storageId: row.storage_id
|
|
1385
|
-
}));
|
|
1386
|
-
return DurableObjectAlarmEvent.make({
|
|
1387
|
-
_tag: "AlarmDue",
|
|
1388
|
-
id: row.alarm_id,
|
|
1389
|
-
payload: yield* decodeStoredPayload(row),
|
|
1390
|
-
scheduledAt: DateTime.makeUnsafe(row.run_at),
|
|
1391
|
-
tag: row.tag
|
|
1068
|
+
};
|
|
1069
|
+
const toAlarmDue = (row) => Effect.gen(function* () {
|
|
1070
|
+
if (!Number.isFinite(row.run_at)) return yield* Effect.fail(new StoredAlarmDecodeError({
|
|
1071
|
+
cause: /* @__PURE__ */ new Error("Stored alarm run_at must be a finite number"),
|
|
1072
|
+
storageId: row.storage_id
|
|
1073
|
+
}));
|
|
1074
|
+
return DurableObjectAlarmEvent.make({
|
|
1075
|
+
_tag: "AlarmDue",
|
|
1076
|
+
id: row.alarm_id,
|
|
1077
|
+
payload: yield* decodeStoredPayload(row),
|
|
1078
|
+
scheduledAt: DateTime.makeUnsafe(row.run_at),
|
|
1079
|
+
tag: row.tag
|
|
1392
1080
|
});
|
|
1393
1081
|
});
|
|
1394
1082
|
const getProcessLimit = (options) => {
|
|
@@ -1410,6 +1098,7 @@ const getFailureActionRetryDelay = (action) => Predicate.isString(action) || act
|
|
|
1410
1098
|
const processDue = (handle, options = {}) => Effect.gen(function* () {
|
|
1411
1099
|
return yield* (yield* DurableObjectAlarm).processDueAlarms(handle, options);
|
|
1412
1100
|
});
|
|
1101
|
+
const TypedAlarmSchedulerTypeId = Symbol.for("effect-cf/DurableObjectAlarm/TypedScheduler");
|
|
1413
1102
|
const isAlarmDefinitionConfig = (definition) => Predicate.isObject(definition) && "payload" in definition;
|
|
1414
1103
|
const getAlarmDefinitionSchema = (definition) => isAlarmDefinitionConfig(definition) ? definition.payload : definition;
|
|
1415
1104
|
const getAlarmDefinitionFailureAction = (definition) => {
|
|
@@ -1420,27 +1109,66 @@ const getAlarmDefinitionFailureAction = (definition) => {
|
|
|
1420
1109
|
retryFailedAfter: definition.retry?.initialDelay
|
|
1421
1110
|
} : { mode: definition.failure };
|
|
1422
1111
|
};
|
|
1423
|
-
const
|
|
1424
|
-
const
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
})
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1112
|
+
const makeDefinition$3 = (definitions) => {
|
|
1113
|
+
const definitionFor = (tag) => Object.hasOwn(definitions, tag) ? definitions[tag] : void 0;
|
|
1114
|
+
const bind = (mutations) => ({
|
|
1115
|
+
scheduleAlarm: Effect.fn("DefinedAlarms.scheduleAlarm")(function* (input) {
|
|
1116
|
+
const definition = definitionFor(input.tag);
|
|
1117
|
+
if (definition === void 0) return yield* Effect.fail(new InvalidAlarmRefError({ cause: /* @__PURE__ */ new Error(`Unknown alarm tag "${input.tag}"`) }));
|
|
1118
|
+
const payload = yield* Schema.encodeEffect(getAlarmDefinitionSchema(definition))(input.payload).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.Json)), Effect.mapError((cause) => new InvalidAlarmPayloadError({ cause })));
|
|
1119
|
+
yield* mutations.scheduleAlarm({
|
|
1120
|
+
...input,
|
|
1121
|
+
payload
|
|
1122
|
+
});
|
|
1123
|
+
}),
|
|
1124
|
+
cancelAlarm: Effect.fn("DefinedAlarms.cancelAlarm")(function* (input) {
|
|
1125
|
+
if (definitionFor(input.tag) === void 0) return yield* Effect.fail(new InvalidAlarmRefError({ cause: /* @__PURE__ */ new Error(`Unknown alarm tag "${input.tag}"`) }));
|
|
1126
|
+
yield* mutations.cancelAlarm(input);
|
|
1127
|
+
})
|
|
1128
|
+
});
|
|
1129
|
+
return {
|
|
1130
|
+
make: (alarms) => ({
|
|
1131
|
+
[TypedAlarmSchedulerTypeId]: TypedAlarmSchedulerTypeId,
|
|
1132
|
+
...bind(alarms),
|
|
1133
|
+
transaction: (closure) => alarms.transaction((tx) => closure(bind(tx)))
|
|
1134
|
+
}),
|
|
1135
|
+
handlers: (handlers, options) => processDue((event) => Effect.gen(function* () {
|
|
1136
|
+
const definition = definitionFor(event.tag);
|
|
1137
|
+
if (definition === void 0) return yield* Effect.fail(new StoredAlarmDecodeError({
|
|
1138
|
+
cause: /* @__PURE__ */ new Error(`Unknown alarm tag "${event.tag}"`),
|
|
1139
|
+
storageId: getScheduledEventId(event)
|
|
1140
|
+
}));
|
|
1141
|
+
const schema = getAlarmDefinitionSchema(definition);
|
|
1142
|
+
const payload = yield* Schema.decodeUnknownEffect(schema)(event.payload).pipe(Effect.mapError((cause) => new StoredAlarmDecodeError({
|
|
1143
|
+
cause,
|
|
1144
|
+
storageId: getScheduledEventId(event)
|
|
1145
|
+
})));
|
|
1146
|
+
const handler = handlers[event.tag];
|
|
1147
|
+
yield* handler({
|
|
1148
|
+
...event,
|
|
1149
|
+
payload
|
|
1150
|
+
});
|
|
1151
|
+
}), {
|
|
1152
|
+
...options,
|
|
1153
|
+
onFailure: (failure) => Effect.gen(function* () {
|
|
1154
|
+
const action = getAlarmDefinitionFailureAction(definitionFor(failure.tag));
|
|
1155
|
+
const optionAction = options?.onFailure === void 0 ? void 0 : yield* options.onFailure(failure);
|
|
1156
|
+
return action ?? optionAction;
|
|
1157
|
+
})
|
|
1158
|
+
})
|
|
1159
|
+
};
|
|
1160
|
+
};
|
|
1161
|
+
/** Handler-only definitions for applications using the raw scheduler. Prefer Tag for typed scheduling. */
|
|
1162
|
+
const define = (definitions) => ({ handlers: makeDefinition$3(definitions).handlers });
|
|
1163
|
+
/** The typed scheduler becomes available when its handlers are registered on a Durable Object. */
|
|
1164
|
+
const Tag$9 = () => (id, definitions) => {
|
|
1165
|
+
const tag = Context.Service()(id);
|
|
1166
|
+
const definition = makeDefinition$3(definitions);
|
|
1167
|
+
return Object.assign(tag, { handlers: (handlers, options) => ({
|
|
1168
|
+
layer: Layer.effect(tag, Effect.map(DurableObjectAlarm, definition.make)),
|
|
1169
|
+
run: definition.handlers(handlers, options)
|
|
1170
|
+
}) });
|
|
1171
|
+
};
|
|
1444
1172
|
var DurableObjectAlarm = class DurableObjectAlarm extends Context.Service()("effect-cf/DurableObjectAlarm") {
|
|
1445
1173
|
static layer = Layer.effect(DurableObjectAlarm, Effect.gen(function* () {
|
|
1446
1174
|
const state = yield* DurableObjectState;
|
|
@@ -1581,9 +1309,321 @@ var DurableObjectAlarm = class DurableObjectAlarm extends Context.Service()("eff
|
|
|
1581
1309
|
scheduleAlarm: (input) => transaction((alarms) => alarms.scheduleAlarm(input)),
|
|
1582
1310
|
transaction
|
|
1583
1311
|
});
|
|
1584
|
-
})
|
|
1312
|
+
}));
|
|
1585
1313
|
};
|
|
1586
1314
|
//#endregion
|
|
1315
|
+
//#region src/DurableObjectNamespace.ts
|
|
1316
|
+
var DurableObjectNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
1317
|
+
DurableObjectFetchError: () => DurableObjectFetchError,
|
|
1318
|
+
DurableObjectRpcError: () => DurableObjectRpcError,
|
|
1319
|
+
isDurableObjectNamespaceClient: () => isDurableObjectNamespaceClient,
|
|
1320
|
+
layer: () => layer$9,
|
|
1321
|
+
makeClient: () => makeClient$7,
|
|
1322
|
+
makeDirectMethods: () => makeDirectMethods
|
|
1323
|
+
});
|
|
1324
|
+
const expectedDurableObjectNamespace = "Durable Object namespace binding with getByName(), get(), idFromName(), idFromString(), newUniqueId(), and jurisdiction()";
|
|
1325
|
+
/**
|
|
1326
|
+
* Failure raised when invoking an RPC method on a Durable Object stub.
|
|
1327
|
+
*/
|
|
1328
|
+
var DurableObjectRpcError = class extends Data.TaggedError("DurableObjectRpcError") {
|
|
1329
|
+
get message() {
|
|
1330
|
+
return `Durable Object RPC method "${this.method}" failed for binding "${this.binding}": ${causeMessage(this.cause)}`;
|
|
1331
|
+
}
|
|
1332
|
+
};
|
|
1333
|
+
/**
|
|
1334
|
+
* Failure raised when forwarding a request to a Durable Object stub.
|
|
1335
|
+
*/
|
|
1336
|
+
var DurableObjectFetchError = class extends Data.TaggedError("DurableObjectFetchError") {
|
|
1337
|
+
get message() {
|
|
1338
|
+
return `Durable Object fetch failed for binding "${this.binding}": ${causeMessage(this.cause)}`;
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
const hasFunction$1 = (value, key) => Predicate.hasProperty(value, key) && Predicate.isFunction(value[key]);
|
|
1342
|
+
const isDurableObjectNamespaceClient = (value) => hasFunction$1(value, "getByName") && hasFunction$1(value, "get") && hasFunction$1(value, "idFromName") && hasFunction$1(value, "idFromString") && hasFunction$1(value, "newUniqueId") && hasFunction$1(value, "jurisdiction");
|
|
1343
|
+
const makeClient$7 = (definition) => {
|
|
1344
|
+
return (namespace) => {
|
|
1345
|
+
const newUniqueId = (options) => Effect.sync(() => namespace.newUniqueId(options));
|
|
1346
|
+
const idFromName = (name) => Effect.sync(() => namespace.idFromName(name));
|
|
1347
|
+
const idFromString = (id) => Effect.sync(() => namespace.idFromString(id));
|
|
1348
|
+
const get = (id, options) => Effect.sync(() => namespace.get(id, options));
|
|
1349
|
+
const getByName = (name, options) => Effect.sync(() => namespace.getByName(name, options));
|
|
1350
|
+
const jurisdiction = (value) => Effect.sync(() => namespace.jurisdiction(value));
|
|
1351
|
+
const fetch = (stub, input, init) => Effect.tryPromise({
|
|
1352
|
+
try: (signal) => {
|
|
1353
|
+
const callerSignal = init?.signal !== void 0 ? init.signal : input instanceof Request ? input.signal : void 0;
|
|
1354
|
+
return stub.fetch(input, {
|
|
1355
|
+
...init,
|
|
1356
|
+
signal: callerSignal === null || callerSignal === void 0 ? signal : AbortSignal.any([callerSignal, signal])
|
|
1357
|
+
});
|
|
1358
|
+
},
|
|
1359
|
+
catch: (cause) => new DurableObjectFetchError({
|
|
1360
|
+
binding: definition.binding,
|
|
1361
|
+
cause
|
|
1362
|
+
})
|
|
1363
|
+
});
|
|
1364
|
+
const rpc = Effect.fnUntraced(function* (stub, method, ...args) {
|
|
1365
|
+
const methodName = String(method);
|
|
1366
|
+
const encodedArgs = definition.definition === void 0 ? args : yield* encodeArgs(definition.definition, methodName, args).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1367
|
+
binding: definition.binding,
|
|
1368
|
+
method: methodName,
|
|
1369
|
+
cause
|
|
1370
|
+
})));
|
|
1371
|
+
const nativeArgs = definition.rpcTracing ? yield* withRpcTraceContext(encodedArgs) : encodedArgs;
|
|
1372
|
+
return yield* invokeRpcMethod(stub, method, nativeArgs, (cause) => new DurableObjectRpcError({
|
|
1373
|
+
binding: definition.binding,
|
|
1374
|
+
method: methodName,
|
|
1375
|
+
cause
|
|
1376
|
+
}));
|
|
1377
|
+
});
|
|
1378
|
+
const decodeSuccess$1 = Effect.fnUntraced(function* (methodName, value) {
|
|
1379
|
+
if (definition.definition === void 0) return value;
|
|
1380
|
+
return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1381
|
+
binding: definition.binding,
|
|
1382
|
+
method: methodName,
|
|
1383
|
+
cause
|
|
1384
|
+
})));
|
|
1385
|
+
});
|
|
1386
|
+
const call = Effect.fnUntraced(function* (stub, method, ...args) {
|
|
1387
|
+
const methodName = String(method);
|
|
1388
|
+
const value = yield* resolve(yield* rpc(stub, method, ...args)).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1389
|
+
binding: definition.binding,
|
|
1390
|
+
method: methodName,
|
|
1391
|
+
cause
|
|
1392
|
+
})));
|
|
1393
|
+
return yield* decodeSuccess$1(methodName, value);
|
|
1394
|
+
}, (effect, ...args) => withRpcClientSpan(effect, definition.binding, String(args[1])));
|
|
1395
|
+
const scopedCall = Effect.fnUntraced(function* (stub, method, ...args) {
|
|
1396
|
+
const methodName = String(method);
|
|
1397
|
+
const result = yield* rpc(stub, method, ...args);
|
|
1398
|
+
const value = yield* scoped(result).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1399
|
+
binding: definition.binding,
|
|
1400
|
+
method: methodName,
|
|
1401
|
+
cause
|
|
1402
|
+
})));
|
|
1403
|
+
return yield* decodeSuccess$1(methodName, value);
|
|
1404
|
+
}, (effect, ...args) => withRpcClientSpan(effect, definition.binding, String(args[1])));
|
|
1405
|
+
const directMethods = makeDirectMethods(definition.definition, {
|
|
1406
|
+
call,
|
|
1407
|
+
fetch,
|
|
1408
|
+
get,
|
|
1409
|
+
getByName
|
|
1410
|
+
});
|
|
1411
|
+
return Object.assign(directMethods, {
|
|
1412
|
+
newUniqueId,
|
|
1413
|
+
idFromName,
|
|
1414
|
+
idFromString,
|
|
1415
|
+
get,
|
|
1416
|
+
getByName,
|
|
1417
|
+
jurisdiction,
|
|
1418
|
+
fetch,
|
|
1419
|
+
rpc,
|
|
1420
|
+
call,
|
|
1421
|
+
scopedCall,
|
|
1422
|
+
rawUnsafe: Effect.succeed(namespace)
|
|
1423
|
+
});
|
|
1424
|
+
};
|
|
1425
|
+
};
|
|
1426
|
+
const layer$9 = (tag, definition) => layer$18(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$7(definition), { expected: expectedDurableObjectNamespace });
|
|
1427
|
+
const makeDirectMethods = (rpcDefinition, helpers) => {
|
|
1428
|
+
const methods = {};
|
|
1429
|
+
if (rpcDefinition !== void 0) {
|
|
1430
|
+
for (const methodName of Object.keys(rpcDefinition.methods)) methods[methodName] = (stub, ...args) => helpers.call(stub, methodName, ...args);
|
|
1431
|
+
const makeClient = (getStub) => {
|
|
1432
|
+
const client = { fetch: (input, init) => Effect.gen(function* () {
|
|
1433
|
+
const stub = yield* getStub();
|
|
1434
|
+
return yield* helpers.fetch(stub, input, init);
|
|
1435
|
+
}) };
|
|
1436
|
+
for (const methodName of Object.keys(rpcDefinition.methods)) client[methodName] = (...args) => Effect.gen(function* () {
|
|
1437
|
+
const stub = yield* getStub();
|
|
1438
|
+
return yield* helpers.call(stub, methodName, ...args);
|
|
1439
|
+
});
|
|
1440
|
+
return client;
|
|
1441
|
+
};
|
|
1442
|
+
methods.byName = (name, options) => makeClient(() => helpers.getByName(name, options));
|
|
1443
|
+
methods.byId = (id, options) => makeClient(() => helpers.get(id, options));
|
|
1444
|
+
}
|
|
1445
|
+
return methods;
|
|
1446
|
+
};
|
|
1447
|
+
//#endregion
|
|
1448
|
+
//#region src/DurableObjectDefinition.ts
|
|
1449
|
+
var DurableObjectDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
1450
|
+
DurableObject: () => DurableObject$1,
|
|
1451
|
+
Tag: () => Tag$8,
|
|
1452
|
+
implement: () => implement$2,
|
|
1453
|
+
make: () => make$8,
|
|
1454
|
+
method: () => method
|
|
1455
|
+
});
|
|
1456
|
+
const reservedMethodNames$1 = /* @__PURE__ */ new Set([
|
|
1457
|
+
"constructor",
|
|
1458
|
+
"dup",
|
|
1459
|
+
"fetch",
|
|
1460
|
+
"alarm",
|
|
1461
|
+
"webSocketMessage",
|
|
1462
|
+
"webSocketClose",
|
|
1463
|
+
"webSocketError"
|
|
1464
|
+
]);
|
|
1465
|
+
function method(definition) {
|
|
1466
|
+
return method$1(definition);
|
|
1467
|
+
}
|
|
1468
|
+
const makeDefinition$2 = (id, methods) => {
|
|
1469
|
+
assertNoReservedMethods("Durable Object", methods, reservedMethodNames$1);
|
|
1470
|
+
const definition = make$15(id, methods);
|
|
1471
|
+
return Object.assign(definition, { make: (layer, options) => make$7(layer, {
|
|
1472
|
+
...options,
|
|
1473
|
+
rpc: wrapHandlers(definition, options.rpc)
|
|
1474
|
+
}) });
|
|
1475
|
+
};
|
|
1476
|
+
const make$8 = (id, methods) => Tag$8()(id, methods);
|
|
1477
|
+
const Tag$8 = () => (id, methods) => {
|
|
1478
|
+
const definition = makeDefinition$2(id, methods);
|
|
1479
|
+
const serviceKey = `effect-cf/DurableObject/${id}`;
|
|
1480
|
+
const tag = Context.Service()(serviceKey);
|
|
1481
|
+
const bindingDefinition = (binding) => ({
|
|
1482
|
+
...binding,
|
|
1483
|
+
definition
|
|
1484
|
+
});
|
|
1485
|
+
const layer = (binding) => layer$9(tag, bindingDefinition(binding));
|
|
1486
|
+
const newUniqueId = Effect.fn("DurableObject.newUniqueId")(function* (options) {
|
|
1487
|
+
return yield* (yield* tag).newUniqueId(options);
|
|
1488
|
+
});
|
|
1489
|
+
const idFromName = Effect.fn("DurableObject.idFromName")(function* (name) {
|
|
1490
|
+
return yield* (yield* tag).idFromName(name);
|
|
1491
|
+
});
|
|
1492
|
+
const idFromString = Effect.fn("DurableObject.idFromString")(function* (value) {
|
|
1493
|
+
return yield* (yield* tag).idFromString(value);
|
|
1494
|
+
});
|
|
1495
|
+
const get = Effect.fn("DurableObject.get")(function* (objectId, options) {
|
|
1496
|
+
return yield* (yield* tag).get(objectId, options);
|
|
1497
|
+
});
|
|
1498
|
+
const getByName = Effect.fn("DurableObject.getByName")(function* (name, options) {
|
|
1499
|
+
return yield* (yield* tag).getByName(name, options);
|
|
1500
|
+
});
|
|
1501
|
+
const jurisdiction = Effect.fn("DurableObject.jurisdiction")(function* (value) {
|
|
1502
|
+
return yield* (yield* tag).jurisdiction(value);
|
|
1503
|
+
});
|
|
1504
|
+
const fetch = Effect.fn("DurableObject.fetch")(function* (stub, input, init) {
|
|
1505
|
+
return yield* (yield* tag).fetch(stub, input, init);
|
|
1506
|
+
});
|
|
1507
|
+
const rpc = Effect.fnUntraced(function* (stub, methodName, ...args) {
|
|
1508
|
+
const invokeRpc = (yield* tag).rpc;
|
|
1509
|
+
return yield* invokeRpc(stub, methodName, ...args);
|
|
1510
|
+
});
|
|
1511
|
+
const call = Effect.fnUntraced(function* (stub, methodName, ...args) {
|
|
1512
|
+
const invokeCall = (yield* tag).call;
|
|
1513
|
+
return yield* invokeCall(stub, methodName, ...args);
|
|
1514
|
+
});
|
|
1515
|
+
const scopedCall = Effect.fnUntraced(function* (stub, methodName, ...args) {
|
|
1516
|
+
const invokeScopedCall = (yield* tag).scopedCall;
|
|
1517
|
+
return yield* invokeScopedCall(stub, methodName, ...args);
|
|
1518
|
+
});
|
|
1519
|
+
const rawUnsafe = Effect.fnUntraced(function* () {
|
|
1520
|
+
return yield* (yield* tag).rawUnsafe;
|
|
1521
|
+
});
|
|
1522
|
+
const directMethods = makeDirectMethods(definition, {
|
|
1523
|
+
call,
|
|
1524
|
+
fetch,
|
|
1525
|
+
get,
|
|
1526
|
+
getByName
|
|
1527
|
+
});
|
|
1528
|
+
return Object.assign(tag, directMethods, {
|
|
1529
|
+
id: definition.id,
|
|
1530
|
+
methods: definition.methods,
|
|
1531
|
+
make: definition.make,
|
|
1532
|
+
layer,
|
|
1533
|
+
newUniqueId,
|
|
1534
|
+
idFromName,
|
|
1535
|
+
idFromString,
|
|
1536
|
+
get,
|
|
1537
|
+
getByName,
|
|
1538
|
+
jurisdiction,
|
|
1539
|
+
fetch,
|
|
1540
|
+
rpc,
|
|
1541
|
+
call,
|
|
1542
|
+
scopedCall,
|
|
1543
|
+
rawUnsafe
|
|
1544
|
+
});
|
|
1545
|
+
};
|
|
1546
|
+
const DurableObject$1 = Tag$8;
|
|
1547
|
+
const wrapHandlers = (definition, handlers) => {
|
|
1548
|
+
const wrapped = Object.create(Object.prototype);
|
|
1549
|
+
for (const key of Object.keys(definition.methods)) {
|
|
1550
|
+
const handler = handlers[key];
|
|
1551
|
+
wrapped[key] = (...args) => Effect.gen(function* () {
|
|
1552
|
+
const decodedArgs = yield* decodeArgs(definition, key, args);
|
|
1553
|
+
yield* recordDecodedArgs(decodedArgs);
|
|
1554
|
+
const value = yield* handler(...decodedArgs);
|
|
1555
|
+
return yield* encodeSuccess(definition, key, value);
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
return wrapped;
|
|
1559
|
+
};
|
|
1560
|
+
/**
|
|
1561
|
+
* Helper for implementing handlers with the exact method shape of a definition.
|
|
1562
|
+
*/
|
|
1563
|
+
const implement$2 = (_definition, handlers) => handlers;
|
|
1564
|
+
//#endregion
|
|
1565
|
+
//#region src/DurableObject.ts
|
|
1566
|
+
var DurableObject_exports = /* @__PURE__ */ __exportAll({
|
|
1567
|
+
RunSymbol: () => RunSymbol,
|
|
1568
|
+
Tag: () => Tag$8,
|
|
1569
|
+
implement: () => implement$2,
|
|
1570
|
+
make: () => make$7,
|
|
1571
|
+
method: () => method
|
|
1572
|
+
});
|
|
1573
|
+
const reservedMethodNames = reservedMethodNames$2;
|
|
1574
|
+
/** Override to instrument the whole event, then call super[RunSymbol]. */
|
|
1575
|
+
const RunSymbol = Symbol.for("effect-cf/DurableObject/run");
|
|
1576
|
+
const scheduleTelemetryFlush = scheduleTelemetryFlush$1((flush) => Effect.flatMap(DurableObjectState, (state) => state.waitUntil(flush)));
|
|
1577
|
+
function make$7(layer, options = {}) {
|
|
1578
|
+
const registration = options.alarms !== void 0 && !Effect.isEffect(options.alarms) ? options.alarms : void 0;
|
|
1579
|
+
const logicalAlarms = (registration?.run ?? (Effect.isEffect(options.alarms) ? options.alarms : void 0))?.pipe(Effect.asVoid);
|
|
1580
|
+
class EffectDurableObject extends DurableObject {
|
|
1581
|
+
runtime;
|
|
1582
|
+
constructor(state, env) {
|
|
1583
|
+
super(state, env);
|
|
1584
|
+
const baseServices = DurableObjectAlarm.layer.pipe(Layer.provideMerge(Layer.succeed(DurableObjectState, fromDurableObjectState(state))));
|
|
1585
|
+
const services = (registration?.layer ?? Layer.empty).pipe(Layer.provideMerge(baseServices));
|
|
1586
|
+
this.runtime = makeEntrypointRuntime(layer, env, services);
|
|
1587
|
+
const initialize = options.initialize;
|
|
1588
|
+
if (initialize !== void 0) state.waitUntil(this[RunSymbol](initialize, { eventLayer: false }));
|
|
1589
|
+
}
|
|
1590
|
+
[RunSymbol](effect, runOptions = {}) {
|
|
1591
|
+
const eventLayer = runOptions.eventLayer === false ? void 0 : options.eventLayer;
|
|
1592
|
+
const parent = runOptions.rpc?.parent;
|
|
1593
|
+
const parentSpan = parent === void 0 ? void 0 : Tracer.externalSpan(parent);
|
|
1594
|
+
if (eventLayer === void 0) return runEventPromise(this.runtime, effect, void 0, parentSpan);
|
|
1595
|
+
return runEventPromise(this.runtime, effect, eventLayer, parentSpan);
|
|
1596
|
+
}
|
|
1597
|
+
fetch(request) {
|
|
1598
|
+
const fetchHandler = options.fetch;
|
|
1599
|
+
if (fetchHandler === void 0) return Promise.resolve(new Response("Not Found", { status: 404 }));
|
|
1600
|
+
return this[RunSymbol](Effect.provideService(fetchHandler, NativeRequest, request), { event: "fetch" });
|
|
1601
|
+
}
|
|
1602
|
+
alarm(alarmInfo) {
|
|
1603
|
+
const rawAlarm = options.alarm?.(alarmInfo);
|
|
1604
|
+
const alarmEffect = logicalAlarms !== void 0 && rawAlarm !== void 0 ? Effect.gen(function* () {
|
|
1605
|
+
yield* logicalAlarms;
|
|
1606
|
+
yield* rawAlarm;
|
|
1607
|
+
}) : logicalAlarms ?? rawAlarm;
|
|
1608
|
+
if (alarmEffect !== void 0) return this[RunSymbol](alarmEffect.pipe(Effect.onExit(() => scheduleTelemetryFlush)), { event: "alarm" });
|
|
1609
|
+
}
|
|
1610
|
+
webSocketMessage(socket, message) {
|
|
1611
|
+
if (options.webSocketMessage !== void 0) return this[RunSymbol](options.webSocketMessage(fromWebSocket(socket), message), { event: "webSocketMessage" });
|
|
1612
|
+
}
|
|
1613
|
+
webSocketClose(socket, code, reason, wasClean) {
|
|
1614
|
+
if (options.webSocketClose !== void 0) return this[RunSymbol](options.webSocketClose(fromWebSocket(socket), code, reason, wasClean), { event: "webSocketClose" });
|
|
1615
|
+
}
|
|
1616
|
+
webSocketError(socket, cause) {
|
|
1617
|
+
if (options.webSocketError !== void 0) return this[RunSymbol](options.webSocketError(fromWebSocket(socket), cause), { event: "webSocketError" });
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
defineEntrypointRpcMethods("Durable Object", EffectDurableObject.prototype, options.rpc, reservedMethodNames, (self, effect, rpc) => self[RunSymbol](effect, {
|
|
1621
|
+
event: "rpc",
|
|
1622
|
+
rpc
|
|
1623
|
+
}), () => scheduleTelemetryFlush, options.rpcTracing);
|
|
1624
|
+
return assumeEntrypointClass(EffectDurableObject);
|
|
1625
|
+
}
|
|
1626
|
+
//#endregion
|
|
1587
1627
|
//#region src/DurableObjectRpcWebSocket.ts
|
|
1588
1628
|
var DurableObjectRpcWebSocket_exports = /* @__PURE__ */ __exportAll({
|
|
1589
1629
|
DurableObjectRpcWebSocket: () => DurableObjectRpcWebSocket,
|
|
@@ -2145,10 +2185,10 @@ const textEncoder = new TextEncoder();
|
|
|
2145
2185
|
const sendLimits = {
|
|
2146
2186
|
maxRecipients: 50,
|
|
2147
2187
|
maxAttachments: 32,
|
|
2148
|
-
maxMessageBytes:
|
|
2188
|
+
maxMessageBytes: 5242880,
|
|
2149
2189
|
maxHeaderNameBytes: 100,
|
|
2150
2190
|
maxHeaderValueBytes: 2048,
|
|
2151
|
-
maxHeadersBytes:
|
|
2191
|
+
maxHeadersBytes: 16384,
|
|
2152
2192
|
maxAllowlistHeaders: 20
|
|
2153
2193
|
};
|
|
2154
2194
|
/**
|