effect-cf 0.40.3 → 0.41.1
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 +12 -0
- package/dist/ContainerNamespace.mjs +23 -20
- package/dist/DurableObjectNamespace.mjs +17 -8
- package/dist/RpcTargets.d.mts +31 -0
- package/dist/RpcTargets.mjs +72 -0
- package/dist/Sandbox.mjs +87 -65
- package/dist/Worker.mjs +5 -4
- package/dist/Workflow.mjs +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/internal/RpcTargets.mjs +5 -0
- package/dist/internal/Runtime.mjs +3 -2
- package/package.json +1 -1
- package/src/ContainerNamespace.ts +32 -39
- package/src/DurableObjectNamespace.ts +13 -4
- package/src/RpcTargets.ts +94 -0
- package/src/Sandbox.ts +131 -146
- package/src/Worker.ts +27 -22
- package/src/Workflow.ts +6 -1
- package/src/index.ts +1 -0
- package/src/internal/RpcTargets.ts +10 -0
- package/src/internal/Runtime.ts +5 -2
package/src/Worker.ts
CHANGED
|
@@ -13,6 +13,7 @@ import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
|
|
13
13
|
import { WorkerEnvironment, type WorkerEnv } from "./Environment";
|
|
14
14
|
import { fromMessage, fromMessageBatch, type QueueHandler } from "./Queue";
|
|
15
15
|
import * as RpcDefinition from "./RpcDefinition";
|
|
16
|
+
import * as RpcTargets from "./RpcTargets";
|
|
16
17
|
import type { ReceiverOptions, RpcInvocationInfo } from "./RpcTracing";
|
|
17
18
|
import * as Entrypoint from "./internal/Entrypoint";
|
|
18
19
|
import * as Runtime from "./internal/Runtime";
|
|
@@ -273,11 +274,13 @@ const renderFetchSuccess = <E, R, REvent, EventLayerError, EventLayerRequirement
|
|
|
273
274
|
});
|
|
274
275
|
});
|
|
275
276
|
const telemetryMiddleware = HttpMiddleware.make((self) =>
|
|
276
|
-
|
|
277
|
-
|
|
277
|
+
RpcTargets.withScope(
|
|
278
|
+
Effect.gen(function* () {
|
|
279
|
+
yield* Effect.addFinalizer(() => scheduleTelemetryFlush);
|
|
278
280
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
+
return yield* self;
|
|
282
|
+
}),
|
|
283
|
+
),
|
|
281
284
|
);
|
|
282
285
|
const handled =
|
|
283
286
|
eventLayer === undefined
|
|
@@ -287,24 +290,26 @@ const renderFetchSuccess = <E, R, REvent, EventLayerError, EventLayerRequirement
|
|
|
287
290
|
httpApp,
|
|
288
291
|
handleResponse,
|
|
289
292
|
HttpMiddleware.make((self) =>
|
|
290
|
-
|
|
291
|
-
Effect.
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
Effect.
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
293
|
+
RpcTargets.withScope(
|
|
294
|
+
Effect.provideService(
|
|
295
|
+
Effect.gen(function* () {
|
|
296
|
+
const context = yield* Layer.build(Layer.fresh(eventLayer));
|
|
297
|
+
|
|
298
|
+
yield* Effect.addFinalizer(() =>
|
|
299
|
+
Effect.provideContext(scheduleTelemetryFlush, context),
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
return yield* HttpMiddleware.tracer(self).pipe(
|
|
303
|
+
// The tracer schedules span completion. Let it publish on
|
|
304
|
+
// every exit with event references still installed, before
|
|
305
|
+
// the exporter scope finalizes.
|
|
306
|
+
Effect.onExit(() => Effect.yieldNow),
|
|
307
|
+
Effect.provideContext(context),
|
|
308
|
+
);
|
|
309
|
+
}),
|
|
310
|
+
References.TracerEnabled,
|
|
311
|
+
tracerEnabled,
|
|
312
|
+
),
|
|
308
313
|
),
|
|
309
314
|
),
|
|
310
315
|
).pipe(Effect.withTracerEnabled(false)),
|
package/src/Workflow.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as RpcTargets from "./RpcTargets";
|
|
1
2
|
import {
|
|
2
3
|
WorkflowEntrypoint as CloudflareWorkflowEntrypoint,
|
|
3
4
|
type WorkflowEvent as CloudflareWorkflowEvent,
|
|
@@ -151,7 +152,11 @@ const fromWorkflowStep = (step: CloudflareWorkflowStep): WorkflowStepService =>
|
|
|
151
152
|
A,
|
|
152
153
|
E,
|
|
153
154
|
Exclude<R, WorkflowStepContext>
|
|
154
|
-
> = Effect.scoped(
|
|
155
|
+
> = Effect.scoped(
|
|
156
|
+
RpcTargets.withScope(
|
|
157
|
+
Effect.provideService(effect, WorkflowStepContext, stepContext),
|
|
158
|
+
),
|
|
159
|
+
);
|
|
155
160
|
|
|
156
161
|
return runPromise(
|
|
157
162
|
exposeCloudflareNonRetryableError(Effect.provideContext(stepEffect, context)),
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ export * as R2 from "./R2";
|
|
|
29
29
|
export * as Rpc from "./Rpc";
|
|
30
30
|
export * as RpcDefinition from "./RpcDefinition";
|
|
31
31
|
export * as RpcTracing from "./RpcTracing";
|
|
32
|
+
export * as RpcTargets from "./RpcTargets";
|
|
32
33
|
export * as ServiceBinding from "./ServiceBinding";
|
|
33
34
|
export * as Vectorize from "./Vectorize";
|
|
34
35
|
export * as WebTransport from "./WebTransport";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
|
|
3
|
+
export interface Targets {
|
|
4
|
+
get<A extends object, Owner extends object>(owner: Owner, address: string, create: () => A): A;
|
|
5
|
+
invalidate<Target extends object>(target: Target): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class CurrentTargets extends Context.Service<CurrentTargets, Targets>()(
|
|
9
|
+
"effect-cf/RpcTargets",
|
|
10
|
+
) {}
|
package/src/internal/Runtime.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
|
5
5
|
import type { Scope, Tracer } from "effect";
|
|
6
6
|
|
|
7
7
|
import { WorkerConfig, WorkerEnvironment, type WorkerEnv } from "../Environment";
|
|
8
|
+
import * as RpcTargets from "../RpcTargets";
|
|
8
9
|
import { provideEntrypointServices } from "./Entrypoint";
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -61,12 +62,14 @@ export function runEventPromise<A, E, R, REvent, EventLayerError, LayerError>(
|
|
|
61
62
|
const [runtime, effect, eventLayer, parent] = args;
|
|
62
63
|
|
|
63
64
|
if (eventLayer === undefined) {
|
|
64
|
-
const event = Effect.scoped(effect);
|
|
65
|
+
const event = Effect.scoped(RpcTargets.withScope(effect));
|
|
65
66
|
|
|
66
67
|
return runtime.runPromise(parent === undefined ? event : Effect.withParentSpan(event, parent));
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
const event = Effect.scoped(
|
|
70
|
+
const event = Effect.scoped(
|
|
71
|
+
RpcTargets.withScope(effect.pipe(Effect.provide(eventLayer, { local: true }))),
|
|
72
|
+
);
|
|
70
73
|
|
|
71
74
|
return runtime.runPromise(parent === undefined ? event : Effect.withParentSpan(event, parent));
|
|
72
75
|
}
|