effect-cf 0.7.0 → 0.9.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,103 +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$2,
33
- TypeId: () => TypeId$2,
34
- layer: () => layer$6
35
- });
36
- /** Internal type id marker used by binding helper services. */
37
- const TypeId$2 = "effect-cf/Binding";
38
- /** Error raised when a configured binding does not exist on `env`. */
39
- var BindingNotFoundError = class extends Data.TaggedError("BindingNotFoundError") {};
40
- /** Error raised when a binding exists but does not match the expected shape. */
41
- var BindingValidationError = class extends Data.TaggedError("BindingValidationError") {};
42
- const isPropertyTarget$1 = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
43
- const getBinding = (env, binding, isResource) => Effect.gen(function* () {
44
- if (!isPropertyTarget$1(env)) return yield* Effect.fail(new BindingValidationError({ binding }));
45
- const resource = Reflect.get(env, binding);
46
- if (resource === void 0) return yield* Effect.fail(new BindingNotFoundError({ binding }));
47
- if (!isResource(resource)) return yield* Effect.fail(new BindingValidationError({ binding }));
48
- return resource;
49
- });
50
- const layer$6 = (tag, binding, isResource, wrap) => Layer.effect(tag, Effect.gen(function* () {
51
- const resource = yield* getBinding(yield* WorkerEnvironment, binding, isResource);
52
- return wrap === void 0 ? resource : wrap(resource);
53
- }));
54
- const Service$2 = () => (id, binding, isResource, wrap) => {
55
- const tag = Context.Service()(id);
56
- const serviceLayer = layer$6(tag, binding, isResource, wrap);
57
- return Object.assign(tag, {
58
- [TypeId$2]: TypeId$2,
59
- binding,
60
- layer: serviceLayer
61
- });
62
- };
63
- //#endregion
64
10
  //#region src/D1.ts
65
11
  var D1_exports = /* @__PURE__ */ __exportAll({
66
- D1OperationError: () => D1OperationError,
67
12
  Service: () => Service$1,
68
- make: () => make$8
13
+ make: () => make$10
69
14
  });
70
- const TypeId$1 = "effect-cf/D1";
71
- /** Error raised when a D1 operation fails. */
72
- var D1OperationError = class extends Data.TaggedError("D1OperationError") {};
15
+ const TypeId$2 = "effect-cf/D1";
73
16
  const isD1Database = (value) => {
74
17
  if (typeof value !== "object" || value === null) return false;
75
18
  const resource = value;
76
19
  return typeof resource.prepare === "function" && typeof resource.batch === "function" && typeof resource.exec === "function";
77
20
  };
78
- const d1Error = (binding, operation, cause) => new D1OperationError({
79
- binding,
80
- operation,
81
- cause
82
- });
83
- const tryD1Promise = (binding, operation, evaluate) => Effect.tryPromise({
84
- try: evaluate,
85
- catch: (cause) => d1Error(binding, operation, cause)
86
- });
87
- const tryD1Sync = (binding, operation, evaluate) => Effect.try({
88
- try: evaluate,
89
- catch: (cause) => d1Error(binding, operation, cause)
90
- });
91
21
  /**
92
22
  * Creates a typed D1 service tag plus Effect helpers.
93
23
  */
94
- const make$8 = (id, definition) => Service$1()(id, definition);
24
+ const make$10 = (id, definition) => Service$1()(id, definition);
95
25
  /**
96
26
  * Builds a D1 service around a Cloudflare D1 database binding.
97
27
  *
98
- * The returned service exposes the raw `D1Database` binding, small native D1
99
- * helpers, and `sqlLayer(...)` for providing `effect/unstable/sql` via
100
- * `@effect/sql-d1`.
28
+ * The returned service exposes the raw `D1Database` binding and `sqlLayer(...)`
29
+ * for providing `effect/unstable/sql` via `@effect/sql-d1`.
101
30
  *
102
31
  * @example
103
32
  * ```ts
@@ -117,29 +46,10 @@ const Service$1 = () => (id, definition) => {
117
46
  db
118
47
  });
119
48
  })).pipe(Layer.provide(tag.layer));
120
- const prepare = Effect.fnUntraced(function* (query) {
121
- const db = yield* tag;
122
- return yield* tryD1Sync(definition.binding, "prepare", () => db.prepare(query));
123
- });
124
- const batch = Effect.fnUntraced(function* (statements) {
125
- const db = yield* tag;
126
- return yield* tryD1Promise(definition.binding, "batch", () => db.batch([...statements]));
127
- });
128
- const exec = Effect.fnUntraced(function* (query) {
129
- const db = yield* tag;
130
- return yield* tryD1Promise(definition.binding, "exec", () => db.exec(query));
131
- });
132
- const unsafeRaw = Effect.fnUntraced(function* () {
133
- return yield* tag;
134
- });
135
49
  return Object.assign(tag, {
136
- [TypeId$1]: TypeId$1,
50
+ [TypeId$2]: TypeId$2,
137
51
  definition,
138
- sqlLayer,
139
- prepare,
140
- batch,
141
- exec,
142
- unsafeRaw
52
+ sqlLayer
143
53
  });
144
54
  };
145
55
  //#endregion
@@ -147,8 +57,8 @@ const Service$1 = () => (id, definition) => {
147
57
  var QueueBinding_exports = /* @__PURE__ */ __exportAll({
148
58
  QueueOperationError: () => QueueOperationError,
149
59
  isQueue: () => isQueue,
150
- layer: () => layer$5,
151
- makeClient: () => makeClient$4
60
+ layer: () => layer$7,
61
+ makeClient: () => makeClient$6
152
62
  });
153
63
  var QueueOperationError = class extends Data.TaggedError("QueueOperationError") {};
154
64
  const queueError = (binding, operation, cause) => new QueueOperationError({
@@ -165,7 +75,7 @@ const isQueue = (value) => {
165
75
  const resource = value;
166
76
  return typeof resource.send === "function" && typeof resource.sendBatch === "function" && typeof resource.metrics === "function";
167
77
  };
168
- const makeClient$4 = (definition) => {
78
+ const makeClient$6 = (definition) => {
169
79
  const encodeMessage = Schema.encodeEffect(definition.message);
170
80
  return (queue) => ({
171
81
  send: Effect.fnUntraced(function* (message, options) {
@@ -184,30 +94,30 @@ const makeClient$4 = (definition) => {
184
94
  unsafeRaw: Effect.succeed(queue)
185
95
  });
186
96
  };
187
- const layer$5 = (tag, definition) => layer$6(tag, definition.binding, (value) => isQueue(value), makeClient$4(definition));
97
+ const layer$7 = (tag, definition) => layer$8(tag, definition.binding, (value) => isQueue(value), makeClient$6(definition));
188
98
  //#endregion
189
99
  //#region src/QueueDefinition.ts
190
100
  var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
191
101
  Queue: () => Queue$1,
192
- Tag: () => Tag$8,
102
+ Tag: () => Tag$10,
193
103
  implement: () => implement$7,
194
- make: () => make$7
104
+ make: () => make$9
195
105
  });
196
106
  const makeDefinition$4 = (id, definition) => {
197
107
  const queueDefinition = {
198
108
  id,
199
109
  message: definition.message
200
110
  };
201
- return Object.assign(queueDefinition, { make: (layer, options) => make$4(layer, {
111
+ return Object.assign(queueDefinition, { make: (layer, options) => make$6(layer, {
202
112
  ...options,
203
113
  queue: wrapHandler$1(queueDefinition, options.queue)
204
114
  }) });
205
115
  };
206
- const make$7 = (id, definition) => Tag$8()(id, definition);
207
- const Tag$8 = () => (id, definition) => {
116
+ const make$9 = (id, definition) => Tag$10()(id, definition);
117
+ const Tag$10 = () => (id, definition) => {
208
118
  const queueDefinition = makeDefinition$4(id, definition);
209
119
  const tag = Context.Service()(id);
210
- const layer = (binding) => layer$5(tag, {
120
+ const layer = (binding) => layer$7(tag, {
211
121
  ...binding,
212
122
  message: definition.message
213
123
  });
@@ -234,7 +144,7 @@ const Tag$8 = () => (id, definition) => {
234
144
  unsafeRaw
235
145
  });
236
146
  };
237
- const Queue$1 = Tag$8;
147
+ const Queue$1 = Tag$10;
238
148
  const wrapHandler$1 = (definition, handler) => {
239
149
  const decodeBody = Schema.decodeUnknownEffect(definition.message);
240
150
  return (batch) => Effect.gen(function* () {
@@ -246,7 +156,7 @@ const implement$7 = (_definition, handler) => handler;
246
156
  //#region src/Queue.ts
247
157
  var Queue_exports = /* @__PURE__ */ __exportAll({
248
158
  QueueMessageDecodeError: () => QueueMessageDecodeError,
249
- Tag: () => Tag$7,
159
+ Tag: () => Tag$9,
250
160
  decodeBatch: () => decodeBatch,
251
161
  fromMessage: () => fromMessage,
252
162
  fromMessageBatch: () => fromMessageBatch,
@@ -284,7 +194,7 @@ const decodeBatch = (batch, decodeBody) => Effect.gen(function* () {
284
194
  }
285
195
  return fromMessageBatch(batch, messages);
286
196
  });
287
- const Tag$7 = Tag$8;
197
+ const Tag$9 = Tag$10;
288
198
  const implement$6 = implement$7;
289
199
  //#endregion
290
200
  //#region src/RpcDefinition.ts
@@ -302,7 +212,7 @@ var RpcDefinition_exports = /* @__PURE__ */ __exportAll({
302
212
  decodeSuccess: () => decodeSuccess,
303
213
  encodeArgs: () => encodeArgs,
304
214
  encodeSuccess: () => encodeSuccess,
305
- make: () => make$6,
215
+ make: () => make$8,
306
216
  method: () => method$4,
307
217
  reservedMethodNames: () => reservedMethodNames$4
308
218
  });
@@ -405,7 +315,7 @@ const decodeSuccess = (definition, methodName, value) => {
405
315
  cause
406
316
  })));
407
317
  };
408
- const make$6 = (id, methods) => {
318
+ const make$8 = (id, methods) => {
409
319
  const definition = {
410
320
  id,
411
321
  methods
@@ -463,11 +373,11 @@ var ServiceBinding_exports = /* @__PURE__ */ __exportAll({
463
373
  ServiceBindingFetchError: () => ServiceBindingFetchError,
464
374
  ServiceBindingRpcError: () => ServiceBindingRpcError,
465
375
  isServiceBindingClient: () => isServiceBindingClient,
466
- layer: () => layer$4,
467
- makeClient: () => makeClient$3,
376
+ layer: () => layer$6,
377
+ makeClient: () => makeClient$5,
468
378
  makeDirectMethods: () => makeDirectMethods$1
469
379
  });
470
- const TypeId = "effect-cf/ServiceBinding";
380
+ const TypeId$1 = "effect-cf/ServiceBinding";
471
381
  /**
472
382
  * Failure raised when calling `fetch` on a service binding.
473
383
  */
@@ -477,7 +387,7 @@ var ServiceBindingFetchError = class extends Data.TaggedError("ServiceBindingFet
477
387
  */
478
388
  var ServiceBindingRpcError = class extends Data.TaggedError("ServiceBindingRpcError") {};
479
389
  const isServiceBindingClient = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "fetch") === "function";
480
- const makeClient$3 = (definition) => {
390
+ const makeClient$5 = (definition) => {
481
391
  return (service) => {
482
392
  const fetch = (input, init) => Effect.tryPromise({
483
393
  try: () => service.fetch(input, init),
@@ -526,7 +436,7 @@ const makeClient$3 = (definition) => {
526
436
  });
527
437
  };
528
438
  };
529
- const layer$4 = (tag, definition) => layer$6(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$3(definition));
439
+ const layer$6 = (tag, definition) => layer$8(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$5(definition));
530
440
  /**
531
441
  * Creates a typed Effect service for a Worker service binding.
532
442
  *
@@ -557,7 +467,7 @@ const layer$4 = (tag, definition) => layer$6(tag, definition.binding, (value) =>
557
467
  * ```
558
468
  */
559
469
  const Service = () => (id, definition) => {
560
- const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$3(definition));
470
+ const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$5(definition));
561
471
  const fetch = (input, init) => Effect.gen(function* () {
562
472
  return yield* (yield* tag).fetch(input, init);
563
473
  });
@@ -572,7 +482,7 @@ const Service = () => (id, definition) => {
572
482
  });
573
483
  const directMethods = makeDirectMethods$1(definition.definition, call);
574
484
  return Object.assign(tag, directMethods, {
575
- [TypeId]: TypeId,
485
+ [TypeId$1]: TypeId$1,
576
486
  definition,
577
487
  fetch,
578
488
  rpc,
@@ -588,10 +498,10 @@ const makeDirectMethods$1 = (rpcDefinition, call) => {
588
498
  //#endregion
589
499
  //#region src/WorkerDefinition.ts
590
500
  var WorkerDefinition_exports = /* @__PURE__ */ __exportAll({
591
- Tag: () => Tag$6,
501
+ Tag: () => Tag$8,
592
502
  Worker: () => Worker,
593
503
  implement: () => implement$5,
594
- make: () => make$5,
504
+ make: () => make$7,
595
505
  method: () => method$3
596
506
  });
597
507
  const reservedMethodNames$3 = new Set([
@@ -629,21 +539,21 @@ const method$3 = method$4;
629
539
  */
630
540
  const makeDefinition$3 = (id, methods) => {
631
541
  assertNoReservedMethods("Worker", methods, reservedMethodNames$3);
632
- const definition = make$6(id, methods);
633
- return Object.assign(definition, { make: (layer, options) => make$4(layer, {
542
+ const definition = make$8(id, methods);
543
+ return Object.assign(definition, { make: (layer, options) => make$6(layer, {
634
544
  ...options,
635
545
  rpc: wrapHandlers$1(definition, options.rpc)
636
546
  }) });
637
547
  };
638
- const make$5 = (id, methods) => Tag$6()(id, methods);
639
- const Tag$6 = () => (id, methods) => {
548
+ const make$7 = (id, methods) => Tag$8()(id, methods);
549
+ const Tag$8 = () => (id, methods) => {
640
550
  const definition = makeDefinition$3(id, methods);
641
551
  const tag = Context.Service()(id);
642
552
  const bindingDefinition = (binding) => ({
643
553
  ...binding,
644
554
  definition
645
555
  });
646
- const layer = (binding) => layer$4(tag, bindingDefinition(binding));
556
+ const layer = (binding) => layer$6(tag, bindingDefinition(binding));
647
557
  const fetch = (input, init) => Effect.gen(function* () {
648
558
  return yield* (yield* tag).fetch(input, init);
649
559
  });
@@ -668,7 +578,7 @@ const Tag$6 = () => (id, methods) => {
668
578
  scopedCall
669
579
  });
670
580
  };
671
- const Worker = Tag$6;
581
+ const Worker = Tag$8;
672
582
  const wrapHandlers$1 = (definition, handlers) => {
673
583
  const wrapped = {};
674
584
  for (const key of Object.keys(definition.methods)) {
@@ -724,11 +634,11 @@ const fromExecutionContext = (ctx, runPromiseExit) => {
724
634
  var Worker_exports = /* @__PURE__ */ __exportAll({
725
635
  ExecutionContext: () => ExecutionContext,
726
636
  NativeRequest: () => NativeRequest,
727
- Tag: () => Tag$5,
637
+ Tag: () => Tag$7,
728
638
  WorkerContext: () => WorkerContext,
729
639
  implement: () => implement$4,
730
640
  isWebSocketUpgrade: () => isWebSocketUpgrade,
731
- make: () => make$4,
641
+ make: () => make$6,
732
642
  makeFetchHandler: () => makeFetchHandler,
733
643
  method: () => method$2,
734
644
  renderHttpResponse: () => renderHttpResponse
@@ -757,7 +667,7 @@ const RunSymbol$1 = Symbol.for("effect-cf/Worker/run");
757
667
  const renderHttpResponse = (effect) => Effect.flatMap(effect, (response) => Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
758
668
  const renderFetchSuccess = (effect) => Effect.flatMap(effect, (response) => response instanceof Response ? Effect.succeed(response) : Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
759
669
  const isWorkerOptions = (options) => typeof options === "object" && options !== null && ("fetch" in options || "queue" in options || "rpc" in options);
760
- function make$4(layer, optionsOrFetch) {
670
+ function make$6(layer, optionsOrFetch) {
761
671
  const options = isWorkerOptions(optionsOrFetch) ? optionsOrFetch : { fetch: optionsOrFetch };
762
672
  class EffectWorker extends WorkerEntrypoint {
763
673
  runtime;
@@ -788,10 +698,10 @@ function make$4(layer, optionsOrFetch) {
788
698
  return assumeEntrypointClass(EffectWorker);
789
699
  }
790
700
  const makeFetchHandler = (layer, options) => {
791
- const WorkerClass = make$4(layer, options);
701
+ const WorkerClass = make$6(layer, options);
792
702
  return { fetch: (request, env, ctx) => Promise.resolve(new WorkerClass(ctx, env).fetch(request)) };
793
703
  };
794
- const Tag$5 = Tag$6;
704
+ const Tag$7 = Tag$8;
795
705
  const method$2 = method$3;
796
706
  const implement$4 = implement$5;
797
707
  //#endregion
@@ -1089,8 +999,8 @@ var DurableObjectNamespace_exports = /* @__PURE__ */ __exportAll({
1089
999
  DurableObjectFetchError: () => DurableObjectFetchError,
1090
1000
  DurableObjectRpcError: () => DurableObjectRpcError,
1091
1001
  isDurableObjectNamespaceClient: () => isDurableObjectNamespaceClient,
1092
- layer: () => layer$3,
1093
- makeClient: () => makeClient$2,
1002
+ layer: () => layer$5,
1003
+ makeClient: () => makeClient$4,
1094
1004
  makeDirectMethods: () => makeDirectMethods
1095
1005
  });
1096
1006
  /**
@@ -1101,9 +1011,9 @@ var DurableObjectRpcError = class extends Data.TaggedError("DurableObjectRpcErro
1101
1011
  * Failure raised when forwarding a request to a Durable Object stub.
1102
1012
  */
1103
1013
  var DurableObjectFetchError = class extends Data.TaggedError("DurableObjectFetchError") {};
1104
- const hasFunction = (value, key) => typeof Reflect.get(value, key) === "function";
1105
- 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");
1106
- const makeClient$2 = (definition) => {
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) => {
1107
1017
  return (namespace) => {
1108
1018
  const newUniqueId = (options) => Effect.sync(() => namespace.newUniqueId(options));
1109
1019
  const idFromName = (name) => Effect.sync(() => namespace.idFromName(name));
@@ -1170,7 +1080,7 @@ const makeClient$2 = (definition) => {
1170
1080
  });
1171
1081
  };
1172
1082
  };
1173
- const layer$3 = (tag, definition) => layer$6(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$2(definition));
1083
+ const layer$5 = (tag, definition) => layer$8(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$4(definition));
1174
1084
  const makeDirectMethods = (rpcDefinition, helpers) => {
1175
1085
  const methods = {};
1176
1086
  if (rpcDefinition !== void 0) {
@@ -1195,9 +1105,9 @@ const makeDirectMethods = (rpcDefinition, helpers) => {
1195
1105
  //#region src/DurableObjectDefinition.ts
1196
1106
  var DurableObjectDefinition_exports = /* @__PURE__ */ __exportAll({
1197
1107
  DurableObject: () => DurableObject$1,
1198
- Tag: () => Tag$4,
1108
+ Tag: () => Tag$6,
1199
1109
  implement: () => implement$3,
1200
- make: () => make$3,
1110
+ make: () => make$5,
1201
1111
  method: () => method$1
1202
1112
  });
1203
1113
  const reservedMethodNames$1 = new Set([
@@ -1228,21 +1138,21 @@ const method$1 = method$4;
1228
1138
  */
1229
1139
  const makeDefinition$2 = (id, methods) => {
1230
1140
  assertNoReservedMethods("Durable Object", methods, reservedMethodNames$1);
1231
- const definition = make$6(id, methods);
1232
- return Object.assign(definition, { make: (layer, options) => make$2(layer, {
1141
+ const definition = make$8(id, methods);
1142
+ return Object.assign(definition, { make: (layer, options) => make$4(layer, {
1233
1143
  ...options,
1234
1144
  rpc: wrapHandlers(definition, options.rpc)
1235
1145
  }) });
1236
1146
  };
1237
- const make$3 = (id, methods) => Tag$4()(id, methods);
1238
- const Tag$4 = () => (id, methods) => {
1147
+ const make$5 = (id, methods) => Tag$6()(id, methods);
1148
+ const Tag$6 = () => (id, methods) => {
1239
1149
  const definition = makeDefinition$2(id, methods);
1240
1150
  const tag = Context.Service()(id);
1241
1151
  const bindingDefinition = (binding) => ({
1242
1152
  ...binding,
1243
1153
  definition
1244
1154
  });
1245
- const layer = (binding) => layer$3(tag, bindingDefinition(binding));
1155
+ const layer = (binding) => layer$5(tag, bindingDefinition(binding));
1246
1156
  const newUniqueId = Effect.fnUntraced(function* (options) {
1247
1157
  return yield* (yield* tag).newUniqueId(options);
1248
1158
  });
@@ -1300,7 +1210,7 @@ const Tag$4 = () => (id, methods) => {
1300
1210
  unsafeRaw
1301
1211
  });
1302
1212
  };
1303
- const DurableObject$1 = Tag$4;
1213
+ const DurableObject$1 = Tag$6;
1304
1214
  const wrapHandlers = (definition, handlers) => {
1305
1215
  const wrapped = {};
1306
1216
  for (const key of Object.keys(definition.methods)) {
@@ -1318,9 +1228,9 @@ const implement$3 = (_definition, handlers) => handlers;
1318
1228
  //#endregion
1319
1229
  //#region src/DurableObject.ts
1320
1230
  var DurableObject_exports = /* @__PURE__ */ __exportAll({
1321
- Tag: () => Tag$3,
1231
+ Tag: () => Tag$5,
1322
1232
  implement: () => implement$2,
1323
- make: () => make$2,
1233
+ make: () => make$4,
1324
1234
  method: () => method
1325
1235
  });
1326
1236
  const reservedMethodNames = new Set([
@@ -1336,13 +1246,15 @@ const RunSymbol = Symbol.for("effect-cf/DurableObject/run");
1336
1246
  /**
1337
1247
  * Creates a Durable Object class backed by a single managed Effect runtime.
1338
1248
  */
1339
- const make$2 = (layer, options = {}) => {
1249
+ const make$4 = (layer, options = {}) => {
1340
1250
  class EffectDurableObject extends DurableObject {
1341
1251
  runtime;
1342
1252
  constructor(state, env) {
1343
1253
  super(state, env);
1344
1254
  const runtimeLayer = provideEntrypointServices(layer, Layer.mergeAll(Layer.succeed(DurableObjectState, fromDurableObjectState(state)), Layer.succeed(WorkerEnvironment, env)));
1345
1255
  this.runtime = ManagedRuntime.make(runtimeLayer);
1256
+ const initialize = options.initialize;
1257
+ if (initialize !== void 0) state.waitUntil(this[RunSymbol](initialize));
1346
1258
  }
1347
1259
  [RunSymbol](effect) {
1348
1260
  return this.runtime.runPromise(Effect.scoped(effect));
@@ -1375,7 +1287,7 @@ const make$2 = (layer, options = {}) => {
1375
1287
  defineEntrypointRpcMethods("Durable Object", EffectDurableObject.prototype, options.rpc, reservedMethodNames, (self, effect) => self[RunSymbol](effect));
1376
1288
  return assumeEntrypointClass(EffectDurableObject);
1377
1289
  };
1378
- const Tag$3 = Tag$4;
1290
+ const Tag$5 = Tag$6;
1379
1291
  const method = method$1;
1380
1292
  const implement$2 = implement$3;
1381
1293
  //#endregion
@@ -1704,7 +1616,7 @@ var DurableObjectAlarm = class DurableObjectAlarm extends Context.Service()("eff
1704
1616
  //#region src/DurableObjectRpcWebSocket.ts
1705
1617
  var DurableObjectRpcWebSocket_exports = /* @__PURE__ */ __exportAll({
1706
1618
  DurableObjectRpcWebSocket: () => DurableObjectRpcWebSocket,
1707
- layer: () => layer$2
1619
+ layer: () => layer$4
1708
1620
  });
1709
1621
  const defaultAttachmentKey = "effectCloudflareRpcClientId";
1710
1622
  const defaultTag = "effect-cf-rpc";
@@ -1715,7 +1627,7 @@ var DurableObjectRpcWebSocket = class extends Context.Service()("effect-cf/Durab
1715
1627
  /**
1716
1628
  * Builds a layer that bridges Durable Object websocket events to `RpcServer.Protocol`.
1717
1629
  */
1718
- const layer$2 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
1630
+ const layer$4 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
1719
1631
  const tag = options.tag ?? defaultTag;
1720
1632
  const attachmentKey = options.attachmentKey ?? defaultAttachmentKey;
1721
1633
  const durableObjectState = yield* DurableObjectState;
@@ -1827,13 +1739,119 @@ const writeAttachment = (socket, key, clientId) => {
1827
1739
  });
1828
1740
  };
1829
1741
  //#endregion
1742
+ //#region src/Images.ts
1743
+ var Images_exports = /* @__PURE__ */ __exportAll({
1744
+ ImagesOperationError: () => ImagesOperationError,
1745
+ Tag: () => Tag$4,
1746
+ draw: () => draw,
1747
+ empty: () => empty,
1748
+ isImagesBinding: () => isImagesBinding,
1749
+ layer: () => layer$3,
1750
+ make: () => make$3,
1751
+ makeClient: () => makeClient$3,
1752
+ transform: () => transform
1753
+ });
1754
+ const TypeId = "effect-cf/Images/Steps";
1755
+ /** Error raised when a Cloudflare Images operation fails. */
1756
+ var ImagesOperationError = class extends Data.TaggedError("ImagesOperationError") {};
1757
+ const makeSteps = (steps) => ({
1758
+ [TypeId]: TypeId,
1759
+ steps
1760
+ });
1761
+ /** Empty Images transformation pipeline. */
1762
+ const empty = makeSteps([]);
1763
+ function transform(stepsOrTransform, transformValue) {
1764
+ if (transformValue === void 0) return (steps) => transform(steps, stepsOrTransform);
1765
+ return makeSteps([...stepsOrTransform.steps, {
1766
+ _tag: "Transform",
1767
+ transform: transformValue
1768
+ }]);
1769
+ }
1770
+ function draw(stepsOrDraw, drawValue) {
1771
+ if (drawValue === void 0) return (steps) => draw(steps, stepsOrDraw);
1772
+ return makeSteps([...stepsOrDraw.steps, {
1773
+ _tag: "Draw",
1774
+ ...drawValue
1775
+ }]);
1776
+ }
1777
+ const imagesError = (binding, operation, cause) => new ImagesOperationError({
1778
+ binding,
1779
+ operation,
1780
+ cause
1781
+ });
1782
+ const tryImagesPromise = (binding, operation, evaluate) => Effect.tryPromise({
1783
+ try: evaluate,
1784
+ catch: (cause) => imagesError(binding, operation, cause)
1785
+ });
1786
+ const tryImagesSync = (binding, operation, evaluate) => Effect.try({
1787
+ try: evaluate,
1788
+ catch: (cause) => imagesError(binding, operation, cause)
1789
+ });
1790
+ const maybe$1 = (value) => value === null ? Option.none() : Option.some(value);
1791
+ const hasFunction = (value, key) => typeof Reflect.get(value, key) === "function";
1792
+ const isHostedImagesBinding = (value) => typeof value === "object" && value !== null && hasFunction(value, "image") && hasFunction(value, "upload") && hasFunction(value, "list");
1793
+ const isImagesBinding = (value) => typeof value === "object" && value !== null && hasFunction(value, "info") && hasFunction(value, "input");
1794
+ const wrapResult = (binding, result) => ({
1795
+ raw: result,
1796
+ response: tryImagesSync(binding, "response", () => result.response()),
1797
+ contentType: tryImagesSync(binding, "contentType", () => result.contentType()),
1798
+ image: (options) => tryImagesSync(binding, "image", () => result.image(options))
1799
+ });
1800
+ const wrapHandle = (binding, handle) => ({
1801
+ raw: handle,
1802
+ details: tryImagesPromise(binding, "details", () => handle.details()).pipe(Effect.map(maybe$1)),
1803
+ bytes: tryImagesPromise(binding, "bytes", () => handle.bytes()).pipe(Effect.map(maybe$1)),
1804
+ update: (options) => tryImagesPromise(binding, "update", () => handle.update(options)),
1805
+ delete: tryImagesPromise(binding, "delete", () => handle.delete())
1806
+ });
1807
+ const wrapHosted = (binding, hosted) => ({
1808
+ image: (imageId) => wrapHandle(binding, hosted.image(imageId)),
1809
+ upload: (image, options) => tryImagesPromise(binding, "upload", () => hosted.upload(image, options)),
1810
+ list: (options) => tryImagesPromise(binding, "list", () => hosted.list(options)),
1811
+ unsafeRaw: Effect.succeed(hosted)
1812
+ });
1813
+ const makeClient$3 = (definition) => (images) => {
1814
+ const input = (image, options) => tryImagesSync(definition.binding, "input", () => images.input(image, options));
1815
+ const process = (steps, options) => Effect.gen(function* () {
1816
+ let transformer = yield* input(options.stream, options.inputOptions);
1817
+ for (const step of steps.steps) switch (step._tag) {
1818
+ case "Draw":
1819
+ transformer = yield* tryImagesSync(definition.binding, "draw", () => transformer.draw(step.image, step.options));
1820
+ break;
1821
+ case "Transform":
1822
+ transformer = yield* tryImagesSync(definition.binding, "transform", () => transformer.transform(step.transform));
1823
+ break;
1824
+ }
1825
+ const result = yield* tryImagesPromise(definition.binding, "output", () => transformer.output(options.outputOptions));
1826
+ return wrapResult(definition.binding, result);
1827
+ });
1828
+ return {
1829
+ definition,
1830
+ info: (image, options) => tryImagesPromise(definition.binding, "info", () => images.info(image, options)),
1831
+ input,
1832
+ process,
1833
+ hosted: isHostedImagesBinding(images.hosted) ? Option.some(wrapHosted(definition.binding, images.hosted)) : Option.none(),
1834
+ unsafeRaw: Effect.succeed(images)
1835
+ };
1836
+ };
1837
+ const layer$3 = (tag, definition) => layer$8(tag, definition.binding, isImagesBinding, makeClient$3(definition));
1838
+ const make$3 = (id) => Tag$4()(id);
1839
+ const Tag$4 = () => (id) => {
1840
+ const tag = Context.Service()(id);
1841
+ const makeLayer = (definition) => layer$3(tag, definition);
1842
+ return Object.assign(tag, {
1843
+ id,
1844
+ layer: makeLayer
1845
+ });
1846
+ };
1847
+ //#endregion
1830
1848
  //#region src/Kv.ts
1831
1849
  var Kv_exports = /* @__PURE__ */ __exportAll({
1832
1850
  KvOperationError: () => KvOperationError,
1833
- Tag: () => Tag$2,
1851
+ Tag: () => Tag$3,
1834
1852
  isKvNamespace: () => isKvNamespace,
1835
- layer: () => layer$1,
1836
- makeClient: () => makeClient$1
1853
+ layer: () => layer$2,
1854
+ makeClient: () => makeClient$2
1837
1855
  });
1838
1856
  /** Error raised when a KV operation fails. */
1839
1857
  var KvOperationError = class extends Data.TaggedError("KvOperationError") {};
@@ -1853,7 +1871,7 @@ const isKvNamespace = (value) => {
1853
1871
  const resource = value;
1854
1872
  return typeof resource.get === "function" && typeof resource.put === "function" && typeof resource.delete === "function" && typeof resource.getWithMetadata === "function" && typeof resource.list === "function";
1855
1873
  };
1856
- const makeClient$1 = (definition) => {
1874
+ const makeClient$2 = (definition) => {
1857
1875
  const encodeKey = Schema.encodeEffect(definition.key);
1858
1876
  const decodeKey = Schema.decodeUnknownEffect(definition.key);
1859
1877
  const encodeValue = Schema.encodeEffect(Schema.fromJsonString(Schema.toCodecJson(definition.value)));
@@ -1910,52 +1928,97 @@ const makeClient$1 = (definition) => {
1910
1928
  unsafeRaw: Effect.succeed(kv)
1911
1929
  });
1912
1930
  };
1913
- const layer$1 = (tag, definition) => layer$6(tag, definition.binding, isKvNamespace, makeClient$1(definition));
1931
+ const layer$2 = (tag, definition) => layer$8(tag, definition.binding, isKvNamespace, makeClient$2(definition));
1914
1932
  const makeDefinition$1 = (id, definition) => {
1915
1933
  const kvDefinition = {
1916
1934
  id,
1917
1935
  key: definition.key,
1918
1936
  value: definition.value
1919
1937
  };
1920
- return Object.assign(kvDefinition, { layer: (tag, binding) => layer$1(tag, {
1938
+ return Object.assign(kvDefinition, { layer: (tag, binding) => layer$2(tag, {
1921
1939
  ...binding,
1922
1940
  key: definition.key,
1923
1941
  value: definition.value
1924
1942
  }) });
1925
1943
  };
1926
- const Tag$2 = () => (id, definition) => {
1944
+ const Tag$3 = () => (id, definition) => {
1927
1945
  const kvDefinition = makeDefinition$1(id, definition);
1928
1946
  const tag = Context.Service()(id);
1929
1947
  const makeLayer = (binding) => kvDefinition.layer(tag, binding);
1930
- const put = Effect.fnUntraced(function* (key, value, options) {
1931
- yield* (yield* tag).put(key, value, options);
1932
- });
1933
- const get = Effect.fnUntraced(function* (key) {
1934
- return yield* (yield* tag).get(key);
1935
- });
1936
- const getWithMetadata = Effect.fnUntraced(function* (key, metadataSchema) {
1937
- return yield* (yield* tag).getWithMetadata(key, metadataSchema);
1938
- });
1939
- const list = Effect.fnUntraced(function* (options) {
1940
- return yield* (yield* tag).list(options);
1941
- });
1942
- const remove = Effect.fnUntraced(function* (key) {
1943
- yield* (yield* tag).remove(key);
1944
- });
1945
- const unsafeRaw = Effect.fnUntraced(function* () {
1946
- return yield* (yield* tag).unsafeRaw;
1947
- });
1948
1948
  return Object.assign(tag, {
1949
1949
  id: kvDefinition.id,
1950
1950
  keySchema: kvDefinition.key,
1951
1951
  valueSchema: kvDefinition.value,
1952
- layer: makeLayer,
1953
- put,
1954
- get,
1955
- getWithMetadata,
1956
- list,
1957
- remove,
1958
- unsafeRaw
1952
+ layer: makeLayer
1953
+ });
1954
+ };
1955
+ //#endregion
1956
+ //#region src/R2.ts
1957
+ var R2_exports = /* @__PURE__ */ __exportAll({
1958
+ R2OperationError: () => R2OperationError,
1959
+ Tag: () => Tag$2,
1960
+ isR2Bucket: () => isR2Bucket,
1961
+ layer: () => layer$1,
1962
+ make: () => make$2,
1963
+ makeClient: () => makeClient$1
1964
+ });
1965
+ /** Error raised when an R2 operation fails. */
1966
+ var R2OperationError = class extends Data.TaggedError("R2OperationError") {};
1967
+ const r2Error = (binding, operation, cause) => new R2OperationError({
1968
+ binding,
1969
+ operation,
1970
+ cause
1971
+ });
1972
+ const tryR2Promise = (binding, operation, evaluate) => Effect.tryPromise({
1973
+ try: evaluate,
1974
+ catch: (cause) => r2Error(binding, operation, cause)
1975
+ });
1976
+ const tryR2Sync = (binding, operation, evaluate) => Effect.try({
1977
+ try: evaluate,
1978
+ catch: (cause) => r2Error(binding, operation, cause)
1979
+ });
1980
+ const maybe = (value) => value === null ? Option.none() : Option.some(value);
1981
+ const isR2Bucket = (value) => {
1982
+ if (typeof value !== "object" || value === null) return false;
1983
+ const resource = value;
1984
+ 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";
1985
+ };
1986
+ const makeClient$1 = (definition) => {
1987
+ const wrapUpload = (upload) => ({
1988
+ raw: upload,
1989
+ key: upload.key,
1990
+ uploadId: upload.uploadId,
1991
+ uploadPart: (partNumber, value, options) => tryR2Promise(definition.binding, "uploadPart", () => upload.uploadPart(partNumber, value, options)),
1992
+ abort: tryR2Promise(definition.binding, "abortMultipartUpload", () => upload.abort()),
1993
+ complete: (uploadedParts) => tryR2Promise(definition.binding, "completeMultipartUpload", () => upload.complete([...uploadedParts]))
1994
+ });
1995
+ return (bucket) => ({
1996
+ definition,
1997
+ head: (key) => tryR2Promise(definition.binding, "head", () => bucket.head(key)).pipe(Effect.map(maybe)),
1998
+ get: ((key, options) => tryR2Promise(definition.binding, "get", () => bucket.get(key, options)).pipe(Effect.map(maybe))),
1999
+ put: ((key, value, options) => tryR2Promise(definition.binding, "put", () => bucket.put(key, value, options)).pipe(Effect.map((object) => {
2000
+ if (object === null) return Option.none();
2001
+ if (options !== void 0 && "onlyIf" in options) return Option.some(object);
2002
+ return object;
2003
+ }))),
2004
+ createMultipartUpload: (key, options) => tryR2Promise(definition.binding, "createMultipartUpload", () => bucket.createMultipartUpload(key, options)).pipe(Effect.map(wrapUpload)),
2005
+ resumeMultipartUpload: (key, uploadId) => tryR2Sync(definition.binding, "resumeMultipartUpload", () => wrapUpload(bucket.resumeMultipartUpload(key, uploadId))),
2006
+ delete: (keys) => {
2007
+ const nativeKeys = typeof keys === "string" ? keys : [...keys];
2008
+ return tryR2Promise(definition.binding, "delete", () => bucket.delete(nativeKeys));
2009
+ },
2010
+ list: (options) => tryR2Promise(definition.binding, "list", () => bucket.list(options)),
2011
+ unsafeRaw: Effect.succeed(bucket)
2012
+ });
2013
+ };
2014
+ const layer$1 = (tag, definition) => layer$8(tag, definition.binding, isR2Bucket, makeClient$1(definition));
2015
+ const make$2 = (id) => Tag$2()(id);
2016
+ const Tag$2 = () => (id) => {
2017
+ const tag = Context.Service()(id);
2018
+ const makeLayer = (definition) => layer$1(tag, definition);
2019
+ return Object.assign(tag, {
2020
+ id,
2021
+ layer: makeLayer
1959
2022
  });
1960
2023
  };
1961
2024
  //#endregion
@@ -2033,7 +2096,7 @@ const makeClient = (definition) => {
2033
2096
  unsafeRaw: Effect.succeed(workflow)
2034
2097
  });
2035
2098
  };
2036
- const layer = (tag, definition) => layer$6(tag, definition.binding, (value) => isWorkflow(value), makeClient(definition));
2099
+ const layer = (tag, definition) => layer$8(tag, definition.binding, (value) => isWorkflow(value), makeClient(definition));
2037
2100
  //#endregion
2038
2101
  //#region src/WorkflowDefinition.ts
2039
2102
  var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
@@ -2054,7 +2117,7 @@ const make$1 = (id, definition) => Tag$1()(id, definition);
2054
2117
  const Tag$1 = () => (id, definition) => {
2055
2118
  const workflowDefinition = makeDefinition(id, definition);
2056
2119
  const tag = Context.Service()(id);
2057
- const layer$7 = (binding) => layer(tag, {
2120
+ const layer$9 = (binding) => layer(tag, {
2058
2121
  ...binding,
2059
2122
  payload: definition.payload,
2060
2123
  result: definition.result
@@ -2076,7 +2139,7 @@ const Tag$1 = () => (id, definition) => {
2076
2139
  payload: workflowDefinition.payload,
2077
2140
  result: workflowDefinition.result,
2078
2141
  make: workflowDefinition.make,
2079
- layer: layer$7,
2142
+ layer: layer$9,
2080
2143
  create,
2081
2144
  createBatch,
2082
2145
  get,
@@ -2167,4 +2230,4 @@ const waitForEvent = (name, options) => Effect.flatMap(WorkflowStep$1.asEffect()
2167
2230
  const Tag = Tag$1;
2168
2231
  const implement = implement$1;
2169
2232
  //#endregion
2170
- 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 };
2233
+ 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 };