effect-cf 0.14.0 → 0.16.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,7 +1,7 @@
1
1
  import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
2
- import { a as WorkerConfig, i as layer$15, n as Binding_exports, o as WorkerEnvironment, r as Service$2, t as Hyperdrive_exports } from "./Hyperdrive-89hg_Fck.mjs";
3
- import { Cause, Clock, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Layer, ManagedRuntime, Option, Queue, Schema } from "effect";
4
- import { FetchHttpClient, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
2
+ import { a as WorkerConfig, i as layer$17, n as Binding_exports, o as WorkerEnvironment, r as Service$2, t as Hyperdrive_exports } from "./Hyperdrive-89hg_Fck.mjs";
3
+ import { Cause, Clock, Config, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Layer, ManagedRuntime, Option, Queue, Result, Schema } from "effect";
4
+ import { FetchHttpClient, HttpClient, HttpClientRequest, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
5
5
  import { OtlpLogger, OtlpMetrics, OtlpSerialization, OtlpTracer } from "effect/unstable/observability";
6
6
  import { D1Client } from "@effect/sql-d1";
7
7
  import { DurableObject, RpcStub, RpcTarget, WorkerEntrypoint, WorkflowEntrypoint } from "cloudflare:workers";
@@ -11,13 +11,13 @@ import * as RpcServer from "effect/unstable/rpc/RpcServer";
11
11
  import { SqliteClient } from "@effect/sql-sqlite-do";
12
12
  //#region src/WorkersAi.ts
13
13
  var WorkersAi_exports = /* @__PURE__ */ __exportAll({
14
- Tag: () => Tag$14,
14
+ Tag: () => Tag$16,
15
15
  WorkersAiOperationError: () => WorkersAiOperationError,
16
16
  embeddingResponse: () => embeddingResponse,
17
17
  isWorkersAiBinding: () => isWorkersAiBinding,
18
- layer: () => layer$14,
19
- make: () => make$14,
20
- makeClient: () => makeClient$10
18
+ layer: () => layer$16,
19
+ make: () => make$16,
20
+ makeClient: () => makeClient$12
21
21
  });
22
22
  const expectedWorkersAiBinding = "Workers AI binding with run(), gateway(), and models()";
23
23
  /** Error raised when a Workers AI operation fails. */
@@ -41,7 +41,7 @@ const embeddingResponse = (value) => ({
41
41
  data: value.data ?? [],
42
42
  shape: value.shape ?? []
43
43
  });
44
- const makeClient$10 = (definition) => (ai) => {
44
+ const makeClient$12 = (definition) => (ai) => {
45
45
  const run = ((model, input, options) => tryWorkersAiPromise(definition.binding, "run", () => ai.run(model, input, options)));
46
46
  return {
47
47
  definition,
@@ -53,11 +53,11 @@ const makeClient$10 = (definition) => (ai) => {
53
53
  unsafeRaw: Effect.succeed(ai)
54
54
  };
55
55
  };
56
- const layer$14 = (tag, definition) => layer$15(tag, definition.binding, (value) => isWorkersAiBinding(value), makeClient$10(definition), { expected: expectedWorkersAiBinding });
57
- const make$14 = (id) => Tag$14()(id);
58
- const Tag$14 = () => (id) => {
56
+ const layer$16 = (tag, definition) => layer$17(tag, definition.binding, (value) => isWorkersAiBinding(value), makeClient$12(definition), { expected: expectedWorkersAiBinding });
57
+ const make$16 = (id) => Tag$16()(id);
58
+ const Tag$16 = () => (id) => {
59
59
  const tag = Context.Service()(id);
60
- const makeLayer = (definition) => layer$14(tag, definition);
60
+ const makeLayer = (definition) => layer$16(tag, definition);
61
61
  return Object.assign(tag, {
62
62
  id,
63
63
  layer: makeLayer
@@ -67,11 +67,11 @@ const Tag$14 = () => (id) => {
67
67
  //#region src/AiGateway.ts
68
68
  var AiGateway_exports = /* @__PURE__ */ __exportAll({
69
69
  AiGatewayOperationError: () => AiGatewayOperationError,
70
- Tag: () => Tag$13,
70
+ Tag: () => Tag$15,
71
71
  isAiGatewayBinding: () => isAiGatewayBinding,
72
- layer: () => layer$13,
73
- make: () => make$13,
74
- makeClient: () => makeClient$9,
72
+ layer: () => layer$15,
73
+ make: () => make$15,
74
+ makeClient: () => makeClient$11,
75
75
  makeClientFromAi: () => makeClientFromAi,
76
76
  makeHttpClient: () => makeHttpClient
77
77
  });
@@ -98,7 +98,7 @@ const providerUrl = (baseUrl, path = "") => {
98
98
  };
99
99
  const gatewayUrl = (definition) => `https://gateway.ai.cloudflare.com/v1/${definition.accountId}/${definition.gatewayId}/`;
100
100
  const isAiGatewayBinding = (value) => isWorkersAiBinding(value);
101
- const makeClient$9 = (definition, gateway) => ({
101
+ const makeClient$11 = (definition, gateway) => ({
102
102
  definition,
103
103
  run: (data, options) => tryAiGatewayPromise(definition.binding, "run", () => gateway.run(Array.isArray(data) ? [...data] : data, options)),
104
104
  getUrl: (provider) => tryAiGatewayPromise(definition.binding, "getUrl", () => gateway.getUrl(provider)),
@@ -115,11 +115,11 @@ const makeClientFromAi = (definition, ai) => {
115
115
  const withGateway = (operation) => gateway.pipe(Effect.flatMap(operation));
116
116
  return {
117
117
  definition,
118
- run: (data, options) => withGateway((raw) => makeClient$9(definition, raw).run(data, options)),
119
- getUrl: (provider) => withGateway((raw) => makeClient$9(definition, raw).getUrl(provider)),
120
- fetch: (options) => withGateway((raw) => makeClient$9(definition, raw).fetch(options)),
121
- patchLog: (logId, data) => withGateway((raw) => makeClient$9(definition, raw).patchLog(logId, data)),
122
- getLog: (logId) => withGateway((raw) => makeClient$9(definition, raw).getLog(logId)),
118
+ run: (data, options) => withGateway((raw) => makeClient$11(definition, raw).run(data, options)),
119
+ getUrl: (provider) => withGateway((raw) => makeClient$11(definition, raw).getUrl(provider)),
120
+ fetch: (options) => withGateway((raw) => makeClient$11(definition, raw).fetch(options)),
121
+ patchLog: (logId, data) => withGateway((raw) => makeClient$11(definition, raw).patchLog(logId, data)),
122
+ getLog: (logId) => withGateway((raw) => makeClient$11(definition, raw).getLog(logId)),
123
123
  unsafeRaw: gateway
124
124
  };
125
125
  };
@@ -159,25 +159,291 @@ const makeHttpClient = (definition, request = fetch) => {
159
159
  unsafeRaw: Effect.fail(aiGatewayError(binding, "unsafeRaw", /* @__PURE__ */ new TypeError("HTTP AI Gateway clients have no raw binding")))
160
160
  };
161
161
  };
162
- const layer$13 = (tag, definition) => layer$15(tag, definition.binding, isAiGatewayBinding, (ai) => makeClientFromAi(definition, ai), { expected: expectedAiGatewayBinding });
163
- const make$13 = (id) => Tag$13()(id);
164
- const Tag$13 = () => (id) => {
162
+ const layer$15 = (tag, definition) => layer$17(tag, definition.binding, isAiGatewayBinding, (ai) => makeClientFromAi(definition, ai), { expected: expectedAiGatewayBinding });
163
+ const make$15 = (id) => Tag$15()(id);
164
+ const Tag$15 = () => (id) => {
165
165
  const tag = Context.Service()(id);
166
- const makeLayer = (definition) => layer$13(tag, definition);
166
+ const makeLayer = (definition) => layer$15(tag, definition);
167
+ return Object.assign(tag, {
168
+ id,
169
+ layer: makeLayer
170
+ });
171
+ };
172
+ //#endregion
173
+ //#region src/AnalyticsEngine.ts
174
+ var AnalyticsEngine_exports = /* @__PURE__ */ __exportAll({
175
+ AnalyticsEngineDataPointSchema: () => AnalyticsEngineDataPointSchema,
176
+ AnalyticsEngineFieldValueSchema: () => AnalyticsEngineFieldValueSchema,
177
+ AnalyticsEngineOperationError: () => AnalyticsEngineOperationError,
178
+ AnalyticsEngineQueryError: () => AnalyticsEngineQueryError,
179
+ AnalyticsEngineWriteValidationError: () => AnalyticsEngineWriteValidationError,
180
+ QueryTag: () => QueryTag,
181
+ Tag: () => Tag$14,
182
+ isAnalyticsEngineDataset: () => isAnalyticsEngineDataset,
183
+ layer: () => layer$14,
184
+ make: () => make$14,
185
+ makeClient: () => makeClient$10,
186
+ makeQuery: () => makeQuery,
187
+ makeQueryClient: () => makeQueryClient,
188
+ queryConfig: () => queryConfig,
189
+ queryFetchLayer: () => queryFetchLayer,
190
+ queryFetchLayerConfig: () => queryFetchLayerConfig,
191
+ queryLayer: () => queryLayer,
192
+ queryLayerConfig: () => queryLayerConfig,
193
+ writeLimits: () => writeLimits
194
+ });
195
+ const expectedAnalyticsEngineDataset = "Analytics Engine dataset binding with writeDataPoint()";
196
+ const defaultQueryApiBaseUrl = "https://api.cloudflare.com/client/v4";
197
+ const textEncoder = new TextEncoder();
198
+ const writeLimits = {
199
+ maxBlobs: 20,
200
+ maxDoubles: 20,
201
+ maxIndexes: 1,
202
+ maxBlobBytes: 16 * 1024,
203
+ maxIndexBytes: 96,
204
+ maxDataPointsPerInvocation: 250
205
+ };
206
+ const queryColumnSchema = Schema.Struct({
207
+ name: Schema.String,
208
+ type: Schema.String
209
+ });
210
+ const queryRowSchema = Schema.Record(Schema.String, Schema.Unknown);
211
+ const queryResponseSchema = Schema.Struct({
212
+ meta: Schema.Array(queryColumnSchema),
213
+ data: Schema.Array(queryRowSchema),
214
+ rows: Schema.Number
215
+ });
216
+ const AnalyticsEngineFieldValueSchema = Schema.NullOr(Schema.Union([Schema.String, Schema.instanceOf(ArrayBuffer)]));
217
+ const AnalyticsEngineDataPointSchema = Schema.Struct({
218
+ indexes: Schema.optional(Schema.Array(AnalyticsEngineFieldValueSchema)),
219
+ doubles: Schema.optional(Schema.Array(Schema.Finite)),
220
+ blobs: Schema.optional(Schema.Array(AnalyticsEngineFieldValueSchema))
221
+ });
222
+ const decodeQueryResponse = Schema.decodeUnknownEffect(queryResponseSchema);
223
+ const decodeDataPoint = Schema.decodeUnknownEffect(AnalyticsEngineDataPointSchema);
224
+ /** Error raised when an Analytics Engine operation fails. */
225
+ var AnalyticsEngineOperationError = class extends Data.TaggedError("AnalyticsEngineOperationError") {};
226
+ /** Error raised when an Analytics Engine write input violates Cloudflare limits. */
227
+ var AnalyticsEngineWriteValidationError = class extends Data.TaggedError("AnalyticsEngineWriteValidationError") {};
228
+ /** Error raised when an Analytics Engine SQL API query fails. */
229
+ var AnalyticsEngineQueryError = class extends Data.TaggedError("AnalyticsEngineQueryError") {};
230
+ const analyticsEngineError = (binding, operation, cause) => new AnalyticsEngineOperationError({
231
+ binding,
232
+ operation,
233
+ cause
234
+ });
235
+ const analyticsEngineWriteValidationError = (binding, operation, violations, cause) => new AnalyticsEngineWriteValidationError({
236
+ binding,
237
+ operation,
238
+ violations,
239
+ cause
240
+ });
241
+ const analyticsEngineQueryError = (definition, operation, message, options) => new AnalyticsEngineQueryError({
242
+ operation,
243
+ accountId: definition.accountId,
244
+ message,
245
+ status: options?.status,
246
+ body: options?.body,
247
+ cause: options?.cause
248
+ });
249
+ const tryAnalyticsEngineSync = (binding, operation, evaluate) => Effect.try({
250
+ try: evaluate,
251
+ catch: (cause) => analyticsEngineError(binding, operation, cause)
252
+ });
253
+ const normalizeBatchSize = (batchSize) => {
254
+ if (batchSize === void 0 || !Number.isFinite(batchSize) || batchSize <= 0) return writeLimits.maxDataPointsPerInvocation;
255
+ return Math.min(Math.floor(batchSize), writeLimits.maxDataPointsPerInvocation);
256
+ };
257
+ const resolveWritePolicy = (defaults, options) => ({
258
+ onInvalid: options?.onInvalid ?? defaults?.onInvalid ?? "error",
259
+ batchSize: normalizeBatchSize(options?.batchSize ?? defaults?.batchSize)
260
+ });
261
+ const fieldPath = (prefix, field) => prefix === "" ? field : `${prefix}.${field}`;
262
+ const indexedPath = (prefix, field, index) => `${fieldPath(prefix, field)}[${index}]`;
263
+ const byteLength = (value) => {
264
+ if (value === null) return 0;
265
+ return typeof value === "string" ? textEncoder.encode(value).byteLength : value.byteLength;
266
+ };
267
+ const lengthViolation = (path, label, actual, limit) => ({
268
+ path,
269
+ message: `${label} exceeds Cloudflare Analytics Engine limit`,
270
+ actual,
271
+ limit
272
+ });
273
+ const validateDataPointLimits = (dataPoint, pathPrefix = "") => {
274
+ const violations = [];
275
+ if (dataPoint.blobs !== void 0 && dataPoint.blobs.length > writeLimits.maxBlobs) violations.push(lengthViolation(fieldPath(pathPrefix, "blobs"), "blobs", dataPoint.blobs.length, writeLimits.maxBlobs));
276
+ if (dataPoint.doubles !== void 0 && dataPoint.doubles.length > writeLimits.maxDoubles) violations.push(lengthViolation(fieldPath(pathPrefix, "doubles"), "doubles", dataPoint.doubles.length, writeLimits.maxDoubles));
277
+ if (dataPoint.indexes !== void 0 && dataPoint.indexes.length > writeLimits.maxIndexes) violations.push(lengthViolation(fieldPath(pathPrefix, "indexes"), "indexes", dataPoint.indexes.length, writeLimits.maxIndexes));
278
+ if (dataPoint.blobs !== void 0) {
279
+ const blobBytes = dataPoint.blobs.reduce((total, value) => total + byteLength(value), 0);
280
+ if (blobBytes > writeLimits.maxBlobBytes) violations.push(lengthViolation(fieldPath(pathPrefix, "blobs"), "blob bytes", blobBytes, writeLimits.maxBlobBytes));
281
+ }
282
+ if (dataPoint.indexes !== void 0) for (let index = 0; index < dataPoint.indexes.length; index++) {
283
+ const indexBytes = byteLength(dataPoint.indexes[index] ?? null);
284
+ if (indexBytes > writeLimits.maxIndexBytes) violations.push(lengthViolation(indexedPath(pathPrefix, "indexes", index), "index bytes", indexBytes, writeLimits.maxIndexBytes));
285
+ }
286
+ return violations;
287
+ };
288
+ const schemaViolation = (pathPrefix, cause) => ({
289
+ path: pathPrefix === "" ? "$" : pathPrefix,
290
+ message: cause.message
291
+ });
292
+ const toAnalyticsEngineDataPoint = (dataPoint) => ({
293
+ ...dataPoint.indexes === void 0 ? {} : { indexes: [...dataPoint.indexes] },
294
+ ...dataPoint.doubles === void 0 ? {} : { doubles: [...dataPoint.doubles] },
295
+ ...dataPoint.blobs === void 0 ? {} : { blobs: [...dataPoint.blobs] }
296
+ });
297
+ const validateDataPoint = (binding, operation, dataPoint, pathPrefix = "") => Effect.gen(function* () {
298
+ const validated = toAnalyticsEngineDataPoint(yield* decodeDataPoint(dataPoint).pipe(Effect.mapError((cause) => analyticsEngineWriteValidationError(binding, operation, [schemaViolation(pathPrefix, cause)], cause))));
299
+ const violations = validateDataPointLimits(validated, pathPrefix);
300
+ if (violations.length > 0) return yield* Effect.fail(analyticsEngineWriteValidationError(binding, operation, violations));
301
+ return validated;
302
+ });
303
+ const validateOptionalDataPoint = (binding, operation, dataPoint) => dataPoint === void 0 ? Effect.succeed(void 0) : validateDataPoint(binding, operation, dataPoint);
304
+ const validateDataPoints = (binding, operation, dataPoints, policy) => Effect.gen(function* () {
305
+ const points = dataPoints.length > writeLimits.maxDataPointsPerInvocation && policy.onInvalid === "drop" ? dataPoints.slice(0, writeLimits.maxDataPointsPerInvocation) : dataPoints;
306
+ const violations = [];
307
+ if (dataPoints.length > writeLimits.maxDataPointsPerInvocation && policy.onInvalid === "error") violations.push(lengthViolation("dataPoints", "data points per Worker invocation", dataPoints.length, writeLimits.maxDataPointsPerInvocation));
308
+ const validPoints = [];
309
+ for (let index = 0; index < points.length; index++) {
310
+ const result = yield* Effect.result(validateDataPoint(binding, operation, points[index], `dataPoints[${index}]`));
311
+ if (Result.isSuccess(result)) validPoints.push(result.success);
312
+ else if (policy.onInvalid === "error") violations.push(...result.failure.violations);
313
+ }
314
+ if (violations.length > 0) return yield* Effect.fail(analyticsEngineWriteValidationError(binding, operation, violations));
315
+ return validPoints;
316
+ });
317
+ const writeChunks = (binding, operation, dataset, dataPoints, batchSize) => Effect.gen(function* () {
318
+ const writeDataPoints = Reflect.get(dataset, "writeDataPoints");
319
+ for (let index = 0; index < dataPoints.length; index += batchSize) {
320
+ const chunk = dataPoints.slice(index, index + batchSize);
321
+ if (typeof writeDataPoints === "function") yield* tryAnalyticsEngineSync(binding, operation, () => writeDataPoints.call(dataset, chunk));
322
+ else for (const point of chunk) yield* tryAnalyticsEngineSync(binding, operation, () => dataset.writeDataPoint(point));
323
+ }
324
+ });
325
+ const queryApiUrl = (definition) => {
326
+ const baseUrl = new URL(definition.apiBaseUrl ?? defaultQueryApiBaseUrl);
327
+ baseUrl.pathname = `${baseUrl.pathname.replace(/\/+$/, "")}/accounts/${definition.accountId}/analytics_engine/sql`;
328
+ return baseUrl.href;
329
+ };
330
+ const queryRequest = (definition, sql, options) => {
331
+ let request = HttpClientRequest.post(queryApiUrl(definition)).pipe(HttpClientRequest.bodyText(sql, "text/plain;charset=UTF-8"));
332
+ if (options?.headers !== void 0) request = HttpClientRequest.setHeaders(request, options.headers);
333
+ return HttpClientRequest.bearerToken(request, definition.apiToken);
334
+ };
335
+ const responseText = (definition, response, operation) => response.text.pipe(Effect.catch((cause) => Effect.fail(analyticsEngineQueryError(definition, operation, "Failed to read Analytics Engine SQL API response body", { cause }))));
336
+ const executeQueryRequest = (definition, httpClient, sql, options) => Effect.gen(function* () {
337
+ const response = yield* httpClient.execute(queryRequest(definition, sql, options)).pipe(Effect.mapError((cause) => analyticsEngineQueryError(definition, "query", "Analytics Engine SQL API request failed", { cause })));
338
+ if (response.status < 200 || response.status >= 300) {
339
+ const body = yield* responseText(definition, response, "queryErrorBody");
340
+ return yield* Effect.fail(analyticsEngineQueryError(definition, "query", `Analytics Engine SQL API returned HTTP ${response.status}`, {
341
+ status: response.status,
342
+ body
343
+ }));
344
+ }
345
+ return response;
346
+ });
347
+ const makeQueryClientWith = (definition, httpClient) => {
348
+ const raw = (sql, options) => executeQueryRequest(definition, httpClient, sql, options);
349
+ const query = (sql, options) => Effect.gen(function* () {
350
+ return yield* decodeQueryResponse(yield* (yield* raw(sql, options)).json.pipe(Effect.catch((cause) => Effect.fail(analyticsEngineQueryError(definition, "json", "Failed to read Analytics Engine SQL API JSON response body", { cause })))));
351
+ });
352
+ const queryResult = (row, sql, options) => Effect.gen(function* () {
353
+ const result = yield* query(sql, options);
354
+ const decodeRow = Schema.decodeUnknownEffect(row);
355
+ const data = [];
356
+ for (const value of result.data) data.push(yield* decodeRow(value));
357
+ return {
358
+ ...result,
359
+ data,
360
+ rows: result.rows
361
+ };
362
+ });
363
+ return {
364
+ definition,
365
+ raw,
366
+ query,
367
+ queryResult,
368
+ queryRows: (row, sql, options) => queryResult(row, sql, options).pipe(Effect.map((result) => result.data)),
369
+ queryOne: (row, sql, options) => queryResult(row, sql, options).pipe(Effect.map((result) => result.data[0] === void 0 ? Option.none() : Option.some(result.data[0]))),
370
+ queryText: (sql, options) => raw(sql, options).pipe(Effect.flatMap((response) => responseText(definition, response, "text")))
371
+ };
372
+ };
373
+ const makeQueryClient = (definition) => Effect.map(HttpClient.HttpClient, (httpClient) => makeQueryClientWith(definition, httpClient));
374
+ const isAnalyticsEngineDataset = (value) => {
375
+ if (typeof value !== "object" || value === null) return false;
376
+ return typeof Reflect.get(value, "writeDataPoint") === "function";
377
+ };
378
+ const makeClient$10 = (definition, defaults) => (dataset) => {
379
+ const writeDataPoint = (dataPoint, options) => {
380
+ const policy = resolveWritePolicy(defaults, options);
381
+ return validateOptionalDataPoint(definition.binding, "writeDataPoint", dataPoint).pipe(Effect.matchEffect({
382
+ onFailure: (error) => policy.onInvalid === "drop" ? Effect.succeed(void 0) : Effect.fail(error),
383
+ onSuccess: (point) => tryAnalyticsEngineSync(definition.binding, "writeDataPoint", () => dataset.writeDataPoint(point))
384
+ }));
385
+ };
386
+ const writeDataPoints = (dataPoints, options) => {
387
+ const policy = resolveWritePolicy(defaults, options);
388
+ return Effect.gen(function* () {
389
+ const validPoints = yield* validateDataPoints(definition.binding, "writeDataPoints", dataPoints, policy);
390
+ yield* writeChunks(definition.binding, "writeDataPoints", dataset, validPoints, policy.batchSize);
391
+ });
392
+ };
393
+ return {
394
+ definition,
395
+ writeDataPoint,
396
+ write: writeDataPoint,
397
+ writeDataPoints,
398
+ writeBatch: writeDataPoints,
399
+ unsafeRaw: Effect.succeed(dataset)
400
+ };
401
+ };
402
+ const queryConfig = (options) => Config.all({
403
+ accountId: options?.accountId ?? Config.string("CLOUDFLARE_ACCOUNT_ID"),
404
+ apiToken: options?.apiToken ?? Config.redacted("CLOUDFLARE_API_TOKEN"),
405
+ apiBaseUrl: options?.apiBaseUrl ?? Config.string("CLOUDFLARE_API_BASE_URL").pipe(Config.withDefault(defaultQueryApiBaseUrl))
406
+ });
407
+ const queryLayer = (tag, definition) => Layer.effect(tag, makeQueryClient(definition));
408
+ const queryFetchLayer = (tag, definition) => queryLayer(tag, definition).pipe(Layer.provide(FetchHttpClient.layer));
409
+ const queryLayerConfig = (tag, config = queryConfig()) => Layer.effect(tag, Effect.gen(function* () {
410
+ return yield* makeQueryClient(yield* config);
411
+ }));
412
+ const queryFetchLayerConfig = (tag, config = queryConfig()) => queryLayerConfig(tag, config).pipe(Layer.provide(FetchHttpClient.layer));
413
+ const layer$14 = (tag, definition) => layer$17(tag, definition.binding, isAnalyticsEngineDataset, makeClient$10(definition, definition.write), { expected: expectedAnalyticsEngineDataset });
414
+ const make$14 = (id) => Tag$14()(id);
415
+ const makeQuery = (id) => QueryTag()(id);
416
+ const Tag$14 = () => (id) => {
417
+ const tag = Context.Service()(id);
418
+ const makeLayer = (definition) => layer$14(tag, definition);
167
419
  return Object.assign(tag, {
168
420
  id,
169
421
  layer: makeLayer
170
422
  });
171
423
  };
424
+ const QueryTag = () => (id) => {
425
+ const tag = Context.Service()(id);
426
+ const makeLayer = (definition) => queryLayer(tag, definition);
427
+ const makeFetchLayer = (definition) => queryFetchLayer(tag, definition);
428
+ const makeLayerConfig = (config) => queryLayerConfig(tag, config);
429
+ const makeFetchLayerConfig = (config) => queryFetchLayerConfig(tag, config);
430
+ return Object.assign(tag, {
431
+ id,
432
+ layer: makeLayer,
433
+ fetchLayer: makeFetchLayer,
434
+ layerConfig: makeLayerConfig,
435
+ fetchLayerConfig: makeFetchLayerConfig
436
+ });
437
+ };
172
438
  //#endregion
173
439
  //#region src/BrowserRendering.ts
174
440
  var BrowserRendering_exports = /* @__PURE__ */ __exportAll({
175
441
  BrowserRenderingOperationError: () => BrowserRenderingOperationError,
176
- Tag: () => Tag$12,
442
+ Tag: () => Tag$13,
177
443
  isBrowserRenderingBinding: () => isBrowserRenderingBinding,
178
- layer: () => layer$12,
179
- make: () => make$12,
180
- makeClient: () => makeClient$8
444
+ layer: () => layer$13,
445
+ make: () => make$13,
446
+ makeClient: () => makeClient$9
181
447
  });
182
448
  const expectedBrowserRenderingBinding = "Browser Rendering binding resource";
183
449
  /** Error raised when a Browser Rendering operation fails. */
@@ -214,17 +480,17 @@ const wrapBrowser = (binding, browser) => ({
214
480
  disconnect: browser.disconnect === void 0 ? Effect.void : tryBrowserRenderingSync(binding, "disconnect", () => browser.disconnect())
215
481
  });
216
482
  const isBrowserRenderingBinding = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
217
- const makeClient$8 = (definition) => (binding) => ({
483
+ const makeClient$9 = (definition) => (binding) => ({
218
484
  definition,
219
485
  launchWith: (launch, options) => tryBrowserRenderingPromise(definition.binding, "launch", () => launch(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser))),
220
486
  connectWith: (connect, options) => tryBrowserRenderingPromise(definition.binding, "connect", () => connect(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser))),
221
487
  unsafeRaw: Effect.succeed(binding)
222
488
  });
223
- const layer$12 = (tag, definition) => layer$15(tag, definition.binding, isBrowserRenderingBinding, makeClient$8(definition), { expected: expectedBrowserRenderingBinding });
224
- const make$12 = (id) => Tag$12()(id);
225
- const Tag$12 = () => (id) => {
489
+ const layer$13 = (tag, definition) => layer$17(tag, definition.binding, isBrowserRenderingBinding, makeClient$9(definition), { expected: expectedBrowserRenderingBinding });
490
+ const make$13 = (id) => Tag$13()(id);
491
+ const Tag$13 = () => (id) => {
226
492
  const tag = Context.Service()(id);
227
- const makeLayer = (definition) => layer$12(tag, definition);
493
+ const makeLayer = (definition) => layer$13(tag, definition);
228
494
  return Object.assign(tag, {
229
495
  id,
230
496
  layer: makeLayer
@@ -523,7 +789,7 @@ const runPromiseExitPreservingTypedFailures = async (effect) => {
523
789
  //#region src/CloudflareOtlp.ts
524
790
  var CloudflareOtlp_exports = /* @__PURE__ */ __exportAll({
525
791
  durableObjectLayer: () => durableObjectLayer,
526
- layer: () => layer$11,
792
+ layer: () => layer$12,
527
793
  layerJson: () => layerJson,
528
794
  layerProtobuf: () => layerProtobuf,
529
795
  workerLayer: () => workerLayer
@@ -585,14 +851,14 @@ const makeLayer = (options = {}, runtimeAttributes = {}) => {
585
851
  * installed as the primary `ConfigProvider`; outside Cloudflare, the ambient
586
852
  * Effect `ConfigProvider` remains the fallback.
587
853
  */
588
- const layer$11 = (options = {}) => makeLayer(options);
854
+ const layer$12 = (options = {}) => makeLayer(options);
589
855
  /** Base OTLP telemetry layer forced to JSON serialization. */
590
- const layerJson = (options = {}) => layer$11({
856
+ const layerJson = (options = {}) => layer$12({
591
857
  ...options,
592
858
  serialization: "json"
593
859
  });
594
860
  /** Base OTLP telemetry layer forced to protobuf serialization. */
595
- const layerProtobuf = (options = {}) => layer$11({
861
+ const layerProtobuf = (options = {}) => layer$12({
596
862
  ...options,
597
863
  serialization: "protobuf"
598
864
  });
@@ -622,7 +888,7 @@ const durableObjectLayer = (options = {}) => Layer.unwrap(Effect.map(DurableObje
622
888
  //#region src/D1.ts
623
889
  var D1_exports = /* @__PURE__ */ __exportAll({
624
890
  Service: () => Service$1,
625
- make: () => make$11
891
+ make: () => make$12
626
892
  });
627
893
  const TypeId$2 = "effect-cf/D1";
628
894
  const expectedD1Database = "D1 database binding with prepare(), batch(), and exec()";
@@ -634,7 +900,7 @@ const isD1Database = (value) => {
634
900
  /**
635
901
  * Creates a typed D1 service tag plus Effect helpers.
636
902
  */
637
- const make$11 = (id, definition) => Service$1()(id, definition);
903
+ const make$12 = (id, definition) => Service$1()(id, definition);
638
904
  /**
639
905
  * Builds a D1 service around a Cloudflare D1 database binding.
640
906
  *
@@ -670,8 +936,8 @@ const Service$1 = () => (id, definition) => {
670
936
  var QueueBinding_exports = /* @__PURE__ */ __exportAll({
671
937
  QueueOperationError: () => QueueOperationError,
672
938
  isQueue: () => isQueue,
673
- layer: () => layer$10,
674
- makeClient: () => makeClient$7
939
+ layer: () => layer$11,
940
+ makeClient: () => makeClient$8
675
941
  });
676
942
  const expectedQueueProducer = "Queue producer binding with send(); optional sendBatch()/metrics()";
677
943
  var QueueOperationError = class extends Data.TaggedError("QueueOperationError") {};
@@ -688,7 +954,7 @@ const isQueue = (value) => {
688
954
  if (typeof value !== "object" || value === null) return false;
689
955
  return typeof value.send === "function";
690
956
  };
691
- const makeClient$7 = (definition) => {
957
+ const makeClient$8 = (definition) => {
692
958
  const encodeMessage = Schema.encodeEffect(definition.message);
693
959
  return (queue) => ({
694
960
  send: Effect.fnUntraced(function* (message, options) {
@@ -726,30 +992,30 @@ const makeClient$7 = (definition) => {
726
992
  unsafeRaw: Effect.succeed(queue)
727
993
  });
728
994
  };
729
- const layer$10 = (tag, definition) => layer$15(tag, definition.binding, (value) => isQueue(value), makeClient$7(definition), { expected: expectedQueueProducer });
995
+ const layer$11 = (tag, definition) => layer$17(tag, definition.binding, (value) => isQueue(value), makeClient$8(definition), { expected: expectedQueueProducer });
730
996
  //#endregion
731
997
  //#region src/QueueDefinition.ts
732
998
  var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
733
999
  Queue: () => Queue$1,
734
- Tag: () => Tag$11,
1000
+ Tag: () => Tag$12,
735
1001
  implement: () => implement$7,
736
- make: () => make$10
1002
+ make: () => make$11
737
1003
  });
738
1004
  const makeDefinition$4 = (id, definition) => {
739
1005
  const queueDefinition = {
740
1006
  id,
741
1007
  message: definition.message
742
1008
  };
743
- return Object.assign(queueDefinition, { make: (layer, options) => make$7(layer, {
1009
+ return Object.assign(queueDefinition, { make: (layer, options) => make$8(layer, {
744
1010
  ...options,
745
1011
  queue: wrapHandler$1(queueDefinition, options.queue)
746
1012
  }) });
747
1013
  };
748
- const make$10 = (id, definition) => Tag$11()(id, definition);
749
- const Tag$11 = () => (id, definition) => {
1014
+ const make$11 = (id, definition) => Tag$12()(id, definition);
1015
+ const Tag$12 = () => (id, definition) => {
750
1016
  const queueDefinition = makeDefinition$4(id, definition);
751
1017
  const tag = Context.Service()(id);
752
- const layer = (binding) => layer$10(tag, {
1018
+ const layer = (binding) => layer$11(tag, {
753
1019
  ...binding,
754
1020
  message: definition.message
755
1021
  });
@@ -776,7 +1042,7 @@ const Tag$11 = () => (id, definition) => {
776
1042
  unsafeRaw
777
1043
  });
778
1044
  };
779
- const Queue$1 = Tag$11;
1045
+ const Queue$1 = Tag$12;
780
1046
  const wrapHandler$1 = (definition, handler) => {
781
1047
  const decodeBody = Schema.decodeUnknownEffect(definition.message);
782
1048
  return (batch) => Effect.gen(function* () {
@@ -788,7 +1054,7 @@ const implement$7 = (_definition, handler) => handler;
788
1054
  //#region src/Queue.ts
789
1055
  var Queue_exports = /* @__PURE__ */ __exportAll({
790
1056
  QueueMessageDecodeError: () => QueueMessageDecodeError,
791
- Tag: () => Tag$10,
1057
+ Tag: () => Tag$11,
792
1058
  decodeBatch: () => decodeBatch,
793
1059
  fromMessage: () => fromMessage,
794
1060
  fromMessageBatch: () => fromMessageBatch,
@@ -826,7 +1092,7 @@ const decodeBatch = (batch, decodeBody) => Effect.gen(function* () {
826
1092
  }
827
1093
  return fromMessageBatch(batch, messages);
828
1094
  });
829
- const Tag$10 = Tag$11;
1095
+ const Tag$11 = Tag$12;
830
1096
  const implement$6 = implement$7;
831
1097
  //#endregion
832
1098
  //#region src/RpcDefinition.ts
@@ -844,7 +1110,7 @@ var RpcDefinition_exports = /* @__PURE__ */ __exportAll({
844
1110
  decodeSuccess: () => decodeSuccess,
845
1111
  encodeArgs: () => encodeArgs,
846
1112
  encodeSuccess: () => encodeSuccess,
847
- make: () => make$9,
1113
+ make: () => make$10,
848
1114
  method: () => method$4,
849
1115
  reservedMethodNames: () => reservedMethodNames$4
850
1116
  });
@@ -947,7 +1213,7 @@ const decodeSuccess = (definition, methodName, value) => {
947
1213
  cause
948
1214
  })));
949
1215
  };
950
- const make$9 = (id, methods) => {
1216
+ const make$10 = (id, methods) => {
951
1217
  const definition = {
952
1218
  id,
953
1219
  methods
@@ -1005,8 +1271,8 @@ var ServiceBinding_exports = /* @__PURE__ */ __exportAll({
1005
1271
  ServiceBindingFetchError: () => ServiceBindingFetchError,
1006
1272
  ServiceBindingRpcError: () => ServiceBindingRpcError,
1007
1273
  isServiceBindingClient: () => isServiceBindingClient,
1008
- layer: () => layer$9,
1009
- makeClient: () => makeClient$6,
1274
+ layer: () => layer$10,
1275
+ makeClient: () => makeClient$7,
1010
1276
  makeDirectMethods: () => makeDirectMethods$1
1011
1277
  });
1012
1278
  const TypeId$1 = "effect-cf/ServiceBinding";
@@ -1020,7 +1286,7 @@ var ServiceBindingFetchError = class extends Data.TaggedError("ServiceBindingFet
1020
1286
  */
1021
1287
  var ServiceBindingRpcError = class extends Data.TaggedError("ServiceBindingRpcError") {};
1022
1288
  const isServiceBindingClient = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "fetch") === "function";
1023
- const makeClient$6 = (definition) => {
1289
+ const makeClient$7 = (definition) => {
1024
1290
  return (service) => {
1025
1291
  const fetch = (input, init) => Effect.tryPromise({
1026
1292
  try: () => service.fetch(input, init),
@@ -1069,7 +1335,7 @@ const makeClient$6 = (definition) => {
1069
1335
  });
1070
1336
  };
1071
1337
  };
1072
- const layer$9 = (tag, definition) => layer$15(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$6(definition), { expected: expectedServiceBinding });
1338
+ const layer$10 = (tag, definition) => layer$17(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$7(definition), { expected: expectedServiceBinding });
1073
1339
  /**
1074
1340
  * Creates a typed Effect service for a Worker service binding.
1075
1341
  *
@@ -1100,7 +1366,7 @@ const layer$9 = (tag, definition) => layer$15(tag, definition.binding, (value) =
1100
1366
  * ```
1101
1367
  */
1102
1368
  const Service = () => (id, definition) => {
1103
- const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$6(definition));
1369
+ const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$7(definition));
1104
1370
  const fetch = (input, init) => Effect.gen(function* () {
1105
1371
  return yield* (yield* tag).fetch(input, init);
1106
1372
  });
@@ -1131,10 +1397,10 @@ const makeDirectMethods$1 = (rpcDefinition, call) => {
1131
1397
  //#endregion
1132
1398
  //#region src/WorkerDefinition.ts
1133
1399
  var WorkerDefinition_exports = /* @__PURE__ */ __exportAll({
1134
- Tag: () => Tag$9,
1400
+ Tag: () => Tag$10,
1135
1401
  Worker: () => Worker,
1136
1402
  implement: () => implement$5,
1137
- make: () => make$8,
1403
+ make: () => make$9,
1138
1404
  method: () => method$3
1139
1405
  });
1140
1406
  const reservedMethodNames$3 = new Set([
@@ -1172,21 +1438,21 @@ const method$3 = method$4;
1172
1438
  */
1173
1439
  const makeDefinition$3 = (id, methods) => {
1174
1440
  assertNoReservedMethods("Worker", methods, reservedMethodNames$3);
1175
- const definition = make$9(id, methods);
1176
- return Object.assign(definition, { make: (layer, options) => make$7(layer, {
1441
+ const definition = make$10(id, methods);
1442
+ return Object.assign(definition, { make: (layer, options) => make$8(layer, {
1177
1443
  ...options,
1178
1444
  rpc: wrapHandlers$1(definition, options.rpc)
1179
1445
  }) });
1180
1446
  };
1181
- const make$8 = (id, methods) => Tag$9()(id, methods);
1182
- const Tag$9 = () => (id, methods) => {
1447
+ const make$9 = (id, methods) => Tag$10()(id, methods);
1448
+ const Tag$10 = () => (id, methods) => {
1183
1449
  const definition = makeDefinition$3(id, methods);
1184
1450
  const tag = Context.Service()(id);
1185
1451
  const bindingDefinition = (binding) => ({
1186
1452
  ...binding,
1187
1453
  definition
1188
1454
  });
1189
- const layer = (binding) => layer$9(tag, bindingDefinition(binding));
1455
+ const layer = (binding) => layer$10(tag, bindingDefinition(binding));
1190
1456
  const fetch = (input, init) => Effect.gen(function* () {
1191
1457
  return yield* (yield* tag).fetch(input, init);
1192
1458
  });
@@ -1211,7 +1477,7 @@ const Tag$9 = () => (id, methods) => {
1211
1477
  scopedCall
1212
1478
  });
1213
1479
  };
1214
- const Worker = Tag$9;
1480
+ const Worker = Tag$10;
1215
1481
  const wrapHandlers$1 = (definition, handlers) => {
1216
1482
  const wrapped = {};
1217
1483
  for (const key of Object.keys(definition.methods)) {
@@ -1245,7 +1511,7 @@ const clock = {
1245
1511
  });
1246
1512
  }
1247
1513
  };
1248
- const layer$8 = Layer.effect(Clock.Clock, Effect.succeed(clock));
1514
+ const layer$9 = Layer.effect(Clock.Clock, Effect.succeed(clock));
1249
1515
  //#endregion
1250
1516
  //#region src/internal/Entrypoint.ts
1251
1517
  const provideEntrypointServices = (layer, services) => layer.pipe(Layer.provideMerge(services));
@@ -1287,11 +1553,11 @@ const fromExecutionContext = (ctx, runPromiseExit) => {
1287
1553
  var Worker_exports = /* @__PURE__ */ __exportAll({
1288
1554
  ExecutionContext: () => ExecutionContext,
1289
1555
  NativeRequest: () => NativeRequest,
1290
- Tag: () => Tag$8,
1556
+ Tag: () => Tag$9,
1291
1557
  WorkerContext: () => WorkerContext,
1292
1558
  implement: () => implement$4,
1293
1559
  isWebSocketUpgrade: () => isWebSocketUpgrade,
1294
- make: () => make$7,
1560
+ make: () => make$8,
1295
1561
  makeFetchHandler: () => makeFetchHandler,
1296
1562
  method: () => method$2,
1297
1563
  renderHttpResponse: () => renderHttpResponse
@@ -1320,14 +1586,14 @@ const RunSymbol$1 = Symbol.for("effect-cf/Worker/run");
1320
1586
  const renderHttpResponse = (effect) => Effect.flatMap(effect, (response) => Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
1321
1587
  const renderFetchSuccess = (effect) => Effect.flatMap(effect, (response) => response instanceof Response ? Effect.succeed(response) : Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
1322
1588
  const isWorkerOptions = (options) => typeof options === "object" && options !== null && ("eventLayer" in options || "fetch" in options || "queue" in options || "rpc" in options);
1323
- function make$7(layer, optionsOrFetch) {
1589
+ function make$8(layer, optionsOrFetch) {
1324
1590
  const options = isWorkerOptions(optionsOrFetch) ? optionsOrFetch : { fetch: optionsOrFetch };
1325
1591
  class EffectWorker extends WorkerEntrypoint {
1326
1592
  runtime;
1327
1593
  constructor(ctx, env) {
1328
1594
  super(ctx, env);
1329
1595
  let runWaitUntilEffect = () => Promise.reject(/* @__PURE__ */ new Error("WorkerContext runtime is not initialized"));
1330
- const runtimeLayer = provideEntrypointServices(layer, Layer.mergeAll(layer$8, Layer.succeed(ExecutionContext, ctx), ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env))), Layer.succeed(WorkerContext, fromExecutionContext(ctx, (effect) => runWaitUntilEffect(effect))), Layer.succeed(WorkerEnvironment, env)));
1596
+ const runtimeLayer = provideEntrypointServices(layer, Layer.mergeAll(layer$9, Layer.succeed(ExecutionContext, ctx), ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env))), Layer.succeed(WorkerContext, fromExecutionContext(ctx, (effect) => runWaitUntilEffect(effect))), Layer.succeed(WorkerEnvironment, env)));
1331
1597
  this.runtime = ManagedRuntime.make(runtimeLayer);
1332
1598
  runWaitUntilEffect = (effect) => this.runtime.runPromiseExit(effect);
1333
1599
  }
@@ -1352,10 +1618,10 @@ function make$7(layer, optionsOrFetch) {
1352
1618
  return assumeEntrypointClass(EffectWorker);
1353
1619
  }
1354
1620
  const makeFetchHandler = (layer, options) => {
1355
- const WorkerClass = make$7(layer, options);
1621
+ const WorkerClass = make$8(layer, options);
1356
1622
  return { fetch: (request, env, ctx) => Promise.resolve(new WorkerClass(ctx, env).fetch(request)) };
1357
1623
  };
1358
- const Tag$8 = Tag$9;
1624
+ const Tag$9 = Tag$10;
1359
1625
  const method$2 = method$3;
1360
1626
  const implement$4 = implement$5;
1361
1627
  //#endregion
@@ -1364,8 +1630,8 @@ var DurableObjectNamespace_exports = /* @__PURE__ */ __exportAll({
1364
1630
  DurableObjectFetchError: () => DurableObjectFetchError,
1365
1631
  DurableObjectRpcError: () => DurableObjectRpcError,
1366
1632
  isDurableObjectNamespaceClient: () => isDurableObjectNamespaceClient,
1367
- layer: () => layer$7,
1368
- makeClient: () => makeClient$5,
1633
+ layer: () => layer$8,
1634
+ makeClient: () => makeClient$6,
1369
1635
  makeDirectMethods: () => makeDirectMethods
1370
1636
  });
1371
1637
  const expectedDurableObjectNamespace = "Durable Object namespace binding with getByName(), get(), idFromName(), idFromString(), newUniqueId(), and jurisdiction()";
@@ -1379,7 +1645,7 @@ var DurableObjectRpcError = class extends Data.TaggedError("DurableObjectRpcErro
1379
1645
  var DurableObjectFetchError = class extends Data.TaggedError("DurableObjectFetchError") {};
1380
1646
  const hasFunction$2 = (value, key) => typeof Reflect.get(value, key) === "function";
1381
1647
  const isDurableObjectNamespaceClient = (value) => typeof value === "object" && value !== null && hasFunction$2(value, "getByName") && hasFunction$2(value, "get") && hasFunction$2(value, "idFromName") && hasFunction$2(value, "idFromString") && hasFunction$2(value, "newUniqueId") && hasFunction$2(value, "jurisdiction");
1382
- const makeClient$5 = (definition) => {
1648
+ const makeClient$6 = (definition) => {
1383
1649
  return (namespace) => {
1384
1650
  const newUniqueId = (options) => Effect.sync(() => namespace.newUniqueId(options));
1385
1651
  const idFromName = (name) => Effect.sync(() => namespace.idFromName(name));
@@ -1446,7 +1712,7 @@ const makeClient$5 = (definition) => {
1446
1712
  });
1447
1713
  };
1448
1714
  };
1449
- const layer$7 = (tag, definition) => layer$15(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$5(definition), { expected: expectedDurableObjectNamespace });
1715
+ const layer$8 = (tag, definition) => layer$17(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$6(definition), { expected: expectedDurableObjectNamespace });
1450
1716
  const makeDirectMethods = (rpcDefinition, helpers) => {
1451
1717
  const methods = {};
1452
1718
  if (rpcDefinition !== void 0) {
@@ -1471,9 +1737,9 @@ const makeDirectMethods = (rpcDefinition, helpers) => {
1471
1737
  //#region src/DurableObjectDefinition.ts
1472
1738
  var DurableObjectDefinition_exports = /* @__PURE__ */ __exportAll({
1473
1739
  DurableObject: () => DurableObject$1,
1474
- Tag: () => Tag$7,
1740
+ Tag: () => Tag$8,
1475
1741
  implement: () => implement$3,
1476
- make: () => make$6,
1742
+ make: () => make$7,
1477
1743
  method: () => method$1
1478
1744
  });
1479
1745
  const reservedMethodNames$1 = new Set([
@@ -1504,21 +1770,21 @@ const method$1 = method$4;
1504
1770
  */
1505
1771
  const makeDefinition$2 = (id, methods) => {
1506
1772
  assertNoReservedMethods("Durable Object", methods, reservedMethodNames$1);
1507
- const definition = make$9(id, methods);
1508
- return Object.assign(definition, { make: (layer, options) => make$5(layer, {
1773
+ const definition = make$10(id, methods);
1774
+ return Object.assign(definition, { make: (layer, options) => make$6(layer, {
1509
1775
  ...options,
1510
1776
  rpc: wrapHandlers(definition, options.rpc)
1511
1777
  }) });
1512
1778
  };
1513
- const make$6 = (id, methods) => Tag$7()(id, methods);
1514
- const Tag$7 = () => (id, methods) => {
1779
+ const make$7 = (id, methods) => Tag$8()(id, methods);
1780
+ const Tag$8 = () => (id, methods) => {
1515
1781
  const definition = makeDefinition$2(id, methods);
1516
1782
  const tag = Context.Service()(id);
1517
1783
  const bindingDefinition = (binding) => ({
1518
1784
  ...binding,
1519
1785
  definition
1520
1786
  });
1521
- const layer = (binding) => layer$7(tag, bindingDefinition(binding));
1787
+ const layer = (binding) => layer$8(tag, bindingDefinition(binding));
1522
1788
  const newUniqueId = Effect.fnUntraced(function* (options) {
1523
1789
  return yield* (yield* tag).newUniqueId(options);
1524
1790
  });
@@ -1576,7 +1842,7 @@ const Tag$7 = () => (id, methods) => {
1576
1842
  unsafeRaw
1577
1843
  });
1578
1844
  };
1579
- const DurableObject$1 = Tag$7;
1845
+ const DurableObject$1 = Tag$8;
1580
1846
  const wrapHandlers = (definition, handlers) => {
1581
1847
  const wrapped = {};
1582
1848
  for (const key of Object.keys(definition.methods)) {
@@ -1594,9 +1860,9 @@ const implement$3 = (_definition, handlers) => handlers;
1594
1860
  //#endregion
1595
1861
  //#region src/DurableObject.ts
1596
1862
  var DurableObject_exports = /* @__PURE__ */ __exportAll({
1597
- Tag: () => Tag$6,
1863
+ Tag: () => Tag$7,
1598
1864
  implement: () => implement$2,
1599
- make: () => make$5,
1865
+ make: () => make$6,
1600
1866
  method: () => method
1601
1867
  });
1602
1868
  const reservedMethodNames = new Set([
@@ -1612,12 +1878,12 @@ const RunSymbol = Symbol.for("effect-cf/DurableObject/run");
1612
1878
  /**
1613
1879
  * Creates a Durable Object class backed by a single managed Effect runtime.
1614
1880
  */
1615
- const make$5 = (layer, options = {}) => {
1881
+ const make$6 = (layer, options = {}) => {
1616
1882
  class EffectDurableObject extends DurableObject {
1617
1883
  runtime;
1618
1884
  constructor(state, env) {
1619
1885
  super(state, env);
1620
- const runtimeLayer = provideEntrypointServices(layer, Layer.mergeAll(layer$8, ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env))), Layer.succeed(DurableObjectState, fromDurableObjectState(state)), Layer.succeed(WorkerEnvironment, env)));
1886
+ const runtimeLayer = provideEntrypointServices(layer, Layer.mergeAll(layer$9, ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env))), Layer.succeed(DurableObjectState, fromDurableObjectState(state)), Layer.succeed(WorkerEnvironment, env)));
1621
1887
  this.runtime = ManagedRuntime.make(runtimeLayer);
1622
1888
  const initialize = options.initialize;
1623
1889
  if (initialize !== void 0) state.waitUntil(this[RunSymbol](initialize, { eventLayer: false }));
@@ -1654,7 +1920,7 @@ const make$5 = (layer, options = {}) => {
1654
1920
  defineEntrypointRpcMethods("Durable Object", EffectDurableObject.prototype, options.rpc, reservedMethodNames, (self, effect) => self[RunSymbol](effect));
1655
1921
  return assumeEntrypointClass(EffectDurableObject);
1656
1922
  };
1657
- const Tag$6 = Tag$7;
1923
+ const Tag$7 = Tag$8;
1658
1924
  const method = method$1;
1659
1925
  const implement$2 = implement$3;
1660
1926
  //#endregion
@@ -1983,7 +2249,7 @@ var DurableObjectAlarm = class DurableObjectAlarm extends Context.Service()("eff
1983
2249
  //#region src/DurableObjectRpcWebSocket.ts
1984
2250
  var DurableObjectRpcWebSocket_exports = /* @__PURE__ */ __exportAll({
1985
2251
  DurableObjectRpcWebSocket: () => DurableObjectRpcWebSocket,
1986
- layer: () => layer$6
2252
+ layer: () => layer$7
1987
2253
  });
1988
2254
  const defaultAttachmentKey = "effectCloudflareRpcClientId";
1989
2255
  const defaultTag = "effect-cf-rpc";
@@ -1994,7 +2260,7 @@ var DurableObjectRpcWebSocket = class extends Context.Service()("effect-cf/Durab
1994
2260
  /**
1995
2261
  * Builds a layer that bridges Durable Object websocket events to `RpcServer.Protocol`.
1996
2262
  */
1997
- const layer$6 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
2263
+ const layer$7 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
1998
2264
  const tag = options.tag ?? defaultTag;
1999
2265
  const attachmentKey = options.attachmentKey ?? defaultAttachmentKey;
2000
2266
  const durableObjectState = yield* DurableObjectState;
@@ -2107,7 +2373,7 @@ const writeAttachment = (socket, key, clientId) => {
2107
2373
  };
2108
2374
  //#endregion
2109
2375
  //#region src/DurableObjectSqlite.ts
2110
- var DurableObjectSqlite_exports = /* @__PURE__ */ __exportAll({ layer: () => layer$5 });
2376
+ var DurableObjectSqlite_exports = /* @__PURE__ */ __exportAll({ layer: () => layer$6 });
2111
2377
  /**
2112
2378
  * Provides `effect/unstable/sql` from the current Durable Object SQLite storage.
2113
2379
  *
@@ -2119,7 +2385,7 @@ var DurableObjectSqlite_exports = /* @__PURE__ */ __exportAll({ layer: () => lay
2119
2385
  * );
2120
2386
  * ```
2121
2387
  */
2122
- const layer$5 = (options) => Layer.unwrap(Effect.gen(function* () {
2388
+ const layer$6 = (options) => Layer.unwrap(Effect.gen(function* () {
2123
2389
  const state = yield* DurableObjectState;
2124
2390
  return SqliteClient.layer({
2125
2391
  ...options,
@@ -2127,6 +2393,51 @@ const layer$5 = (options) => Layer.unwrap(Effect.gen(function* () {
2127
2393
  });
2128
2394
  }));
2129
2395
  //#endregion
2396
+ //#region src/Email.ts
2397
+ var Email_exports = /* @__PURE__ */ __exportAll({
2398
+ EmailOperationError: () => EmailOperationError,
2399
+ Tag: () => Tag$6,
2400
+ isEmailBinding: () => isEmailBinding,
2401
+ layer: () => layer$5,
2402
+ make: () => make$5,
2403
+ makeClient: () => makeClient$5
2404
+ });
2405
+ const expectedSendEmailBinding = "Send Email binding with send()";
2406
+ /** Error raised when a Cloudflare Send Email operation fails. */
2407
+ var EmailOperationError = class extends Data.TaggedError("EmailOperationError") {};
2408
+ const emailError = (binding, operation, cause) => new EmailOperationError({
2409
+ binding,
2410
+ operation,
2411
+ cause
2412
+ });
2413
+ const tryEmailPromise = (binding, operation, evaluate) => Effect.tryPromise({
2414
+ try: evaluate,
2415
+ catch: (cause) => emailError(binding, operation, cause)
2416
+ });
2417
+ const isEmailBinding = (value) => {
2418
+ if (typeof value !== "object" || value === null) return false;
2419
+ return typeof value.send === "function";
2420
+ };
2421
+ const makeClient$5 = (definition) => (email) => {
2422
+ const runtime = email;
2423
+ const send = ((message) => tryEmailPromise(definition.binding, "send", () => runtime.send(message)));
2424
+ return {
2425
+ definition,
2426
+ send,
2427
+ unsafeRaw: Effect.succeed(email)
2428
+ };
2429
+ };
2430
+ const layer$5 = (tag, definition) => layer$17(tag, definition.binding, isEmailBinding, makeClient$5(definition), { expected: expectedSendEmailBinding });
2431
+ const make$5 = (id) => Tag$6()(id);
2432
+ const Tag$6 = () => (id) => {
2433
+ const tag = Context.Service()(id);
2434
+ const makeLayer = (definition) => layer$5(tag, definition);
2435
+ return Object.assign(tag, {
2436
+ id,
2437
+ layer: makeLayer
2438
+ });
2439
+ };
2440
+ //#endregion
2130
2441
  //#region src/Images.ts
2131
2442
  var Images_exports = /* @__PURE__ */ __exportAll({
2132
2443
  ImagesOperationError: () => ImagesOperationError,
@@ -2223,7 +2534,7 @@ const makeClient$4 = (definition) => (images) => {
2223
2534
  unsafeRaw: Effect.succeed(images)
2224
2535
  };
2225
2536
  };
2226
- const layer$4 = (tag, definition) => layer$15(tag, definition.binding, isImagesBinding, makeClient$4(definition), { expected: expectedImagesBinding });
2537
+ const layer$4 = (tag, definition) => layer$17(tag, definition.binding, isImagesBinding, makeClient$4(definition), { expected: expectedImagesBinding });
2227
2538
  const make$4 = (id) => Tag$5()(id);
2228
2539
  const Tag$5 = () => (id) => {
2229
2540
  const tag = Context.Service()(id);
@@ -2318,7 +2629,7 @@ const makeClient$3 = (definition) => {
2318
2629
  unsafeRaw: Effect.succeed(kv)
2319
2630
  });
2320
2631
  };
2321
- const layer$3 = (tag, definition) => layer$15(tag, definition.binding, isKvNamespace, makeClient$3(definition), { expected: expectedKvNamespace });
2632
+ const layer$3 = (tag, definition) => layer$17(tag, definition.binding, isKvNamespace, makeClient$3(definition), { expected: expectedKvNamespace });
2322
2633
  const makeDefinition$1 = (id, definition) => {
2323
2634
  const kvDefinition = {
2324
2635
  id,
@@ -2435,7 +2746,7 @@ const makeClient$2 = (definition) => {
2435
2746
  };
2436
2747
  };
2437
2748
  };
2438
- const layer$2 = (tag, definition) => layer$15(tag, definition.binding, isR2Bucket, makeClient$2(definition), { expected: expectedR2Bucket });
2749
+ const layer$2 = (tag, definition) => layer$17(tag, definition.binding, isR2Bucket, makeClient$2(definition), { expected: expectedR2Bucket });
2439
2750
  const make$3 = (id) => Tag$3()(id);
2440
2751
  const Tag$3 = () => (id) => {
2441
2752
  const tag = Context.Service()(id);
@@ -2521,7 +2832,7 @@ const makeClient$1 = (definition) => {
2521
2832
  unsafeRaw: Effect.succeed(workflow)
2522
2833
  });
2523
2834
  };
2524
- const layer$1 = (tag, definition) => layer$15(tag, definition.binding, (value) => isWorkflow(value), makeClient$1(definition), { expected: expectedWorkflow });
2835
+ const layer$1 = (tag, definition) => layer$17(tag, definition.binding, (value) => isWorkflow(value), makeClient$1(definition), { expected: expectedWorkflow });
2525
2836
  //#endregion
2526
2837
  //#region src/WorkflowDefinition.ts
2527
2838
  var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
@@ -2695,7 +3006,7 @@ const makeClient = (definition) => (index) => {
2695
3006
  unsafeRaw: Effect.succeed(index)
2696
3007
  };
2697
3008
  };
2698
- const layer = (tag, definition) => layer$15(tag, definition.binding, isVectorizeBinding, makeClient(definition), { expected: expectedVectorizeBinding });
3009
+ const layer = (tag, definition) => layer$17(tag, definition.binding, isVectorizeBinding, makeClient(definition), { expected: expectedVectorizeBinding });
2699
3010
  const make = (id) => Tag()(id);
2700
3011
  const Tag = () => (id) => {
2701
3012
  const tag = Context.Service()(id);
@@ -2706,4 +3017,4 @@ const Tag = () => (id) => {
2706
3017
  });
2707
3018
  };
2708
3019
  //#endregion
2709
- export { AiGateway_exports as AiGateway, Binding_exports as Binding, BrowserRendering_exports as BrowserRendering, CloudflareOtlp_exports as CloudflareOtlp, D1_exports as D1, DurableObject_exports as DurableObject, DurableObjectAlarm_exports as DurableObjectAlarm, DurableObjectDefinition_exports as DurableObjectDefinition, DurableObjectNamespace_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_exports as DurableObjectSqlite, 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, Vectorize_exports as Vectorize, Worker_exports as Worker, WorkerConfig, WorkerDefinition_exports as WorkerDefinition, WorkerEnvironment, WorkersAi_exports as WorkersAi, Workflow_exports as Workflow, WorkflowBinding_exports as WorkflowBinding, WorkflowDefinition_exports as WorkflowDefinition };
3020
+ export { AiGateway_exports as AiGateway, AnalyticsEngine_exports as AnalyticsEngine, Binding_exports as Binding, BrowserRendering_exports as BrowserRendering, CloudflareOtlp_exports as CloudflareOtlp, D1_exports as D1, DurableObject_exports as DurableObject, DurableObjectAlarm_exports as DurableObjectAlarm, DurableObjectDefinition_exports as DurableObjectDefinition, DurableObjectNamespace_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_exports as DurableObjectSqlite, DurableObjectState_exports as DurableObjectState, DurableObjectStorage_exports as DurableObjectStorage, DurableObjectWebSocket_exports as DurableObjectWebSocket, Email_exports as Email, 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, Vectorize_exports as Vectorize, Worker_exports as Worker, WorkerConfig, WorkerDefinition_exports as WorkerDefinition, WorkerEnvironment, WorkersAi_exports as WorkersAi, Workflow_exports as Workflow, WorkflowBinding_exports as WorkflowBinding, WorkflowDefinition_exports as WorkflowDefinition };