effect-cf 0.15.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/CHANGELOG.md +6 -0
- package/README.md +83 -1
- package/dist/index.d.mts +194 -23
- package/dist/index.mjs +300 -34
- package/package.json +1 -1
- package/src/AnalyticsEngine.ts +846 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# effect-cf
|
|
2
2
|
|
|
3
|
+
## 0.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#51](https://github.com/danieljvdm/effect-cf/pull/51) [`9a6abd2`](https://github.com/danieljvdm/effect-cf/commit/9a6abd27366c71867a420f872459b3d5fc1b2143) Thanks [@owensbla](https://github.com/owensbla)! - Add Effect-native Cloudflare Analytics Engine helpers. `AnalyticsEngine.Tag(...)` now provides validated dataset writes, configurable invalid-write policy, and batch write helpers. `AnalyticsEngine.QueryTag(...)` / `makeQueryClient(...)` provide SQL API querying backed by Effect `HttpClient`, config and redacted API token support, typed result envelopes, and row decoding through Effect schemas.
|
|
8
|
+
|
|
3
9
|
## 0.15.0
|
|
4
10
|
|
|
5
11
|
### 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, bindings, KV, D1, Queues, Email, Workflows, and Durable Object storage.
|
|
3
|
+
Effect-native Cloudflare primitives for Workers, Durable Objects, bindings, KV, D1, Queues, Email, Analytics Engine, Workflows, and Durable Object storage.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -36,6 +36,7 @@ Runtime creation belongs at Cloudflare entrypoints, not inside binding helpers.
|
|
|
36
36
|
- `Hyperdrive` - typed Hyperdrive binding helper for connection strings and optional Postgres SQL integration
|
|
37
37
|
- `Images` - typed Cloudflare Images binding helper with transformation APIs and optional hosted image operations
|
|
38
38
|
- `Email` - typed Cloudflare Send Email binding helper for `send_email` bindings
|
|
39
|
+
- `AnalyticsEngine` - typed Cloudflare Analytics Engine write bindings and SQL API query helpers
|
|
39
40
|
- `Queue` - typed Queue producer/consumer tags plus client and error types
|
|
40
41
|
- `Workflow` - typed Workflow entrypoints, steps, starter clients, and instance types
|
|
41
42
|
- `Rpc` - Cloudflare RPC type helpers and scoped disposal utilities
|
|
@@ -233,6 +234,87 @@ export const sendWelcomeEmail = (to: string) =>
|
|
|
233
234
|
});
|
|
234
235
|
```
|
|
235
236
|
|
|
237
|
+
## Analytics Engine Example
|
|
238
|
+
|
|
239
|
+
Analytics Engine tags expose Cloudflare dataset bindings as Effect-wrapped `writeDataPoint(...)` operations. Writes use Cloudflare's native non-blocking runtime API and are validated against Workers Analytics Engine limits before reaching the binding.
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
import { Effect } from "effect";
|
|
243
|
+
import { AnalyticsEngine } from "effect-cf";
|
|
244
|
+
|
|
245
|
+
class RequestAnalytics extends AnalyticsEngine.Tag<RequestAnalytics>()("RequestAnalytics") {}
|
|
246
|
+
|
|
247
|
+
export const RequestAnalyticsLayer = RequestAnalytics.layer({
|
|
248
|
+
binding: "REQUEST_ANALYTICS",
|
|
249
|
+
write: {
|
|
250
|
+
onInvalid: "error",
|
|
251
|
+
batchSize: 100,
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
export const recordPageView = (request: Request) =>
|
|
256
|
+
Effect.gen(function* () {
|
|
257
|
+
const analytics = yield* RequestAnalytics;
|
|
258
|
+
const url = new URL(request.url);
|
|
259
|
+
|
|
260
|
+
yield* analytics.writeDataPoint({
|
|
261
|
+
indexes: [url.hostname],
|
|
262
|
+
blobs: [url.pathname, request.headers.get("cf-connecting-country") ?? "unknown"],
|
|
263
|
+
doubles: [1],
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
yield* analytics.writeBatch(
|
|
267
|
+
[
|
|
268
|
+
{
|
|
269
|
+
indexes: [url.hostname],
|
|
270
|
+
blobs: [url.pathname, "page-view"],
|
|
271
|
+
doubles: [1],
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
{ onInvalid: "drop" },
|
|
275
|
+
);
|
|
276
|
+
});
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Define the dataset binding in the consuming Worker's `wrangler.jsonc` with `analytics_engine_datasets`, then provide `RequestAnalytics.layer({ binding: "REQUEST_ANALYTICS" })` from the Worker layer. Invalid writes fail with `AnalyticsEngineWriteValidationError` by default. Use `write: { onInvalid: "drop" }` on the layer or `{ onInvalid: "drop" }` per call when dropping invalid points is preferable.
|
|
280
|
+
|
|
281
|
+
Analytics Engine query tags wrap Cloudflare's HTTP SQL API. Configuration can stay in Effect `Config`, including a redacted API token, the outbound transport is an Effect `HttpClient` dependency, and rows can be decoded with Effect schemas at the query boundary. Use `fetchLayerConfig(...)` as shorthand when the platform fetch-backed client is enough.
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
import { Effect, Layer, Schema as S } from "effect";
|
|
285
|
+
import { FetchHttpClient } from "effect/unstable/http";
|
|
286
|
+
import { AnalyticsEngine, WorkerConfig } from "effect-cf";
|
|
287
|
+
|
|
288
|
+
class AnalyticsQuery extends AnalyticsEngine.QueryTag<AnalyticsQuery>()("AnalyticsQuery") {}
|
|
289
|
+
|
|
290
|
+
export const AnalyticsQueryLayer = AnalyticsQuery.layerConfig(
|
|
291
|
+
AnalyticsEngine.queryConfig({
|
|
292
|
+
accountId: WorkerConfig.string("CLOUDFLARE_ACCOUNT_ID"),
|
|
293
|
+
apiToken: WorkerConfig.redacted("CLOUDFLARE_API_TOKEN"),
|
|
294
|
+
}),
|
|
295
|
+
).pipe(Layer.provide(FetchHttpClient.layer));
|
|
296
|
+
|
|
297
|
+
const PageView = S.Struct({
|
|
298
|
+
path: S.String,
|
|
299
|
+
views: S.Number,
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
export const topPages = Effect.gen(function* () {
|
|
303
|
+
const analytics = yield* AnalyticsQuery;
|
|
304
|
+
|
|
305
|
+
return yield* analytics.queryRows(
|
|
306
|
+
PageView,
|
|
307
|
+
`
|
|
308
|
+
SELECT blob1 AS path, SUM(_sample_interval) AS views
|
|
309
|
+
FROM request_metrics
|
|
310
|
+
GROUP BY path
|
|
311
|
+
ORDER BY views DESC
|
|
312
|
+
LIMIT 10
|
|
313
|
+
`,
|
|
314
|
+
);
|
|
315
|
+
});
|
|
316
|
+
```
|
|
317
|
+
|
|
236
318
|
## Workflow Example
|
|
237
319
|
|
|
238
320
|
Workflow definitions type the payload and result. Runtime handlers can access `Workflow.WorkflowEvent`, use durable `Workflow.step(...)`, and use normal binding services inside steps.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as BindingService, c as WorkerConfig, i as BindingNotFoundError, l as WorkerEnv, o as BindingValidationError, s as Binding_d_exports, t as Hyperdrive_d_exports, u as WorkerEnvironment } from "./Hyperdrive-C0vfrPeG.mjs";
|
|
2
|
-
import { Cause, Context, Data, DateTime, Duration, Effect, Layer, Option, Schema, Scope } from "effect";
|
|
3
|
-
import { Headers as Headers$1, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
2
|
+
import { Cause, Config, Context, Data, DateTime, Duration, Effect, Layer, Option, Redacted, Schema, Scope } from "effect";
|
|
3
|
+
import { Headers as Headers$1, HttpClient, HttpClientResponse, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
4
4
|
import { D1Client } from "@effect/sql-d1";
|
|
5
5
|
import { DurableObject, RpcStub, RpcTarget, WorkerEntrypoint, WorkflowEntrypoint, WorkflowEvent, WorkflowSleepDuration, WorkflowStep, WorkflowStepConfig, WorkflowStepContext, WorkflowStepEvent, WorkflowTimeoutDuration } from "cloudflare:workers";
|
|
6
6
|
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
|
|
@@ -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
|
+
export { LayerOptions$18 as LayerOptions, Tag$17 as Tag, TagClass$16 as TagClass, WorkersAiAsyncBatchResponse, WorkersAiBinding, WorkersAiClient, WorkersAiDefinition, WorkersAiEmbeddingInput, WorkersAiEmbeddingResponse, WorkersAiModelsSearchObject, WorkersAiModelsSearchParams, WorkersAiOperationError, WorkersAiOptions, WorkersAiService, embeddingResponse, isWorkersAiBinding, layer$15 as layer, make$16 as make, makeClient$12 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";
|
|
@@ -75,24 +75,24 @@ interface WorkersAiService<Id extends string> {
|
|
|
75
75
|
readonly id: Id;
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
-
type LayerOptions$
|
|
78
|
+
type LayerOptions$18 = {
|
|
79
79
|
readonly binding: string;
|
|
80
80
|
};
|
|
81
|
-
interface TagClass$
|
|
81
|
+
interface TagClass$16<Self, Id extends string, ModelList extends AiModelListType = AiModels> extends Context.ServiceClass<Self, Id, WorkersAiClient<ModelList>> {
|
|
82
82
|
readonly id: Id;
|
|
83
|
-
readonly layer: (options: LayerOptions$
|
|
83
|
+
readonly layer: (options: LayerOptions$18) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
84
84
|
}
|
|
85
85
|
declare const isWorkersAiBinding: (value: unknown) => value is WorkersAiBinding;
|
|
86
86
|
declare const embeddingResponse: (value: {
|
|
87
87
|
readonly data?: ReadonlyArray<ReadonlyArray<number>>;
|
|
88
88
|
readonly shape?: ReadonlyArray<number>;
|
|
89
89
|
}) => WorkersAiEmbeddingResponse;
|
|
90
|
-
declare const makeClient$
|
|
91
|
-
declare const layer$
|
|
92
|
-
declare const make$
|
|
93
|
-
declare const Tag$
|
|
90
|
+
declare const makeClient$12: <ModelList extends AiModelListType = AiModels>(definition: WorkersAiDefinition) => (ai: WorkersAiBinding<ModelList>) => WorkersAiClient<ModelList>;
|
|
91
|
+
declare const layer$15: <Self, ModelList extends AiModelListType = AiModels>(tag: Context.Service<Self, WorkersAiClient<ModelList>>, definition: WorkersAiDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
92
|
+
declare const make$16: <Id extends string>(id: Id) => TagClass$16<WorkersAiService<Id>, Id, AiModels>;
|
|
93
|
+
declare const Tag$17: <Self>() => <Id extends string, ModelList extends AiModelListType = AiModels>(id: Id) => TagClass$16<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$
|
|
95
|
+
export { AiGatewayBinding, AiGatewayClient, AiGatewayDefinition, AiGatewayFetchOptions, AiGatewayHeaders, AiGatewayLog, AiGatewayOperationError, AiGatewayPatchLog, AiGatewayProvider, AiGatewayRunOptions, AiGatewayService, AiGatewayUniversalRequest, LayerOptions$17 as LayerOptions, Tag$16 as Tag, TagClass$15 as TagClass, isAiGatewayBinding, layer$14 as layer, make$15 as make, makeClient$11 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";
|
|
@@ -141,17 +141,17 @@ interface AiGatewayService<Id extends string> {
|
|
|
141
141
|
readonly id: Id;
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
type LayerOptions$
|
|
144
|
+
type LayerOptions$17 = {
|
|
145
145
|
readonly binding: string;
|
|
146
146
|
readonly gatewayId: string;
|
|
147
147
|
readonly accountId?: string;
|
|
148
148
|
};
|
|
149
|
-
interface TagClass$
|
|
149
|
+
interface TagClass$15<Self, Id extends string> extends Context.ServiceClass<Self, Id, AiGatewayClient> {
|
|
150
150
|
readonly id: Id;
|
|
151
|
-
readonly layer: (options: LayerOptions$
|
|
151
|
+
readonly layer: (options: LayerOptions$17) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError | AiGatewayOperationError, WorkerEnvironment>;
|
|
152
152
|
}
|
|
153
153
|
declare const isAiGatewayBinding: (value: unknown) => value is WorkersAiBinding;
|
|
154
|
-
declare const makeClient$
|
|
154
|
+
declare const makeClient$11: (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,9 +169,180 @@ 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$
|
|
173
|
-
declare const make$
|
|
172
|
+
declare const layer$14: <Self>(tag: Context.Service<Self, AiGatewayClient>, definition: AiGatewayDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
173
|
+
declare const make$15: <Id extends string>(id: Id) => TagClass$15<AiGatewayService<Id>, Id>;
|
|
174
|
+
declare const Tag$16: <Self>() => <Id extends string>(id: Id) => TagClass$15<Self, Id>;
|
|
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$16 as LayerOptions, QueryConfigOptions, QueryTag, QueryTagClass, Tag$15 as Tag, TagClass$14 as TagClass, isAnalyticsEngineDataset, layer$13 as layer, make$14 as make, makeClient$10 as makeClient, makeQuery, makeQueryClient, queryConfig, queryFetchLayer, queryFetchLayerConfig, queryLayer, queryLayerConfig, writeLimits };
|
|
177
|
+
}
|
|
178
|
+
declare const writeLimits: {
|
|
179
|
+
readonly maxBlobs: 20;
|
|
180
|
+
readonly maxDoubles: 20;
|
|
181
|
+
readonly maxIndexes: 1;
|
|
182
|
+
readonly maxBlobBytes: number;
|
|
183
|
+
readonly maxIndexBytes: 96;
|
|
184
|
+
readonly maxDataPointsPerInvocation: 250;
|
|
185
|
+
};
|
|
186
|
+
declare const queryColumnSchema: Schema.Struct<{
|
|
187
|
+
readonly name: Schema.String;
|
|
188
|
+
readonly type: Schema.String;
|
|
189
|
+
}>;
|
|
190
|
+
declare const queryRowSchema: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
191
|
+
declare const AnalyticsEngineFieldValueSchema: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.instanceOf<ArrayBuffer, unknown>]>>;
|
|
192
|
+
declare const AnalyticsEngineDataPointSchema: Schema.Struct<{
|
|
193
|
+
readonly indexes: Schema.optional<Schema.$Array<Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.instanceOf<ArrayBuffer, unknown>]>>>>;
|
|
194
|
+
readonly doubles: Schema.optional<Schema.$Array<Schema.Finite>>;
|
|
195
|
+
readonly blobs: Schema.optional<Schema.$Array<Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.instanceOf<ArrayBuffer, unknown>]>>>>;
|
|
196
|
+
}>;
|
|
197
|
+
declare const AnalyticsEngineOperationError_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 & {
|
|
198
|
+
readonly _tag: "AnalyticsEngineOperationError";
|
|
199
|
+
} & Readonly<A>;
|
|
200
|
+
/** Error raised when an Analytics Engine operation fails. */
|
|
201
|
+
declare class AnalyticsEngineOperationError extends AnalyticsEngineOperationError_base<{
|
|
202
|
+
readonly binding: string;
|
|
203
|
+
readonly operation: string;
|
|
204
|
+
readonly cause: unknown;
|
|
205
|
+
}> {}
|
|
206
|
+
interface AnalyticsEngineWriteViolation {
|
|
207
|
+
readonly path: string;
|
|
208
|
+
readonly message: string;
|
|
209
|
+
readonly limit?: number;
|
|
210
|
+
readonly actual?: number;
|
|
211
|
+
}
|
|
212
|
+
declare const AnalyticsEngineWriteValidationError_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 & {
|
|
213
|
+
readonly _tag: "AnalyticsEngineWriteValidationError";
|
|
214
|
+
} & Readonly<A>;
|
|
215
|
+
/** Error raised when an Analytics Engine write input violates Cloudflare limits. */
|
|
216
|
+
declare class AnalyticsEngineWriteValidationError extends AnalyticsEngineWriteValidationError_base<{
|
|
217
|
+
readonly binding: string;
|
|
218
|
+
readonly operation: string;
|
|
219
|
+
readonly violations: ReadonlyArray<AnalyticsEngineWriteViolation>;
|
|
220
|
+
readonly cause?: unknown;
|
|
221
|
+
}> {}
|
|
222
|
+
declare const AnalyticsEngineQueryError_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 & {
|
|
223
|
+
readonly _tag: "AnalyticsEngineQueryError";
|
|
224
|
+
} & Readonly<A>;
|
|
225
|
+
/** Error raised when an Analytics Engine SQL API query fails. */
|
|
226
|
+
declare class AnalyticsEngineQueryError extends AnalyticsEngineQueryError_base<{
|
|
227
|
+
readonly operation: string;
|
|
228
|
+
readonly accountId: string;
|
|
229
|
+
readonly message: string;
|
|
230
|
+
readonly status?: number;
|
|
231
|
+
readonly body?: string;
|
|
232
|
+
readonly cause?: unknown;
|
|
233
|
+
}> {}
|
|
234
|
+
/** Typed Analytics Engine dataset binding definition. */
|
|
235
|
+
interface AnalyticsEngineDefinition {
|
|
236
|
+
/** Binding name as configured in `wrangler.jsonc`. */
|
|
237
|
+
readonly binding: string;
|
|
238
|
+
}
|
|
239
|
+
type AnalyticsEngineBinding = CloudflareAnalyticsEngineDataset;
|
|
240
|
+
type AnalyticsEngineDataPoint = CloudflareAnalyticsEngineDataPoint;
|
|
241
|
+
type AnalyticsEngineFieldValue = ArrayBuffer | string | null;
|
|
242
|
+
type AnalyticsEngineWriteError = AnalyticsEngineOperationError | AnalyticsEngineWriteValidationError;
|
|
243
|
+
type AnalyticsEngineInvalidWritePolicy = "error" | "drop";
|
|
244
|
+
type AnalyticsEngineQueryColumn = Schema.Schema.Type<typeof queryColumnSchema>;
|
|
245
|
+
type AnalyticsEngineQueryRow = Schema.Schema.Type<typeof queryRowSchema>;
|
|
246
|
+
interface AnalyticsEngineWriteOptions {
|
|
247
|
+
/**
|
|
248
|
+
* Controls invalid write behavior. The default is `"error"`, which fails with
|
|
249
|
+
* `AnalyticsEngineWriteValidationError`. `"drop"` skips invalid points.
|
|
250
|
+
*/
|
|
251
|
+
readonly onInvalid?: AnalyticsEngineInvalidWritePolicy;
|
|
252
|
+
}
|
|
253
|
+
interface AnalyticsEngineWriteBatchOptions extends AnalyticsEngineWriteOptions {
|
|
254
|
+
/**
|
|
255
|
+
* Maximum points per native batch call. Values are clamped to Cloudflare's
|
|
256
|
+
* per-invocation limit.
|
|
257
|
+
*/
|
|
258
|
+
readonly batchSize?: number;
|
|
259
|
+
}
|
|
260
|
+
type AnalyticsEngineWritePolicy = AnalyticsEngineWriteBatchOptions;
|
|
261
|
+
interface AnalyticsEngineQueryResult<Row = AnalyticsEngineQueryRow> {
|
|
262
|
+
readonly meta: ReadonlyArray<AnalyticsEngineQueryColumn>;
|
|
263
|
+
readonly data: ReadonlyArray<Row>;
|
|
264
|
+
readonly rows: number;
|
|
265
|
+
}
|
|
266
|
+
interface AnalyticsEngineQueryDefinition {
|
|
267
|
+
/** Cloudflare account id that owns the Analytics Engine datasets. */
|
|
268
|
+
readonly accountId: string;
|
|
269
|
+
/** API token with Account Analytics Read permission. */
|
|
270
|
+
readonly apiToken: Redacted.Redacted<string>;
|
|
271
|
+
/** Base Cloudflare API URL. Defaults to `https://api.cloudflare.com/client/v4`. */
|
|
272
|
+
readonly apiBaseUrl?: string | URL;
|
|
273
|
+
}
|
|
274
|
+
interface AnalyticsEngineQueryOptions {
|
|
275
|
+
/** Additional request headers. Authorization is always derived from `apiToken`. */
|
|
276
|
+
readonly headers?: Headers$1.Input;
|
|
277
|
+
}
|
|
278
|
+
interface AnalyticsEngineClient {
|
|
279
|
+
readonly writeDataPoint: (dataPoint?: AnalyticsEngineDataPoint, options?: AnalyticsEngineWriteOptions) => Effect.Effect<void, AnalyticsEngineWriteError>;
|
|
280
|
+
readonly write: (dataPoint?: AnalyticsEngineDataPoint, options?: AnalyticsEngineWriteOptions) => Effect.Effect<void, AnalyticsEngineWriteError>;
|
|
281
|
+
readonly writeDataPoints: (dataPoints: ReadonlyArray<AnalyticsEngineDataPoint>, options?: AnalyticsEngineWriteBatchOptions) => Effect.Effect<void, AnalyticsEngineWriteError>;
|
|
282
|
+
readonly writeBatch: (dataPoints: ReadonlyArray<AnalyticsEngineDataPoint>, options?: AnalyticsEngineWriteBatchOptions) => Effect.Effect<void, AnalyticsEngineWriteError>;
|
|
283
|
+
readonly unsafeRaw: Effect.Effect<AnalyticsEngineBinding>;
|
|
284
|
+
readonly definition: AnalyticsEngineDefinition;
|
|
285
|
+
}
|
|
286
|
+
interface AnalyticsEngineQueryClient {
|
|
287
|
+
readonly query: (sql: string, options?: AnalyticsEngineQueryOptions) => Effect.Effect<AnalyticsEngineQueryResult, AnalyticsEngineQueryError | Schema.SchemaError>;
|
|
288
|
+
readonly queryResult: <Row>(row: Schema.Codec<Row, unknown>, sql: string, options?: AnalyticsEngineQueryOptions) => Effect.Effect<AnalyticsEngineQueryResult<Row>, AnalyticsEngineQueryError | Schema.SchemaError>;
|
|
289
|
+
readonly queryRows: <Row>(row: Schema.Codec<Row, unknown>, sql: string, options?: AnalyticsEngineQueryOptions) => Effect.Effect<ReadonlyArray<Row>, AnalyticsEngineQueryError | Schema.SchemaError>;
|
|
290
|
+
readonly queryOne: <Row>(row: Schema.Codec<Row, unknown>, sql: string, options?: AnalyticsEngineQueryOptions) => Effect.Effect<Option.Option<Row>, AnalyticsEngineQueryError | Schema.SchemaError>;
|
|
291
|
+
readonly queryText: (sql: string, options?: AnalyticsEngineQueryOptions) => Effect.Effect<string, AnalyticsEngineQueryError>;
|
|
292
|
+
readonly raw: (sql: string, options?: AnalyticsEngineQueryOptions) => Effect.Effect<HttpClientResponse.HttpClientResponse, AnalyticsEngineQueryError>;
|
|
293
|
+
readonly definition: AnalyticsEngineQueryDefinition;
|
|
294
|
+
}
|
|
295
|
+
declare const AnalyticsEngineServiceTypeId: unique symbol;
|
|
296
|
+
declare const AnalyticsEngineQueryServiceTypeId: unique symbol;
|
|
297
|
+
/** Nominal service marker for Analytics Engine services created with {@link make}. */
|
|
298
|
+
interface AnalyticsEngineService<Id extends string> {
|
|
299
|
+
readonly [AnalyticsEngineServiceTypeId]: {
|
|
300
|
+
readonly id: Id;
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/** Nominal service marker for Analytics Engine query services created with {@link makeQuery}. */
|
|
304
|
+
interface AnalyticsEngineQueryService<Id extends string> {
|
|
305
|
+
readonly [AnalyticsEngineQueryServiceTypeId]: {
|
|
306
|
+
readonly id: Id;
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
type LayerOptions$16 = {
|
|
310
|
+
readonly binding: string;
|
|
311
|
+
readonly write?: AnalyticsEngineWritePolicy;
|
|
312
|
+
};
|
|
313
|
+
type QueryConfigOptions = {
|
|
314
|
+
readonly accountId?: Config.Config<string>;
|
|
315
|
+
readonly apiToken?: Config.Config<Redacted.Redacted<string>>;
|
|
316
|
+
readonly apiBaseUrl?: Config.Config<string>;
|
|
317
|
+
};
|
|
318
|
+
interface TagClass$14<Self, Id extends string> extends Context.ServiceClass<Self, Id, AnalyticsEngineClient> {
|
|
319
|
+
readonly id: Id;
|
|
320
|
+
readonly layer: (options: LayerOptions$16) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
321
|
+
}
|
|
322
|
+
interface QueryTagClass<Self, Id extends string> extends Context.ServiceClass<Self, Id, AnalyticsEngineQueryClient> {
|
|
323
|
+
readonly id: Id;
|
|
324
|
+
readonly layer: (definition: AnalyticsEngineQueryDefinition) => Layer.Layer<Self, never, HttpClient.HttpClient>;
|
|
325
|
+
readonly fetchLayer: (definition: AnalyticsEngineQueryDefinition) => Layer.Layer<Self>;
|
|
326
|
+
readonly layerConfig: (config?: Config.Config<AnalyticsEngineQueryDefinition>) => Layer.Layer<Self, Config.ConfigError, HttpClient.HttpClient>;
|
|
327
|
+
readonly fetchLayerConfig: (config?: Config.Config<AnalyticsEngineQueryDefinition>) => Layer.Layer<Self, Config.ConfigError>;
|
|
328
|
+
}
|
|
329
|
+
declare const makeQueryClient: (definition: AnalyticsEngineQueryDefinition) => Effect.Effect<AnalyticsEngineQueryClient, never, HttpClient.HttpClient>;
|
|
330
|
+
declare const isAnalyticsEngineDataset: (value: unknown) => value is AnalyticsEngineBinding;
|
|
331
|
+
declare const makeClient$10: (definition: AnalyticsEngineDefinition, defaults?: AnalyticsEngineWritePolicy) => (dataset: AnalyticsEngineBinding) => AnalyticsEngineClient;
|
|
332
|
+
declare const queryConfig: (options?: QueryConfigOptions) => Config.Config<{
|
|
333
|
+
accountId: string;
|
|
334
|
+
apiToken: Redacted.Redacted<string>;
|
|
335
|
+
apiBaseUrl: string;
|
|
336
|
+
}>;
|
|
337
|
+
declare const queryLayer: <Self>(tag: Context.Service<Self, AnalyticsEngineQueryClient>, definition: AnalyticsEngineQueryDefinition) => Layer.Layer<Self, never, HttpClient.HttpClient>;
|
|
338
|
+
declare const queryFetchLayer: <Self>(tag: Context.Service<Self, AnalyticsEngineQueryClient>, definition: AnalyticsEngineQueryDefinition) => Layer.Layer<Self, never, never>;
|
|
339
|
+
declare const queryLayerConfig: <Self>(tag: Context.Service<Self, AnalyticsEngineQueryClient>, config?: Config.Config<AnalyticsEngineQueryDefinition>) => Layer.Layer<Self, Config.ConfigError, HttpClient.HttpClient>;
|
|
340
|
+
declare const queryFetchLayerConfig: <Self>(tag: Context.Service<Self, AnalyticsEngineQueryClient>, config?: Config.Config<AnalyticsEngineQueryDefinition>) => Layer.Layer<Self, Config.ConfigError, never>;
|
|
341
|
+
declare const layer$13: <Self>(tag: Context.Service<Self, AnalyticsEngineClient>, definition: LayerOptions$16) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
342
|
+
declare const make$14: <Id extends string>(id: Id) => TagClass$14<AnalyticsEngineService<Id>, Id>;
|
|
343
|
+
declare const makeQuery: <Id extends string>(id: Id) => QueryTagClass<AnalyticsEngineQueryService<Id>, Id>;
|
|
174
344
|
declare const Tag$15: <Self>() => <Id extends string>(id: Id) => TagClass$14<Self, Id>;
|
|
345
|
+
declare const QueryTag: <Self>() => <Id extends string>(id: Id) => QueryTagClass<Self, Id>;
|
|
175
346
|
declare namespace BrowserRendering_d_exports {
|
|
176
347
|
export { BrowserRenderingBinding, BrowserRenderingBrowserClient, BrowserRenderingBrowserLike, BrowserRenderingClient, BrowserRenderingConnect, BrowserRenderingDefinition, BrowserRenderingLaunch, BrowserRenderingOperationError, BrowserRenderingPageClient, BrowserRenderingPageLike, BrowserRenderingService, LayerOptions$15 as LayerOptions, Tag$14 as Tag, TagClass$13 as TagClass, isBrowserRenderingBinding, layer$12 as layer, make$13 as make, makeClient$9 as makeClient };
|
|
177
348
|
}
|
|
@@ -683,7 +854,7 @@ declare const Service$1: <Self>() => <Id extends string>(id: Id, definition: D1D
|
|
|
683
854
|
sqlLayer: (options?: D1SqlLayerOptions) => Layer.Layer<D1Client.D1Client | _$effect_unstable_sql_SqlClient0.SqlClient, BindingNotFoundError | BindingValidationError | _$effect_Config0.ConfigError, WorkerEnvironment | Exclude<Exclude<Self, _$effect_Scope0.Scope>, Self>>;
|
|
684
855
|
};
|
|
685
856
|
declare namespace Rpc_d_exports {
|
|
686
|
-
export { DisposableValue, MethodArgs, MethodKey, MethodReturn, Provider, Result, RpcStub, RpcTarget, Serializable, Stub, Stubable, Stubify, dispose, isDisposable, resolve, scoped };
|
|
857
|
+
export { DisposableValue, MethodArgs, MethodKey, MethodReturn, Provider, Result$1 as Result, RpcStub, RpcTarget, Serializable, Stub, Stubable, Stubify, dispose, isDisposable, resolve, scoped };
|
|
687
858
|
}
|
|
688
859
|
type Stubable = Rpc.Stubable;
|
|
689
860
|
type Stub<T extends Stubable> = Rpc.Stub<T>;
|
|
@@ -695,7 +866,7 @@ type Stubify<T> = T extends Stubable ? Stub<T> : T extends Map<infer Key, infer
|
|
|
695
866
|
} ? { [Key in keyof T]: Stubify<T[Key]> } : T;
|
|
696
867
|
type MaybeProvider<T> = T extends object ? Provider<T> : unknown;
|
|
697
868
|
type MaybeDisposable<T> = T extends object ? Disposable : unknown;
|
|
698
|
-
type Result<T> = T extends Stubable ? Promise<Stub<T>> & Provider<T> : T extends Serializable<T> ? Promise<Stubify<T> & MaybeDisposable<T>> & MaybeProvider<T> : never;
|
|
869
|
+
type Result$1<T> = T extends Stubable ? Promise<Stub<T>> & Provider<T> : T extends Serializable<T> ? Promise<Stubify<T> & MaybeDisposable<T>> & MaybeProvider<T> : never;
|
|
699
870
|
type MethodKey<Api> = { [Key in keyof Api]-?: Key extends string ? Api[Key] extends ((...args: Array<any>) => unknown) ? Key : never : never }[keyof Api];
|
|
700
871
|
type MethodArgs<Api, Method extends keyof Api> = Api[Method] extends ((...args: infer Args) => unknown) ? Args : never;
|
|
701
872
|
type MethodReturn<Api, Method extends keyof Api> = Api[Method] extends ((...args: Array<any>) => infer Return) ? Return : never;
|
|
@@ -1024,7 +1195,7 @@ type AnyArgs = Array<any>;
|
|
|
1024
1195
|
type AsyncMethodKey<Api> = { [Key in keyof Api]-?: Key extends string ? Api[Key] extends ((...args: AnyArgs) => Promise<unknown>) ? Key : never : never }[keyof Api];
|
|
1025
1196
|
type AsyncMethodArgs<Api, Method extends keyof Api> = Api[Method] extends ((...args: infer Args) => Promise<unknown>) ? Args : never;
|
|
1026
1197
|
type AsyncMethodSuccess<Api, Method extends keyof Api> = Api[Method] extends ((...args: AnyArgs) => Promise<infer A>) ? A : never;
|
|
1027
|
-
type AsyncMethodCloudflareReturn<Api, Method extends keyof Api> = Result<AsyncMethodSuccess<Api, Method>>;
|
|
1198
|
+
type AsyncMethodCloudflareReturn<Api, Method extends keyof Api> = Result$1<AsyncMethodSuccess<Api, Method>>;
|
|
1028
1199
|
declare namespace ServiceBinding_d_exports {
|
|
1029
1200
|
export { Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceFetcher, isServiceBindingClient, layer$9 as layer, makeClient$7 as makeClient, makeDirectMethods$1 as makeDirectMethods };
|
|
1030
1201
|
}
|
|
@@ -1207,7 +1378,7 @@ declare const Service: <Self, Api extends object = never>() => <Id extends strin
|
|
|
1207
1378
|
readonly [TypeId$1]: typeof TypeId$1;
|
|
1208
1379
|
readonly definition: ServiceBindingDefinition<Definition>;
|
|
1209
1380
|
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<Response, ServiceBindingFetchError, Self>;
|
|
1210
|
-
readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: ServiceMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Result<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>, ServiceBindingRpcError, Self>;
|
|
1381
|
+
readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: ServiceMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Result$1<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>, ServiceBindingRpcError, Self>;
|
|
1211
1382
|
readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: ServiceMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>, ServiceBindingRpcError, Self>;
|
|
1212
1383
|
readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: ServiceMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Awaited<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>, unknown, Self | Scope.Scope>;
|
|
1213
1384
|
};
|
|
@@ -1309,7 +1480,7 @@ declare const method$2: {
|
|
|
1309
1480
|
<Success extends ServiceFreeSchema$2>(definition: {
|
|
1310
1481
|
readonly success: Success;
|
|
1311
1482
|
}): Method$3<readonly [], Success>;
|
|
1312
|
-
<const Args extends
|
|
1483
|
+
<const Args extends ReadonlyArray<ServiceFreeSchema$2>, Success extends ServiceFreeSchema$2>(definition: {
|
|
1313
1484
|
readonly args: Args;
|
|
1314
1485
|
readonly success: Success;
|
|
1315
1486
|
}): Method$3<Args, Success>;
|
|
@@ -2638,4 +2809,4 @@ declare const layer: <Self>(tag: Context.Service<Self, VectorizeClient>, definit
|
|
|
2638
2809
|
declare const make: <Id extends string>(id: Id) => TagClass<VectorizeService<Id>, Id>;
|
|
2639
2810
|
declare const Tag$1: <Self>() => <Id extends string>(id: Id) => TagClass<Self, Id>;
|
|
2640
2811
|
//#endregion
|
|
2641
|
-
export { AiGateway_d_exports as AiGateway, Binding_d_exports as Binding, BrowserRendering_d_exports as BrowserRendering, CloudflareOtlp_d_exports as CloudflareOtlp, 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 };
|
|
2812
|
+
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, 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 };
|