effect-cf 0.35.0 → 0.37.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 +14 -0
- package/README.md +2 -0
- package/dist/ComputerWorkspace.d.mts +1 -1
- package/dist/ComputerWorkspace.mjs +1 -1
- package/dist/DurableObjectState-CpgAmFqo.d.mts +244 -0
- package/dist/{DurableObjectState-DcqElJ4e.mjs → DurableObjectState-DLL0YgBd.mjs} +3 -60
- package/dist/Mcp.d.mts +122 -0
- package/dist/Mcp.mjs +270 -0
- package/dist/Vitest.d.mts +2 -2
- package/dist/Vitest.mjs +2 -1
- package/dist/{DurableObjectState-DpYdNZgT.d.mts → Worker-Dl6_Pijl.d.mts} +2 -242
- package/dist/Worker-XsGJsCJX.mjs +885 -0
- package/dist/WorkerContext-Yobnfw-K.mjs +60 -0
- package/dist/{WorkflowBinding-Cn3AuUyP.d.mts → WorkflowBinding-CvJT9hB5.d.mts} +1 -1
- package/dist/index.d.mts +22 -3
- package/dist/index.mjs +114 -979
- package/package.json +12 -1
- package/src/DurableObjectAlarm.ts +80 -30
- package/src/Mcp.ts +531 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Cause, Effect, Exit, FiberSet } from "effect";
|
|
2
|
+
//#region src/internal/NativeCallback.ts
|
|
3
|
+
/**
|
|
4
|
+
* Runs an Effect callback owned by a native Promise operation.
|
|
5
|
+
*
|
|
6
|
+
* The callback keeps the caller's context, while a private scope owns its
|
|
7
|
+
* fiber. Closing that scope interrupts and joins the callback before awaiting
|
|
8
|
+
* the native operation's settlement.
|
|
9
|
+
*/
|
|
10
|
+
const runNativeCallback = Effect.fnUntraced(function* (operation) {
|
|
11
|
+
const callerContext = yield* Effect.context();
|
|
12
|
+
return yield* Effect.scoped(Effect.gen(function* () {
|
|
13
|
+
let nativePromise;
|
|
14
|
+
yield* Effect.addFinalizer(() => {
|
|
15
|
+
const promise = nativePromise;
|
|
16
|
+
return promise === void 0 ? Effect.void : Effect.promise(() => promise.then(() => void 0, () => void 0));
|
|
17
|
+
});
|
|
18
|
+
const runPromise = yield* FiberSet.makeRuntimePromise();
|
|
19
|
+
return yield* Effect.callback((resume) => {
|
|
20
|
+
try {
|
|
21
|
+
nativePromise = operation((effect) => runPromise(Effect.provideContext(Effect.exit(effect), callerContext)));
|
|
22
|
+
} catch (cause) {
|
|
23
|
+
resume(Effect.fail(cause));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
nativePromise.then((value) => resume(Effect.succeed(value)), (cause) => resume(Effect.fail(cause)));
|
|
27
|
+
});
|
|
28
|
+
}));
|
|
29
|
+
});
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/internal/WorkerContext.ts
|
|
32
|
+
const causeError = (cause) => {
|
|
33
|
+
const squashed = Cause.squash(cause);
|
|
34
|
+
return squashed instanceof Error ? squashed : new Error(Cause.pretty(cause), { cause: squashed });
|
|
35
|
+
};
|
|
36
|
+
const failureHandler = (label, cause, options) => Effect.suspend(() => options?.onFailure?.(cause) ?? Effect.logError(`${label} failed`, Cause.pretty(cause))).pipe(Effect.catchCause((handlerCause) => Effect.logError(`${label} failure handler failed`, Cause.pretty(cause), Cause.pretty(handlerCause))));
|
|
37
|
+
const makeWaitUntilScheduler = (label, register, runPromiseExit = (effect) => Effect.runPromiseExit(effect)) => {
|
|
38
|
+
return (effect, options, mode) => Effect.context().pipe(Effect.flatMap((context) => Effect.sync(() => {
|
|
39
|
+
const runHandler = (cause) => runPromiseExit(Effect.provideContext(Effect.scoped(failureHandler(label, cause, options)), context)).then((exit) => {
|
|
40
|
+
if (Exit.isFailure(exit)) console.error(`${label} failure handler failed`, Cause.pretty(exit.cause));
|
|
41
|
+
});
|
|
42
|
+
register(runPromiseExit(Effect.provideContext(Effect.scoped(effect), context)).then(async (exit) => {
|
|
43
|
+
if (Exit.isSuccess(exit)) return;
|
|
44
|
+
await runHandler(exit.cause);
|
|
45
|
+
if (mode === "propagate") throw causeError(exit.cause);
|
|
46
|
+
}));
|
|
47
|
+
})));
|
|
48
|
+
};
|
|
49
|
+
const fromExecutionContext = (ctx, runPromiseExit = (effect) => Effect.runPromiseExit(effect)) => {
|
|
50
|
+
const schedule = makeWaitUntilScheduler("WorkerContext.waitUntil", (promise) => ctx.waitUntil(promise), runPromiseExit);
|
|
51
|
+
return {
|
|
52
|
+
raw: ctx,
|
|
53
|
+
waitUntil: (effect, options) => schedule(effect, options, options?.mode ?? "observe"),
|
|
54
|
+
waitUntilPropagating: (effect, options) => schedule(effect, options, "propagate"),
|
|
55
|
+
passThroughOnException: Effect.sync(() => ctx.passThroughOnException()),
|
|
56
|
+
abort: (reason) => Effect.sync(() => ctx.abort(reason))
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
export { makeWaitUntilScheduler as n, runNativeCallback as r, fromExecutionContext as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { S as ServiceFreeSchema } from "./Worker-Dl6_Pijl.mjs";
|
|
3
3
|
import { Context, Effect, Option, Schema } from "effect";
|
|
4
4
|
declare namespace WorkflowBinding_d_exports {
|
|
5
5
|
export { WorkflowBindingClient, WorkflowBindingDefinition, WorkflowInstance, WorkflowInstanceCreateBatchOptions, WorkflowInstanceCreateOptions, WorkflowInstanceEvent, WorkflowInstanceLocationHint, WorkflowInstanceRestartOptions, WorkflowInstanceStatus, WorkflowInstanceStatusName, WorkflowInstanceTerminateOptions, WorkflowOperationError, WorkflowResultDecodeError, isWorkflow, layer, makeClient };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { a as Environment_d_exports, c as WorkerEnvironment, i as Binding_d_exports, n as BindingService, o as WorkerConfig, r as BindingValidationError, s as WorkerEnv, t as BindingNotFoundError } from "./Binding-DKcLrQCM.mjs";
|
|
2
2
|
import { l as Artifacts_d_exports } from "./Artifacts-B3r3RuTB.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { a as AcceptedUpgrade, c as DurableWebSocketAttachmentError, i as AcceptUpgradeOptions, l as DurableObjectStorage_d_exports, o as DurableObjectWebSocket_d_exports, r as DurableObjectState_d_exports, s as DurableWebSocket, t as DurableObjectState, u as StorageOperationError } from "./DurableObjectState-CpgAmFqo.mjs";
|
|
4
|
+
import { C as Provider, S as ServiceFreeSchema$1, _ as QueueBinding_d_exports, a as Worker_d_exports, b as ReservedMethodName$2, c as AsyncMethodArgs, d as AsyncMethodSuccess, f as ReceiverOptions, g as QueueDefinition_d_exports, h as Queue_d_exports, l as AsyncMethodCloudflareReturn, m as RpcTracing_d_exports, n as NativeRequest, o as WorkerDefinition_d_exports, p as RpcInvocationInfo, r as WorkerContext, s as ServiceBinding_d_exports, t as ExecutionContext, u as AsyncMethodKey, v as Definition$4, w as Rpc_d_exports, x as RpcDefinition_d_exports, y as Method$2 } from "./Worker-Dl6_Pijl.mjs";
|
|
4
5
|
import { t as Hyperdrive_d_exports } from "./Hyperdrive-HrwFlZ6x.mjs";
|
|
5
6
|
import { t as ContainerNamespace_d_exports } from "./ContainerNamespace-DbLaeFhN.mjs";
|
|
6
|
-
import { a as WorkflowInstanceCreateOptions, i as WorkflowInstanceCreateBatchOptions, n as WorkflowBinding_d_exports, r as WorkflowInstance, s as WorkflowOperationError, t as WorkflowBindingClient } from "./WorkflowBinding-
|
|
7
|
+
import { a as WorkflowInstanceCreateOptions, i as WorkflowInstanceCreateBatchOptions, n as WorkflowBinding_d_exports, r as WorkflowInstance, s as WorkflowOperationError, t as WorkflowBindingClient } from "./WorkflowBinding-CvJT9hB5.mjs";
|
|
7
8
|
import { Cause, Config, Context, Data, DateTime, Duration, Effect, Layer, Option, Predicate, Redacted, Schema, Scope } from "effect";
|
|
8
9
|
import { Headers as Headers$1, HttpClient, HttpClientResponse } from "effect/unstable/http";
|
|
9
10
|
import { OtlpExporter, OtlpResource } from "effect/unstable/observability";
|
|
@@ -852,7 +853,7 @@ type DurableObjectClass<Rpc extends DurableObjectRpc<ROut>, ROut> = new (state:
|
|
|
852
853
|
*/
|
|
853
854
|
declare const make$6: <ROut, LayerError, REvent = never, EventLayerError = never, const Rpc extends DurableObjectRpc<ROut | REvent> = Record<never, never>>(layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>, options?: DurableObjectOptions<ROut, REvent, EventLayerError, Rpc>) => DurableObjectClass<Rpc, ROut | REvent>;
|
|
854
855
|
declare namespace DurableObjectAlarm_d_exports {
|
|
855
|
-
export { AlarmDefinitionConfig, AlarmDefinitionEntry, AlarmDefinitionPayload, AlarmDefinitions, AlarmFailurePolicy, AlarmPayload, AlarmPayloadSchema, AlarmRef, AlarmRetryPolicy, AlarmScheduler, DefinedAlarmEvent, DefinedAlarmHandlers, DurableObjectAlarm, DurableObjectAlarmError, DurableObjectAlarmEvent, InvalidAlarmPayloadError, InvalidAlarmRefError, InvalidProcessDueAlarmsOptionsError, InvalidRepeatEveryError, ProcessDueAlarmsFailure, ProcessDueAlarmsFailureAction, ProcessDueAlarmsHandler, ProcessDueAlarmsMode, ProcessDueAlarmsOptions, ProcessDueAlarmsResult, ScheduleAlarmInput, StoredAlarmDecodeError, define, processDue };
|
|
856
|
+
export { AlarmDefinitionConfig, AlarmDefinitionEntry, AlarmDefinitionPayload, AlarmDefinitions, AlarmFailurePolicy, AlarmPayload, AlarmPayloadSchema, AlarmRef, AlarmRetryPolicy, AlarmScheduler, AlarmTransaction, DefinedAlarmEvent, DefinedAlarmHandlers, DurableObjectAlarm, DurableObjectAlarmError, DurableObjectAlarmEvent, InvalidAlarmPayloadError, InvalidAlarmRefError, InvalidProcessDueAlarmsOptionsError, InvalidRepeatEveryError, ProcessDueAlarmsFailure, ProcessDueAlarmsFailureAction, ProcessDueAlarmsHandler, ProcessDueAlarmsMode, ProcessDueAlarmsOptions, ProcessDueAlarmsResult, ScheduleAlarmInput, StoredAlarmDecodeError, define, processDue };
|
|
856
857
|
}
|
|
857
858
|
type AlarmPayload = Schema.Json;
|
|
858
859
|
declare const InvalidAlarmRefError_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 & {
|
|
@@ -945,8 +946,26 @@ interface ProcessDueAlarmsOptions<OnFailureR = never, OnFailureE = never> {
|
|
|
945
946
|
readonly retryFailedAfter?: Duration.Input;
|
|
946
947
|
}
|
|
947
948
|
type ProcessDueAlarmsHandler<R = never, E = never> = (event: DurableObjectAlarmEvent) => Effect.Effect<void, E, R>;
|
|
949
|
+
/**
|
|
950
|
+
* Alarm mutations owned by one transaction callback. Run them in the callback's
|
|
951
|
+
* fiber; forked work and use after the callback ends fail with StorageOperationError.
|
|
952
|
+
*/
|
|
953
|
+
type AlarmTransaction = Pick<AlarmScheduler, "scheduleAlarm" | "cancelAlarm">;
|
|
948
954
|
/** Own `storage.setAlarm()` exclusively: a Durable Object has one platform alarm timestamp. */
|
|
949
955
|
type AlarmScheduler = {
|
|
956
|
+
/**
|
|
957
|
+
* Commits local application storage and logical alarms in one native SQLite
|
|
958
|
+
* Durable Object transaction, reconciling the native alarm before commit.
|
|
959
|
+
* Use the supplied mutations, not standalone alarm methods or nested transactions.
|
|
960
|
+
* SqlClient queries must use this same Durable Object's storage.
|
|
961
|
+
*
|
|
962
|
+
* Failure, defects and interruption before commit roll back. A lost reply or
|
|
963
|
+
* interruption after commit does not undo committed state. Keep RPC and other
|
|
964
|
+
* external effects outside; atomically pre-arm a later wake before fallible work.
|
|
965
|
+
* Cloudflare's native retries are bounded; composition does not remove the
|
|
966
|
+
* pre-arm requirement or promise infinite retry liveness.
|
|
967
|
+
*/
|
|
968
|
+
readonly transaction: <A, E, R>(closure: (alarms: AlarmTransaction) => Effect.Effect<A, E, R>) => Effect.Effect<A, E | StorageOperationError, R>;
|
|
950
969
|
readonly cancelAlarm: (input: AlarmRef) => Effect.Effect<void, InvalidAlarmRefError | StorageOperationError>;
|
|
951
970
|
/** Acknowledge after handling. Conditional writes preserve handler replacements; alarms are at-least-once. */
|
|
952
971
|
readonly processDueAlarms: <R = never, E = never, OnFailureR = never, OnFailureE = never>(handle: ProcessDueAlarmsHandler<R, E>, options?: ProcessDueAlarmsOptions<OnFailureR, OnFailureE>) => Effect.Effect<ProcessDueAlarmsResult, E | OnFailureE | DurableObjectAlarmError, R | OnFailureR>;
|