effect-cf 0.6.0 → 0.8.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/dist/index.mjs CHANGED
@@ -1,101 +1,32 @@
1
1
  import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
2
- import { Cause, Clock, Config, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Layer, ManagedRuntime, Option, Queue, Schema } from "effect";
2
+ import { a as WorkerConfig, i as layer$8, n as Binding_exports, o as WorkerEnvironment, r as Service$2, t as Hyperdrive_exports } from "./Hyperdrive-LuQaVhXU.mjs";
3
+ import { Cause, Clock, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Layer, ManagedRuntime, Option, Queue, Schema } from "effect";
3
4
  import { D1Client } from "@effect/sql-d1";
4
5
  import { DurableObject, RpcStub, RpcTarget, WorkerEntrypoint, WorkflowEntrypoint } from "cloudflare:workers";
5
6
  import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
6
7
  import * as RpcMessage from "effect/unstable/rpc/RpcMessage";
7
8
  import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
8
9
  import * as RpcServer from "effect/unstable/rpc/RpcServer";
9
- //#region src/Environment.ts
10
- /**
11
- * Context service for reading worker bindings from the current `env` object.
12
- */
13
- var WorkerEnvironment = class extends Context.Service()("effect-cf/WorkerEnvironment") {};
14
- let WorkerConfig;
15
- (function(_WorkerConfig) {
16
- _WorkerConfig.string = (name) => Config.string(name);
17
- _WorkerConfig.redacted = (name) => Config.redacted(name);
18
- _WorkerConfig.number = (name) => Config.number(name);
19
- _WorkerConfig.integer = (name) => Config.int(name);
20
- _WorkerConfig.boolean = (name) => Config.boolean(name);
21
- const providerFromEnv = _WorkerConfig.providerFromEnv = (env) => ConfigProvider.fromUnknown(env);
22
- const providerWith = _WorkerConfig.providerWith = (makeProvider) => Effect.map(WorkerEnvironment.asEffect(), makeProvider);
23
- const provider = _WorkerConfig.provider = providerWith(providerFromEnv);
24
- _WorkerConfig.layer = _WorkerConfig.providerLayer = ConfigProvider.layer(provider);
25
- _WorkerConfig.layerWith = (makeProvider) => ConfigProvider.layer(providerWith(makeProvider));
26
- })(WorkerConfig || (WorkerConfig = {}));
27
- //#endregion
28
- //#region src/Binding.ts
29
- var Binding_exports = /* @__PURE__ */ __exportAll({
30
- BindingNotFoundError: () => BindingNotFoundError,
31
- BindingValidationError: () => BindingValidationError,
32
- Service: () => Service$6,
33
- TypeId: () => TypeId$6
34
- });
35
- /** Internal type id marker used by binding helper services. */
36
- const TypeId$6 = "effect-cf/Binding";
37
- /** Error raised when a configured binding does not exist on `env`. */
38
- var BindingNotFoundError = class extends Data.TaggedError("BindingNotFoundError") {};
39
- /** Error raised when a binding exists but does not match the expected shape. */
40
- var BindingValidationError = class extends Data.TaggedError("BindingValidationError") {};
41
- const isPropertyTarget$1 = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
42
- const getBinding = (env, binding, isResource) => Effect.gen(function* () {
43
- if (!isPropertyTarget$1(env)) return yield* Effect.fail(new BindingValidationError({ binding }));
44
- const resource = Reflect.get(env, binding);
45
- if (resource === void 0) return yield* Effect.fail(new BindingNotFoundError({ binding }));
46
- if (!isResource(resource)) return yield* Effect.fail(new BindingValidationError({ binding }));
47
- return resource;
48
- });
49
- const Service$6 = () => (id, binding, isResource, wrap) => {
50
- const tag = Context.Service()(id);
51
- const layer = Layer.effect(tag, Effect.gen(function* () {
52
- const resource = yield* getBinding(yield* WorkerEnvironment, binding, isResource);
53
- return wrap === void 0 ? resource : wrap(resource);
54
- }));
55
- return Object.assign(tag, {
56
- [TypeId$6]: TypeId$6,
57
- binding,
58
- layer
59
- });
60
- };
61
- //#endregion
62
10
  //#region src/D1.ts
63
11
  var D1_exports = /* @__PURE__ */ __exportAll({
64
- D1OperationError: () => D1OperationError,
65
- Service: () => Service$5,
66
- make: () => make$11
12
+ Service: () => Service$1,
13
+ make: () => make$10
67
14
  });
68
- const TypeId$5 = "effect-cf/D1";
69
- /** Error raised when a D1 operation fails. */
70
- var D1OperationError = class extends Data.TaggedError("D1OperationError") {};
15
+ const TypeId$2 = "effect-cf/D1";
71
16
  const isD1Database = (value) => {
72
17
  if (typeof value !== "object" || value === null) return false;
73
18
  const resource = value;
74
19
  return typeof resource.prepare === "function" && typeof resource.batch === "function" && typeof resource.exec === "function";
75
20
  };
76
- const d1Error = (binding, operation, cause) => new D1OperationError({
77
- binding,
78
- operation,
79
- cause
80
- });
81
- const tryD1Promise = (binding, operation, evaluate) => Effect.tryPromise({
82
- try: evaluate,
83
- catch: (cause) => d1Error(binding, operation, cause)
84
- });
85
- const tryD1Sync = (binding, operation, evaluate) => Effect.try({
86
- try: evaluate,
87
- catch: (cause) => d1Error(binding, operation, cause)
88
- });
89
21
  /**
90
22
  * Creates a typed D1 service tag plus Effect helpers.
91
23
  */
92
- const make$11 = (id, definition) => Service$5()(id, definition);
24
+ const make$10 = (id, definition) => Service$1()(id, definition);
93
25
  /**
94
26
  * Builds a D1 service around a Cloudflare D1 database binding.
95
27
  *
96
- * The returned service exposes the raw `D1Database` binding, small native D1
97
- * helpers, and `sqlLayer(...)` for providing `effect/unstable/sql` via
98
- * `@effect/sql-d1`.
28
+ * The returned service exposes the raw `D1Database` binding and `sqlLayer(...)`
29
+ * for providing `effect/unstable/sql` via `@effect/sql-d1`.
99
30
  *
100
31
  * @example
101
32
  * ```ts
@@ -106,8 +37,8 @@ const make$11 = (id, definition) => Service$5()(id, definition);
106
37
  * const SqlLive = TodoDatabase.sqlLayer();
107
38
  * ```
108
39
  */
109
- const Service$5 = () => (id, definition) => {
110
- const tag = Service$6()(id, definition.binding, isD1Database);
40
+ const Service$1 = () => (id, definition) => {
41
+ const tag = Service$2()(id, definition.binding, isD1Database);
111
42
  const sqlLayer = (options) => Layer.unwrap(Effect.gen(function* () {
112
43
  const db = yield* tag;
113
44
  return D1Client.layer({
@@ -115,39 +46,20 @@ const Service$5 = () => (id, definition) => {
115
46
  db
116
47
  });
117
48
  })).pipe(Layer.provide(tag.layer));
118
- const prepare = Effect.fnUntraced(function* (query) {
119
- const db = yield* tag;
120
- return yield* tryD1Sync(definition.binding, "prepare", () => db.prepare(query));
121
- });
122
- const batch = Effect.fnUntraced(function* (statements) {
123
- const db = yield* tag;
124
- return yield* tryD1Promise(definition.binding, "batch", () => db.batch([...statements]));
125
- });
126
- const exec = Effect.fnUntraced(function* (query) {
127
- const db = yield* tag;
128
- return yield* tryD1Promise(definition.binding, "exec", () => db.exec(query));
129
- });
130
- const unsafeRaw = Effect.fnUntraced(function* () {
131
- return yield* tag;
132
- });
133
49
  return Object.assign(tag, {
134
- [TypeId$5]: TypeId$5,
50
+ [TypeId$2]: TypeId$2,
135
51
  definition,
136
- sqlLayer,
137
- prepare,
138
- batch,
139
- exec,
140
- unsafeRaw
52
+ sqlLayer
141
53
  });
142
54
  };
143
55
  //#endregion
144
56
  //#region src/QueueBinding.ts
145
57
  var QueueBinding_exports = /* @__PURE__ */ __exportAll({
146
58
  QueueOperationError: () => QueueOperationError,
147
- Service: () => Service$4,
148
- make: () => make$10
59
+ isQueue: () => isQueue,
60
+ layer: () => layer$7,
61
+ makeClient: () => makeClient$6
149
62
  });
150
- const TypeId$4 = "effect-cf/QueueBinding";
151
63
  var QueueOperationError = class extends Data.TaggedError("QueueOperationError") {};
152
64
  const queueError = (binding, operation, cause) => new QueueOperationError({
153
65
  binding,
@@ -163,14 +75,9 @@ const isQueue = (value) => {
163
75
  const resource = value;
164
76
  return typeof resource.send === "function" && typeof resource.sendBatch === "function" && typeof resource.metrics === "function";
165
77
  };
166
- /** Creates a typed Queue binding service tag plus Effect helpers. */
167
- const make$10 = (id, definition) => Service$4()(id, definition);
168
- /**
169
- * Builds an Effect service around a Cloudflare Queue producer binding.
170
- */
171
- const Service$4 = () => (id, definition) => {
78
+ const makeClient$6 = (definition) => {
172
79
  const encodeMessage = Schema.encodeEffect(definition.message);
173
- const makeClient = (queue) => ({
80
+ return (queue) => ({
174
81
  send: Effect.fnUntraced(function* (message, options) {
175
82
  const encoded = yield* encodeMessage(message);
176
83
  yield* tryQueuePromise(definition.binding, "send", () => queue.send(encoded, options));
@@ -186,7 +93,34 @@ const Service$4 = () => (id, definition) => {
186
93
  metrics: () => tryQueuePromise(definition.binding, "metrics", () => queue.metrics()),
187
94
  unsafeRaw: Effect.succeed(queue)
188
95
  });
189
- const tag = Service$6()(id, definition.binding, (value) => isQueue(value), makeClient);
96
+ };
97
+ const layer$7 = (tag, definition) => layer$8(tag, definition.binding, (value) => isQueue(value), makeClient$6(definition));
98
+ //#endregion
99
+ //#region src/QueueDefinition.ts
100
+ var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
101
+ Queue: () => Queue$1,
102
+ Tag: () => Tag$10,
103
+ implement: () => implement$7,
104
+ make: () => make$9
105
+ });
106
+ const makeDefinition$4 = (id, definition) => {
107
+ const queueDefinition = {
108
+ id,
109
+ message: definition.message
110
+ };
111
+ return Object.assign(queueDefinition, { make: (layer, options) => make$6(layer, {
112
+ ...options,
113
+ queue: wrapHandler$1(queueDefinition, options.queue)
114
+ }) });
115
+ };
116
+ const make$9 = (id, definition) => Tag$10()(id, definition);
117
+ const Tag$10 = () => (id, definition) => {
118
+ const queueDefinition = makeDefinition$4(id, definition);
119
+ const tag = Context.Service()(id);
120
+ const layer = (binding) => layer$7(tag, {
121
+ ...binding,
122
+ message: definition.message
123
+ });
190
124
  const send = Effect.fnUntraced(function* (message, options) {
191
125
  yield* (yield* tag).send(message, options);
192
126
  });
@@ -200,55 +134,17 @@ const Service$4 = () => (id, definition) => {
200
134
  return yield* (yield* tag).unsafeRaw;
201
135
  });
202
136
  return Object.assign(tag, {
203
- [TypeId$4]: TypeId$4,
204
- binding: definition.binding,
137
+ id: queueDefinition.id,
138
+ message: queueDefinition.message,
139
+ make: queueDefinition.make,
140
+ layer,
205
141
  send,
206
142
  sendBatch,
207
143
  metrics,
208
144
  unsafeRaw
209
145
  });
210
146
  };
211
- //#endregion
212
- //#region src/QueueDefinition.ts
213
- var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
214
- Queue: () => Queue$1,
215
- Tag: () => Tag$8,
216
- implement: () => implement$7,
217
- make: () => make$9
218
- });
219
- const makeDefinition$4 = (id, definition) => {
220
- const queueDefinition = {
221
- id,
222
- message: definition.message
223
- };
224
- return Object.assign(queueDefinition, {
225
- make: (layer, options) => make$6(layer, {
226
- ...options,
227
- queue: wrapHandler$1(queueDefinition, options.queue)
228
- }),
229
- Binding: () => (bindingId, binding) => Service$4()(bindingId, {
230
- ...binding,
231
- message: definition.message
232
- }),
233
- binding: (bindingId, binding) => Service$4()(bindingId, {
234
- ...binding,
235
- message: definition.message
236
- })
237
- });
238
- };
239
- const make$9 = makeDefinition$4;
240
- const Tag$8 = () => (id, definition) => {
241
- const queueDefinition = makeDefinition$4(id, definition);
242
- class QueueDefinitionClass {
243
- static id = queueDefinition.id;
244
- static message = queueDefinition.message;
245
- static make = queueDefinition.make;
246
- static Binding = queueDefinition.Binding;
247
- static binding = queueDefinition.binding;
248
- }
249
- return QueueDefinitionClass;
250
- };
251
- const Queue$1 = Tag$8;
147
+ const Queue$1 = Tag$10;
252
148
  const wrapHandler$1 = (definition, handler) => {
253
149
  const decodeBody = Schema.decodeUnknownEffect(definition.message);
254
150
  return (batch) => Effect.gen(function* () {
@@ -260,7 +156,7 @@ const implement$7 = (_definition, handler) => handler;
260
156
  //#region src/Queue.ts
261
157
  var Queue_exports = /* @__PURE__ */ __exportAll({
262
158
  QueueMessageDecodeError: () => QueueMessageDecodeError,
263
- Tag: () => Tag$7,
159
+ Tag: () => Tag$9,
264
160
  decodeBatch: () => decodeBatch,
265
161
  fromMessage: () => fromMessage,
266
162
  fromMessageBatch: () => fromMessageBatch,
@@ -298,7 +194,7 @@ const decodeBatch = (batch, decodeBody) => Effect.gen(function* () {
298
194
  }
299
195
  return fromMessageBatch(batch, messages);
300
196
  });
301
- const Tag$7 = Tag$8;
197
+ const Tag$9 = Tag$10;
302
198
  const implement$6 = implement$7;
303
199
  //#endregion
304
200
  //#region src/RpcDefinition.ts
@@ -473,11 +369,15 @@ const invokeRpcMethod = (target, method, args, makeError) => Effect.gen(function
473
369
  //#endregion
474
370
  //#region src/ServiceBinding.ts
475
371
  var ServiceBinding_exports = /* @__PURE__ */ __exportAll({
476
- Service: () => Service$3,
372
+ Service: () => Service,
477
373
  ServiceBindingFetchError: () => ServiceBindingFetchError,
478
- ServiceBindingRpcError: () => ServiceBindingRpcError
374
+ ServiceBindingRpcError: () => ServiceBindingRpcError,
375
+ isServiceBindingClient: () => isServiceBindingClient,
376
+ layer: () => layer$6,
377
+ makeClient: () => makeClient$5,
378
+ makeDirectMethods: () => makeDirectMethods$1
479
379
  });
480
- const TypeId$3 = "effect-cf/ServiceBinding";
380
+ const TypeId$1 = "effect-cf/ServiceBinding";
481
381
  /**
482
382
  * Failure raised when calling `fetch` on a service binding.
483
383
  */
@@ -486,34 +386,9 @@ var ServiceBindingFetchError = class extends Data.TaggedError("ServiceBindingFet
486
386
  * Failure raised when invoking an RPC method on a service binding.
487
387
  */
488
388
  var ServiceBindingRpcError = class extends Data.TaggedError("ServiceBindingRpcError") {};
489
- /**
490
- * Creates a typed Effect service for a Worker service binding.
491
- *
492
- * Returned value includes:
493
- * - a Context tag for dependency injection
494
- * - `fetch(...)` for raw HTTP forwarding
495
- * - `call(...)` for generic RPC invocation
496
- * - direct RPC methods when `definition` is provided
497
- *
498
- * @example
499
- * ```ts
500
- * const Counter = WorkerDefinition.make("Counter", {
501
- * increment: WorkerDefinition.method({
502
- * args: [Schema.Number],
503
- * success: Schema.Number,
504
- * }),
505
- * });
506
- *
507
- * const CounterService = Counter.binding("COUNTER", { binding: "COUNTER" });
508
- *
509
- * const program = Effect.gen(function* () {
510
- * const next = yield* CounterService.increment(1);
511
- * return next;
512
- * });
513
- * ```
514
- */
515
- const Service$3 = () => (id, definition) => {
516
- const makeClient = (service) => {
389
+ const isServiceBindingClient = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "fetch") === "function";
390
+ const makeClient$5 = (definition) => {
391
+ return (service) => {
517
392
  const fetch = (input, init) => Effect.tryPromise({
518
393
  try: () => service.fetch(input, init),
519
394
  catch: (cause) => new ServiceBindingFetchError({
@@ -533,22 +408,24 @@ const Service$3 = () => (id, definition) => {
533
408
  cause
534
409
  }));
535
410
  });
536
- const call = (method, ...args) => Effect.gen(function* () {
537
- const methodName = String(method);
538
- const value = yield* resolve(yield* rpc(method, ...args)).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
411
+ const decodeSuccess$2 = (methodName, value) => Effect.gen(function* () {
412
+ if (definition.definition === void 0) return value;
413
+ return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
539
414
  binding: definition.binding,
540
415
  method: methodName,
541
416
  cause
542
417
  })));
543
- if (definition.definition === void 0) return value;
544
- return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
418
+ });
419
+ const call = (method, ...args) => Effect.gen(function* () {
420
+ const methodName = String(method);
421
+ return yield* decodeSuccess$2(methodName, yield* resolve(yield* rpc(method, ...args)).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
545
422
  binding: definition.binding,
546
423
  method: methodName,
547
424
  cause
548
- })));
425
+ }))));
549
426
  });
550
427
  const scopedCall = (method, ...args) => Effect.gen(function* () {
551
- return yield* scoped(yield* rpc(method, ...args));
428
+ return yield* decodeSuccess$2(String(method), yield* scoped(yield* rpc(method, ...args)));
552
429
  });
553
430
  const directMethods = makeDirectMethods$1(definition.definition, call);
554
431
  return Object.assign(directMethods, {
@@ -558,7 +435,39 @@ const Service$3 = () => (id, definition) => {
558
435
  scopedCall
559
436
  });
560
437
  };
561
- const tag = Service$6()(id, definition.binding, (value) => typeof value === "object" && value !== null && "fetch" in value, makeClient);
438
+ };
439
+ const layer$6 = (tag, definition) => layer$8(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$5(definition));
440
+ /**
441
+ * Creates a typed Effect service for a Worker service binding.
442
+ *
443
+ * Returned value includes:
444
+ * - a Context tag for dependency injection
445
+ * - `fetch(...)` for raw HTTP forwarding
446
+ * - `rpc(...)` for raw Cloudflare RPC results
447
+ * - `call(...)` for resolved and decoded RPC results
448
+ * - `scopedCall(...)` for scoped and decoded disposable RPC results
449
+ * - direct RPC methods when `definition` is provided
450
+ *
451
+ * @example
452
+ * ```ts
453
+ * const Counter = WorkerDefinition.make("Counter", {
454
+ * increment: WorkerDefinition.method({
455
+ * args: [Schema.Number],
456
+ * success: Schema.Number,
457
+ * }),
458
+ * });
459
+ *
460
+ * const CounterLive = Counter.layer({ binding: "COUNTER" });
461
+ *
462
+ * const program = Effect.gen(function* () {
463
+ * const counter = yield* Counter;
464
+ * const next = yield* counter.increment(1);
465
+ * return next;
466
+ * });
467
+ * ```
468
+ */
469
+ const Service = () => (id, definition) => {
470
+ const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$5(definition));
562
471
  const fetch = (input, init) => Effect.gen(function* () {
563
472
  return yield* (yield* tag).fetch(input, init);
564
473
  });
@@ -573,7 +482,7 @@ const Service$3 = () => (id, definition) => {
573
482
  });
574
483
  const directMethods = makeDirectMethods$1(definition.definition, call);
575
484
  return Object.assign(tag, directMethods, {
576
- [TypeId$3]: TypeId$3,
485
+ [TypeId$1]: TypeId$1,
577
486
  definition,
578
487
  fetch,
579
488
  rpc,
@@ -589,7 +498,7 @@ const makeDirectMethods$1 = (rpcDefinition, call) => {
589
498
  //#endregion
590
499
  //#region src/WorkerDefinition.ts
591
500
  var WorkerDefinition_exports = /* @__PURE__ */ __exportAll({
592
- Tag: () => Tag$6,
501
+ Tag: () => Tag$8,
593
502
  Worker: () => Worker,
594
503
  implement: () => implement$5,
595
504
  make: () => make$7,
@@ -631,34 +540,45 @@ const method$3 = method$4;
631
540
  const makeDefinition$3 = (id, methods) => {
632
541
  assertNoReservedMethods("Worker", methods, reservedMethodNames$3);
633
542
  const definition = make$8(id, methods);
634
- return Object.assign(definition, {
635
- make: (layer, options) => make$6(layer, {
636
- ...options,
637
- rpc: wrapHandlers$1(definition, options.rpc)
638
- }),
639
- Binding: () => (bindingId, binding) => Service$3()(bindingId, {
640
- ...binding,
641
- definition
642
- }),
643
- binding: (bindingId, binding) => Service$3()(bindingId, {
644
- ...binding,
645
- definition
646
- })
647
- });
543
+ return Object.assign(definition, { make: (layer, options) => make$6(layer, {
544
+ ...options,
545
+ rpc: wrapHandlers$1(definition, options.rpc)
546
+ }) });
648
547
  };
649
- const make$7 = makeDefinition$3;
650
- const Tag$6 = () => (id, methods) => {
548
+ const make$7 = (id, methods) => Tag$8()(id, methods);
549
+ const Tag$8 = () => (id, methods) => {
651
550
  const definition = makeDefinition$3(id, methods);
652
- class WorkerDefinitionClass {
653
- static id = definition.id;
654
- static methods = definition.methods;
655
- static make = definition.make;
656
- static Binding = definition.Binding;
657
- static binding = definition.binding;
658
- }
659
- return WorkerDefinitionClass;
551
+ const tag = Context.Service()(id);
552
+ const bindingDefinition = (binding) => ({
553
+ ...binding,
554
+ definition
555
+ });
556
+ const layer = (binding) => layer$6(tag, bindingDefinition(binding));
557
+ const fetch = (input, init) => Effect.gen(function* () {
558
+ return yield* (yield* tag).fetch(input, init);
559
+ });
560
+ const rpc = (method, ...args) => Effect.gen(function* () {
561
+ return yield* (yield* tag).rpc(method, ...args);
562
+ });
563
+ const call = (method, ...args) => Effect.gen(function* () {
564
+ return yield* (yield* tag).call(method, ...args);
565
+ });
566
+ const scopedCall = (method, ...args) => Effect.gen(function* () {
567
+ return yield* (yield* tag).scopedCall(method, ...args);
568
+ });
569
+ const directMethods = makeDirectMethods$1(definition, call);
570
+ return Object.assign(tag, directMethods, {
571
+ id: definition.id,
572
+ methods: definition.methods,
573
+ make: definition.make,
574
+ layer,
575
+ fetch,
576
+ rpc,
577
+ call,
578
+ scopedCall
579
+ });
660
580
  };
661
- const Worker = Tag$6;
581
+ const Worker = Tag$8;
662
582
  const wrapHandlers$1 = (definition, handlers) => {
663
583
  const wrapped = {};
664
584
  for (const key of Object.keys(definition.methods)) {
@@ -714,7 +634,7 @@ const fromExecutionContext = (ctx, runPromiseExit) => {
714
634
  var Worker_exports = /* @__PURE__ */ __exportAll({
715
635
  ExecutionContext: () => ExecutionContext,
716
636
  NativeRequest: () => NativeRequest,
717
- Tag: () => Tag$5,
637
+ Tag: () => Tag$7,
718
638
  WorkerContext: () => WorkerContext,
719
639
  implement: () => implement$4,
720
640
  isWebSocketUpgrade: () => isWebSocketUpgrade,
@@ -781,7 +701,7 @@ const makeFetchHandler = (layer, options) => {
781
701
  const WorkerClass = make$6(layer, options);
782
702
  return { fetch: (request, env, ctx) => Promise.resolve(new WorkerClass(ctx, env).fetch(request)) };
783
703
  };
784
- const Tag$5 = Tag$6;
704
+ const Tag$7 = Tag$8;
785
705
  const method$2 = method$3;
786
706
  const implement$4 = implement$5;
787
707
  //#endregion
@@ -1078,9 +998,11 @@ const runPromiseExitPreservingTypedFailures = async (effect) => {
1078
998
  var DurableObjectNamespace_exports = /* @__PURE__ */ __exportAll({
1079
999
  DurableObjectFetchError: () => DurableObjectFetchError,
1080
1000
  DurableObjectRpcError: () => DurableObjectRpcError,
1081
- Service: () => Service$2
1001
+ isDurableObjectNamespaceClient: () => isDurableObjectNamespaceClient,
1002
+ layer: () => layer$5,
1003
+ makeClient: () => makeClient$4,
1004
+ makeDirectMethods: () => makeDirectMethods
1082
1005
  });
1083
- const TypeId$2 = "effect-cf/DurableObjectNamespace";
1084
1006
  /**
1085
1007
  * Failure raised when invoking an RPC method on a Durable Object stub.
1086
1008
  */
@@ -1089,33 +1011,10 @@ var DurableObjectRpcError = class extends Data.TaggedError("DurableObjectRpcErro
1089
1011
  * Failure raised when forwarding a request to a Durable Object stub.
1090
1012
  */
1091
1013
  var DurableObjectFetchError = class extends Data.TaggedError("DurableObjectFetchError") {};
1092
- /**
1093
- * Creates a typed Effect service for a Durable Object namespace binding.
1094
- *
1095
- * Returned value includes namespace helpers (`get`, `getByName`, `newUniqueId`),
1096
- * raw `fetch` / `call` helpers, and direct RPC helpers when `definition` is provided.
1097
- *
1098
- * @example
1099
- * ```ts
1100
- * const ChatRoom = DurableObjectDefinition.make("ChatRoom", {
1101
- * postMessage: DurableObjectDefinition.method({
1102
- * args: [Schema.String],
1103
- * success: Schema.Void,
1104
- * }),
1105
- * });
1106
- *
1107
- * const ChatRooms = ChatRoom.namespace("CHAT_ROOMS", { binding: "CHAT_ROOMS" });
1108
- *
1109
- * const program = Effect.gen(function* () {
1110
- * const room = ChatRooms.byName("general");
1111
- * yield* room.postMessage("hello");
1112
- * });
1113
- * ```
1114
- */
1115
- const Service$2 = () => (id, definition) => {
1116
- const hasFunction = (value, key) => typeof Reflect.get(value, key) === "function";
1117
- const isDurableObjectNamespaceClient = (value) => typeof value === "object" && value !== null && hasFunction(value, "getByName") && hasFunction(value, "get") && hasFunction(value, "idFromName") && hasFunction(value, "idFromString") && hasFunction(value, "newUniqueId") && hasFunction(value, "jurisdiction");
1118
- const makeClient = (namespace) => {
1014
+ const hasFunction$1 = (value, key) => typeof Reflect.get(value, key) === "function";
1015
+ const isDurableObjectNamespaceClient = (value) => typeof value === "object" && value !== null && hasFunction$1(value, "getByName") && hasFunction$1(value, "get") && hasFunction$1(value, "idFromName") && hasFunction$1(value, "idFromString") && hasFunction$1(value, "newUniqueId") && hasFunction$1(value, "jurisdiction");
1016
+ const makeClient$4 = (definition) => {
1017
+ return (namespace) => {
1119
1018
  const newUniqueId = (options) => Effect.sync(() => namespace.newUniqueId(options));
1120
1019
  const idFromName = (name) => Effect.sync(() => namespace.idFromName(name));
1121
1020
  const idFromString = (id) => Effect.sync(() => namespace.idFromString(id));
@@ -1141,22 +1040,24 @@ const Service$2 = () => (id, definition) => {
1141
1040
  cause
1142
1041
  }));
1143
1042
  });
1144
- const call = (stub, method, ...args) => Effect.gen(function* () {
1145
- const methodName = String(method);
1146
- const value = yield* resolve(yield* rpc(stub, method, ...args)).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
1043
+ const decodeSuccess$1 = (methodName, value) => Effect.gen(function* () {
1044
+ if (definition.definition === void 0) return value;
1045
+ return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
1147
1046
  binding: definition.binding,
1148
1047
  method: methodName,
1149
1048
  cause
1150
1049
  })));
1151
- if (definition.definition === void 0) return value;
1152
- return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
1050
+ });
1051
+ const call = (stub, method, ...args) => Effect.gen(function* () {
1052
+ const methodName = String(method);
1053
+ return yield* decodeSuccess$1(methodName, yield* resolve(yield* rpc(stub, method, ...args)).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
1153
1054
  binding: definition.binding,
1154
1055
  method: methodName,
1155
1056
  cause
1156
- })));
1057
+ }))));
1157
1058
  });
1158
1059
  const scopedCall = (stub, method, ...args) => Effect.gen(function* () {
1159
- return yield* scoped(yield* rpc(stub, method, ...args));
1060
+ return yield* decodeSuccess$1(String(method), yield* scoped(yield* rpc(stub, method, ...args)));
1160
1061
  });
1161
1062
  const directMethods = makeDirectMethods(definition.definition, {
1162
1063
  call,
@@ -1178,86 +1079,8 @@ const Service$2 = () => (id, definition) => {
1178
1079
  unsafeRaw: Effect.succeed(namespace)
1179
1080
  });
1180
1081
  };
1181
- const tag = Service$6()(id, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient);
1182
- const newUniqueId = Effect.fnUntraced(function* (options) {
1183
- return yield* (yield* tag).newUniqueId(options);
1184
- });
1185
- const idFromName = Effect.fnUntraced(function* (name) {
1186
- return yield* (yield* tag).idFromName(name);
1187
- });
1188
- const idFromString = Effect.fnUntraced(function* (id) {
1189
- return yield* (yield* tag).idFromString(id);
1190
- });
1191
- const get = Effect.fnUntraced(function* (id, options) {
1192
- return yield* (yield* tag).get(id, options);
1193
- });
1194
- const getByName = Effect.fnUntraced(function* (name, options) {
1195
- return yield* (yield* tag).getByName(name, options);
1196
- });
1197
- const jurisdiction = Effect.fnUntraced(function* (value) {
1198
- return yield* (yield* tag).jurisdiction(value);
1199
- });
1200
- const fetch = (stub, input, init) => Effect.tryPromise({
1201
- try: () => stub.fetch(input, init),
1202
- catch: (cause) => new DurableObjectFetchError({
1203
- binding: definition.binding,
1204
- cause
1205
- })
1206
- });
1207
- const rpc = (stub, method, ...args) => Effect.gen(function* () {
1208
- const methodName = String(method);
1209
- return yield* invokeRpcMethod(stub, method, definition.definition === void 0 ? args : yield* encodeArgs(definition.definition, methodName, args).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
1210
- binding: definition.binding,
1211
- method: methodName,
1212
- cause
1213
- }))), (cause) => new DurableObjectRpcError({
1214
- binding: definition.binding,
1215
- method: methodName,
1216
- cause
1217
- }));
1218
- });
1219
- const call = (stub, method, ...args) => Effect.gen(function* () {
1220
- const methodName = String(method);
1221
- const value = yield* resolve(yield* rpc(stub, method, ...args)).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
1222
- binding: definition.binding,
1223
- method: methodName,
1224
- cause
1225
- })));
1226
- if (definition.definition === void 0) return value;
1227
- return yield* decodeSuccess(definition.definition, methodName, value).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
1228
- binding: definition.binding,
1229
- method: methodName,
1230
- cause
1231
- })));
1232
- });
1233
- const scopedCall = (stub, method, ...args) => Effect.gen(function* () {
1234
- return yield* scoped(yield* rpc(stub, method, ...args));
1235
- });
1236
- const unsafeRaw = Effect.fnUntraced(function* () {
1237
- return yield* (yield* tag).unsafeRaw;
1238
- });
1239
- const directMethods = makeDirectMethods(definition.definition, {
1240
- call,
1241
- fetch,
1242
- get,
1243
- getByName
1244
- });
1245
- return Object.assign(tag, directMethods, {
1246
- [TypeId$2]: TypeId$2,
1247
- definition,
1248
- newUniqueId,
1249
- idFromName,
1250
- idFromString,
1251
- get,
1252
- getByName,
1253
- jurisdiction,
1254
- fetch,
1255
- rpc,
1256
- call,
1257
- scopedCall,
1258
- unsafeRaw
1259
- });
1260
1082
  };
1083
+ const layer$5 = (tag, definition) => layer$8(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$4(definition));
1261
1084
  const makeDirectMethods = (rpcDefinition, helpers) => {
1262
1085
  const methods = {};
1263
1086
  if (rpcDefinition !== void 0) {
@@ -1282,7 +1105,7 @@ const makeDirectMethods = (rpcDefinition, helpers) => {
1282
1105
  //#region src/DurableObjectDefinition.ts
1283
1106
  var DurableObjectDefinition_exports = /* @__PURE__ */ __exportAll({
1284
1107
  DurableObject: () => DurableObject$1,
1285
- Tag: () => Tag$4,
1108
+ Tag: () => Tag$6,
1286
1109
  implement: () => implement$3,
1287
1110
  make: () => make$5,
1288
1111
  method: () => method$1
@@ -1316,34 +1139,78 @@ const method$1 = method$4;
1316
1139
  const makeDefinition$2 = (id, methods) => {
1317
1140
  assertNoReservedMethods("Durable Object", methods, reservedMethodNames$1);
1318
1141
  const definition = make$8(id, methods);
1319
- return Object.assign(definition, {
1320
- make: (layer, options) => make$4(layer, {
1321
- ...options,
1322
- rpc: wrapHandlers(definition, options.rpc)
1323
- }),
1324
- Namespace: () => (bindingId, binding) => Service$2()(bindingId, {
1325
- ...binding,
1326
- definition
1327
- }),
1328
- namespace: (bindingId, binding) => Service$2()(bindingId, {
1329
- ...binding,
1330
- definition
1331
- })
1332
- });
1142
+ return Object.assign(definition, { make: (layer, options) => make$4(layer, {
1143
+ ...options,
1144
+ rpc: wrapHandlers(definition, options.rpc)
1145
+ }) });
1333
1146
  };
1334
- const make$5 = makeDefinition$2;
1335
- const Tag$4 = () => (id, methods) => {
1147
+ const make$5 = (id, methods) => Tag$6()(id, methods);
1148
+ const Tag$6 = () => (id, methods) => {
1336
1149
  const definition = makeDefinition$2(id, methods);
1337
- class DurableObjectDefinitionClass {
1338
- static id = definition.id;
1339
- static methods = definition.methods;
1340
- static make = definition.make;
1341
- static Namespace = definition.Namespace;
1342
- static namespace = definition.namespace;
1343
- }
1344
- return DurableObjectDefinitionClass;
1150
+ const tag = Context.Service()(id);
1151
+ const bindingDefinition = (binding) => ({
1152
+ ...binding,
1153
+ definition
1154
+ });
1155
+ const layer = (binding) => layer$5(tag, bindingDefinition(binding));
1156
+ const newUniqueId = Effect.fnUntraced(function* (options) {
1157
+ return yield* (yield* tag).newUniqueId(options);
1158
+ });
1159
+ const idFromName = Effect.fnUntraced(function* (name) {
1160
+ return yield* (yield* tag).idFromName(name);
1161
+ });
1162
+ const idFromString = Effect.fnUntraced(function* (value) {
1163
+ return yield* (yield* tag).idFromString(value);
1164
+ });
1165
+ const get = Effect.fnUntraced(function* (objectId, options) {
1166
+ return yield* (yield* tag).get(objectId, options);
1167
+ });
1168
+ const getByName = Effect.fnUntraced(function* (name, options) {
1169
+ return yield* (yield* tag).getByName(name, options);
1170
+ });
1171
+ const jurisdiction = Effect.fnUntraced(function* (value) {
1172
+ return yield* (yield* tag).jurisdiction(value);
1173
+ });
1174
+ const fetch = (stub, input, init) => Effect.gen(function* () {
1175
+ return yield* (yield* tag).fetch(stub, input, init);
1176
+ });
1177
+ const rpc = (stub, method, ...args) => Effect.gen(function* () {
1178
+ return yield* (yield* tag).rpc(stub, method, ...args);
1179
+ });
1180
+ const call = (stub, method, ...args) => Effect.gen(function* () {
1181
+ return yield* (yield* tag).call(stub, method, ...args);
1182
+ });
1183
+ const scopedCall = (stub, method, ...args) => Effect.gen(function* () {
1184
+ return yield* (yield* tag).scopedCall(stub, method, ...args);
1185
+ });
1186
+ const unsafeRaw = Effect.fnUntraced(function* () {
1187
+ return yield* (yield* tag).unsafeRaw;
1188
+ });
1189
+ const directMethods = makeDirectMethods(definition, {
1190
+ call,
1191
+ fetch,
1192
+ get,
1193
+ getByName
1194
+ });
1195
+ return Object.assign(tag, directMethods, {
1196
+ id: definition.id,
1197
+ methods: definition.methods,
1198
+ make: definition.make,
1199
+ layer,
1200
+ newUniqueId,
1201
+ idFromName,
1202
+ idFromString,
1203
+ get,
1204
+ getByName,
1205
+ jurisdiction,
1206
+ fetch,
1207
+ rpc,
1208
+ call,
1209
+ scopedCall,
1210
+ unsafeRaw
1211
+ });
1345
1212
  };
1346
- const DurableObject$1 = Tag$4;
1213
+ const DurableObject$1 = Tag$6;
1347
1214
  const wrapHandlers = (definition, handlers) => {
1348
1215
  const wrapped = {};
1349
1216
  for (const key of Object.keys(definition.methods)) {
@@ -1361,7 +1228,7 @@ const implement$3 = (_definition, handlers) => handlers;
1361
1228
  //#endregion
1362
1229
  //#region src/DurableObject.ts
1363
1230
  var DurableObject_exports = /* @__PURE__ */ __exportAll({
1364
- Tag: () => Tag$3,
1231
+ Tag: () => Tag$5,
1365
1232
  implement: () => implement$2,
1366
1233
  make: () => make$4,
1367
1234
  method: () => method
@@ -1418,7 +1285,7 @@ const make$4 = (layer, options = {}) => {
1418
1285
  defineEntrypointRpcMethods("Durable Object", EffectDurableObject.prototype, options.rpc, reservedMethodNames, (self, effect) => self[RunSymbol](effect));
1419
1286
  return assumeEntrypointClass(EffectDurableObject);
1420
1287
  };
1421
- const Tag$3 = Tag$4;
1288
+ const Tag$5 = Tag$6;
1422
1289
  const method = method$1;
1423
1290
  const implement$2 = implement$3;
1424
1291
  //#endregion
@@ -1747,7 +1614,7 @@ var DurableObjectAlarm = class DurableObjectAlarm extends Context.Service()("eff
1747
1614
  //#region src/DurableObjectRpcWebSocket.ts
1748
1615
  var DurableObjectRpcWebSocket_exports = /* @__PURE__ */ __exportAll({
1749
1616
  DurableObjectRpcWebSocket: () => DurableObjectRpcWebSocket,
1750
- layer: () => layer
1617
+ layer: () => layer$4
1751
1618
  });
1752
1619
  const defaultAttachmentKey = "effectCloudflareRpcClientId";
1753
1620
  const defaultTag = "effect-cf-rpc";
@@ -1758,7 +1625,7 @@ var DurableObjectRpcWebSocket = class extends Context.Service()("effect-cf/Durab
1758
1625
  /**
1759
1626
  * Builds a layer that bridges Durable Object websocket events to `RpcServer.Protocol`.
1760
1627
  */
1761
- const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
1628
+ const layer$4 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
1762
1629
  const tag = options.tag ?? defaultTag;
1763
1630
  const attachmentKey = options.attachmentKey ?? defaultAttachmentKey;
1764
1631
  const durableObjectState = yield* DurableObjectState;
@@ -1870,14 +1737,120 @@ const writeAttachment = (socket, key, clientId) => {
1870
1737
  });
1871
1738
  };
1872
1739
  //#endregion
1740
+ //#region src/Images.ts
1741
+ var Images_exports = /* @__PURE__ */ __exportAll({
1742
+ ImagesOperationError: () => ImagesOperationError,
1743
+ Tag: () => Tag$4,
1744
+ draw: () => draw,
1745
+ empty: () => empty,
1746
+ isImagesBinding: () => isImagesBinding,
1747
+ layer: () => layer$3,
1748
+ make: () => make$3,
1749
+ makeClient: () => makeClient$3,
1750
+ transform: () => transform
1751
+ });
1752
+ const TypeId = "effect-cf/Images/Steps";
1753
+ /** Error raised when a Cloudflare Images operation fails. */
1754
+ var ImagesOperationError = class extends Data.TaggedError("ImagesOperationError") {};
1755
+ const makeSteps = (steps) => ({
1756
+ [TypeId]: TypeId,
1757
+ steps
1758
+ });
1759
+ /** Empty Images transformation pipeline. */
1760
+ const empty = makeSteps([]);
1761
+ function transform(stepsOrTransform, transformValue) {
1762
+ if (transformValue === void 0) return (steps) => transform(steps, stepsOrTransform);
1763
+ return makeSteps([...stepsOrTransform.steps, {
1764
+ _tag: "Transform",
1765
+ transform: transformValue
1766
+ }]);
1767
+ }
1768
+ function draw(stepsOrDraw, drawValue) {
1769
+ if (drawValue === void 0) return (steps) => draw(steps, stepsOrDraw);
1770
+ return makeSteps([...stepsOrDraw.steps, {
1771
+ _tag: "Draw",
1772
+ ...drawValue
1773
+ }]);
1774
+ }
1775
+ const imagesError = (binding, operation, cause) => new ImagesOperationError({
1776
+ binding,
1777
+ operation,
1778
+ cause
1779
+ });
1780
+ const tryImagesPromise = (binding, operation, evaluate) => Effect.tryPromise({
1781
+ try: evaluate,
1782
+ catch: (cause) => imagesError(binding, operation, cause)
1783
+ });
1784
+ const tryImagesSync = (binding, operation, evaluate) => Effect.try({
1785
+ try: evaluate,
1786
+ catch: (cause) => imagesError(binding, operation, cause)
1787
+ });
1788
+ const maybe$1 = (value) => value === null ? Option.none() : Option.some(value);
1789
+ const hasFunction = (value, key) => typeof Reflect.get(value, key) === "function";
1790
+ const isHostedImagesBinding = (value) => typeof value === "object" && value !== null && hasFunction(value, "image") && hasFunction(value, "upload") && hasFunction(value, "list");
1791
+ const isImagesBinding = (value) => typeof value === "object" && value !== null && hasFunction(value, "info") && hasFunction(value, "input");
1792
+ const wrapResult = (binding, result) => ({
1793
+ raw: result,
1794
+ response: tryImagesSync(binding, "response", () => result.response()),
1795
+ contentType: tryImagesSync(binding, "contentType", () => result.contentType()),
1796
+ image: (options) => tryImagesSync(binding, "image", () => result.image(options))
1797
+ });
1798
+ const wrapHandle = (binding, handle) => ({
1799
+ raw: handle,
1800
+ details: tryImagesPromise(binding, "details", () => handle.details()).pipe(Effect.map(maybe$1)),
1801
+ bytes: tryImagesPromise(binding, "bytes", () => handle.bytes()).pipe(Effect.map(maybe$1)),
1802
+ update: (options) => tryImagesPromise(binding, "update", () => handle.update(options)),
1803
+ delete: tryImagesPromise(binding, "delete", () => handle.delete())
1804
+ });
1805
+ const wrapHosted = (binding, hosted) => ({
1806
+ image: (imageId) => wrapHandle(binding, hosted.image(imageId)),
1807
+ upload: (image, options) => tryImagesPromise(binding, "upload", () => hosted.upload(image, options)),
1808
+ list: (options) => tryImagesPromise(binding, "list", () => hosted.list(options)),
1809
+ unsafeRaw: Effect.succeed(hosted)
1810
+ });
1811
+ const makeClient$3 = (definition) => (images) => {
1812
+ const input = (image, options) => tryImagesSync(definition.binding, "input", () => images.input(image, options));
1813
+ const process = (steps, options) => Effect.gen(function* () {
1814
+ let transformer = yield* input(options.stream, options.inputOptions);
1815
+ for (const step of steps.steps) switch (step._tag) {
1816
+ case "Draw":
1817
+ transformer = yield* tryImagesSync(definition.binding, "draw", () => transformer.draw(step.image, step.options));
1818
+ break;
1819
+ case "Transform":
1820
+ transformer = yield* tryImagesSync(definition.binding, "transform", () => transformer.transform(step.transform));
1821
+ break;
1822
+ }
1823
+ const result = yield* tryImagesPromise(definition.binding, "output", () => transformer.output(options.outputOptions));
1824
+ return wrapResult(definition.binding, result);
1825
+ });
1826
+ return {
1827
+ definition,
1828
+ info: (image, options) => tryImagesPromise(definition.binding, "info", () => images.info(image, options)),
1829
+ input,
1830
+ process,
1831
+ hosted: isHostedImagesBinding(images.hosted) ? Option.some(wrapHosted(definition.binding, images.hosted)) : Option.none(),
1832
+ unsafeRaw: Effect.succeed(images)
1833
+ };
1834
+ };
1835
+ const layer$3 = (tag, definition) => layer$8(tag, definition.binding, isImagesBinding, makeClient$3(definition));
1836
+ const make$3 = (id) => Tag$4()(id);
1837
+ const Tag$4 = () => (id) => {
1838
+ const tag = Context.Service()(id);
1839
+ const makeLayer = (definition) => layer$3(tag, definition);
1840
+ return Object.assign(tag, {
1841
+ id,
1842
+ layer: makeLayer
1843
+ });
1844
+ };
1845
+ //#endregion
1873
1846
  //#region src/Kv.ts
1874
1847
  var Kv_exports = /* @__PURE__ */ __exportAll({
1875
1848
  KvOperationError: () => KvOperationError,
1876
- Service: () => Service$1,
1877
- Tag: () => Tag$2,
1878
- make: () => make$3
1849
+ Tag: () => Tag$3,
1850
+ isKvNamespace: () => isKvNamespace,
1851
+ layer: () => layer$2,
1852
+ makeClient: () => makeClient$2
1879
1853
  });
1880
- const TypeId$1 = "effect-cf/Kv";
1881
1854
  /** Error raised when a KV operation fails. */
1882
1855
  var KvOperationError = class extends Data.TaggedError("KvOperationError") {};
1883
1856
  const maybeString = (value) => value == null ? Option.none() : Option.some(value);
@@ -1891,66 +1864,17 @@ const tryKvPromise = (binding, operation, evaluate) => Effect.tryPromise({
1891
1864
  try: evaluate,
1892
1865
  catch: (cause) => kvError(binding, operation, cause)
1893
1866
  });
1894
- /**
1895
- * Creates a typed KV service tag plus Effect helpers.
1896
- */
1897
- const make$3 = (id, definition) => Service$1()(id, definition);
1898
- const makeDefinition$1 = (id, definition) => {
1899
- const kvDefinition = {
1900
- id,
1901
- key: definition.key,
1902
- value: definition.value
1903
- };
1904
- return Object.assign(kvDefinition, {
1905
- Binding: () => (bindingId, binding) => Service$1()(bindingId, {
1906
- ...binding,
1907
- key: definition.key,
1908
- value: definition.value
1909
- }),
1910
- binding: (bindingId, binding) => Service$1()(bindingId, {
1911
- ...binding,
1912
- key: definition.key,
1913
- value: definition.value
1914
- })
1915
- });
1916
- };
1917
- const Tag$2 = () => (id, definition) => {
1918
- const kvDefinition = makeDefinition$1(id, definition);
1919
- class KvDefinitionClass {
1920
- static id = kvDefinition.id;
1921
- static key = kvDefinition.key;
1922
- static value = kvDefinition.value;
1923
- static Binding = kvDefinition.Binding;
1924
- static binding = kvDefinition.binding;
1925
- }
1926
- return KvDefinitionClass;
1867
+ const isKvNamespace = (value) => {
1868
+ if (typeof value !== "object" || value === null) return false;
1869
+ const resource = value;
1870
+ return typeof resource.get === "function" && typeof resource.put === "function" && typeof resource.delete === "function" && typeof resource.getWithMetadata === "function" && typeof resource.list === "function";
1927
1871
  };
1928
- /**
1929
- * Builds a KV service around a Cloudflare KV namespace binding.
1930
- *
1931
- * Returned service includes schema-aware `put`, `get`, `getWithMetadata`,
1932
- * `list`, and `remove` helpers.
1933
- *
1934
- * @example
1935
- * ```ts
1936
- * const Sessions = Kv.make("Sessions", {
1937
- * binding: "SESSIONS",
1938
- * key: Schema.String,
1939
- * value: Schema.Struct({ userId: Schema.String }),
1940
- * });
1941
- *
1942
- * const program = Effect.gen(function* () {
1943
- * yield* Sessions.put("abc", { userId: "u_1" });
1944
- * return yield* Sessions.get("abc");
1945
- * });
1946
- * ```
1947
- */
1948
- const Service$1 = () => (id, definition) => {
1872
+ const makeClient$2 = (definition) => {
1949
1873
  const encodeKey = Schema.encodeEffect(definition.key);
1950
1874
  const decodeKey = Schema.decodeUnknownEffect(definition.key);
1951
1875
  const encodeValue = Schema.encodeEffect(Schema.fromJsonString(Schema.toCodecJson(definition.value)));
1952
1876
  const decodeValue = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.toCodecJson(definition.value)));
1953
- const makeClient = (kv) => ({
1877
+ return (kv) => ({
1954
1878
  definition,
1955
1879
  put: Effect.fnUntraced(function* (key, value, options) {
1956
1880
  const keyEncoded = yield* encodeKey(key);
@@ -2001,49 +1925,109 @@ const Service$1 = () => (id, definition) => {
2001
1925
  }),
2002
1926
  unsafeRaw: Effect.succeed(kv)
2003
1927
  });
2004
- const tag = Service$6()(id, definition.binding, (value) => {
2005
- if (typeof value !== "object" || value === null) return false;
2006
- const resource = value;
2007
- return typeof resource.get === "function" && typeof resource.put === "function" && typeof resource.delete === "function" && typeof resource.getWithMetadata === "function" && typeof resource.list === "function";
2008
- }, makeClient);
2009
- const put = Effect.fnUntraced(function* (key, value, options) {
2010
- yield* (yield* tag).put(key, value, options);
2011
- });
2012
- const get = Effect.fnUntraced(function* (key) {
2013
- return yield* (yield* tag).get(key);
2014
- });
2015
- const getWithMetadata = Effect.fnUntraced(function* (key, metadataSchema) {
2016
- return yield* (yield* tag).getWithMetadata(key, metadataSchema);
2017
- });
2018
- const list = Effect.fnUntraced(function* (options) {
2019
- return yield* (yield* tag).list(options);
1928
+ };
1929
+ const layer$2 = (tag, definition) => layer$8(tag, definition.binding, isKvNamespace, makeClient$2(definition));
1930
+ const makeDefinition$1 = (id, definition) => {
1931
+ const kvDefinition = {
1932
+ id,
1933
+ key: definition.key,
1934
+ value: definition.value
1935
+ };
1936
+ return Object.assign(kvDefinition, { layer: (tag, binding) => layer$2(tag, {
1937
+ ...binding,
1938
+ key: definition.key,
1939
+ value: definition.value
1940
+ }) });
1941
+ };
1942
+ const Tag$3 = () => (id, definition) => {
1943
+ const kvDefinition = makeDefinition$1(id, definition);
1944
+ const tag = Context.Service()(id);
1945
+ const makeLayer = (binding) => kvDefinition.layer(tag, binding);
1946
+ return Object.assign(tag, {
1947
+ id: kvDefinition.id,
1948
+ keySchema: kvDefinition.key,
1949
+ valueSchema: kvDefinition.value,
1950
+ layer: makeLayer
2020
1951
  });
2021
- const remove = Effect.fnUntraced(function* (key) {
2022
- yield* (yield* tag).remove(key);
1952
+ };
1953
+ //#endregion
1954
+ //#region src/R2.ts
1955
+ var R2_exports = /* @__PURE__ */ __exportAll({
1956
+ R2OperationError: () => R2OperationError,
1957
+ Tag: () => Tag$2,
1958
+ isR2Bucket: () => isR2Bucket,
1959
+ layer: () => layer$1,
1960
+ make: () => make$2,
1961
+ makeClient: () => makeClient$1
1962
+ });
1963
+ /** Error raised when an R2 operation fails. */
1964
+ var R2OperationError = class extends Data.TaggedError("R2OperationError") {};
1965
+ const r2Error = (binding, operation, cause) => new R2OperationError({
1966
+ binding,
1967
+ operation,
1968
+ cause
1969
+ });
1970
+ const tryR2Promise = (binding, operation, evaluate) => Effect.tryPromise({
1971
+ try: evaluate,
1972
+ catch: (cause) => r2Error(binding, operation, cause)
1973
+ });
1974
+ const tryR2Sync = (binding, operation, evaluate) => Effect.try({
1975
+ try: evaluate,
1976
+ catch: (cause) => r2Error(binding, operation, cause)
1977
+ });
1978
+ const maybe = (value) => value === null ? Option.none() : Option.some(value);
1979
+ const isR2Bucket = (value) => {
1980
+ if (typeof value !== "object" || value === null) return false;
1981
+ const resource = value;
1982
+ return typeof resource.head === "function" && typeof resource.get === "function" && typeof resource.put === "function" && typeof resource.createMultipartUpload === "function" && typeof resource.resumeMultipartUpload === "function" && typeof resource.delete === "function" && typeof resource.list === "function";
1983
+ };
1984
+ const makeClient$1 = (definition) => {
1985
+ const wrapUpload = (upload) => ({
1986
+ raw: upload,
1987
+ key: upload.key,
1988
+ uploadId: upload.uploadId,
1989
+ uploadPart: (partNumber, value, options) => tryR2Promise(definition.binding, "uploadPart", () => upload.uploadPart(partNumber, value, options)),
1990
+ abort: tryR2Promise(definition.binding, "abortMultipartUpload", () => upload.abort()),
1991
+ complete: (uploadedParts) => tryR2Promise(definition.binding, "completeMultipartUpload", () => upload.complete([...uploadedParts]))
2023
1992
  });
2024
- const unsafeRaw = Effect.fnUntraced(function* () {
2025
- return yield* (yield* tag).unsafeRaw;
1993
+ return (bucket) => ({
1994
+ definition,
1995
+ head: (key) => tryR2Promise(definition.binding, "head", () => bucket.head(key)).pipe(Effect.map(maybe)),
1996
+ get: ((key, options) => tryR2Promise(definition.binding, "get", () => bucket.get(key, options)).pipe(Effect.map(maybe))),
1997
+ put: ((key, value, options) => tryR2Promise(definition.binding, "put", () => bucket.put(key, value, options)).pipe(Effect.map((object) => {
1998
+ if (object === null) return Option.none();
1999
+ if (options !== void 0 && "onlyIf" in options) return Option.some(object);
2000
+ return object;
2001
+ }))),
2002
+ createMultipartUpload: (key, options) => tryR2Promise(definition.binding, "createMultipartUpload", () => bucket.createMultipartUpload(key, options)).pipe(Effect.map(wrapUpload)),
2003
+ resumeMultipartUpload: (key, uploadId) => tryR2Sync(definition.binding, "resumeMultipartUpload", () => wrapUpload(bucket.resumeMultipartUpload(key, uploadId))),
2004
+ delete: (keys) => {
2005
+ const nativeKeys = typeof keys === "string" ? keys : [...keys];
2006
+ return tryR2Promise(definition.binding, "delete", () => bucket.delete(nativeKeys));
2007
+ },
2008
+ list: (options) => tryR2Promise(definition.binding, "list", () => bucket.list(options)),
2009
+ unsafeRaw: Effect.succeed(bucket)
2026
2010
  });
2011
+ };
2012
+ const layer$1 = (tag, definition) => layer$8(tag, definition.binding, isR2Bucket, makeClient$1(definition));
2013
+ const make$2 = (id) => Tag$2()(id);
2014
+ const Tag$2 = () => (id) => {
2015
+ const tag = Context.Service()(id);
2016
+ const makeLayer = (definition) => layer$1(tag, definition);
2027
2017
  return Object.assign(tag, {
2028
- [TypeId$1]: TypeId$1,
2029
- definition,
2030
- put,
2031
- get,
2032
- getWithMetadata,
2033
- list,
2034
- remove,
2035
- unsafeRaw
2018
+ id,
2019
+ layer: makeLayer
2036
2020
  });
2037
2021
  };
2038
2022
  //#endregion
2039
2023
  //#region src/WorkflowBinding.ts
2040
2024
  var WorkflowBinding_exports = /* @__PURE__ */ __exportAll({
2041
- Service: () => Service,
2042
2025
  WorkflowOperationError: () => WorkflowOperationError,
2043
2026
  WorkflowResultDecodeError: () => WorkflowResultDecodeError,
2044
- make: () => make$2
2027
+ isWorkflow: () => isWorkflow,
2028
+ layer: () => layer,
2029
+ makeClient: () => makeClient
2045
2030
  });
2046
- const TypeId = "effect-cf/WorkflowBinding";
2047
2031
  var WorkflowOperationError = class extends Data.TaggedError("WorkflowOperationError") {};
2048
2032
  var WorkflowResultDecodeError = class extends Data.TaggedError("WorkflowResultDecodeError") {};
2049
2033
  const workflowError = (binding, operation, cause) => new WorkflowOperationError({
@@ -2060,9 +2044,7 @@ const isWorkflow = (value) => {
2060
2044
  const resource = value;
2061
2045
  return typeof resource.create === "function" && typeof resource.createBatch === "function" && typeof resource.get === "function";
2062
2046
  };
2063
- const make$2 = (id, definition) => Service()(id, definition);
2064
- const Service = () => (id, definition) => {
2065
- const tag = Service$6()(id, definition.binding, (value) => isWorkflow(value));
2047
+ const makeClient = (definition) => {
2066
2048
  const encodePayload = Schema.encodeEffect(definition.payload);
2067
2049
  const decodeResult = Schema.decodeUnknownEffect(definition.result);
2068
2050
  const wrapInstance = (raw) => {
@@ -2089,38 +2071,30 @@ const Service = () => (id, definition) => {
2089
2071
  sendEvent: (event) => operation("sendEvent", () => raw.sendEvent(event))
2090
2072
  };
2091
2073
  };
2092
- const create = Effect.fnUntraced(function* (payload, options) {
2093
- const workflow = yield* tag;
2094
- const encoded = yield* encodePayload(payload);
2095
- return wrapInstance(yield* tryWorkflowPromise(definition.binding, "create", () => workflow.create({
2096
- ...options,
2097
- params: encoded
2098
- })));
2099
- });
2100
- const createBatch = Effect.fnUntraced(function* (batch) {
2101
- const workflow = yield* tag;
2102
- const encodedBatch = [];
2103
- for (const item of batch) {
2104
- const { payload, ...options } = item;
2105
- encodedBatch.push({
2074
+ return (workflow) => ({
2075
+ create: Effect.fnUntraced(function* (payload, options) {
2076
+ const encoded = yield* encodePayload(payload);
2077
+ return wrapInstance(yield* tryWorkflowPromise(definition.binding, "create", () => workflow.create({
2106
2078
  ...options,
2107
- params: yield* encodePayload(payload)
2108
- });
2109
- }
2110
- return (yield* tryWorkflowPromise(definition.binding, "createBatch", () => workflow.createBatch(encodedBatch))).map(wrapInstance);
2111
- });
2112
- const get = Effect.fnUntraced(function* (instanceId) {
2113
- const workflow = yield* tag;
2114
- return wrapInstance(yield* tryWorkflowPromise(definition.binding, "get", () => workflow.get(instanceId)));
2115
- });
2116
- return Object.assign(tag, {
2117
- [TypeId]: TypeId,
2118
- binding: definition.binding,
2119
- create,
2120
- createBatch,
2121
- get
2079
+ params: encoded
2080
+ })));
2081
+ }),
2082
+ createBatch: Effect.fnUntraced(function* (batch) {
2083
+ const encodedBatch = [];
2084
+ for (const item of batch) {
2085
+ const { payload, ...options } = item;
2086
+ encodedBatch.push({
2087
+ ...options,
2088
+ params: yield* encodePayload(payload)
2089
+ });
2090
+ }
2091
+ return (yield* tryWorkflowPromise(definition.binding, "createBatch", () => workflow.createBatch(encodedBatch))).map(wrapInstance);
2092
+ }),
2093
+ get: (instanceId) => tryWorkflowPromise(definition.binding, "get", () => workflow.get(instanceId)).pipe(Effect.map(wrapInstance)),
2094
+ unsafeRaw: Effect.succeed(workflow)
2122
2095
  });
2123
2096
  };
2097
+ const layer = (tag, definition) => layer$8(tag, definition.binding, (value) => isWorkflow(value), makeClient(definition));
2124
2098
  //#endregion
2125
2099
  //#region src/WorkflowDefinition.ts
2126
2100
  var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
@@ -2135,32 +2109,40 @@ const makeDefinition = (id, definition) => {
2135
2109
  payload: definition.payload,
2136
2110
  result: definition.result
2137
2111
  };
2138
- return Object.assign(workflowDefinition, {
2139
- make: (layer, options) => make(layer, { run: wrapHandler(workflowDefinition, options.run) }),
2140
- Binding: () => (bindingId, binding) => Service()(bindingId, {
2141
- ...binding,
2142
- payload: definition.payload,
2143
- result: definition.result
2144
- }),
2145
- binding: (bindingId, binding) => Service()(bindingId, {
2146
- ...binding,
2147
- payload: definition.payload,
2148
- result: definition.result
2149
- })
2150
- });
2112
+ return Object.assign(workflowDefinition, { make: (layer, options) => make(layer, { run: wrapHandler(workflowDefinition, options.run) }) });
2151
2113
  };
2152
- const make$1 = makeDefinition;
2114
+ const make$1 = (id, definition) => Tag$1()(id, definition);
2153
2115
  const Tag$1 = () => (id, definition) => {
2154
2116
  const workflowDefinition = makeDefinition(id, definition);
2155
- class WorkflowDefinitionClass {
2156
- static id = workflowDefinition.id;
2157
- static payload = workflowDefinition.payload;
2158
- static result = workflowDefinition.result;
2159
- static make = workflowDefinition.make;
2160
- static Binding = workflowDefinition.Binding;
2161
- static binding = workflowDefinition.binding;
2162
- }
2163
- return WorkflowDefinitionClass;
2117
+ const tag = Context.Service()(id);
2118
+ const layer$9 = (binding) => layer(tag, {
2119
+ ...binding,
2120
+ payload: definition.payload,
2121
+ result: definition.result
2122
+ });
2123
+ const create = Effect.fnUntraced(function* (payload, options) {
2124
+ return yield* (yield* tag).create(payload, options);
2125
+ });
2126
+ const createBatch = Effect.fnUntraced(function* (batch) {
2127
+ return yield* (yield* tag).createBatch(batch);
2128
+ });
2129
+ const get = Effect.fnUntraced(function* (instanceId) {
2130
+ return yield* (yield* tag).get(instanceId);
2131
+ });
2132
+ const unsafeRaw = Effect.fnUntraced(function* () {
2133
+ return yield* (yield* tag).unsafeRaw;
2134
+ });
2135
+ return Object.assign(tag, {
2136
+ id: workflowDefinition.id,
2137
+ payload: workflowDefinition.payload,
2138
+ result: workflowDefinition.result,
2139
+ make: workflowDefinition.make,
2140
+ layer: layer$9,
2141
+ create,
2142
+ createBatch,
2143
+ get,
2144
+ unsafeRaw
2145
+ });
2164
2146
  };
2165
2147
  const Workflow = Tag$1;
2166
2148
  const wrapHandler = (definition, handler) => {
@@ -2246,4 +2228,4 @@ const waitForEvent = (name, options) => Effect.flatMap(WorkflowStep$1.asEffect()
2246
2228
  const Tag = Tag$1;
2247
2229
  const implement = implement$1;
2248
2230
  //#endregion
2249
- export { Binding_exports as Binding, D1_exports as D1, DurableObject_exports as DurableObject, DurableObjectAlarm_exports as DurableObjectAlarm, DurableObjectDefinition_exports as DurableObjectDefinition, DurableObjectNamespace_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_exports as DurableObjectRpcWebSocket, DurableObjectState_exports as DurableObjectState, DurableObjectStorage_exports as DurableObjectStorage, DurableObjectWebSocket_exports as DurableObjectWebSocket, Kv_exports as Kv, Queue_exports as Queue, QueueBinding_exports as QueueBinding, QueueDefinition_exports as QueueDefinition, Rpc_exports as Rpc, RpcDefinition_exports as RpcDefinition, ServiceBinding_exports as ServiceBinding, Worker_exports as Worker, WorkerConfig, WorkerDefinition_exports as WorkerDefinition, WorkerEnvironment, Workflow_exports as Workflow, WorkflowBinding_exports as WorkflowBinding, WorkflowDefinition_exports as WorkflowDefinition };
2231
+ export { Binding_exports as Binding, D1_exports as D1, DurableObject_exports as DurableObject, DurableObjectAlarm_exports as DurableObjectAlarm, DurableObjectDefinition_exports as DurableObjectDefinition, DurableObjectNamespace_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_exports as DurableObjectRpcWebSocket, DurableObjectState_exports as DurableObjectState, DurableObjectStorage_exports as DurableObjectStorage, DurableObjectWebSocket_exports as DurableObjectWebSocket, Hyperdrive_exports as Hyperdrive, Images_exports as Images, Kv_exports as Kv, Queue_exports as Queue, QueueBinding_exports as QueueBinding, QueueDefinition_exports as QueueDefinition, R2_exports as R2, Rpc_exports as Rpc, RpcDefinition_exports as RpcDefinition, ServiceBinding_exports as ServiceBinding, Worker_exports as Worker, WorkerConfig, WorkerDefinition_exports as WorkerDefinition, WorkerEnvironment, Workflow_exports as Workflow, WorkflowBinding_exports as WorkflowBinding, WorkflowDefinition_exports as WorkflowDefinition };