effect-cf 0.20.0 → 0.22.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +2 -2
  3. package/dist/{Hyperdrive-RTjgirMV.d.mts → Hyperdrive-COyg7R26.d.mts} +40 -13
  4. package/dist/HyperdrivePg.d.mts +13 -5
  5. package/dist/HyperdrivePg.mjs +12 -7
  6. package/dist/index.d.mts +708 -549
  7. package/dist/index.mjs +946 -589
  8. package/package.json +10 -5
  9. package/src/AiGateway.ts +82 -47
  10. package/src/AnalyticsEngine.ts +74 -58
  11. package/src/Binding.ts +66 -13
  12. package/src/BrowserRendering.ts +30 -7
  13. package/src/Cache.ts +32 -8
  14. package/src/CloudflareOtlp.ts +32 -9
  15. package/src/ContainerNamespace.ts +87 -55
  16. package/src/D1.ts +13 -3
  17. package/src/DurableObject.ts +27 -164
  18. package/src/DurableObjectAlarm.ts +30 -9
  19. package/src/DurableObjectDefinition.ts +58 -54
  20. package/src/DurableObjectNamespace.ts +99 -96
  21. package/src/DurableObjectRpcWebSocket.ts +14 -6
  22. package/src/DurableObjectSqlite.ts +6 -3
  23. package/src/DurableObjectState.ts +6 -9
  24. package/src/DurableObjectStorage.ts +7 -1
  25. package/src/DurableObjectWebSocket.ts +51 -41
  26. package/src/Email.ts +40 -13
  27. package/src/Environment.ts +26 -6
  28. package/src/Hyperdrive.ts +2 -2
  29. package/src/HyperdrivePg.ts +25 -13
  30. package/src/Images.ts +77 -82
  31. package/src/Kv.ts +37 -27
  32. package/src/Queue.ts +6 -1
  33. package/src/QueueBinding.ts +18 -21
  34. package/src/QueueDefinition.ts +15 -14
  35. package/src/R2.ts +107 -29
  36. package/src/Rpc.ts +3 -1
  37. package/src/RpcDefinition.ts +177 -133
  38. package/src/ServiceBinding.ts +112 -108
  39. package/src/Vectorize.ts +59 -14
  40. package/src/Worker.ts +205 -198
  41. package/src/WorkerDefinition.ts +5 -10
  42. package/src/WorkersAi.ts +27 -17
  43. package/src/Workflow.ts +54 -49
  44. package/src/WorkflowBinding.ts +19 -11
  45. package/src/WorkflowDefinition.ts +24 -27
  46. package/src/index.ts +4 -3
  47. package/src/internal/Entrypoint.ts +3 -1
  48. package/src/internal/ErrorMessage.ts +24 -0
  49. package/src/internal/RpcInvocation.ts +11 -8
  50. package/src/internal/Runtime.ts +52 -0
  51. package/src/internal/WorkerContext.ts +14 -2
  52. package/src/Entry.ts +0 -259
  53. package/src/internal/Clock.ts +0 -37
@@ -1,24 +1,12 @@
1
1
  import { DurableObject as CloudflareDurableObject } from "cloudflare:workers";
2
- import {
3
- ConfigProvider,
4
- Effect,
5
- Layer,
6
- ManagedRuntime,
7
- type Context,
8
- type Scope,
9
- type Schema as S,
10
- } from "effect";
2
+ import { Effect, Layer, type ManagedRuntime, type Scope } from "effect";
11
3
 
12
4
  import { NativeRequest } from "./Worker";
13
- import { WorkerConfig, WorkerEnvironment, type WorkerEnv } from "./Environment";
5
+ import { WorkerEnvironment, type WorkerEnv } from "./Environment";
14
6
  import { DurableObjectState, fromDurableObjectState } from "./DurableObjectState";
15
7
  import { fromWebSocket, type DurableWebSocket } from "./DurableObjectWebSocket";
16
- import type * as Binding from "./Binding";
17
- import * as DurableObjectDefinition from "./DurableObjectDefinition";
18
- import type * as DurableObjectNamespace from "./DurableObjectNamespace";
19
- import type * as Rpc from "./Rpc";
20
- import * as CloudflareClock from "./internal/Clock";
21
8
  import * as Entrypoint from "./internal/Entrypoint";
9
+ import * as Runtime from "./internal/Runtime";
22
10
 
23
11
  const reservedMethodNames = new Set<string>([
24
12
  "constructor",
@@ -168,17 +156,12 @@ export const make = <
168
156
  constructor(state: globalThis.DurableObjectState, env: WorkerEnv) {
169
157
  super(state, env);
170
158
 
171
- const services = Layer.mergeAll(
172
- CloudflareClock.layer,
173
- ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env))),
159
+ this.runtime = Runtime.makeEntrypointRuntime<ROut, LayerError, DurableObjectState>(
160
+ layer,
161
+ env,
174
162
  Layer.succeed(DurableObjectState, fromDurableObjectState(state)),
175
- Layer.succeed(WorkerEnvironment, env),
176
163
  );
177
164
 
178
- const runtimeLayer = Entrypoint.provideEntrypointServices(layer, services);
179
-
180
- this.runtime = ManagedRuntime.make(runtimeLayer);
181
-
182
165
  const initialize = options.initialize;
183
166
 
184
167
  if (initialize !== undefined) {
@@ -190,15 +173,10 @@ export const make = <
190
173
  effect: Effect.Effect<A, E, HandlerContext<ROut | REvent>>,
191
174
  runOptions: RunOptions = {},
192
175
  ): Promise<A> {
193
- const effectWithEventLayer =
194
- runOptions.eventLayer === false || options.eventLayer === undefined
195
- ? effect
196
- : effect.pipe(Effect.provide(options.eventLayer, { local: true }));
197
-
198
- return this.runtime.runPromise(
199
- Effect.scoped(
200
- effectWithEventLayer as Effect.Effect<A, E | EventLayerError, HandlerContext<ROut>>,
201
- ),
176
+ return Runtime.runEventPromise(
177
+ this.runtime,
178
+ effect,
179
+ runOptions.eventLayer === false ? undefined : options.eventLayer,
202
180
  );
203
181
  }
204
182
 
@@ -273,135 +251,20 @@ export const make = <
273
251
  );
274
252
  };
275
253
 
276
- export type ServiceFreeSchema = S.Codec<any, any, never, never>;
277
-
278
- export interface Method<
279
- Args extends ReadonlyArray<ServiceFreeSchema> = ReadonlyArray<ServiceFreeSchema>,
280
- Success extends ServiceFreeSchema = ServiceFreeSchema,
281
- > {
282
- readonly args: Args;
283
- readonly success: Success;
284
- }
285
-
286
- export namespace Method {
287
- export type Any = Method<ReadonlyArray<ServiceFreeSchema>, ServiceFreeSchema>;
288
-
289
- type ArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema>> = Args extends readonly []
290
- ? []
291
- : Args extends readonly [
292
- infer Head extends ServiceFreeSchema,
293
- ...infer Tail extends ReadonlyArray<ServiceFreeSchema>,
294
- ]
295
- ? [S.Schema.Type<Head>, ...ArgsFromSchemas<Tail>]
296
- : Array<S.Schema.Type<Args[number]>>;
297
-
298
- export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
299
-
300
- export type Success<Self extends Any> = S.Schema.Type<Self["success"]>;
301
- }
302
-
303
- export type Methods = Record<string, Method.Any>;
304
-
305
- export type ReservedMethodName = DurableObjectDefinition.ReservedMethodName;
306
-
307
- export type NoReservedMethods<MethodsShape extends Methods> =
308
- Extract<keyof MethodsShape, ReservedMethodName> extends never ? MethodsShape : never;
309
-
310
- export interface Definition<Id extends string = string, MethodsShape extends Methods = Methods> {
311
- readonly id: Id;
312
- readonly methods: MethodsShape;
313
- }
314
-
315
- export namespace Definition {
316
- export type Any = Definition<string, Methods>;
317
- }
318
-
319
- export type LayerOptions = DurableObjectDefinition.LayerOptions;
320
-
321
- export type ServerApi<Self extends Definition.Any> = {
322
- readonly [Key in keyof Self["methods"]]: (
323
- ...args: Method.Args<Self["methods"][Key]>
324
- ) => Promise<Method.Success<Self["methods"][Key]>>;
325
- };
326
-
327
- export type Api<Self extends Definition.Any> = Rpc.Provider<ServerApi<Self>, ReservedMethodName>;
328
-
329
- export type Handlers<ROut, Self extends Definition.Any> = {
330
- readonly [Key in keyof Self["methods"]]: (
331
- ...args: Method.Args<Self["methods"][Key]>
332
- ) => DurableObjectHandler<ROut, Method.Success<Self["methods"][Key]>>;
333
- };
334
-
335
- export interface Options<
336
- ROut,
337
- Self extends Definition.Any,
338
- REvent = never,
339
- EventLayerError = never,
340
- > extends Omit<
341
- DurableObjectOptions<ROut, REvent, EventLayerError, Handlers<ROut | REvent, Self>>,
342
- "rpc"
343
- > {
344
- readonly rpc: Handlers<ROut | REvent, Self>;
345
- }
346
-
347
- export type TagClass<Self, Id extends string, MethodsShape extends Methods> = Context.ServiceClass<
348
- Self,
349
- Id,
350
- DurableObjectNamespace.DurableObjectNamespaceEffectClient<
351
- Api<Definition<Id, MethodsShape>>,
352
- Definition<Id, MethodsShape>
353
- >
354
- > &
355
- DurableObjectNamespace.DurableObjectNamespaceStaticClient<
356
- Self,
357
- Api<Definition<Id, MethodsShape>>,
358
- Definition<Id, MethodsShape>
359
- > & {
360
- readonly id: Id;
361
- readonly methods: MethodsShape;
362
- readonly make: <ROut, LayerError, REvent = never, EventLayerError = never>(
363
- layer: Layer.Layer<ROut, LayerError, DurableObjectState | WorkerEnvironment>,
364
- options: Options<ROut, Definition<Id, MethodsShape>, REvent, EventLayerError>,
365
- ) => DurableObjectClass<Handlers<ROut | REvent, Definition<Id, MethodsShape>>, ROut | REvent>;
366
- readonly layer: (
367
- options: LayerOptions,
368
- ) => Layer.Layer<
369
- Self,
370
- Binding.BindingNotFoundError | Binding.BindingValidationError,
371
- WorkerEnvironment
372
- >;
373
- };
374
-
375
- export type TagFactory = <Self>() => <Id extends string, const MethodsShape extends Methods>(
376
- id: Id,
377
- methods: MethodsShape & NoReservedMethods<MethodsShape>,
378
- ) => TagClass<Self, Id, MethodsShape>;
379
-
380
- export const Tag = DurableObjectDefinition.Tag as unknown as TagFactory;
381
-
382
- export const method = DurableObjectDefinition.method as {
383
- <Success extends ServiceFreeSchema>(definition: {
384
- readonly success: Success;
385
- }): Method<readonly [], Success>;
386
- <
387
- const Args extends ReadonlyArray<ServiceFreeSchema>,
388
- Success extends ServiceFreeSchema,
389
- >(definition: {
390
- readonly args: Args;
391
- readonly success: Success;
392
- }): Method<Args, Success>;
393
- };
394
-
395
- export const implement = DurableObjectDefinition.implement as unknown as <
396
- ROut,
397
- const Self extends Definition.Any,
398
- >(
399
- _definition: Self,
400
- handlers: Handlers<ROut, Self>,
401
- ) => Handlers<ROut, Self>;
402
-
403
- export type HandlerEffect<
404
- ROut,
405
- Self extends Definition.Any,
406
- Key extends keyof Self["methods"],
407
- > = DurableObjectHandler<ROut, Method.Success<Self["methods"][Key]>>;
254
+ export type {
255
+ Api,
256
+ Definition,
257
+ HandlerEffect,
258
+ Handlers,
259
+ LayerOptions,
260
+ Method,
261
+ Methods,
262
+ NoReservedMethods,
263
+ Options,
264
+ ReservedMethodName,
265
+ ServerApi,
266
+ ServiceFreeSchema,
267
+ TagClass,
268
+ } from "./DurableObjectDefinition";
269
+
270
+ export { implement, method, Tag } from "./DurableObjectDefinition";
@@ -2,6 +2,7 @@ import { Clock, Context, Data, DateTime, Duration, Effect, Exit, Layer, Schema a
2
2
 
3
3
  import { DurableObjectState } from "./DurableObjectState";
4
4
  import type { SqlStorageValue, StorageOperationError } from "./DurableObjectStorage";
5
+ import * as ErrorMessage from "./internal/ErrorMessage";
5
6
 
6
7
  const INIT_TABLE_SQL = `
7
8
  CREATE TABLE IF NOT EXISTS effect_cf_scheduled_alarms (
@@ -46,26 +47,46 @@ interface NextAlarmRow extends Record<string, SqlStorageValue> {
46
47
 
47
48
  export class InvalidAlarmRefError extends Data.TaggedError("InvalidAlarmRefError")<{
48
49
  readonly cause: unknown;
49
- }> {}
50
+ }> {
51
+ override get message(): string {
52
+ return `Invalid Durable Object alarm ref: ${ErrorMessage.causeMessage(this.cause)}`;
53
+ }
54
+ }
50
55
 
51
56
  export class InvalidAlarmPayloadError extends Data.TaggedError("InvalidAlarmPayloadError")<{
52
57
  readonly cause: unknown;
53
- }> {}
58
+ }> {
59
+ override get message(): string {
60
+ return `Invalid Durable Object alarm payload: ${ErrorMessage.causeMessage(this.cause)}`;
61
+ }
62
+ }
54
63
 
55
64
  export class InvalidRepeatEveryError extends Data.TaggedError("InvalidRepeatEveryError")<{
56
65
  readonly cause: unknown;
57
- }> {}
66
+ }> {
67
+ override get message(): string {
68
+ return `Invalid Durable Object alarm repeatEvery: ${ErrorMessage.causeMessage(this.cause)}`;
69
+ }
70
+ }
58
71
 
59
72
  export class InvalidProcessDueAlarmsOptionsError extends Data.TaggedError(
60
73
  "InvalidProcessDueAlarmsOptionsError",
61
74
  )<{
62
75
  readonly cause: unknown;
63
- }> {}
76
+ }> {
77
+ override get message(): string {
78
+ return `Invalid processDueAlarms options: ${ErrorMessage.causeMessage(this.cause)}`;
79
+ }
80
+ }
64
81
 
65
82
  export class StoredAlarmDecodeError extends Data.TaggedError("StoredAlarmDecodeError")<{
66
83
  readonly cause: unknown;
67
84
  readonly storageId: string;
68
- }> {}
85
+ }> {
86
+ override get message(): string {
87
+ return `Failed to decode stored alarm "${this.storageId}": ${ErrorMessage.causeMessage(this.cause)}`;
88
+ }
89
+ }
69
90
 
70
91
  export type DurableObjectAlarmError =
71
92
  | InvalidAlarmPayloadError
@@ -355,7 +376,7 @@ const toRepeatEveryMillis = (input: Duration.Input | undefined) => {
355
376
 
356
377
  return Effect.try({
357
378
  try: () => {
358
- const millis = Duration.toMillis(Duration.fromInputUnsafe(input));
379
+ const millis = Duration.toMillis(input);
359
380
 
360
381
  if (!Number.isFinite(millis) || millis <= 0) {
361
382
  throw new Error("Alarm repeatEvery must be a positive finite duration");
@@ -382,7 +403,7 @@ const toAlarmDue = (row: AlarmRow) =>
382
403
  _tag: "AlarmDue",
383
404
  id: row.alarm_id,
384
405
  payload: yield* decodeStoredPayload(row),
385
- scheduledAt: DateTime.toUtc(DateTime.makeUnsafe(row.run_at)),
406
+ scheduledAt: DateTime.makeUnsafe(row.run_at),
386
407
  tag: row.tag,
387
408
  });
388
409
  });
@@ -404,7 +425,7 @@ const getProcessLimit = (options: ProcessDueAlarmsOptions<unknown, unknown> | un
404
425
  const toFailureRescheduleMillis = (input: Duration.Input) =>
405
426
  Effect.try({
406
427
  try: () => {
407
- const millis = Duration.toMillis(Duration.fromInputUnsafe(input));
428
+ const millis = Duration.toMillis(input);
408
429
 
409
430
  if (!Number.isFinite(millis) || millis <= 0) {
410
431
  throw new Error("Alarm failure rescheduleAfter must be a positive finite duration");
@@ -594,7 +615,7 @@ export const define = <const Definitions extends AlarmDefinitions>(definitions:
594
615
  export class DurableObjectAlarm extends Context.Service<DurableObjectAlarm, AlarmScheduler>()(
595
616
  "effect-cf/DurableObjectAlarm",
596
617
  ) {
597
- static readonly layer = Layer.effect(
618
+ static readonly layer: Layer.Layer<DurableObjectAlarm, never, DurableObjectState> = Layer.effect(
598
619
  DurableObjectAlarm,
599
620
  Effect.gen(function* () {
600
621
  const state = yield* DurableObjectState;
@@ -38,15 +38,10 @@ export namespace Method {
38
38
  ? [S.Schema.Type<Head>, ...ArgsFromSchemas<Tail>]
39
39
  : Array<S.Schema.Type<Args[number]>>;
40
40
 
41
- type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema>> =
42
- Args extends readonly []
43
- ? []
44
- : Args extends readonly [
45
- infer Head extends ServiceFreeSchema,
46
- ...infer Tail extends ReadonlyArray<ServiceFreeSchema>,
47
- ]
48
- ? [S.Codec.Encoded<Head>, ...EncodedArgsFromSchemas<Tail>]
49
- : Array<S.Codec.Encoded<Args[number]>>;
41
+ /** Method schemas cross the wire through their canonical JSON codec. */
42
+ type EncodedArgsFromSchemas<Args extends ReadonlyArray<ServiceFreeSchema>> = {
43
+ [Index in keyof Args]: S.Json;
44
+ };
50
45
 
51
46
  export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
52
47
 
@@ -54,7 +49,7 @@ export namespace Method {
54
49
 
55
50
  export type Success<Self extends Any> = S.Schema.Type<Self["success"]>;
56
51
 
57
- export type EncodedSuccess<Self extends Any> = S.Codec.Encoded<Self["success"]>;
52
+ export type EncodedSuccess<Self extends Any> = S.Json;
58
53
  }
59
54
 
60
55
  export type Methods = Record<string, Method.Any>;
@@ -144,7 +139,7 @@ export type LayerOptions = {
144
139
 
145
140
  export type TagClass<Self, Id extends string, MethodsShape extends Methods> = Context.ServiceClass<
146
141
  Self,
147
- Id,
142
+ `effect-cf/DurableObject/${Id}`,
148
143
  DurableObjectNamespace.DurableObjectNamespaceEffectClient<
149
144
  Api<Definition<Id, MethodsShape>>,
150
145
  Definition<Id, MethodsShape>
@@ -241,23 +236,30 @@ export const Tag =
241
236
 
242
237
  type SelfDefinition = Definition<Id, MethodsShape>;
243
238
  type ClientApi = Api<SelfDefinition>;
239
+ const serviceKey: `effect-cf/DurableObject/${Id}` = `effect-cf/DurableObject/${id}`;
244
240
  const tag = Context.Service<
245
241
  Self,
246
242
  DurableObjectNamespace.DurableObjectNamespaceEffectClient<ClientApi, SelfDefinition>
247
- >()(id);
243
+ >()(serviceKey);
248
244
 
249
245
  const bindingDefinition = (binding: LayerOptions) => ({
250
246
  ...binding,
251
247
  definition,
252
248
  });
253
249
 
254
- const layer = (binding: LayerOptions) =>
250
+ const layer = (
251
+ binding: LayerOptions,
252
+ ): Layer.Layer<
253
+ Self,
254
+ Binding.BindingNotFoundError | Binding.BindingValidationError,
255
+ WorkerEnvironment
256
+ > =>
255
257
  DurableObjectNamespace.layer<Self, ClientApi, SelfDefinition>(
256
258
  tag,
257
259
  bindingDefinition(binding),
258
260
  );
259
261
 
260
- const newUniqueId = Effect.fnUntraced(function* (
262
+ const newUniqueId = Effect.fn("DurableObject.newUniqueId")(function* (
261
263
  options?: globalThis.DurableObjectNamespaceNewUniqueIdOptions,
262
264
  ) {
263
265
  const namespace = yield* tag;
@@ -265,19 +267,19 @@ export const Tag =
265
267
  return yield* namespace.newUniqueId(options);
266
268
  });
267
269
 
268
- const idFromName = Effect.fnUntraced(function* (name: string) {
270
+ const idFromName = Effect.fn("DurableObject.idFromName")(function* (name: string) {
269
271
  const namespace = yield* tag;
270
272
 
271
273
  return yield* namespace.idFromName(name);
272
274
  });
273
275
 
274
- const idFromString = Effect.fnUntraced(function* (value: string) {
276
+ const idFromString = Effect.fn("DurableObject.idFromString")(function* (value: string) {
275
277
  const namespace = yield* tag;
276
278
 
277
279
  return yield* namespace.idFromString(value);
278
280
  });
279
281
 
280
- const get = Effect.fnUntraced(function* (
282
+ const get = Effect.fn("DurableObject.get")(function* (
281
283
  objectId: globalThis.DurableObjectId,
282
284
  options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions,
283
285
  ) {
@@ -286,7 +288,7 @@ export const Tag =
286
288
  return yield* namespace.get(objectId, options);
287
289
  });
288
290
 
289
- const getByName = Effect.fnUntraced(function* (
291
+ const getByName = Effect.fn("DurableObject.getByName")(function* (
290
292
  name: string,
291
293
  options?: globalThis.DurableObjectNamespaceGetDurableObjectOptions,
292
294
  ) {
@@ -295,68 +297,70 @@ export const Tag =
295
297
  return yield* namespace.getByName(name, options);
296
298
  });
297
299
 
298
- const jurisdiction = Effect.fnUntraced(function* (value: globalThis.DurableObjectJurisdiction) {
300
+ const jurisdiction = Effect.fn("DurableObject.jurisdiction")(function* (
301
+ value: globalThis.DurableObjectJurisdiction,
302
+ ) {
299
303
  const namespace = yield* tag;
300
304
 
301
305
  return yield* namespace.jurisdiction(value);
302
306
  });
303
307
 
304
- const fetch = (
308
+ const fetch = Effect.fn("DurableObject.fetch")(function* (
305
309
  stub: DurableObjectNamespace.DurableObjectStubClient<ClientApi>,
306
310
  input: RequestInfo | URL,
307
311
  init?: RequestInit,
308
- ) =>
309
- Effect.gen(function* () {
310
- const namespace = yield* tag;
312
+ ) {
313
+ const namespace = yield* tag;
311
314
 
312
- return yield* namespace.fetch(stub, input, init);
313
- });
315
+ return yield* namespace.fetch(stub, input, init);
316
+ });
314
317
 
315
- const rpc = <Method extends keyof ClientApi>(
318
+ const rpc = Effect.fn("DurableObject.rpc")(function* <Method extends keyof ClientApi>(
316
319
  stub: DurableObjectNamespace.DurableObjectStubClient<ClientApi>,
317
320
  method: Method,
318
321
  ...args: ClientApi[Method] extends (...args: infer Args) => unknown ? Args : never
319
- ) =>
320
- Effect.gen(function* () {
321
- const namespace = yield* tag;
322
+ ) {
323
+ const namespace = yield* tag;
322
324
 
323
- return yield* (namespace.rpc as UnsafeInvoke<DurableObjectNamespace.DurableObjectRpcError>)(
324
- stub,
325
- method,
326
- ...args,
327
- );
328
- });
325
+ return yield* (namespace.rpc as UnsafeInvoke<DurableObjectNamespace.DurableObjectRpcError>)(
326
+ stub,
327
+ method,
328
+ ...args,
329
+ );
330
+ });
329
331
 
330
- const call = <Method extends keyof ClientApi>(
332
+ const call = Effect.fn("DurableObject.call")(function* <Method extends keyof ClientApi>(
331
333
  stub: DurableObjectNamespace.DurableObjectStubClient<ClientApi>,
332
334
  method: Method,
333
335
  ...args: ClientApi[Method] extends (...args: infer Args) => unknown ? Args : never
334
- ) =>
335
- Effect.gen(function* () {
336
- const namespace = yield* tag;
336
+ ) {
337
+ const namespace = yield* tag;
337
338
 
338
- return yield* (
339
- namespace.call as UnsafeInvoke<DurableObjectNamespace.DurableObjectRpcError>
340
- )(stub, method, ...args);
341
- });
339
+ return yield* (namespace.call as UnsafeInvoke<DurableObjectNamespace.DurableObjectRpcError>)(
340
+ stub,
341
+ method,
342
+ ...args,
343
+ );
344
+ });
342
345
 
343
- const scopedCall = <Method extends keyof ClientApi>(
346
+ const scopedCall = Effect.fn("DurableObject.scopedCall")(function* <
347
+ Method extends keyof ClientApi,
348
+ >(
344
349
  stub: DurableObjectNamespace.DurableObjectStubClient<ClientApi>,
345
350
  method: Method,
346
351
  ...args: ClientApi[Method] extends (...args: infer Args) => unknown ? Args : never
347
- ) =>
348
- Effect.gen(function* () {
349
- const namespace = yield* tag;
352
+ ) {
353
+ const namespace = yield* tag;
350
354
 
351
- return yield* (
352
- namespace.scopedCall as UnsafeInvoke<DurableObjectNamespace.DurableObjectRpcError>
353
- )(stub, method, ...args);
354
- });
355
+ return yield* (
356
+ namespace.scopedCall as UnsafeInvoke<DurableObjectNamespace.DurableObjectRpcError>
357
+ )(stub, method, ...args);
358
+ });
355
359
 
356
- const unsafeRaw = Effect.fnUntraced(function* () {
360
+ const rawUnsafe = Effect.fnUntraced(function* () {
357
361
  const namespace = yield* tag;
358
362
 
359
- return yield* namespace.unsafeRaw;
363
+ return yield* namespace.rawUnsafe;
360
364
  });
361
365
 
362
366
  const directMethods = DurableObjectNamespace.makeDirectMethods<Self, ClientApi, SelfDefinition>(
@@ -384,7 +388,7 @@ export const Tag =
384
388
  rpc,
385
389
  call,
386
390
  scopedCall,
387
- unsafeRaw,
391
+ rawUnsafe,
388
392
  }) as unknown as TagClass<Self, Id, MethodsShape>;
389
393
  };
390
394