effect-cf 0.10.0 → 0.12.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 +12 -0
- package/dist/index.d.mts +312 -84
- package/dist/index.mjs +439 -91
- package/package.json +4 -1
- package/src/CloudflareOtlp.ts +628 -0
- package/src/DurableObjectSqlite.ts +26 -0
- package/src/index.ts +2 -0
package/dist/index.mjs
CHANGED
|
@@ -1,64 +1,19 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
|
|
2
|
-
import { a as WorkerConfig, i as layer$
|
|
3
|
-
import { Cause, Clock, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Layer, ManagedRuntime, Option, Queue, Schema } from "effect";
|
|
4
|
-
import {
|
|
2
|
+
import { a as WorkerConfig, i as layer$10, 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, Schema } from "effect";
|
|
4
|
+
import { FetchHttpClient, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
5
|
+
import { Otlp, OtlpLogger, OtlpMetrics, OtlpSerialization, OtlpTracer } from "effect/unstable/observability";
|
|
5
6
|
import { DurableObject, RpcStub, RpcTarget, WorkerEntrypoint, WorkflowEntrypoint } from "cloudflare:workers";
|
|
6
|
-
import {
|
|
7
|
+
import { D1Client } from "@effect/sql-d1";
|
|
7
8
|
import * as RpcMessage from "effect/unstable/rpc/RpcMessage";
|
|
8
9
|
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
|
|
9
10
|
import * as RpcServer from "effect/unstable/rpc/RpcServer";
|
|
10
|
-
|
|
11
|
-
var D1_exports = /* @__PURE__ */ __exportAll({
|
|
12
|
-
Service: () => Service$1,
|
|
13
|
-
make: () => make$10
|
|
14
|
-
});
|
|
15
|
-
const TypeId$2 = "effect-cf/D1";
|
|
16
|
-
const expectedD1Database = "D1 database binding with prepare(), batch(), and exec()";
|
|
17
|
-
const isD1Database = (value) => {
|
|
18
|
-
if (typeof value !== "object" || value === null) return false;
|
|
19
|
-
const resource = value;
|
|
20
|
-
return typeof resource.prepare === "function" && typeof resource.batch === "function" && typeof resource.exec === "function";
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Creates a typed D1 service tag plus Effect helpers.
|
|
24
|
-
*/
|
|
25
|
-
const make$10 = (id, definition) => Service$1()(id, definition);
|
|
26
|
-
/**
|
|
27
|
-
* Builds a D1 service around a Cloudflare D1 database binding.
|
|
28
|
-
*
|
|
29
|
-
* The returned service exposes the raw `D1Database` binding and `sqlLayer(...)`
|
|
30
|
-
* for providing `effect/unstable/sql` via `@effect/sql-d1`.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* class TodoDatabase extends D1.Service<TodoDatabase>()("TodoDatabase", {
|
|
35
|
-
* binding: "TODO_DB",
|
|
36
|
-
* }) {}
|
|
37
|
-
*
|
|
38
|
-
* const SqlLive = TodoDatabase.sqlLayer();
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
const Service$1 = () => (id, definition) => {
|
|
42
|
-
const tag = Service$2()(id, definition.binding, isD1Database, void 0, { expected: expectedD1Database });
|
|
43
|
-
const sqlLayer = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
44
|
-
const db = yield* tag;
|
|
45
|
-
return D1Client.layer({
|
|
46
|
-
...options,
|
|
47
|
-
db
|
|
48
|
-
});
|
|
49
|
-
})).pipe(Layer.provide(tag.layer));
|
|
50
|
-
return Object.assign(tag, {
|
|
51
|
-
[TypeId$2]: TypeId$2,
|
|
52
|
-
definition,
|
|
53
|
-
sqlLayer
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
//#endregion
|
|
11
|
+
import { SqliteClient } from "@effect/sql-sqlite-do";
|
|
57
12
|
//#region src/QueueBinding.ts
|
|
58
13
|
var QueueBinding_exports = /* @__PURE__ */ __exportAll({
|
|
59
14
|
QueueOperationError: () => QueueOperationError,
|
|
60
15
|
isQueue: () => isQueue,
|
|
61
|
-
layer: () => layer$
|
|
16
|
+
layer: () => layer$9,
|
|
62
17
|
makeClient: () => makeClient$6
|
|
63
18
|
});
|
|
64
19
|
const expectedQueueProducer = "Queue producer binding with send(); optional sendBatch()/metrics()";
|
|
@@ -114,30 +69,30 @@ const makeClient$6 = (definition) => {
|
|
|
114
69
|
unsafeRaw: Effect.succeed(queue)
|
|
115
70
|
});
|
|
116
71
|
};
|
|
117
|
-
const layer$
|
|
72
|
+
const layer$9 = (tag, definition) => layer$10(tag, definition.binding, (value) => isQueue(value), makeClient$6(definition), { expected: expectedQueueProducer });
|
|
118
73
|
//#endregion
|
|
119
74
|
//#region src/QueueDefinition.ts
|
|
120
75
|
var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
121
76
|
Queue: () => Queue$1,
|
|
122
77
|
Tag: () => Tag$10,
|
|
123
78
|
implement: () => implement$7,
|
|
124
|
-
make: () => make$
|
|
79
|
+
make: () => make$10
|
|
125
80
|
});
|
|
126
81
|
const makeDefinition$4 = (id, definition) => {
|
|
127
82
|
const queueDefinition = {
|
|
128
83
|
id,
|
|
129
84
|
message: definition.message
|
|
130
85
|
};
|
|
131
|
-
return Object.assign(queueDefinition, { make: (layer, options) => make$
|
|
86
|
+
return Object.assign(queueDefinition, { make: (layer, options) => make$7(layer, {
|
|
132
87
|
...options,
|
|
133
88
|
queue: wrapHandler$1(queueDefinition, options.queue)
|
|
134
89
|
}) });
|
|
135
90
|
};
|
|
136
|
-
const make$
|
|
91
|
+
const make$10 = (id, definition) => Tag$10()(id, definition);
|
|
137
92
|
const Tag$10 = () => (id, definition) => {
|
|
138
93
|
const queueDefinition = makeDefinition$4(id, definition);
|
|
139
94
|
const tag = Context.Service()(id);
|
|
140
|
-
const layer = (binding) => layer$
|
|
95
|
+
const layer = (binding) => layer$9(tag, {
|
|
141
96
|
...binding,
|
|
142
97
|
message: definition.message
|
|
143
98
|
});
|
|
@@ -232,7 +187,7 @@ var RpcDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
|
232
187
|
decodeSuccess: () => decodeSuccess,
|
|
233
188
|
encodeArgs: () => encodeArgs,
|
|
234
189
|
encodeSuccess: () => encodeSuccess,
|
|
235
|
-
make: () => make$
|
|
190
|
+
make: () => make$9,
|
|
236
191
|
method: () => method$4,
|
|
237
192
|
reservedMethodNames: () => reservedMethodNames$4
|
|
238
193
|
});
|
|
@@ -335,7 +290,7 @@ const decodeSuccess = (definition, methodName, value) => {
|
|
|
335
290
|
cause
|
|
336
291
|
})));
|
|
337
292
|
};
|
|
338
|
-
const make$
|
|
293
|
+
const make$9 = (id, methods) => {
|
|
339
294
|
const definition = {
|
|
340
295
|
id,
|
|
341
296
|
methods
|
|
@@ -389,15 +344,15 @@ const invokeRpcMethod = (target, method, args, makeError) => Effect.gen(function
|
|
|
389
344
|
//#endregion
|
|
390
345
|
//#region src/ServiceBinding.ts
|
|
391
346
|
var ServiceBinding_exports = /* @__PURE__ */ __exportAll({
|
|
392
|
-
Service: () => Service,
|
|
347
|
+
Service: () => Service$1,
|
|
393
348
|
ServiceBindingFetchError: () => ServiceBindingFetchError,
|
|
394
349
|
ServiceBindingRpcError: () => ServiceBindingRpcError,
|
|
395
350
|
isServiceBindingClient: () => isServiceBindingClient,
|
|
396
|
-
layer: () => layer$
|
|
351
|
+
layer: () => layer$8,
|
|
397
352
|
makeClient: () => makeClient$5,
|
|
398
353
|
makeDirectMethods: () => makeDirectMethods$1
|
|
399
354
|
});
|
|
400
|
-
const TypeId$
|
|
355
|
+
const TypeId$2 = "effect-cf/ServiceBinding";
|
|
401
356
|
const expectedServiceBinding = "Worker service binding with fetch()";
|
|
402
357
|
/**
|
|
403
358
|
* Failure raised when calling `fetch` on a service binding.
|
|
@@ -457,7 +412,7 @@ const makeClient$5 = (definition) => {
|
|
|
457
412
|
});
|
|
458
413
|
};
|
|
459
414
|
};
|
|
460
|
-
const layer$
|
|
415
|
+
const layer$8 = (tag, definition) => layer$10(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$5(definition), { expected: expectedServiceBinding });
|
|
461
416
|
/**
|
|
462
417
|
* Creates a typed Effect service for a Worker service binding.
|
|
463
418
|
*
|
|
@@ -487,7 +442,7 @@ const layer$6 = (tag, definition) => layer$8(tag, definition.binding, (value) =>
|
|
|
487
442
|
* });
|
|
488
443
|
* ```
|
|
489
444
|
*/
|
|
490
|
-
const Service = () => (id, definition) => {
|
|
445
|
+
const Service$1 = () => (id, definition) => {
|
|
491
446
|
const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$5(definition));
|
|
492
447
|
const fetch = (input, init) => Effect.gen(function* () {
|
|
493
448
|
return yield* (yield* tag).fetch(input, init);
|
|
@@ -503,7 +458,7 @@ const Service = () => (id, definition) => {
|
|
|
503
458
|
});
|
|
504
459
|
const directMethods = makeDirectMethods$1(definition.definition, call);
|
|
505
460
|
return Object.assign(tag, directMethods, {
|
|
506
|
-
[TypeId$
|
|
461
|
+
[TypeId$2]: TypeId$2,
|
|
507
462
|
definition,
|
|
508
463
|
fetch,
|
|
509
464
|
rpc,
|
|
@@ -522,7 +477,7 @@ var WorkerDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
|
522
477
|
Tag: () => Tag$8,
|
|
523
478
|
Worker: () => Worker,
|
|
524
479
|
implement: () => implement$5,
|
|
525
|
-
make: () => make$
|
|
480
|
+
make: () => make$8,
|
|
526
481
|
method: () => method$3
|
|
527
482
|
});
|
|
528
483
|
const reservedMethodNames$3 = new Set([
|
|
@@ -560,13 +515,13 @@ const method$3 = method$4;
|
|
|
560
515
|
*/
|
|
561
516
|
const makeDefinition$3 = (id, methods) => {
|
|
562
517
|
assertNoReservedMethods("Worker", methods, reservedMethodNames$3);
|
|
563
|
-
const definition = make$
|
|
564
|
-
return Object.assign(definition, { make: (layer, options) => make$
|
|
518
|
+
const definition = make$9(id, methods);
|
|
519
|
+
return Object.assign(definition, { make: (layer, options) => make$7(layer, {
|
|
565
520
|
...options,
|
|
566
521
|
rpc: wrapHandlers$1(definition, options.rpc)
|
|
567
522
|
}) });
|
|
568
523
|
};
|
|
569
|
-
const make$
|
|
524
|
+
const make$8 = (id, methods) => Tag$8()(id, methods);
|
|
570
525
|
const Tag$8 = () => (id, methods) => {
|
|
571
526
|
const definition = makeDefinition$3(id, methods);
|
|
572
527
|
const tag = Context.Service()(id);
|
|
@@ -574,7 +529,7 @@ const Tag$8 = () => (id, methods) => {
|
|
|
574
529
|
...binding,
|
|
575
530
|
definition
|
|
576
531
|
});
|
|
577
|
-
const layer = (binding) => layer$
|
|
532
|
+
const layer = (binding) => layer$8(tag, bindingDefinition(binding));
|
|
578
533
|
const fetch = (input, init) => Effect.gen(function* () {
|
|
579
534
|
return yield* (yield* tag).fetch(input, init);
|
|
580
535
|
});
|
|
@@ -659,7 +614,7 @@ var Worker_exports = /* @__PURE__ */ __exportAll({
|
|
|
659
614
|
WorkerContext: () => WorkerContext,
|
|
660
615
|
implement: () => implement$4,
|
|
661
616
|
isWebSocketUpgrade: () => isWebSocketUpgrade,
|
|
662
|
-
make: () => make$
|
|
617
|
+
make: () => make$7,
|
|
663
618
|
makeFetchHandler: () => makeFetchHandler,
|
|
664
619
|
method: () => method$2,
|
|
665
620
|
renderHttpResponse: () => renderHttpResponse
|
|
@@ -688,7 +643,7 @@ const RunSymbol$1 = Symbol.for("effect-cf/Worker/run");
|
|
|
688
643
|
const renderHttpResponse = (effect) => Effect.flatMap(effect, (response) => Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
|
|
689
644
|
const renderFetchSuccess = (effect) => Effect.flatMap(effect, (response) => response instanceof Response ? Effect.succeed(response) : Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
|
|
690
645
|
const isWorkerOptions = (options) => typeof options === "object" && options !== null && ("fetch" in options || "queue" in options || "rpc" in options);
|
|
691
|
-
function make$
|
|
646
|
+
function make$7(layer, optionsOrFetch) {
|
|
692
647
|
const options = isWorkerOptions(optionsOrFetch) ? optionsOrFetch : { fetch: optionsOrFetch };
|
|
693
648
|
class EffectWorker extends WorkerEntrypoint {
|
|
694
649
|
runtime;
|
|
@@ -719,7 +674,7 @@ function make$6(layer, optionsOrFetch) {
|
|
|
719
674
|
return assumeEntrypointClass(EffectWorker);
|
|
720
675
|
}
|
|
721
676
|
const makeFetchHandler = (layer, options) => {
|
|
722
|
-
const WorkerClass = make$
|
|
677
|
+
const WorkerClass = make$7(layer, options);
|
|
723
678
|
return { fetch: (request, env, ctx) => Promise.resolve(new WorkerClass(ctx, env).fetch(request)) };
|
|
724
679
|
};
|
|
725
680
|
const Tag$7 = Tag$8;
|
|
@@ -1020,7 +975,7 @@ var DurableObjectNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
|
1020
975
|
DurableObjectFetchError: () => DurableObjectFetchError,
|
|
1021
976
|
DurableObjectRpcError: () => DurableObjectRpcError,
|
|
1022
977
|
isDurableObjectNamespaceClient: () => isDurableObjectNamespaceClient,
|
|
1023
|
-
layer: () => layer$
|
|
978
|
+
layer: () => layer$7,
|
|
1024
979
|
makeClient: () => makeClient$4,
|
|
1025
980
|
makeDirectMethods: () => makeDirectMethods
|
|
1026
981
|
});
|
|
@@ -1102,7 +1057,7 @@ const makeClient$4 = (definition) => {
|
|
|
1102
1057
|
});
|
|
1103
1058
|
};
|
|
1104
1059
|
};
|
|
1105
|
-
const layer$
|
|
1060
|
+
const layer$7 = (tag, definition) => layer$10(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$4(definition), { expected: expectedDurableObjectNamespace });
|
|
1106
1061
|
const makeDirectMethods = (rpcDefinition, helpers) => {
|
|
1107
1062
|
const methods = {};
|
|
1108
1063
|
if (rpcDefinition !== void 0) {
|
|
@@ -1129,7 +1084,7 @@ var DurableObjectDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
|
1129
1084
|
DurableObject: () => DurableObject$1,
|
|
1130
1085
|
Tag: () => Tag$6,
|
|
1131
1086
|
implement: () => implement$3,
|
|
1132
|
-
make: () => make$
|
|
1087
|
+
make: () => make$6,
|
|
1133
1088
|
method: () => method$1
|
|
1134
1089
|
});
|
|
1135
1090
|
const reservedMethodNames$1 = new Set([
|
|
@@ -1160,13 +1115,13 @@ const method$1 = method$4;
|
|
|
1160
1115
|
*/
|
|
1161
1116
|
const makeDefinition$2 = (id, methods) => {
|
|
1162
1117
|
assertNoReservedMethods("Durable Object", methods, reservedMethodNames$1);
|
|
1163
|
-
const definition = make$
|
|
1164
|
-
return Object.assign(definition, { make: (layer, options) => make$
|
|
1118
|
+
const definition = make$9(id, methods);
|
|
1119
|
+
return Object.assign(definition, { make: (layer, options) => make$5(layer, {
|
|
1165
1120
|
...options,
|
|
1166
1121
|
rpc: wrapHandlers(definition, options.rpc)
|
|
1167
1122
|
}) });
|
|
1168
1123
|
};
|
|
1169
|
-
const make$
|
|
1124
|
+
const make$6 = (id, methods) => Tag$6()(id, methods);
|
|
1170
1125
|
const Tag$6 = () => (id, methods) => {
|
|
1171
1126
|
const definition = makeDefinition$2(id, methods);
|
|
1172
1127
|
const tag = Context.Service()(id);
|
|
@@ -1174,7 +1129,7 @@ const Tag$6 = () => (id, methods) => {
|
|
|
1174
1129
|
...binding,
|
|
1175
1130
|
definition
|
|
1176
1131
|
});
|
|
1177
|
-
const layer = (binding) => layer$
|
|
1132
|
+
const layer = (binding) => layer$7(tag, bindingDefinition(binding));
|
|
1178
1133
|
const newUniqueId = Effect.fnUntraced(function* (options) {
|
|
1179
1134
|
return yield* (yield* tag).newUniqueId(options);
|
|
1180
1135
|
});
|
|
@@ -1252,7 +1207,7 @@ const implement$3 = (_definition, handlers) => handlers;
|
|
|
1252
1207
|
var DurableObject_exports = /* @__PURE__ */ __exportAll({
|
|
1253
1208
|
Tag: () => Tag$5,
|
|
1254
1209
|
implement: () => implement$2,
|
|
1255
|
-
make: () => make$
|
|
1210
|
+
make: () => make$5,
|
|
1256
1211
|
method: () => method
|
|
1257
1212
|
});
|
|
1258
1213
|
const reservedMethodNames = new Set([
|
|
@@ -1268,7 +1223,7 @@ const RunSymbol = Symbol.for("effect-cf/DurableObject/run");
|
|
|
1268
1223
|
/**
|
|
1269
1224
|
* Creates a Durable Object class backed by a single managed Effect runtime.
|
|
1270
1225
|
*/
|
|
1271
|
-
const make$
|
|
1226
|
+
const make$5 = (layer, options = {}) => {
|
|
1272
1227
|
class EffectDurableObject extends DurableObject {
|
|
1273
1228
|
runtime;
|
|
1274
1229
|
constructor(state, env) {
|
|
@@ -1313,6 +1268,378 @@ const Tag$5 = Tag$6;
|
|
|
1313
1268
|
const method = method$1;
|
|
1314
1269
|
const implement$2 = implement$3;
|
|
1315
1270
|
//#endregion
|
|
1271
|
+
//#region src/CloudflareOtlp.ts
|
|
1272
|
+
var CloudflareOtlp_exports = /* @__PURE__ */ __exportAll({
|
|
1273
|
+
CloudflareOtlpSettings: () => CloudflareOtlpSettings,
|
|
1274
|
+
durableObjectLayer: () => durableObjectLayer,
|
|
1275
|
+
instrumentDurableObjectOptions: () => instrumentDurableObjectOptions,
|
|
1276
|
+
instrumentWorkerOptions: () => instrumentWorkerOptions,
|
|
1277
|
+
layer: () => layer$6,
|
|
1278
|
+
layerJson: () => layerJson,
|
|
1279
|
+
layerProtobuf: () => layerProtobuf,
|
|
1280
|
+
settingsConfig: () => settingsConfig,
|
|
1281
|
+
settingsLayer: () => settingsLayer,
|
|
1282
|
+
workerLayer: () => workerLayer
|
|
1283
|
+
});
|
|
1284
|
+
/**
|
|
1285
|
+
* Supported OpenTelemetry environment configuration for Cloudflare OTLP export.
|
|
1286
|
+
*
|
|
1287
|
+
* This config intentionally uses the conventional `OTEL_*` variable names so
|
|
1288
|
+
* deployments can share the same settings used by other OpenTelemetry SDKs.
|
|
1289
|
+
* It covers the OTLP HTTP settings supported by the Effect OTLP layers:
|
|
1290
|
+
*
|
|
1291
|
+
* - `OTEL_EXPORTER_OTLP_ENDPOINT`
|
|
1292
|
+
* - `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`
|
|
1293
|
+
* - `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
|
|
1294
|
+
* - `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`
|
|
1295
|
+
* - `OTEL_EXPORTER_OTLP_HEADERS`
|
|
1296
|
+
* - `OTEL_EXPORTER_OTLP_LOGS_HEADERS`
|
|
1297
|
+
* - `OTEL_EXPORTER_OTLP_TRACES_HEADERS`
|
|
1298
|
+
* - `OTEL_EXPORTER_OTLP_METRICS_HEADERS`
|
|
1299
|
+
* - `OTEL_SERVICE_NAME`
|
|
1300
|
+
* - `OTEL_RESOURCE_ATTRIBUTES`
|
|
1301
|
+
*
|
|
1302
|
+
* `OTEL_SERVICE_VERSION` is also accepted as an effect-cf convenience alias.
|
|
1303
|
+
* The standard OpenTelemetry way to configure service version is
|
|
1304
|
+
* `OTEL_RESOURCE_ATTRIBUTES=service.version=...`.
|
|
1305
|
+
*
|
|
1306
|
+
* Consumers with non-standard binding names should map those names into
|
|
1307
|
+
* {@link CloudflareOtlpSettings} rather than changing this config globally.
|
|
1308
|
+
*/
|
|
1309
|
+
const settingsConfig = Config.all({
|
|
1310
|
+
endpoint: Config.string("OTEL_EXPORTER_OTLP_ENDPOINT").pipe(Config.option),
|
|
1311
|
+
logsEndpoint: Config.string("OTEL_EXPORTER_OTLP_LOGS_ENDPOINT").pipe(Config.option),
|
|
1312
|
+
tracesEndpoint: Config.string("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT").pipe(Config.option),
|
|
1313
|
+
metricsEndpoint: Config.string("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT").pipe(Config.option),
|
|
1314
|
+
headers: Config.string("OTEL_EXPORTER_OTLP_HEADERS").pipe(Config.option),
|
|
1315
|
+
logsHeaders: Config.string("OTEL_EXPORTER_OTLP_LOGS_HEADERS").pipe(Config.option),
|
|
1316
|
+
tracesHeaders: Config.string("OTEL_EXPORTER_OTLP_TRACES_HEADERS").pipe(Config.option),
|
|
1317
|
+
metricsHeaders: Config.string("OTEL_EXPORTER_OTLP_METRICS_HEADERS").pipe(Config.option),
|
|
1318
|
+
serviceName: Config.string("OTEL_SERVICE_NAME").pipe(Config.option),
|
|
1319
|
+
serviceVersion: Config.string("OTEL_SERVICE_VERSION").pipe(Config.option),
|
|
1320
|
+
resourceAttributes: Config.schema(Config.Record(Schema.String, Schema.String), "OTEL_RESOURCE_ATTRIBUTES").pipe(Config.option)
|
|
1321
|
+
});
|
|
1322
|
+
/**
|
|
1323
|
+
* Service carrying already-resolved Cloudflare OTLP settings.
|
|
1324
|
+
*
|
|
1325
|
+
* Provide this service directly when an application needs to map custom
|
|
1326
|
+
* Cloudflare binding names, compute settings dynamically, or override settings
|
|
1327
|
+
* in tests. When this service is present, the OTLP layers use it instead of
|
|
1328
|
+
* reading {@link settingsConfig}.
|
|
1329
|
+
*
|
|
1330
|
+
* @example
|
|
1331
|
+
* ```ts
|
|
1332
|
+
* const CustomOtlpSettings = Layer.effect(
|
|
1333
|
+
* CloudflareOtlp.CloudflareOtlpSettings,
|
|
1334
|
+
* Config.all({
|
|
1335
|
+
* ...CloudflareOtlp.settingsConfig,
|
|
1336
|
+
* endpoint: Config.string("MY_OTLP_ENDPOINT").pipe(Config.option),
|
|
1337
|
+
* }),
|
|
1338
|
+
* ).pipe(Layer.provide(WorkerConfig.layer));
|
|
1339
|
+
* ```
|
|
1340
|
+
*/
|
|
1341
|
+
var CloudflareOtlpSettings = class extends Context.Service()("effect-cf/CloudflareOtlpSettings") {};
|
|
1342
|
+
const allSignals = [
|
|
1343
|
+
"logs",
|
|
1344
|
+
"traces",
|
|
1345
|
+
"metrics"
|
|
1346
|
+
];
|
|
1347
|
+
const optionToUndefined = (option) => Option.isSome(option) ? option.value : void 0;
|
|
1348
|
+
const nonEmptyStringOption = (option) => Option.flatMap(option, (value) => {
|
|
1349
|
+
const trimmed = value.trim();
|
|
1350
|
+
return trimmed === "" ? Option.none() : Option.some(trimmed);
|
|
1351
|
+
});
|
|
1352
|
+
const nonEmptyRecordOption = (option) => Option.filter(option, (value) => Object.keys(value).length > 0);
|
|
1353
|
+
const normalizeSettings = (settings) => ({
|
|
1354
|
+
endpoint: nonEmptyStringOption(settings.endpoint),
|
|
1355
|
+
logsEndpoint: nonEmptyStringOption(settings.logsEndpoint),
|
|
1356
|
+
tracesEndpoint: nonEmptyStringOption(settings.tracesEndpoint),
|
|
1357
|
+
metricsEndpoint: nonEmptyStringOption(settings.metricsEndpoint),
|
|
1358
|
+
headers: nonEmptyStringOption(settings.headers),
|
|
1359
|
+
logsHeaders: nonEmptyStringOption(settings.logsHeaders),
|
|
1360
|
+
tracesHeaders: nonEmptyStringOption(settings.tracesHeaders),
|
|
1361
|
+
metricsHeaders: nonEmptyStringOption(settings.metricsHeaders),
|
|
1362
|
+
serviceName: nonEmptyStringOption(settings.serviceName),
|
|
1363
|
+
serviceVersion: nonEmptyStringOption(settings.serviceVersion),
|
|
1364
|
+
resourceAttributes: nonEmptyRecordOption(settings.resourceAttributes)
|
|
1365
|
+
});
|
|
1366
|
+
/**
|
|
1367
|
+
* Layer that reads standard OpenTelemetry settings from the current Cloudflare
|
|
1368
|
+
* `env` object.
|
|
1369
|
+
*
|
|
1370
|
+
* The layer depends on {@link WorkerEnvironment} and installs a
|
|
1371
|
+
* Cloudflare-backed Effect `ConfigProvider`, so `settingsConfig` reads from
|
|
1372
|
+
* Worker vars/secrets instead of Node process environment variables.
|
|
1373
|
+
*/
|
|
1374
|
+
const settingsLayer = Layer.effect(CloudflareOtlpSettings, settingsConfig.pipe(Config.map(normalizeSettings))).pipe(Layer.provide(WorkerConfig.layer));
|
|
1375
|
+
const selectedSignals = (signals) => new Set(signals ?? allSignals);
|
|
1376
|
+
const withDefinedAttributes = (attributes) => {
|
|
1377
|
+
const out = {};
|
|
1378
|
+
for (const [key, value] of Object.entries(attributes)) if (value !== void 0) out[key] = value;
|
|
1379
|
+
return out;
|
|
1380
|
+
};
|
|
1381
|
+
const parseHeaders = (input) => {
|
|
1382
|
+
if (Option.isNone(input) || input.value.trim() === "") return;
|
|
1383
|
+
const headers = {};
|
|
1384
|
+
for (const part of input.value.split(",")) {
|
|
1385
|
+
const index = part.indexOf("=");
|
|
1386
|
+
if (index <= 0) continue;
|
|
1387
|
+
const key = part.slice(0, index).trim();
|
|
1388
|
+
const value = part.slice(index + 1).trim();
|
|
1389
|
+
if (key !== "") headers[decodeHeaderComponent(key)] = decodeHeaderComponent(value);
|
|
1390
|
+
}
|
|
1391
|
+
return headers;
|
|
1392
|
+
};
|
|
1393
|
+
const mergeHeaders = (common, signalSpecific) => {
|
|
1394
|
+
const commonHeaders = parseHeaders(common);
|
|
1395
|
+
const signalHeaders = parseHeaders(signalSpecific);
|
|
1396
|
+
if (commonHeaders === void 0 && signalHeaders === void 0) return;
|
|
1397
|
+
return {
|
|
1398
|
+
...commonHeaders,
|
|
1399
|
+
...signalHeaders
|
|
1400
|
+
};
|
|
1401
|
+
};
|
|
1402
|
+
const decodeHeaderComponent = (value) => {
|
|
1403
|
+
try {
|
|
1404
|
+
return decodeURIComponent(value);
|
|
1405
|
+
} catch {
|
|
1406
|
+
return value;
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
const appendOtlpPath = (baseUrl, path) => `${baseUrl.replace(/\/+$/, "")}${path}`;
|
|
1410
|
+
const makeResource = (settings, options, runtimeAttributes) => ({
|
|
1411
|
+
serviceName: options.serviceName ?? optionToUndefined(settings.serviceName),
|
|
1412
|
+
serviceVersion: options.serviceVersion ?? optionToUndefined(settings.serviceVersion),
|
|
1413
|
+
attributes: {
|
|
1414
|
+
...optionToUndefined(settings.resourceAttributes),
|
|
1415
|
+
...withDefinedAttributes(runtimeAttributes),
|
|
1416
|
+
...options.attributes
|
|
1417
|
+
}
|
|
1418
|
+
});
|
|
1419
|
+
const commonOtlpOptions = (settings, options, runtimeAttributes) => ({
|
|
1420
|
+
resource: makeResource(settings, options, runtimeAttributes),
|
|
1421
|
+
maxBatchSize: options.maxBatchSize,
|
|
1422
|
+
loggerExportInterval: options.loggerExportInterval,
|
|
1423
|
+
loggerExcludeLogSpans: options.loggerExcludeLogSpans,
|
|
1424
|
+
loggerMergeWithExisting: options.loggerMergeWithExisting,
|
|
1425
|
+
tracerExportInterval: options.tracerExportInterval,
|
|
1426
|
+
tracerContext: options.tracerContext,
|
|
1427
|
+
metricsExportInterval: options.metricsExportInterval,
|
|
1428
|
+
metricsTemporality: options.metricsTemporality,
|
|
1429
|
+
shutdownTimeout: options.shutdownTimeout
|
|
1430
|
+
});
|
|
1431
|
+
const serializationLayer = (serialization) => serialization === "json" ? OtlpSerialization.layerJson : OtlpSerialization.layerProtobuf;
|
|
1432
|
+
const resolveSettings = Effect.gen(function* () {
|
|
1433
|
+
const settings = yield* Effect.serviceOption(CloudflareOtlpSettings);
|
|
1434
|
+
if (Option.isSome(settings)) return normalizeSettings(settings.value);
|
|
1435
|
+
const env = yield* Effect.serviceOption(WorkerEnvironment);
|
|
1436
|
+
if (Option.isSome(env)) return normalizeSettings(yield* settingsConfig.pipe(Effect.provide(ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env.value))))));
|
|
1437
|
+
return normalizeSettings(yield* settingsConfig);
|
|
1438
|
+
});
|
|
1439
|
+
const mergeSignalLayers = (layers) => {
|
|
1440
|
+
if (layers.length === 0) return Layer.empty;
|
|
1441
|
+
let merged = layers[0];
|
|
1442
|
+
for (let index = 1; index < layers.length; index++) merged = Layer.mergeAll(merged, layers[index]);
|
|
1443
|
+
return merged;
|
|
1444
|
+
};
|
|
1445
|
+
const emptyLayer = Layer.empty;
|
|
1446
|
+
const makeLayerFromSettings = (options = {}, runtimeAttributes = {}) => Layer.unwrap(Effect.map(resolveSettings, (settings) => {
|
|
1447
|
+
const signals = selectedSignals(options.signals);
|
|
1448
|
+
const endpoint = optionToUndefined(settings.endpoint);
|
|
1449
|
+
const logsEndpoint = optionToUndefined(settings.logsEndpoint);
|
|
1450
|
+
const tracesEndpoint = optionToUndefined(settings.tracesEndpoint);
|
|
1451
|
+
const metricsEndpoint = optionToUndefined(settings.metricsEndpoint);
|
|
1452
|
+
const hasSpecificEndpoint = logsEndpoint !== void 0 || tracesEndpoint !== void 0 || metricsEndpoint !== void 0;
|
|
1453
|
+
const hasSpecificHeaders = Option.isSome(settings.logsHeaders) || Option.isSome(settings.tracesHeaders) || Option.isSome(settings.metricsHeaders);
|
|
1454
|
+
const common = commonOtlpOptions(settings, options, runtimeAttributes);
|
|
1455
|
+
if (endpoint !== void 0 && !hasSpecificEndpoint && !hasSpecificHeaders && signals.size === 3) return Otlp.layer({
|
|
1456
|
+
baseUrl: endpoint,
|
|
1457
|
+
headers: parseHeaders(settings.headers),
|
|
1458
|
+
...common
|
|
1459
|
+
}).pipe(Layer.provide(serializationLayer(options.serialization)), Layer.provide(FetchHttpClient.layer));
|
|
1460
|
+
const layers = [];
|
|
1461
|
+
if (signals.has("logs")) {
|
|
1462
|
+
const url = logsEndpoint ?? (endpoint === void 0 ? void 0 : appendOtlpPath(endpoint, "/v1/logs"));
|
|
1463
|
+
if (url !== void 0) layers.push(OtlpLogger.layer({
|
|
1464
|
+
url,
|
|
1465
|
+
resource: common.resource,
|
|
1466
|
+
headers: mergeHeaders(settings.headers, settings.logsHeaders),
|
|
1467
|
+
exportInterval: common.loggerExportInterval,
|
|
1468
|
+
maxBatchSize: common.maxBatchSize,
|
|
1469
|
+
shutdownTimeout: common.shutdownTimeout,
|
|
1470
|
+
excludeLogSpans: common.loggerExcludeLogSpans,
|
|
1471
|
+
mergeWithExisting: common.loggerMergeWithExisting
|
|
1472
|
+
}).pipe(Layer.provide(serializationLayer(options.serialization)), Layer.provide(FetchHttpClient.layer)));
|
|
1473
|
+
}
|
|
1474
|
+
if (signals.has("traces")) {
|
|
1475
|
+
const url = tracesEndpoint ?? (endpoint === void 0 ? void 0 : appendOtlpPath(endpoint, "/v1/traces"));
|
|
1476
|
+
if (url !== void 0) layers.push(OtlpTracer.layer({
|
|
1477
|
+
url,
|
|
1478
|
+
resource: common.resource,
|
|
1479
|
+
headers: mergeHeaders(settings.headers, settings.tracesHeaders),
|
|
1480
|
+
exportInterval: common.tracerExportInterval,
|
|
1481
|
+
maxBatchSize: common.maxBatchSize,
|
|
1482
|
+
context: common.tracerContext,
|
|
1483
|
+
shutdownTimeout: common.shutdownTimeout
|
|
1484
|
+
}).pipe(Layer.provide(serializationLayer(options.serialization)), Layer.provide(FetchHttpClient.layer)));
|
|
1485
|
+
}
|
|
1486
|
+
if (signals.has("metrics")) {
|
|
1487
|
+
const url = metricsEndpoint ?? (endpoint === void 0 ? void 0 : appendOtlpPath(endpoint, "/v1/metrics"));
|
|
1488
|
+
if (url !== void 0) layers.push(OtlpMetrics.layer({
|
|
1489
|
+
url,
|
|
1490
|
+
resource: common.resource,
|
|
1491
|
+
headers: mergeHeaders(settings.headers, settings.metricsHeaders),
|
|
1492
|
+
exportInterval: common.metricsExportInterval,
|
|
1493
|
+
shutdownTimeout: common.shutdownTimeout,
|
|
1494
|
+
temporality: common.metricsTemporality
|
|
1495
|
+
}).pipe(Layer.provide(serializationLayer(options.serialization)), Layer.provide(FetchHttpClient.layer)));
|
|
1496
|
+
}
|
|
1497
|
+
return mergeSignalLayers(layers);
|
|
1498
|
+
}).pipe(Effect.catch((error) => Effect.logWarning("CloudflareOtlp disabled because OTLP configuration is invalid", { error: String(error) }).pipe(Effect.as(emptyLayer)))));
|
|
1499
|
+
const makeLayer = (options = {}, runtimeAttributes = {}) => makeLayerFromSettings(options, runtimeAttributes);
|
|
1500
|
+
/**
|
|
1501
|
+
* Base OTLP telemetry layer for Cloudflare-compatible runtimes.
|
|
1502
|
+
*
|
|
1503
|
+
* The layer reads {@link CloudflareOtlpSettings} when provided. Otherwise it
|
|
1504
|
+
* reads standard OpenTelemetry config from `WorkerEnvironment` when available,
|
|
1505
|
+
* then falls back to the ambient Effect `ConfigProvider`.
|
|
1506
|
+
*
|
|
1507
|
+
* When only `OTEL_EXPORTER_OTLP_ENDPOINT` is configured, per-signal paths are
|
|
1508
|
+
* derived by appending `/v1/logs`, `/v1/traces`, and `/v1/metrics`. Signal
|
|
1509
|
+
* specific endpoints are used as-is, matching the OpenTelemetry OTLP exporter
|
|
1510
|
+
* convention.
|
|
1511
|
+
*/
|
|
1512
|
+
const layer$6 = (options = {}) => makeLayer(options);
|
|
1513
|
+
/** Base OTLP telemetry layer forced to JSON serialization. */
|
|
1514
|
+
const layerJson = (options = {}) => layer$6({
|
|
1515
|
+
...options,
|
|
1516
|
+
serialization: "json"
|
|
1517
|
+
});
|
|
1518
|
+
/** Base OTLP telemetry layer forced to protobuf serialization. */
|
|
1519
|
+
const layerProtobuf = (options = {}) => layer$6({
|
|
1520
|
+
...options,
|
|
1521
|
+
serialization: "protobuf"
|
|
1522
|
+
});
|
|
1523
|
+
/**
|
|
1524
|
+
* OTLP layer with Cloudflare Worker resource attributes.
|
|
1525
|
+
*
|
|
1526
|
+
* Provide this layer at runtime scope for long-lived metrics aggregation, or at
|
|
1527
|
+
* handler scope when traces/logs should flush as the Cloudflare event finishes.
|
|
1528
|
+
*/
|
|
1529
|
+
const workerLayer = (options = {}) => makeLayer(options, {
|
|
1530
|
+
"cloudflare.resource_type": "worker",
|
|
1531
|
+
"cloudflare.worker.name": options.workerName
|
|
1532
|
+
});
|
|
1533
|
+
/**
|
|
1534
|
+
* OTLP layer with Cloudflare Durable Object resource attributes.
|
|
1535
|
+
*
|
|
1536
|
+
* The layer reads {@link DurableObjectState} so it can optionally include the
|
|
1537
|
+
* Durable Object id. Prefer leaving `includeObjectId` disabled unless the
|
|
1538
|
+
* backend can tolerate high-cardinality resource attributes.
|
|
1539
|
+
*/
|
|
1540
|
+
const durableObjectLayer = (options = {}) => Layer.unwrap(Effect.map(DurableObjectState, (state) => makeLayer(options, {
|
|
1541
|
+
"cloudflare.resource_type": "durable_object",
|
|
1542
|
+
"cloudflare.durable_object.class": options.className,
|
|
1543
|
+
"cloudflare.durable_object.id": options.includeObjectId ? state.id.toString() : void 0
|
|
1544
|
+
})));
|
|
1545
|
+
const provideRpcLayer = (rpc, layer) => {
|
|
1546
|
+
if (rpc === void 0) return;
|
|
1547
|
+
return new Proxy(rpc, { get(target, property, receiver) {
|
|
1548
|
+
const handler = Reflect.get(target, property, receiver);
|
|
1549
|
+
if (typeof handler !== "function") return handler;
|
|
1550
|
+
return (...args) => Effect.suspend(() => Reflect.apply(handler, receiver, args)).pipe(Effect.provide(layer));
|
|
1551
|
+
} });
|
|
1552
|
+
};
|
|
1553
|
+
/**
|
|
1554
|
+
* Instrument Worker lifecycle handlers with event-scoped OTLP telemetry.
|
|
1555
|
+
*
|
|
1556
|
+
* Each defined handler is provided with {@link workerLayer}. Because Worker
|
|
1557
|
+
* handlers run inside `Effect.scoped`, the exporter scope closes and flushes at
|
|
1558
|
+
* the end of each Cloudflare event.
|
|
1559
|
+
*/
|
|
1560
|
+
const instrumentWorkerOptions = (options) => (handlers) => {
|
|
1561
|
+
const telemetryLayer = workerLayer(options);
|
|
1562
|
+
const queue = handlers.queue;
|
|
1563
|
+
return {
|
|
1564
|
+
...handlers,
|
|
1565
|
+
fetch: handlers.fetch === void 0 ? void 0 : handlers.fetch.pipe(Effect.provide(telemetryLayer)),
|
|
1566
|
+
queue: queue === void 0 ? void 0 : (batch) => queue(batch).pipe(Effect.provide(telemetryLayer)),
|
|
1567
|
+
rpc: provideRpcLayer(handlers.rpc, telemetryLayer)
|
|
1568
|
+
};
|
|
1569
|
+
};
|
|
1570
|
+
/**
|
|
1571
|
+
* Instrument Durable Object lifecycle handlers with event-scoped OTLP telemetry.
|
|
1572
|
+
*
|
|
1573
|
+
* Each defined handler is provided with {@link durableObjectLayer}. Because
|
|
1574
|
+
* Durable Object handlers run inside `Effect.scoped`, the exporter scope closes
|
|
1575
|
+
* and flushes at the end of each Cloudflare event.
|
|
1576
|
+
*/
|
|
1577
|
+
const instrumentDurableObjectOptions = (options) => (handlers) => {
|
|
1578
|
+
const telemetryLayer = durableObjectLayer(options);
|
|
1579
|
+
const alarm = handlers.alarm;
|
|
1580
|
+
const webSocketMessage = handlers.webSocketMessage;
|
|
1581
|
+
const webSocketClose = handlers.webSocketClose;
|
|
1582
|
+
const webSocketError = handlers.webSocketError;
|
|
1583
|
+
return {
|
|
1584
|
+
...handlers,
|
|
1585
|
+
initialize: handlers.initialize === void 0 ? void 0 : handlers.initialize.pipe(Effect.provide(telemetryLayer)),
|
|
1586
|
+
fetch: handlers.fetch === void 0 ? void 0 : handlers.fetch.pipe(Effect.provide(telemetryLayer)),
|
|
1587
|
+
alarms: handlers.alarms === void 0 ? void 0 : handlers.alarms.pipe(Effect.provide(telemetryLayer)),
|
|
1588
|
+
alarm: alarm === void 0 ? void 0 : (alarmInfo) => alarm(alarmInfo).pipe(Effect.provide(telemetryLayer)),
|
|
1589
|
+
webSocketMessage: webSocketMessage === void 0 ? void 0 : (socket, message) => webSocketMessage(socket, message).pipe(Effect.provide(telemetryLayer)),
|
|
1590
|
+
webSocketClose: webSocketClose === void 0 ? void 0 : (socket, code, reason, wasClean) => webSocketClose(socket, code, reason, wasClean).pipe(Effect.provide(telemetryLayer)),
|
|
1591
|
+
webSocketError: webSocketError === void 0 ? void 0 : (socket, error) => webSocketError(socket, error).pipe(Effect.provide(telemetryLayer)),
|
|
1592
|
+
rpc: provideRpcLayer(handlers.rpc, telemetryLayer)
|
|
1593
|
+
};
|
|
1594
|
+
};
|
|
1595
|
+
//#endregion
|
|
1596
|
+
//#region src/D1.ts
|
|
1597
|
+
var D1_exports = /* @__PURE__ */ __exportAll({
|
|
1598
|
+
Service: () => Service,
|
|
1599
|
+
make: () => make$4
|
|
1600
|
+
});
|
|
1601
|
+
const TypeId$1 = "effect-cf/D1";
|
|
1602
|
+
const expectedD1Database = "D1 database binding with prepare(), batch(), and exec()";
|
|
1603
|
+
const isD1Database = (value) => {
|
|
1604
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1605
|
+
const resource = value;
|
|
1606
|
+
return typeof resource.prepare === "function" && typeof resource.batch === "function" && typeof resource.exec === "function";
|
|
1607
|
+
};
|
|
1608
|
+
/**
|
|
1609
|
+
* Creates a typed D1 service tag plus Effect helpers.
|
|
1610
|
+
*/
|
|
1611
|
+
const make$4 = (id, definition) => Service()(id, definition);
|
|
1612
|
+
/**
|
|
1613
|
+
* Builds a D1 service around a Cloudflare D1 database binding.
|
|
1614
|
+
*
|
|
1615
|
+
* The returned service exposes the raw `D1Database` binding and `sqlLayer(...)`
|
|
1616
|
+
* for providing `effect/unstable/sql` via `@effect/sql-d1`.
|
|
1617
|
+
*
|
|
1618
|
+
* @example
|
|
1619
|
+
* ```ts
|
|
1620
|
+
* class TodoDatabase extends D1.Service<TodoDatabase>()("TodoDatabase", {
|
|
1621
|
+
* binding: "TODO_DB",
|
|
1622
|
+
* }) {}
|
|
1623
|
+
*
|
|
1624
|
+
* const SqlLive = TodoDatabase.sqlLayer();
|
|
1625
|
+
* ```
|
|
1626
|
+
*/
|
|
1627
|
+
const Service = () => (id, definition) => {
|
|
1628
|
+
const tag = Service$2()(id, definition.binding, isD1Database, void 0, { expected: expectedD1Database });
|
|
1629
|
+
const sqlLayer = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
1630
|
+
const db = yield* tag;
|
|
1631
|
+
return D1Client.layer({
|
|
1632
|
+
...options,
|
|
1633
|
+
db
|
|
1634
|
+
});
|
|
1635
|
+
})).pipe(Layer.provide(tag.layer));
|
|
1636
|
+
return Object.assign(tag, {
|
|
1637
|
+
[TypeId$1]: TypeId$1,
|
|
1638
|
+
definition,
|
|
1639
|
+
sqlLayer
|
|
1640
|
+
});
|
|
1641
|
+
};
|
|
1642
|
+
//#endregion
|
|
1316
1643
|
//#region src/DurableObjectAlarm.ts
|
|
1317
1644
|
var DurableObjectAlarm_exports = /* @__PURE__ */ __exportAll({
|
|
1318
1645
|
DurableObjectAlarm: () => DurableObjectAlarm,
|
|
@@ -1638,7 +1965,7 @@ var DurableObjectAlarm = class DurableObjectAlarm extends Context.Service()("eff
|
|
|
1638
1965
|
//#region src/DurableObjectRpcWebSocket.ts
|
|
1639
1966
|
var DurableObjectRpcWebSocket_exports = /* @__PURE__ */ __exportAll({
|
|
1640
1967
|
DurableObjectRpcWebSocket: () => DurableObjectRpcWebSocket,
|
|
1641
|
-
layer: () => layer$
|
|
1968
|
+
layer: () => layer$5
|
|
1642
1969
|
});
|
|
1643
1970
|
const defaultAttachmentKey = "effectCloudflareRpcClientId";
|
|
1644
1971
|
const defaultTag = "effect-cf-rpc";
|
|
@@ -1649,7 +1976,7 @@ var DurableObjectRpcWebSocket = class extends Context.Service()("effect-cf/Durab
|
|
|
1649
1976
|
/**
|
|
1650
1977
|
* Builds a layer that bridges Durable Object websocket events to `RpcServer.Protocol`.
|
|
1651
1978
|
*/
|
|
1652
|
-
const layer$
|
|
1979
|
+
const layer$5 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
1653
1980
|
const tag = options.tag ?? defaultTag;
|
|
1654
1981
|
const attachmentKey = options.attachmentKey ?? defaultAttachmentKey;
|
|
1655
1982
|
const durableObjectState = yield* DurableObjectState;
|
|
@@ -1761,6 +2088,27 @@ const writeAttachment = (socket, key, clientId) => {
|
|
|
1761
2088
|
});
|
|
1762
2089
|
};
|
|
1763
2090
|
//#endregion
|
|
2091
|
+
//#region src/DurableObjectSqlite.ts
|
|
2092
|
+
var DurableObjectSqlite_exports = /* @__PURE__ */ __exportAll({ layer: () => layer$4 });
|
|
2093
|
+
/**
|
|
2094
|
+
* Provides `effect/unstable/sql` from the current Durable Object SQLite storage.
|
|
2095
|
+
*
|
|
2096
|
+
* @example
|
|
2097
|
+
* ```ts
|
|
2098
|
+
* const RoomLayer = Layer.mergeAll(
|
|
2099
|
+
* DurableObjectSqlite.layer(),
|
|
2100
|
+
* OtherRoomServices,
|
|
2101
|
+
* );
|
|
2102
|
+
* ```
|
|
2103
|
+
*/
|
|
2104
|
+
const layer$4 = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
2105
|
+
const state = yield* DurableObjectState;
|
|
2106
|
+
return SqliteClient.layer({
|
|
2107
|
+
...options,
|
|
2108
|
+
db: state.raw.storage.sql
|
|
2109
|
+
});
|
|
2110
|
+
}));
|
|
2111
|
+
//#endregion
|
|
1764
2112
|
//#region src/Images.ts
|
|
1765
2113
|
var Images_exports = /* @__PURE__ */ __exportAll({
|
|
1766
2114
|
ImagesOperationError: () => ImagesOperationError,
|
|
@@ -1857,7 +2205,7 @@ const makeClient$3 = (definition) => (images) => {
|
|
|
1857
2205
|
unsafeRaw: Effect.succeed(images)
|
|
1858
2206
|
};
|
|
1859
2207
|
};
|
|
1860
|
-
const layer$3 = (tag, definition) => layer$
|
|
2208
|
+
const layer$3 = (tag, definition) => layer$10(tag, definition.binding, isImagesBinding, makeClient$3(definition), { expected: expectedImagesBinding });
|
|
1861
2209
|
const make$3 = (id) => Tag$4()(id);
|
|
1862
2210
|
const Tag$4 = () => (id) => {
|
|
1863
2211
|
const tag = Context.Service()(id);
|
|
@@ -1952,7 +2300,7 @@ const makeClient$2 = (definition) => {
|
|
|
1952
2300
|
unsafeRaw: Effect.succeed(kv)
|
|
1953
2301
|
});
|
|
1954
2302
|
};
|
|
1955
|
-
const layer$2 = (tag, definition) => layer$
|
|
2303
|
+
const layer$2 = (tag, definition) => layer$10(tag, definition.binding, isKvNamespace, makeClient$2(definition), { expected: expectedKvNamespace });
|
|
1956
2304
|
const makeDefinition$1 = (id, definition) => {
|
|
1957
2305
|
const kvDefinition = {
|
|
1958
2306
|
id,
|
|
@@ -2069,7 +2417,7 @@ const makeClient$1 = (definition) => {
|
|
|
2069
2417
|
};
|
|
2070
2418
|
};
|
|
2071
2419
|
};
|
|
2072
|
-
const layer$1 = (tag, definition) => layer$
|
|
2420
|
+
const layer$1 = (tag, definition) => layer$10(tag, definition.binding, isR2Bucket, makeClient$1(definition), { expected: expectedR2Bucket });
|
|
2073
2421
|
const make$2 = (id) => Tag$2()(id);
|
|
2074
2422
|
const Tag$2 = () => (id) => {
|
|
2075
2423
|
const tag = Context.Service()(id);
|
|
@@ -2155,7 +2503,7 @@ const makeClient = (definition) => {
|
|
|
2155
2503
|
unsafeRaw: Effect.succeed(workflow)
|
|
2156
2504
|
});
|
|
2157
2505
|
};
|
|
2158
|
-
const layer = (tag, definition) => layer$
|
|
2506
|
+
const layer = (tag, definition) => layer$10(tag, definition.binding, (value) => isWorkflow(value), makeClient(definition), { expected: expectedWorkflow });
|
|
2159
2507
|
//#endregion
|
|
2160
2508
|
//#region src/WorkflowDefinition.ts
|
|
2161
2509
|
var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -2176,7 +2524,7 @@ const make$1 = (id, definition) => Tag$1()(id, definition);
|
|
|
2176
2524
|
const Tag$1 = () => (id, definition) => {
|
|
2177
2525
|
const workflowDefinition = makeDefinition(id, definition);
|
|
2178
2526
|
const tag = Context.Service()(id);
|
|
2179
|
-
const layer$
|
|
2527
|
+
const layer$11 = (binding) => layer(tag, {
|
|
2180
2528
|
...binding,
|
|
2181
2529
|
payload: definition.payload,
|
|
2182
2530
|
result: definition.result
|
|
@@ -2198,7 +2546,7 @@ const Tag$1 = () => (id, definition) => {
|
|
|
2198
2546
|
payload: workflowDefinition.payload,
|
|
2199
2547
|
result: workflowDefinition.result,
|
|
2200
2548
|
make: workflowDefinition.make,
|
|
2201
|
-
layer: layer$
|
|
2549
|
+
layer: layer$11,
|
|
2202
2550
|
create,
|
|
2203
2551
|
createBatch,
|
|
2204
2552
|
get,
|
|
@@ -2289,4 +2637,4 @@ const waitForEvent = (name, options) => Effect.flatMap(WorkflowStep$1, (workflow
|
|
|
2289
2637
|
const Tag = Tag$1;
|
|
2290
2638
|
const implement = implement$1;
|
|
2291
2639
|
//#endregion
|
|
2292
|
-
export { Binding_exports as Binding, D1_exports as D1, DurableObject_exports as DurableObject, DurableObjectAlarm_exports as DurableObjectAlarm, DurableObjectDefinition_exports as DurableObjectDefinition, DurableObjectNamespace_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_exports as DurableObjectRpcWebSocket, DurableObjectState_exports as DurableObjectState, DurableObjectStorage_exports as DurableObjectStorage, DurableObjectWebSocket_exports as DurableObjectWebSocket, Hyperdrive_exports as Hyperdrive, Images_exports as Images, Kv_exports as Kv, Queue_exports as Queue, QueueBinding_exports as QueueBinding, QueueDefinition_exports as QueueDefinition, R2_exports as R2, Rpc_exports as Rpc, RpcDefinition_exports as RpcDefinition, ServiceBinding_exports as ServiceBinding, Worker_exports as Worker, WorkerConfig, WorkerDefinition_exports as WorkerDefinition, WorkerEnvironment, Workflow_exports as Workflow, WorkflowBinding_exports as WorkflowBinding, WorkflowDefinition_exports as WorkflowDefinition };
|
|
2640
|
+
export { Binding_exports as Binding, 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, Worker_exports as Worker, WorkerConfig, WorkerDefinition_exports as WorkerDefinition, WorkerEnvironment, Workflow_exports as Workflow, WorkflowBinding_exports as WorkflowBinding, WorkflowDefinition_exports as WorkflowDefinition };
|