effect-cf 0.17.0 → 0.18.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # effect-cf
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#58](https://github.com/danieljvdm/effect-cf/pull/58) [`c5bac36`](https://github.com/danieljvdm/effect-cf/commit/c5bac367587c314a17b32e984faee546a488f1ff) Thanks [@danieljvdm](https://github.com/danieljvdm)! - Add Effect-native support for Cloudflare's default and named Cache API instances, including typed operation errors and `Option`-based cache misses.
8
+
9
+ ## 0.17.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#56](https://github.com/danieljvdm/effect-cf/pull/56) [`38df8ed`](https://github.com/danieljvdm/effect-cf/commit/38df8ed3153a77df117810e67a34cf039871c08c) Thanks [@danieljvdm](https://github.com/danieljvdm)! - Treat Cloudflare Workflow status responses with a null error as having no error.
14
+
3
15
  ## 0.17.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # effect-cf
2
2
 
3
- Effect-native Cloudflare primitives for Workers, Durable Objects, Containers, bindings, KV, D1, Queues, Email, Analytics Engine, Workflows, and Durable Object storage.
3
+ Effect-native Cloudflare primitives for Workers, Durable Objects, Containers, bindings, Cache, KV, D1, Queues, Email, Analytics Engine, Workflows, and Durable Object storage.
4
4
 
5
5
  ## Install
6
6
 
@@ -31,6 +31,7 @@ Runtime creation belongs at Cloudflare entrypoints, not inside binding helpers.
31
31
  - `DurableObjectState` / `DurableObjectStorage` - Effect wrappers for state, alarms, SQL, and embedded KV
32
32
  - `DurableObjectWebSocket` - WebSocket upgrade helpers for Durable Objects
33
33
  - `ContainerNamespace` - named Cloudflare Container instances with Effect-wrapped request and lifecycle operations
34
+ - `Cache` - Effect wrapper for Cloudflare's default and named Cache API instances
34
35
  - `Kv` - typed KV namespace helper
35
36
  - `D1` - typed D1 database binding helper with an `@effect/sql-d1` backed SQL layer
36
37
  - `R2` - typed R2 bucket binding helper with Effect-wrapped object and multipart operations
@@ -161,6 +162,38 @@ Producers should usually use `const queue = yield* AvatarQueue` and then call `q
161
162
 
162
163
  Queue handlers run inline failures through Cloudflare's normal retry path. If background work scheduled with `WorkerContext.waitUntil(...)` should also make the batch retry, use `WorkerContext.waitUntilPropagating(...)` or `waitUntil(..., { mode: "propagate" })`; the default `waitUntil` mode observes and logs failures without rejecting the native `waitUntil` promise.
163
164
 
165
+ ## Cache Example
166
+
167
+ `Cache.layer` exposes Cloudflare's global Cache API as an Effect service. Cache misses are represented by `Option.none()`, and named caches are available through `open(...)`.
168
+
169
+ ```ts
170
+ import { Effect, Option } from "effect";
171
+ import { Cache, Worker } from "effect-cf";
172
+
173
+ export default Worker.make(Cache.layer, {
174
+ fetch: Effect.gen(function* () {
175
+ const request = yield* Worker.NativeRequest;
176
+ const storage = yield* Cache.CacheStorage;
177
+ const cached = yield* storage.default.match(request);
178
+
179
+ if (Option.isSome(cached)) {
180
+ return cached.value;
181
+ }
182
+
183
+ const response = new Response("fresh", {
184
+ headers: { "Cache-Control": "public, max-age=300" },
185
+ });
186
+
187
+ const context = yield* Worker.WorkerContext;
188
+ yield* context.waitUntil(storage.default.put(request, response.clone()));
189
+
190
+ return response;
191
+ }),
192
+ });
193
+ ```
194
+
195
+ Use `const cache = yield* storage.open("api-cache")` for a named cache. `match`, `put`, `delete`, and `open` failures are reported as `CacheOperationError` values.
196
+
164
197
  ## R2 Example
165
198
 
166
199
  R2 bucket tags expose Cloudflare object operations as Effects and map nullable reads to `Option`.
package/dist/index.d.mts CHANGED
@@ -16,7 +16,7 @@ import * as _$effect_Config0 from "effect/Config";
16
16
 
17
17
  //#region src/WorkersAi.d.ts
18
18
  declare namespace WorkersAi_d_exports {
19
- export { LayerOptions$19 as LayerOptions, Tag$18 as Tag, TagClass$17 as TagClass, WorkersAiAsyncBatchResponse, WorkersAiBinding, WorkersAiClient, WorkersAiDefinition, WorkersAiEmbeddingInput, WorkersAiEmbeddingResponse, WorkersAiModelsSearchObject, WorkersAiModelsSearchParams, WorkersAiOperationError, WorkersAiOptions, WorkersAiService, embeddingResponse, isWorkersAiBinding, layer$16 as layer, make$17 as make, makeClient$13 as makeClient };
19
+ export { LayerOptions$19 as LayerOptions, Tag$18 as Tag, TagClass$17 as TagClass, WorkersAiAsyncBatchResponse, WorkersAiBinding, WorkersAiClient, WorkersAiDefinition, WorkersAiEmbeddingInput, WorkersAiEmbeddingResponse, WorkersAiModelsSearchObject, WorkersAiModelsSearchParams, WorkersAiOperationError, WorkersAiOptions, WorkersAiService, embeddingResponse, isWorkersAiBinding, layer$17 as layer, make$17 as make, makeClient$14 as makeClient };
20
20
  }
21
21
  declare const WorkersAiOperationError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
22
22
  readonly _tag: "WorkersAiOperationError";
@@ -87,12 +87,12 @@ declare const embeddingResponse: (value: {
87
87
  readonly data?: ReadonlyArray<ReadonlyArray<number>>;
88
88
  readonly shape?: ReadonlyArray<number>;
89
89
  }) => WorkersAiEmbeddingResponse;
90
- declare const makeClient$13: <ModelList extends AiModelListType = AiModels>(definition: WorkersAiDefinition) => (ai: WorkersAiBinding<ModelList>) => WorkersAiClient<ModelList>;
91
- declare const layer$16: <Self, ModelList extends AiModelListType = AiModels>(tag: Context.Service<Self, WorkersAiClient<ModelList>>, definition: WorkersAiDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
90
+ declare const makeClient$14: <ModelList extends AiModelListType = AiModels>(definition: WorkersAiDefinition) => (ai: WorkersAiBinding<ModelList>) => WorkersAiClient<ModelList>;
91
+ declare const layer$17: <Self, ModelList extends AiModelListType = AiModels>(tag: Context.Service<Self, WorkersAiClient<ModelList>>, definition: WorkersAiDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
92
92
  declare const make$17: <Id extends string>(id: Id) => TagClass$17<WorkersAiService<Id>, Id, AiModels>;
93
93
  declare const Tag$18: <Self>() => <Id extends string, ModelList extends AiModelListType = AiModels>(id: Id) => TagClass$17<Self, Id, ModelList>;
94
94
  declare namespace AiGateway_d_exports {
95
- export { AiGatewayBinding, AiGatewayClient, AiGatewayDefinition, AiGatewayFetchOptions, AiGatewayHeaders, AiGatewayLog, AiGatewayOperationError, AiGatewayPatchLog, AiGatewayProvider, AiGatewayRunOptions, AiGatewayService, AiGatewayUniversalRequest, LayerOptions$18 as LayerOptions, Tag$17 as Tag, TagClass$16 as TagClass, isAiGatewayBinding, layer$15 as layer, make$16 as make, makeClient$12 as makeClient, makeClientFromAi, makeHttpClient };
95
+ export { AiGatewayBinding, AiGatewayClient, AiGatewayDefinition, AiGatewayFetchOptions, AiGatewayHeaders, AiGatewayLog, AiGatewayOperationError, AiGatewayPatchLog, AiGatewayProvider, AiGatewayRunOptions, AiGatewayService, AiGatewayUniversalRequest, LayerOptions$18 as LayerOptions, Tag$17 as Tag, TagClass$16 as TagClass, isAiGatewayBinding, layer$16 as layer, make$16 as make, makeClient$13 as makeClient, makeClientFromAi, makeHttpClient };
96
96
  }
97
97
  declare const AiGatewayOperationError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
98
98
  readonly _tag: "AiGatewayOperationError";
@@ -151,7 +151,7 @@ interface TagClass$16<Self, Id extends string> extends Context.ServiceClass<Self
151
151
  readonly layer: (options: LayerOptions$18) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError | AiGatewayOperationError, WorkerEnvironment>;
152
152
  }
153
153
  declare const isAiGatewayBinding: (value: unknown) => value is WorkersAiBinding;
154
- declare const makeClient$12: (definition: AiGatewayDefinition, gateway: AiGatewayBinding) => {
154
+ declare const makeClient$13: (definition: AiGatewayDefinition, gateway: AiGatewayBinding) => {
155
155
  definition: AiGatewayDefinition;
156
156
  run: (data: _$_cloudflare_workers_types0.AIGatewayUniversalRequest | readonly _$_cloudflare_workers_types0.AIGatewayUniversalRequest[], options: {
157
157
  gateway?: _$_cloudflare_workers_types0.UniversalGatewayOptions;
@@ -169,11 +169,11 @@ declare const makeHttpClient: (definition: Omit<AiGatewayDefinition, "binding">
169
169
  readonly accountId: string;
170
170
  readonly binding?: string;
171
171
  }, request?: typeof fetch) => AiGatewayClient;
172
- declare const layer$15: <Self>(tag: Context.Service<Self, AiGatewayClient>, definition: AiGatewayDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
172
+ declare const layer$16: <Self>(tag: Context.Service<Self, AiGatewayClient>, definition: AiGatewayDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
173
173
  declare const make$16: <Id extends string>(id: Id) => TagClass$16<AiGatewayService<Id>, Id>;
174
174
  declare const Tag$17: <Self>() => <Id extends string>(id: Id) => TagClass$16<Self, Id>;
175
175
  declare namespace AnalyticsEngine_d_exports {
176
- export { AnalyticsEngineBinding, AnalyticsEngineClient, AnalyticsEngineDataPoint, AnalyticsEngineDataPointSchema, AnalyticsEngineDefinition, AnalyticsEngineFieldValue, AnalyticsEngineFieldValueSchema, AnalyticsEngineInvalidWritePolicy, AnalyticsEngineOperationError, AnalyticsEngineQueryClient, AnalyticsEngineQueryColumn, AnalyticsEngineQueryDefinition, AnalyticsEngineQueryError, AnalyticsEngineQueryOptions, AnalyticsEngineQueryResult, AnalyticsEngineQueryRow, AnalyticsEngineQueryService, AnalyticsEngineService, AnalyticsEngineWriteBatchOptions, AnalyticsEngineWriteError, AnalyticsEngineWriteOptions, AnalyticsEngineWritePolicy, AnalyticsEngineWriteValidationError, AnalyticsEngineWriteViolation, LayerOptions$17 as LayerOptions, QueryConfigOptions, QueryTag, QueryTagClass, Tag$16 as Tag, TagClass$15 as TagClass, isAnalyticsEngineDataset, layer$14 as layer, make$15 as make, makeClient$11 as makeClient, makeQuery, makeQueryClient, queryConfig, queryFetchLayer, queryFetchLayerConfig, queryLayer, queryLayerConfig, writeLimits };
176
+ export { AnalyticsEngineBinding, AnalyticsEngineClient, AnalyticsEngineDataPoint, AnalyticsEngineDataPointSchema, AnalyticsEngineDefinition, AnalyticsEngineFieldValue, AnalyticsEngineFieldValueSchema, AnalyticsEngineInvalidWritePolicy, AnalyticsEngineOperationError, AnalyticsEngineQueryClient, AnalyticsEngineQueryColumn, AnalyticsEngineQueryDefinition, AnalyticsEngineQueryError, AnalyticsEngineQueryOptions, AnalyticsEngineQueryResult, AnalyticsEngineQueryRow, AnalyticsEngineQueryService, AnalyticsEngineService, AnalyticsEngineWriteBatchOptions, AnalyticsEngineWriteError, AnalyticsEngineWriteOptions, AnalyticsEngineWritePolicy, AnalyticsEngineWriteValidationError, AnalyticsEngineWriteViolation, LayerOptions$17 as LayerOptions, QueryConfigOptions, QueryTag, QueryTagClass, Tag$16 as Tag, TagClass$15 as TagClass, isAnalyticsEngineDataset, layer$15 as layer, make$15 as make, makeClient$12 as makeClient, makeQuery, makeQueryClient, queryConfig, queryFetchLayer, queryFetchLayerConfig, queryLayer, queryLayerConfig, writeLimits };
177
177
  }
178
178
  declare const writeLimits: {
179
179
  readonly maxBlobs: 20;
@@ -328,7 +328,7 @@ interface QueryTagClass<Self, Id extends string> extends Context.ServiceClass<Se
328
328
  }
329
329
  declare const makeQueryClient: (definition: AnalyticsEngineQueryDefinition) => Effect.Effect<AnalyticsEngineQueryClient, never, HttpClient.HttpClient>;
330
330
  declare const isAnalyticsEngineDataset: (value: unknown) => value is AnalyticsEngineBinding;
331
- declare const makeClient$11: (definition: AnalyticsEngineDefinition, defaults?: AnalyticsEngineWritePolicy) => (dataset: AnalyticsEngineBinding) => AnalyticsEngineClient;
331
+ declare const makeClient$12: (definition: AnalyticsEngineDefinition, defaults?: AnalyticsEngineWritePolicy) => (dataset: AnalyticsEngineBinding) => AnalyticsEngineClient;
332
332
  declare const queryConfig: (options?: QueryConfigOptions) => Config.Config<{
333
333
  accountId: string;
334
334
  apiToken: Redacted.Redacted<string>;
@@ -338,13 +338,13 @@ declare const queryLayer: <Self>(tag: Context.Service<Self, AnalyticsEngineQuery
338
338
  declare const queryFetchLayer: <Self>(tag: Context.Service<Self, AnalyticsEngineQueryClient>, definition: AnalyticsEngineQueryDefinition) => Layer.Layer<Self, never, never>;
339
339
  declare const queryLayerConfig: <Self>(tag: Context.Service<Self, AnalyticsEngineQueryClient>, config?: Config.Config<AnalyticsEngineQueryDefinition>) => Layer.Layer<Self, Config.ConfigError, HttpClient.HttpClient>;
340
340
  declare const queryFetchLayerConfig: <Self>(tag: Context.Service<Self, AnalyticsEngineQueryClient>, config?: Config.Config<AnalyticsEngineQueryDefinition>) => Layer.Layer<Self, Config.ConfigError, never>;
341
- declare const layer$14: <Self>(tag: Context.Service<Self, AnalyticsEngineClient>, definition: LayerOptions$17) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
341
+ declare const layer$15: <Self>(tag: Context.Service<Self, AnalyticsEngineClient>, definition: LayerOptions$17) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
342
342
  declare const make$15: <Id extends string>(id: Id) => TagClass$15<AnalyticsEngineService<Id>, Id>;
343
343
  declare const makeQuery: <Id extends string>(id: Id) => QueryTagClass<AnalyticsEngineQueryService<Id>, Id>;
344
344
  declare const Tag$16: <Self>() => <Id extends string>(id: Id) => TagClass$15<Self, Id>;
345
345
  declare const QueryTag: <Self>() => <Id extends string>(id: Id) => QueryTagClass<Self, Id>;
346
346
  declare namespace BrowserRendering_d_exports {
347
- export { BrowserRenderingBinding, BrowserRenderingBrowserClient, BrowserRenderingBrowserLike, BrowserRenderingClient, BrowserRenderingConnect, BrowserRenderingDefinition, BrowserRenderingLaunch, BrowserRenderingOperationError, BrowserRenderingPageClient, BrowserRenderingPageLike, BrowserRenderingService, LayerOptions$16 as LayerOptions, Tag$15 as Tag, TagClass$14 as TagClass, isBrowserRenderingBinding, layer$13 as layer, make$14 as make, makeClient$10 as makeClient };
347
+ export { BrowserRenderingBinding, BrowserRenderingBrowserClient, BrowserRenderingBrowserLike, BrowserRenderingClient, BrowserRenderingConnect, BrowserRenderingDefinition, BrowserRenderingLaunch, BrowserRenderingOperationError, BrowserRenderingPageClient, BrowserRenderingPageLike, BrowserRenderingService, LayerOptions$16 as LayerOptions, Tag$15 as Tag, TagClass$14 as TagClass, isBrowserRenderingBinding, layer$14 as layer, make$14 as make, makeClient$11 as makeClient };
348
348
  }
349
349
  declare const BrowserRenderingOperationError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
350
350
  readonly _tag: "BrowserRenderingOperationError";
@@ -416,10 +416,61 @@ interface TagClass$14<Self, Id extends string> extends Context.ServiceClass<Self
416
416
  readonly layer: (options: LayerOptions$16) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
417
417
  }
418
418
  declare const isBrowserRenderingBinding: (value: unknown) => value is BrowserRenderingBinding;
419
- declare const makeClient$10: <RawBinding extends BrowserRenderingBinding = BrowserRenderingBinding>(definition: BrowserRenderingDefinition) => (binding: RawBinding) => BrowserRenderingClient<RawBinding>;
420
- declare const layer$13: <Self>(tag: Context.Service<Self, BrowserRenderingClient>, definition: BrowserRenderingDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
419
+ declare const makeClient$11: <RawBinding extends BrowserRenderingBinding = BrowserRenderingBinding>(definition: BrowserRenderingDefinition) => (binding: RawBinding) => BrowserRenderingClient<RawBinding>;
420
+ declare const layer$14: <Self>(tag: Context.Service<Self, BrowserRenderingClient>, definition: BrowserRenderingDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
421
421
  declare const make$14: <Id extends string>(id: Id) => TagClass$14<BrowserRenderingService<Id>, Id>;
422
422
  declare const Tag$15: <Self>() => <Id extends string>(id: Id) => TagClass$14<Self, Id>;
423
+ declare namespace Cache_d_exports {
424
+ export { CacheClient, CacheOperation, CacheOperationError, CacheQueryOptions, CacheRequest, CacheStorage, CacheStorageClient, layer$13 as layer, layerFrom, makeCacheClient, makeClient$10 as makeClient };
425
+ }
426
+ /** Request key accepted by Cloudflare's Cache API. */
427
+ type CacheRequest = CloudflareRequestInfo | URL;
428
+ /** Query options supported by Cloudflare's Cache API. */
429
+ type CacheQueryOptions = CloudflareCacheQueryOptions;
430
+ /** Cache operation represented by {@link CacheOperationError}. */
431
+ type CacheOperation = "open" | "match" | "put" | "delete";
432
+ declare const CacheOperationError_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
433
+ readonly _tag: "CacheOperationError";
434
+ } & Readonly<A>;
435
+ /** Error raised when a Cloudflare Cache API operation fails. */
436
+ declare class CacheOperationError extends CacheOperationError_base<{
437
+ readonly cache: string;
438
+ readonly operation: CacheOperation;
439
+ readonly cause: unknown;
440
+ }> {}
441
+ /** Effect wrapper around one Cloudflare `Cache` instance. */
442
+ interface CacheClient {
443
+ /** Cache name (`default` for `caches.default`). */
444
+ readonly name: string;
445
+ /** Finds a cached response, mapping cache misses to `Option.none()`. */
446
+ readonly match: (request: CacheRequest, options?: CacheQueryOptions) => Effect.Effect<Option.Option<Response>, CacheOperationError>;
447
+ /** Stores a response under the request key. */
448
+ readonly put: (request: CacheRequest, response: Response) => Effect.Effect<void, CacheOperationError>;
449
+ /** Deletes a cached response and reports whether it existed. */
450
+ readonly delete: (request: CacheRequest, options?: CacheQueryOptions) => Effect.Effect<boolean, CacheOperationError>;
451
+ /** Access to the native Cloudflare `Cache` instance. */
452
+ readonly unsafeRaw: Effect.Effect<CloudflareCache>;
453
+ }
454
+ /** Effect wrapper around Cloudflare's global `caches` object. */
455
+ interface CacheStorageClient {
456
+ /** Cloudflare's shared default cache. */
457
+ readonly default: CacheClient;
458
+ /** Opens a named cache. */
459
+ readonly open: (name: string) => Effect.Effect<CacheClient, CacheOperationError>;
460
+ /** Access to the native Cloudflare `CacheStorage` instance. */
461
+ readonly unsafeRaw: Effect.Effect<CloudflareCacheStorage>;
462
+ }
463
+ declare const CacheStorage_base: Context.ServiceClass<CacheStorage, "effect-cf/CacheStorage", CacheStorageClient>;
464
+ /** Service for Cloudflare's global Cache API. */
465
+ declare class CacheStorage extends CacheStorage_base {}
466
+ /** Wraps a native Cloudflare `Cache` instance. */
467
+ declare const makeCacheClient: (cache: CloudflareCache, name?: string) => CacheClient;
468
+ /** Wraps a native Cloudflare `CacheStorage` instance. */
469
+ declare const makeClient$10: (storage: CloudflareCacheStorage) => CacheStorageClient;
470
+ /** Provides Cache API services from an explicit native `CacheStorage` instance. */
471
+ declare const layerFrom: (storage: CloudflareCacheStorage) => Layer.Layer<CacheStorage>;
472
+ /** Provides Cache API services from Cloudflare's global `caches` object. */
473
+ declare const layer$13: Layer.Layer<CacheStorage>;
423
474
  declare namespace DurableObjectStorage_d_exports {
424
475
  export { DurableObjectStorage, DurableObjectTransaction, SchemaBackedSyncKvStorage, SqlCursor, SqlStorage, SqlStorageValue, StorageOperationError, SyncKvDefinition, SyncKvStorage, fromDurableObjectStorage };
425
476
  }
@@ -2933,4 +2984,4 @@ declare const layer: <Self>(tag: Context.Service<Self, VectorizeClient>, definit
2933
2984
  declare const make: <Id extends string>(id: Id) => TagClass<VectorizeService<Id>, Id>;
2934
2985
  declare const Tag$1: <Self>() => <Id extends string>(id: Id) => TagClass<Self, Id>;
2935
2986
  //#endregion
2936
- export { AiGateway_d_exports as AiGateway, AnalyticsEngine_d_exports as AnalyticsEngine, Binding_d_exports as Binding, BrowserRendering_d_exports as BrowserRendering, CloudflareOtlp_d_exports as CloudflareOtlp, ContainerNamespace_d_exports as ContainerNamespace, D1_d_exports as D1, DurableObject_d_exports as DurableObject, DurableObjectAlarm_d_exports as DurableObjectAlarm, DurableObjectDefinition_d_exports as DurableObjectDefinition, DurableObjectNamespace_d_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_d_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_d_exports as DurableObjectSqlite, DurableObjectState_d_exports as DurableObjectState, DurableObjectStorage_d_exports as DurableObjectStorage, DurableObjectWebSocket_d_exports as DurableObjectWebSocket, Email_d_exports as Email, Hyperdrive_d_exports as Hyperdrive, Images_d_exports as Images, Kv_d_exports as Kv, Queue_d_exports as Queue, QueueBinding_d_exports as QueueBinding, QueueDefinition_d_exports as QueueDefinition, R2_d_exports as R2, Rpc_d_exports as Rpc, RpcDefinition_d_exports as RpcDefinition, ServiceBinding_d_exports as ServiceBinding, Vectorize_d_exports as Vectorize, Worker_d_exports as Worker, WorkerConfig, WorkerDefinition_d_exports as WorkerDefinition, type WorkerEnv, WorkerEnvironment, WorkersAi_d_exports as WorkersAi, Workflow_d_exports as Workflow, WorkflowBinding_d_exports as WorkflowBinding, WorkflowDefinition_d_exports as WorkflowDefinition };
2987
+ export { AiGateway_d_exports as AiGateway, AnalyticsEngine_d_exports as AnalyticsEngine, Binding_d_exports as Binding, BrowserRendering_d_exports as BrowserRendering, Cache_d_exports as Cache, CloudflareOtlp_d_exports as CloudflareOtlp, ContainerNamespace_d_exports as ContainerNamespace, D1_d_exports as D1, DurableObject_d_exports as DurableObject, DurableObjectAlarm_d_exports as DurableObjectAlarm, DurableObjectDefinition_d_exports as DurableObjectDefinition, DurableObjectNamespace_d_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_d_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_d_exports as DurableObjectSqlite, DurableObjectState_d_exports as DurableObjectState, DurableObjectStorage_d_exports as DurableObjectStorage, DurableObjectWebSocket_d_exports as DurableObjectWebSocket, Email_d_exports as Email, Hyperdrive_d_exports as Hyperdrive, Images_d_exports as Images, Kv_d_exports as Kv, Queue_d_exports as Queue, QueueBinding_d_exports as QueueBinding, QueueDefinition_d_exports as QueueDefinition, R2_d_exports as R2, Rpc_d_exports as Rpc, RpcDefinition_d_exports as RpcDefinition, ServiceBinding_d_exports as ServiceBinding, Vectorize_d_exports as Vectorize, Worker_d_exports as Worker, WorkerConfig, WorkerDefinition_d_exports as WorkerDefinition, type WorkerEnv, WorkerEnvironment, WorkersAi_d_exports as WorkersAi, Workflow_d_exports as Workflow, WorkflowBinding_d_exports as WorkflowBinding, WorkflowDefinition_d_exports as WorkflowDefinition };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
2
- import { a as WorkerConfig, i as layer$18, n as Binding_exports, o as WorkerEnvironment, r as Service$2, t as Hyperdrive_exports } from "./Hyperdrive-89hg_Fck.mjs";
2
+ import { a as WorkerConfig, i as layer$19, n as Binding_exports, o as WorkerEnvironment, r as Service$2, t as Hyperdrive_exports } from "./Hyperdrive-89hg_Fck.mjs";
3
3
  import { Cause, Clock, Config, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Layer, ManagedRuntime, Option, Queue, Result, Schema } from "effect";
4
4
  import { FetchHttpClient, HttpClient, HttpClientRequest, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
5
5
  import { OtlpLogger, OtlpMetrics, OtlpSerialization, OtlpTracer } from "effect/unstable/observability";
@@ -15,9 +15,9 @@ var WorkersAi_exports = /* @__PURE__ */ __exportAll({
15
15
  WorkersAiOperationError: () => WorkersAiOperationError,
16
16
  embeddingResponse: () => embeddingResponse,
17
17
  isWorkersAiBinding: () => isWorkersAiBinding,
18
- layer: () => layer$17,
18
+ layer: () => layer$18,
19
19
  make: () => make$17,
20
- makeClient: () => makeClient$13
20
+ makeClient: () => makeClient$14
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$13 = (definition) => (ai) => {
44
+ const makeClient$14 = (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$13 = (definition) => (ai) => {
53
53
  unsafeRaw: Effect.succeed(ai)
54
54
  };
55
55
  };
56
- const layer$17 = (tag, definition) => layer$18(tag, definition.binding, (value) => isWorkersAiBinding(value), makeClient$13(definition), { expected: expectedWorkersAiBinding });
56
+ const layer$18 = (tag, definition) => layer$19(tag, definition.binding, (value) => isWorkersAiBinding(value), makeClient$14(definition), { expected: expectedWorkersAiBinding });
57
57
  const make$17 = (id) => Tag$17()(id);
58
58
  const Tag$17 = () => (id) => {
59
59
  const tag = Context.Service()(id);
60
- const makeLayer = (definition) => layer$17(tag, definition);
60
+ const makeLayer = (definition) => layer$18(tag, definition);
61
61
  return Object.assign(tag, {
62
62
  id,
63
63
  layer: makeLayer
@@ -69,9 +69,9 @@ var AiGateway_exports = /* @__PURE__ */ __exportAll({
69
69
  AiGatewayOperationError: () => AiGatewayOperationError,
70
70
  Tag: () => Tag$16,
71
71
  isAiGatewayBinding: () => isAiGatewayBinding,
72
- layer: () => layer$16,
72
+ layer: () => layer$17,
73
73
  make: () => make$16,
74
- makeClient: () => makeClient$12,
74
+ makeClient: () => makeClient$13,
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$12 = (definition, gateway) => ({
101
+ const makeClient$13 = (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$12(definition, raw).run(data, options)),
119
- getUrl: (provider) => withGateway((raw) => makeClient$12(definition, raw).getUrl(provider)),
120
- fetch: (options) => withGateway((raw) => makeClient$12(definition, raw).fetch(options)),
121
- patchLog: (logId, data) => withGateway((raw) => makeClient$12(definition, raw).patchLog(logId, data)),
122
- getLog: (logId) => withGateway((raw) => makeClient$12(definition, raw).getLog(logId)),
118
+ run: (data, options) => withGateway((raw) => makeClient$13(definition, raw).run(data, options)),
119
+ getUrl: (provider) => withGateway((raw) => makeClient$13(definition, raw).getUrl(provider)),
120
+ fetch: (options) => withGateway((raw) => makeClient$13(definition, raw).fetch(options)),
121
+ patchLog: (logId, data) => withGateway((raw) => makeClient$13(definition, raw).patchLog(logId, data)),
122
+ getLog: (logId) => withGateway((raw) => makeClient$13(definition, raw).getLog(logId)),
123
123
  unsafeRaw: gateway
124
124
  };
125
125
  };
@@ -159,11 +159,11 @@ 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$16 = (tag, definition) => layer$18(tag, definition.binding, isAiGatewayBinding, (ai) => makeClientFromAi(definition, ai), { expected: expectedAiGatewayBinding });
162
+ const layer$17 = (tag, definition) => layer$19(tag, definition.binding, isAiGatewayBinding, (ai) => makeClientFromAi(definition, ai), { expected: expectedAiGatewayBinding });
163
163
  const make$16 = (id) => Tag$16()(id);
164
164
  const Tag$16 = () => (id) => {
165
165
  const tag = Context.Service()(id);
166
- const makeLayer = (definition) => layer$16(tag, definition);
166
+ const makeLayer = (definition) => layer$17(tag, definition);
167
167
  return Object.assign(tag, {
168
168
  id,
169
169
  layer: makeLayer
@@ -180,9 +180,9 @@ var AnalyticsEngine_exports = /* @__PURE__ */ __exportAll({
180
180
  QueryTag: () => QueryTag,
181
181
  Tag: () => Tag$15,
182
182
  isAnalyticsEngineDataset: () => isAnalyticsEngineDataset,
183
- layer: () => layer$15,
183
+ layer: () => layer$16,
184
184
  make: () => make$15,
185
- makeClient: () => makeClient$11,
185
+ makeClient: () => makeClient$12,
186
186
  makeQuery: () => makeQuery,
187
187
  makeQueryClient: () => makeQueryClient,
188
188
  queryConfig: () => queryConfig,
@@ -375,7 +375,7 @@ const isAnalyticsEngineDataset = (value) => {
375
375
  if (typeof value !== "object" || value === null) return false;
376
376
  return typeof Reflect.get(value, "writeDataPoint") === "function";
377
377
  };
378
- const makeClient$11 = (definition, defaults) => (dataset) => {
378
+ const makeClient$12 = (definition, defaults) => (dataset) => {
379
379
  const writeDataPoint = (dataPoint, options) => {
380
380
  const policy = resolveWritePolicy(defaults, options);
381
381
  return validateOptionalDataPoint(definition.binding, "writeDataPoint", dataPoint).pipe(Effect.matchEffect({
@@ -410,12 +410,12 @@ const queryLayerConfig = (tag, config = queryConfig()) => Layer.effect(tag, Effe
410
410
  return yield* makeQueryClient(yield* config);
411
411
  }));
412
412
  const queryFetchLayerConfig = (tag, config = queryConfig()) => queryLayerConfig(tag, config).pipe(Layer.provide(FetchHttpClient.layer));
413
- const layer$15 = (tag, definition) => layer$18(tag, definition.binding, isAnalyticsEngineDataset, makeClient$11(definition, definition.write), { expected: expectedAnalyticsEngineDataset });
413
+ const layer$16 = (tag, definition) => layer$19(tag, definition.binding, isAnalyticsEngineDataset, makeClient$12(definition, definition.write), { expected: expectedAnalyticsEngineDataset });
414
414
  const make$15 = (id) => Tag$15()(id);
415
415
  const makeQuery = (id) => QueryTag()(id);
416
416
  const Tag$15 = () => (id) => {
417
417
  const tag = Context.Service()(id);
418
- const makeLayer = (definition) => layer$15(tag, definition);
418
+ const makeLayer = (definition) => layer$16(tag, definition);
419
419
  return Object.assign(tag, {
420
420
  id,
421
421
  layer: makeLayer
@@ -441,9 +441,9 @@ var BrowserRendering_exports = /* @__PURE__ */ __exportAll({
441
441
  BrowserRenderingOperationError: () => BrowserRenderingOperationError,
442
442
  Tag: () => Tag$14,
443
443
  isBrowserRenderingBinding: () => isBrowserRenderingBinding,
444
- layer: () => layer$14,
444
+ layer: () => layer$15,
445
445
  make: () => make$14,
446
- makeClient: () => makeClient$10
446
+ makeClient: () => makeClient$11
447
447
  });
448
448
  const expectedBrowserRenderingBinding = "Browser Rendering binding resource";
449
449
  /** Error raised when a Browser Rendering operation fails. */
@@ -480,23 +480,64 @@ const wrapBrowser = (binding, browser) => ({
480
480
  disconnect: browser.disconnect === void 0 ? Effect.void : tryBrowserRenderingSync(binding, "disconnect", () => browser.disconnect())
481
481
  });
482
482
  const isBrowserRenderingBinding = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
483
- const makeClient$10 = (definition) => (binding) => ({
483
+ const makeClient$11 = (definition) => (binding) => ({
484
484
  definition,
485
485
  launchWith: (launch, options) => tryBrowserRenderingPromise(definition.binding, "launch", () => launch(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser))),
486
486
  connectWith: (connect, options) => tryBrowserRenderingPromise(definition.binding, "connect", () => connect(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser))),
487
487
  unsafeRaw: Effect.succeed(binding)
488
488
  });
489
- const layer$14 = (tag, definition) => layer$18(tag, definition.binding, isBrowserRenderingBinding, makeClient$10(definition), { expected: expectedBrowserRenderingBinding });
489
+ const layer$15 = (tag, definition) => layer$19(tag, definition.binding, isBrowserRenderingBinding, makeClient$11(definition), { expected: expectedBrowserRenderingBinding });
490
490
  const make$14 = (id) => Tag$14()(id);
491
491
  const Tag$14 = () => (id) => {
492
492
  const tag = Context.Service()(id);
493
- const makeLayer = (definition) => layer$14(tag, definition);
493
+ const makeLayer = (definition) => layer$15(tag, definition);
494
494
  return Object.assign(tag, {
495
495
  id,
496
496
  layer: makeLayer
497
497
  });
498
498
  };
499
499
  //#endregion
500
+ //#region src/Cache.ts
501
+ var Cache_exports = /* @__PURE__ */ __exportAll({
502
+ CacheOperationError: () => CacheOperationError,
503
+ CacheStorage: () => CacheStorage,
504
+ layer: () => layer$14,
505
+ layerFrom: () => layerFrom,
506
+ makeCacheClient: () => makeCacheClient,
507
+ makeClient: () => makeClient$10
508
+ });
509
+ /** Error raised when a Cloudflare Cache API operation fails. */
510
+ var CacheOperationError = class extends Data.TaggedError("CacheOperationError") {};
511
+ /** Service for Cloudflare's global Cache API. */
512
+ var CacheStorage = class extends Context.Service()("effect-cf/CacheStorage") {};
513
+ const cacheError = (cache, operation, cause) => new CacheOperationError({
514
+ cache,
515
+ operation,
516
+ cause
517
+ });
518
+ const tryCachePromise = (cache, operation, evaluate) => Effect.tryPromise({
519
+ try: evaluate,
520
+ catch: (cause) => cacheError(cache, operation, cause)
521
+ });
522
+ /** Wraps a native Cloudflare `Cache` instance. */
523
+ const makeCacheClient = (cache, name = "default") => ({
524
+ name,
525
+ match: (request, options) => tryCachePromise(name, "match", () => cache.match(request, options)).pipe(Effect.map(Option.fromUndefinedOr)),
526
+ put: (request, response) => tryCachePromise(name, "put", () => cache.put(request, response)),
527
+ delete: (request, options) => tryCachePromise(name, "delete", () => cache.delete(request, options)),
528
+ unsafeRaw: Effect.succeed(cache)
529
+ });
530
+ /** Wraps a native Cloudflare `CacheStorage` instance. */
531
+ const makeClient$10 = (storage) => ({
532
+ default: makeCacheClient(storage.default),
533
+ open: (name) => tryCachePromise(name, "open", () => storage.open(name)).pipe(Effect.map((cache) => makeCacheClient(cache, name))),
534
+ unsafeRaw: Effect.succeed(storage)
535
+ });
536
+ /** Provides Cache API services from an explicit native `CacheStorage` instance. */
537
+ const layerFrom = (storage) => Layer.succeed(CacheStorage, makeClient$10(storage));
538
+ /** Provides Cache API services from Cloudflare's global `caches` object. */
539
+ const layer$14 = Layer.sync(CacheStorage, () => makeClient$10(caches));
540
+ //#endregion
500
541
  //#region src/DurableObjectStorage.ts
501
542
  var DurableObjectStorage_exports = /* @__PURE__ */ __exportAll({
502
543
  StorageOperationError: () => StorageOperationError,
@@ -966,7 +1007,7 @@ const makeClient$9 = (definition) => (namespace) => {
966
1007
  unsafeRaw: Effect.succeed(namespace)
967
1008
  };
968
1009
  };
969
- const layer$12 = (tag, definition) => layer$18(tag, definition.binding, isContainerNamespaceResource, makeClient$9(definition), { expected: expectedContainerNamespace });
1010
+ const layer$12 = (tag, definition) => layer$19(tag, definition.binding, isContainerNamespaceResource, makeClient$9(definition), { expected: expectedContainerNamespace });
970
1011
  const make$13 = (id) => Tag$13()(id);
971
1012
  /** Creates a typed Effect service for a Cloudflare Container namespace. */
972
1013
  const Tag$13 = () => (id) => {
@@ -1104,7 +1145,7 @@ const makeClient$8 = (definition) => {
1104
1145
  unsafeRaw: Effect.succeed(queue)
1105
1146
  });
1106
1147
  };
1107
- const layer$11 = (tag, definition) => layer$18(tag, definition.binding, (value) => isQueue(value), makeClient$8(definition), { expected: expectedQueueProducer });
1148
+ const layer$11 = (tag, definition) => layer$19(tag, definition.binding, (value) => isQueue(value), makeClient$8(definition), { expected: expectedQueueProducer });
1108
1149
  //#endregion
1109
1150
  //#region src/QueueDefinition.ts
1110
1151
  var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
@@ -1447,7 +1488,7 @@ const makeClient$7 = (definition) => {
1447
1488
  });
1448
1489
  };
1449
1490
  };
1450
- const layer$10 = (tag, definition) => layer$18(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$7(definition), { expected: expectedServiceBinding });
1491
+ const layer$10 = (tag, definition) => layer$19(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$7(definition), { expected: expectedServiceBinding });
1451
1492
  /**
1452
1493
  * Creates a typed Effect service for a Worker service binding.
1453
1494
  *
@@ -1824,7 +1865,7 @@ const makeClient$6 = (definition) => {
1824
1865
  });
1825
1866
  };
1826
1867
  };
1827
- const layer$8 = (tag, definition) => layer$18(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$6(definition), { expected: expectedDurableObjectNamespace });
1868
+ const layer$8 = (tag, definition) => layer$19(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$6(definition), { expected: expectedDurableObjectNamespace });
1828
1869
  const makeDirectMethods = (rpcDefinition, helpers) => {
1829
1870
  const methods = {};
1830
1871
  if (rpcDefinition !== void 0) {
@@ -2539,7 +2580,7 @@ const makeClient$5 = (definition) => (email) => {
2539
2580
  unsafeRaw: Effect.succeed(email)
2540
2581
  };
2541
2582
  };
2542
- const layer$5 = (tag, definition) => layer$18(tag, definition.binding, isEmailBinding, makeClient$5(definition), { expected: expectedSendEmailBinding });
2583
+ const layer$5 = (tag, definition) => layer$19(tag, definition.binding, isEmailBinding, makeClient$5(definition), { expected: expectedSendEmailBinding });
2543
2584
  const make$5 = (id) => Tag$6()(id);
2544
2585
  const Tag$6 = () => (id) => {
2545
2586
  const tag = Context.Service()(id);
@@ -2646,7 +2687,7 @@ const makeClient$4 = (definition) => (images) => {
2646
2687
  unsafeRaw: Effect.succeed(images)
2647
2688
  };
2648
2689
  };
2649
- const layer$4 = (tag, definition) => layer$18(tag, definition.binding, isImagesBinding, makeClient$4(definition), { expected: expectedImagesBinding });
2690
+ const layer$4 = (tag, definition) => layer$19(tag, definition.binding, isImagesBinding, makeClient$4(definition), { expected: expectedImagesBinding });
2650
2691
  const make$4 = (id) => Tag$5()(id);
2651
2692
  const Tag$5 = () => (id) => {
2652
2693
  const tag = Context.Service()(id);
@@ -2741,7 +2782,7 @@ const makeClient$3 = (definition) => {
2741
2782
  unsafeRaw: Effect.succeed(kv)
2742
2783
  });
2743
2784
  };
2744
- const layer$3 = (tag, definition) => layer$18(tag, definition.binding, isKvNamespace, makeClient$3(definition), { expected: expectedKvNamespace });
2785
+ const layer$3 = (tag, definition) => layer$19(tag, definition.binding, isKvNamespace, makeClient$3(definition), { expected: expectedKvNamespace });
2745
2786
  const makeDefinition$1 = (id, definition) => {
2746
2787
  const kvDefinition = {
2747
2788
  id,
@@ -2858,7 +2899,7 @@ const makeClient$2 = (definition) => {
2858
2899
  };
2859
2900
  };
2860
2901
  };
2861
- const layer$2 = (tag, definition) => layer$18(tag, definition.binding, isR2Bucket, makeClient$2(definition), { expected: expectedR2Bucket });
2902
+ const layer$2 = (tag, definition) => layer$19(tag, definition.binding, isR2Bucket, makeClient$2(definition), { expected: expectedR2Bucket });
2862
2903
  const make$3 = (id) => Tag$3()(id);
2863
2904
  const Tag$3 = () => (id) => {
2864
2905
  const tag = Context.Service()(id);
@@ -2915,7 +2956,7 @@ const makeClient$1 = (definition) => {
2915
2956
  return {
2916
2957
  status: status.status,
2917
2958
  output,
2918
- error: status.error === void 0 ? Option.none() : Option.some(status.error)
2959
+ error: status.error == null ? Option.none() : Option.some(status.error)
2919
2960
  };
2920
2961
  }))),
2921
2962
  sendEvent: (event) => operation("sendEvent", () => raw.sendEvent(event))
@@ -2944,7 +2985,7 @@ const makeClient$1 = (definition) => {
2944
2985
  unsafeRaw: Effect.succeed(workflow)
2945
2986
  });
2946
2987
  };
2947
- const layer$1 = (tag, definition) => layer$18(tag, definition.binding, (value) => isWorkflow(value), makeClient$1(definition), { expected: expectedWorkflow });
2988
+ const layer$1 = (tag, definition) => layer$19(tag, definition.binding, (value) => isWorkflow(value), makeClient$1(definition), { expected: expectedWorkflow });
2948
2989
  //#endregion
2949
2990
  //#region src/WorkflowDefinition.ts
2950
2991
  var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
@@ -3118,7 +3159,7 @@ const makeClient = (definition) => (index) => {
3118
3159
  unsafeRaw: Effect.succeed(index)
3119
3160
  };
3120
3161
  };
3121
- const layer = (tag, definition) => layer$18(tag, definition.binding, isVectorizeBinding, makeClient(definition), { expected: expectedVectorizeBinding });
3162
+ const layer = (tag, definition) => layer$19(tag, definition.binding, isVectorizeBinding, makeClient(definition), { expected: expectedVectorizeBinding });
3122
3163
  const make = (id) => Tag()(id);
3123
3164
  const Tag = () => (id) => {
3124
3165
  const tag = Context.Service()(id);
@@ -3129,4 +3170,4 @@ const Tag = () => (id) => {
3129
3170
  });
3130
3171
  };
3131
3172
  //#endregion
3132
- export { AiGateway_exports as AiGateway, AnalyticsEngine_exports as AnalyticsEngine, Binding_exports as Binding, BrowserRendering_exports as BrowserRendering, CloudflareOtlp_exports as CloudflareOtlp, ContainerNamespace_exports as ContainerNamespace, 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 };
3173
+ export { AiGateway_exports as AiGateway, AnalyticsEngine_exports as AnalyticsEngine, Binding_exports as Binding, BrowserRendering_exports as BrowserRendering, Cache_exports as Cache, CloudflareOtlp_exports as CloudflareOtlp, ContainerNamespace_exports as ContainerNamespace, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-cf",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Effect-native primitives for Cloudflare Workers and bindings.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/Cache.ts ADDED
@@ -0,0 +1,104 @@
1
+ import type {
2
+ Cache as CloudflareCache,
3
+ CacheQueryOptions as CloudflareCacheQueryOptions,
4
+ CacheStorage as CloudflareCacheStorage,
5
+ RequestInfo as CloudflareRequestInfo,
6
+ } from "@cloudflare/workers-types";
7
+ import { Context, Data, Effect, Layer, Option } from "effect";
8
+
9
+ /** Request key accepted by Cloudflare's Cache API. */
10
+ export type CacheRequest = CloudflareRequestInfo | URL;
11
+
12
+ /** Query options supported by Cloudflare's Cache API. */
13
+ export type CacheQueryOptions = CloudflareCacheQueryOptions;
14
+
15
+ /** Cache operation represented by {@link CacheOperationError}. */
16
+ export type CacheOperation = "open" | "match" | "put" | "delete";
17
+
18
+ /** Error raised when a Cloudflare Cache API operation fails. */
19
+ export class CacheOperationError extends Data.TaggedError("CacheOperationError")<{
20
+ readonly cache: string;
21
+ readonly operation: CacheOperation;
22
+ readonly cause: unknown;
23
+ }> {}
24
+
25
+ /** Effect wrapper around one Cloudflare `Cache` instance. */
26
+ export interface CacheClient {
27
+ /** Cache name (`default` for `caches.default`). */
28
+ readonly name: string;
29
+ /** Finds a cached response, mapping cache misses to `Option.none()`. */
30
+ readonly match: (
31
+ request: CacheRequest,
32
+ options?: CacheQueryOptions,
33
+ ) => Effect.Effect<Option.Option<Response>, CacheOperationError>;
34
+ /** Stores a response under the request key. */
35
+ readonly put: (
36
+ request: CacheRequest,
37
+ response: Response,
38
+ ) => Effect.Effect<void, CacheOperationError>;
39
+ /** Deletes a cached response and reports whether it existed. */
40
+ readonly delete: (
41
+ request: CacheRequest,
42
+ options?: CacheQueryOptions,
43
+ ) => Effect.Effect<boolean, CacheOperationError>;
44
+ /** Access to the native Cloudflare `Cache` instance. */
45
+ readonly unsafeRaw: Effect.Effect<CloudflareCache>;
46
+ }
47
+
48
+ /** Effect wrapper around Cloudflare's global `caches` object. */
49
+ export interface CacheStorageClient {
50
+ /** Cloudflare's shared default cache. */
51
+ readonly default: CacheClient;
52
+ /** Opens a named cache. */
53
+ readonly open: (name: string) => Effect.Effect<CacheClient, CacheOperationError>;
54
+ /** Access to the native Cloudflare `CacheStorage` instance. */
55
+ readonly unsafeRaw: Effect.Effect<CloudflareCacheStorage>;
56
+ }
57
+
58
+ /** Service for Cloudflare's global Cache API. */
59
+ export class CacheStorage extends Context.Service<CacheStorage, CacheStorageClient>()(
60
+ "effect-cf/CacheStorage",
61
+ ) {}
62
+
63
+ const cacheError = (cache: string, operation: CacheOperation, cause: unknown) =>
64
+ new CacheOperationError({ cache, operation, cause });
65
+
66
+ const tryCachePromise = <A>(
67
+ cache: string,
68
+ operation: CacheOperation,
69
+ evaluate: () => Promise<A>,
70
+ ): Effect.Effect<A, CacheOperationError> =>
71
+ Effect.tryPromise({
72
+ try: evaluate,
73
+ catch: (cause) => cacheError(cache, operation, cause),
74
+ });
75
+
76
+ /** Wraps a native Cloudflare `Cache` instance. */
77
+ export const makeCacheClient = (cache: CloudflareCache, name = "default"): CacheClient => ({
78
+ name,
79
+ match: (request, options) =>
80
+ tryCachePromise(name, "match", () => cache.match(request, options)).pipe(
81
+ Effect.map(Option.fromUndefinedOr),
82
+ ),
83
+ put: (request, response) => tryCachePromise(name, "put", () => cache.put(request, response)),
84
+ delete: (request, options) =>
85
+ tryCachePromise(name, "delete", () => cache.delete(request, options)),
86
+ unsafeRaw: Effect.succeed(cache),
87
+ });
88
+
89
+ /** Wraps a native Cloudflare `CacheStorage` instance. */
90
+ export const makeClient = (storage: CloudflareCacheStorage): CacheStorageClient => ({
91
+ default: makeCacheClient(storage.default),
92
+ open: (name) =>
93
+ tryCachePromise(name, "open", () => storage.open(name)).pipe(
94
+ Effect.map((cache) => makeCacheClient(cache, name)),
95
+ ),
96
+ unsafeRaw: Effect.succeed(storage),
97
+ });
98
+
99
+ /** Provides Cache API services from an explicit native `CacheStorage` instance. */
100
+ export const layerFrom = (storage: CloudflareCacheStorage): Layer.Layer<CacheStorage> =>
101
+ Layer.succeed(CacheStorage, makeClient(storage));
102
+
103
+ /** Provides Cache API services from Cloudflare's global `caches` object. */
104
+ export const layer: Layer.Layer<CacheStorage> = Layer.sync(CacheStorage, () => makeClient(caches));
@@ -187,7 +187,7 @@ export const makeClient = <
187
187
  return {
188
188
  status: status.status,
189
189
  output,
190
- error: status.error === undefined ? Option.none() : Option.some(status.error),
190
+ error: status.error == null ? Option.none() : Option.some(status.error),
191
191
  };
192
192
  }),
193
193
  ),
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export * as AiGateway from "./AiGateway";
2
2
  export * as AnalyticsEngine from "./AnalyticsEngine";
3
3
  export * as Binding from "./Binding";
4
4
  export * as BrowserRendering from "./BrowserRendering";
5
+ export * as Cache from "./Cache";
5
6
  export * as CloudflareOtlp from "./CloudflareOtlp";
6
7
  export * as ContainerNamespace from "./ContainerNamespace";
7
8
  export * as D1 from "./D1";