effect-cf 0.17.1 → 0.20.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 +24 -0
- package/README.md +50 -3
- package/dist/{Hyperdrive-C0vfrPeG.d.mts → Hyperdrive-RTjgirMV.d.mts} +7 -12
- package/dist/HyperdrivePg.d.mts +2 -6
- package/dist/HyperdrivePg.mjs +0 -1
- package/dist/index.d.mts +223 -118
- package/dist/index.mjs +587 -164
- package/package.json +8 -9
- package/src/AiGateway.ts +3 -0
- package/src/AnalyticsEngine.ts +6 -1
- package/src/Binding.ts +4 -2
- package/src/Cache.ts +104 -0
- package/src/CloudflareOtlp.ts +20 -7
- package/src/ContainerNamespace.ts +3 -0
- package/src/D1.ts +1 -0
- package/src/DurableObject.ts +10 -2
- package/src/DurableObjectAlarm.ts +19 -0
- package/src/DurableObjectDefinition.ts +34 -6
- package/src/DurableObjectNamespace.ts +4 -1
- package/src/DurableObjectRpcWebSocket.ts +14 -0
- package/src/DurableObjectSqlite.ts +1 -0
- package/src/DurableObjectStorage.ts +2 -0
- package/src/DurableObjectWebSocket.ts +4 -1
- package/src/Email.ts +354 -10
- package/src/HyperdrivePg.ts +1 -1
- package/src/Kv.ts +3 -1
- package/src/QueueBinding.ts +2 -1
- package/src/QueueDefinition.ts +6 -1
- package/src/R2.ts +1 -0
- package/src/RpcDefinition.ts +2 -0
- package/src/ServiceBinding.ts +6 -1
- package/src/Worker.ts +10 -2
- package/src/WorkerDefinition.ts +28 -6
- package/src/WorkflowBinding.ts +5 -2
- package/src/WorkflowDefinition.ts +6 -1
- package/src/index.ts +1 -0
- package/src/internal/Clock.ts +9 -0
- package/src/internal/RpcInvocation.ts +1 -0
- package/dist/Hyperdrive-89hg_Fck.mjs +0 -156
- /package/dist/{chunk-CfYAbeIz.mjs → rolldown-runtime-D7D4PA-g.mjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as __exportAll } from "./
|
|
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";
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
3
2
|
import { Cause, Clock, Config, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Layer, ManagedRuntime, Option, Queue, Result, Schema } from "effect";
|
|
4
3
|
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
5
4
|
import { OtlpLogger, OtlpMetrics, OtlpSerialization, OtlpTracer } from "effect/unstable/observability";
|
|
@@ -9,15 +8,140 @@ import * as RpcMessage from "effect/unstable/rpc/RpcMessage";
|
|
|
9
8
|
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
|
|
10
9
|
import * as RpcServer from "effect/unstable/rpc/RpcServer";
|
|
11
10
|
import { SqliteClient } from "@effect/sql-sqlite-do";
|
|
11
|
+
//#region src/Environment.ts
|
|
12
|
+
/**
|
|
13
|
+
* Context service for reading worker bindings from the current `env` object.
|
|
14
|
+
*/
|
|
15
|
+
var WorkerEnvironment = class extends Context.Service()("effect-cf/WorkerEnvironment") {};
|
|
16
|
+
let WorkerConfig;
|
|
17
|
+
(function(_WorkerConfig) {
|
|
18
|
+
_WorkerConfig.string = (name) => Config.string(name);
|
|
19
|
+
_WorkerConfig.redacted = (name) => Config.redacted(name);
|
|
20
|
+
_WorkerConfig.number = (name) => Config.number(name);
|
|
21
|
+
_WorkerConfig.integer = (name) => Config.int(name);
|
|
22
|
+
_WorkerConfig.boolean = (name) => Config.boolean(name);
|
|
23
|
+
const providerFromEnv = _WorkerConfig.providerFromEnv = (env) => ConfigProvider.fromUnknown(env);
|
|
24
|
+
const providerWith = _WorkerConfig.providerWith = (makeProvider) => Effect.map(WorkerEnvironment, makeProvider);
|
|
25
|
+
const provider = _WorkerConfig.provider = providerWith(providerFromEnv);
|
|
26
|
+
_WorkerConfig.layer = _WorkerConfig.providerLayer = ConfigProvider.layer(provider);
|
|
27
|
+
_WorkerConfig.layerWith = (makeProvider) => ConfigProvider.layer(providerWith(makeProvider));
|
|
28
|
+
})(WorkerConfig || (WorkerConfig = {}));
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/Binding.ts
|
|
31
|
+
var Binding_exports = /* @__PURE__ */ __exportAll({
|
|
32
|
+
BindingNotFoundError: () => BindingNotFoundError,
|
|
33
|
+
BindingValidationError: () => BindingValidationError,
|
|
34
|
+
Service: () => Service$2,
|
|
35
|
+
TypeId: () => TypeId$3,
|
|
36
|
+
layer: () => layer$20
|
|
37
|
+
});
|
|
38
|
+
/** Internal type id marker used by binding helper services. */
|
|
39
|
+
const TypeId$3 = "effect-cf/Binding";
|
|
40
|
+
/** Error raised when a configured binding does not exist on `env`. */
|
|
41
|
+
var BindingNotFoundError = class extends Data.TaggedError("BindingNotFoundError") {};
|
|
42
|
+
/** Error raised when a binding exists but does not match the expected shape. */
|
|
43
|
+
var BindingValidationError = class extends Data.TaggedError("BindingValidationError") {};
|
|
44
|
+
const defaultExpected = "Cloudflare binding resource";
|
|
45
|
+
const isPropertyTarget$1 = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
|
|
46
|
+
const getObjectName = (value) => {
|
|
47
|
+
const tag = (() => {
|
|
48
|
+
try {
|
|
49
|
+
return Object.prototype.toString.call(value).slice(8, -1);
|
|
50
|
+
} catch {
|
|
51
|
+
return typeof value;
|
|
52
|
+
}
|
|
53
|
+
})();
|
|
54
|
+
const constructorName = (() => {
|
|
55
|
+
try {
|
|
56
|
+
return "constructor" in value && typeof value.constructor === "function" && typeof value.constructor.name === "string" ? value.constructor.name : void 0;
|
|
57
|
+
} catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
})();
|
|
61
|
+
if (tag !== "Object") return tag;
|
|
62
|
+
if (constructorName !== void 0 && constructorName !== "" && constructorName !== "Object") return constructorName;
|
|
63
|
+
return tag;
|
|
64
|
+
};
|
|
65
|
+
const propertyNames = (value) => {
|
|
66
|
+
const names = /* @__PURE__ */ new Set();
|
|
67
|
+
for (const target of [value, Object.getPrototypeOf(value)]) {
|
|
68
|
+
if (target === null || target === Object.prototype || target === Function.prototype) continue;
|
|
69
|
+
try {
|
|
70
|
+
for (const name of Object.getOwnPropertyNames(target)) names.add(name);
|
|
71
|
+
} catch {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return [...names].filter((name) => name !== "constructor").sort();
|
|
76
|
+
};
|
|
77
|
+
const isMethod = (value, name) => {
|
|
78
|
+
try {
|
|
79
|
+
return typeof Reflect.get(value, name) === "function";
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const describeActual = (value) => {
|
|
85
|
+
if (value === null) return "null";
|
|
86
|
+
if (typeof value !== "object" && typeof value !== "function") return typeof value;
|
|
87
|
+
const names = propertyNames(value);
|
|
88
|
+
const methods = names.filter((name) => isMethod(value, name));
|
|
89
|
+
const properties = names.filter((name) => !methods.includes(name));
|
|
90
|
+
const details = [methods.length > 0 ? `methods ${methods.join(", ")}` : void 0, properties.length > 0 ? `properties ${properties.join(", ")}` : void 0].filter((detail) => detail !== void 0);
|
|
91
|
+
if (details.length === 0) return getObjectName(value);
|
|
92
|
+
return `${getObjectName(value)} with ${details.join("; ")}`;
|
|
93
|
+
};
|
|
94
|
+
const getBinding = (env, binding, isResource, options) => Effect.gen(function* () {
|
|
95
|
+
if (!isPropertyTarget$1(env)) {
|
|
96
|
+
const actual = describeActual(env);
|
|
97
|
+
return yield* Effect.fail(new BindingValidationError({
|
|
98
|
+
binding,
|
|
99
|
+
expected: "WorkerEnvironment object",
|
|
100
|
+
actual,
|
|
101
|
+
message: `Cloudflare binding "${binding}" failed validation. Expected WorkerEnvironment object; got ${actual}`
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
const resource = Reflect.get(env, binding);
|
|
105
|
+
if (resource === void 0) return yield* Effect.fail(new BindingNotFoundError({
|
|
106
|
+
binding,
|
|
107
|
+
message: `Cloudflare binding "${binding}" was not found in WorkerEnvironment`
|
|
108
|
+
}));
|
|
109
|
+
if (!isResource(resource)) {
|
|
110
|
+
const expected = options?.expected ?? defaultExpected;
|
|
111
|
+
const actual = describeActual(resource);
|
|
112
|
+
return yield* Effect.fail(new BindingValidationError({
|
|
113
|
+
binding,
|
|
114
|
+
expected,
|
|
115
|
+
actual,
|
|
116
|
+
message: `Cloudflare binding "${binding}" failed validation. Expected ${expected}; got ${actual}`
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
return resource;
|
|
120
|
+
});
|
|
121
|
+
const layer$20 = (tag, binding, isResource, wrap, options) => Layer.effect(tag, Effect.gen(function* () {
|
|
122
|
+
const env = yield* WorkerEnvironment;
|
|
123
|
+
const resource = yield* getBinding(env, binding, isResource, options);
|
|
124
|
+
return wrap === void 0 ? resource : wrap(resource);
|
|
125
|
+
}));
|
|
126
|
+
const Service$2 = () => (id, binding, isResource, wrap, options) => {
|
|
127
|
+
const tag = Context.Service()(id);
|
|
128
|
+
const serviceLayer = layer$20(tag, binding, isResource, wrap, options);
|
|
129
|
+
return Object.assign(tag, {
|
|
130
|
+
[TypeId$3]: TypeId$3,
|
|
131
|
+
binding,
|
|
132
|
+
layer: serviceLayer
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
//#endregion
|
|
12
136
|
//#region src/WorkersAi.ts
|
|
13
137
|
var WorkersAi_exports = /* @__PURE__ */ __exportAll({
|
|
14
|
-
Tag: () => Tag$
|
|
138
|
+
Tag: () => Tag$18,
|
|
15
139
|
WorkersAiOperationError: () => WorkersAiOperationError,
|
|
16
140
|
embeddingResponse: () => embeddingResponse,
|
|
17
141
|
isWorkersAiBinding: () => isWorkersAiBinding,
|
|
18
|
-
layer: () => layer$
|
|
19
|
-
make: () => make$
|
|
20
|
-
makeClient: () => makeClient$
|
|
142
|
+
layer: () => layer$19,
|
|
143
|
+
make: () => make$18,
|
|
144
|
+
makeClient: () => makeClient$15
|
|
21
145
|
});
|
|
22
146
|
const expectedWorkersAiBinding = "Workers AI binding with run(), gateway(), and models()";
|
|
23
147
|
/** Error raised when a Workers AI operation fails. */
|
|
@@ -41,7 +165,7 @@ const embeddingResponse = (value) => ({
|
|
|
41
165
|
data: value.data ?? [],
|
|
42
166
|
shape: value.shape ?? []
|
|
43
167
|
});
|
|
44
|
-
const makeClient$
|
|
168
|
+
const makeClient$15 = (definition) => (ai) => {
|
|
45
169
|
const run = ((model, input, options) => tryWorkersAiPromise(definition.binding, "run", () => ai.run(model, input, options)));
|
|
46
170
|
return {
|
|
47
171
|
definition,
|
|
@@ -53,11 +177,11 @@ const makeClient$13 = (definition) => (ai) => {
|
|
|
53
177
|
unsafeRaw: Effect.succeed(ai)
|
|
54
178
|
};
|
|
55
179
|
};
|
|
56
|
-
const layer$
|
|
57
|
-
const make$
|
|
58
|
-
const Tag$
|
|
180
|
+
const layer$19 = (tag, definition) => layer$20(tag, definition.binding, (value) => isWorkersAiBinding(value), makeClient$15(definition), { expected: expectedWorkersAiBinding });
|
|
181
|
+
const make$18 = (id) => Tag$18()(id);
|
|
182
|
+
const Tag$18 = () => (id) => {
|
|
59
183
|
const tag = Context.Service()(id);
|
|
60
|
-
const makeLayer = (definition) => layer$
|
|
184
|
+
const makeLayer = (definition) => layer$19(tag, definition);
|
|
61
185
|
return Object.assign(tag, {
|
|
62
186
|
id,
|
|
63
187
|
layer: makeLayer
|
|
@@ -67,11 +191,11 @@ const Tag$17 = () => (id) => {
|
|
|
67
191
|
//#region src/AiGateway.ts
|
|
68
192
|
var AiGateway_exports = /* @__PURE__ */ __exportAll({
|
|
69
193
|
AiGatewayOperationError: () => AiGatewayOperationError,
|
|
70
|
-
Tag: () => Tag$
|
|
194
|
+
Tag: () => Tag$17,
|
|
71
195
|
isAiGatewayBinding: () => isAiGatewayBinding,
|
|
72
|
-
layer: () => layer$
|
|
73
|
-
make: () => make$
|
|
74
|
-
makeClient: () => makeClient$
|
|
196
|
+
layer: () => layer$18,
|
|
197
|
+
make: () => make$17,
|
|
198
|
+
makeClient: () => makeClient$14,
|
|
75
199
|
makeClientFromAi: () => makeClientFromAi,
|
|
76
200
|
makeHttpClient: () => makeHttpClient
|
|
77
201
|
});
|
|
@@ -98,7 +222,7 @@ const providerUrl = (baseUrl, path = "") => {
|
|
|
98
222
|
};
|
|
99
223
|
const gatewayUrl = (definition) => `https://gateway.ai.cloudflare.com/v1/${definition.accountId}/${definition.gatewayId}/`;
|
|
100
224
|
const isAiGatewayBinding = (value) => isWorkersAiBinding(value);
|
|
101
|
-
const makeClient$
|
|
225
|
+
const makeClient$14 = (definition, gateway) => ({
|
|
102
226
|
definition,
|
|
103
227
|
run: (data, options) => tryAiGatewayPromise(definition.binding, "run", () => gateway.run(Array.isArray(data) ? [...data] : data, options)),
|
|
104
228
|
getUrl: (provider) => tryAiGatewayPromise(definition.binding, "getUrl", () => gateway.getUrl(provider)),
|
|
@@ -115,11 +239,11 @@ const makeClientFromAi = (definition, ai) => {
|
|
|
115
239
|
const withGateway = (operation) => gateway.pipe(Effect.flatMap(operation));
|
|
116
240
|
return {
|
|
117
241
|
definition,
|
|
118
|
-
run: (data, options) => withGateway((raw) => makeClient$
|
|
119
|
-
getUrl: (provider) => withGateway((raw) => makeClient$
|
|
120
|
-
fetch: (options) => withGateway((raw) => makeClient$
|
|
121
|
-
patchLog: (logId, data) => withGateway((raw) => makeClient$
|
|
122
|
-
getLog: (logId) => withGateway((raw) => makeClient$
|
|
242
|
+
run: (data, options) => withGateway((raw) => makeClient$14(definition, raw).run(data, options)),
|
|
243
|
+
getUrl: (provider) => withGateway((raw) => makeClient$14(definition, raw).getUrl(provider)),
|
|
244
|
+
fetch: (options) => withGateway((raw) => makeClient$14(definition, raw).fetch(options)),
|
|
245
|
+
patchLog: (logId, data) => withGateway((raw) => makeClient$14(definition, raw).patchLog(logId, data)),
|
|
246
|
+
getLog: (logId) => withGateway((raw) => makeClient$14(definition, raw).getLog(logId)),
|
|
123
247
|
unsafeRaw: gateway
|
|
124
248
|
};
|
|
125
249
|
};
|
|
@@ -159,11 +283,11 @@ const makeHttpClient = (definition, request = fetch) => {
|
|
|
159
283
|
unsafeRaw: Effect.fail(aiGatewayError(binding, "unsafeRaw", /* @__PURE__ */ new TypeError("HTTP AI Gateway clients have no raw binding")))
|
|
160
284
|
};
|
|
161
285
|
};
|
|
162
|
-
const layer$
|
|
163
|
-
const make$
|
|
164
|
-
const Tag$
|
|
286
|
+
const layer$18 = (tag, definition) => layer$20(tag, definition.binding, isAiGatewayBinding, (ai) => makeClientFromAi(definition, ai), { expected: expectedAiGatewayBinding });
|
|
287
|
+
const make$17 = (id) => Tag$17()(id);
|
|
288
|
+
const Tag$17 = () => (id) => {
|
|
165
289
|
const tag = Context.Service()(id);
|
|
166
|
-
const makeLayer = (definition) => layer$
|
|
290
|
+
const makeLayer = (definition) => layer$18(tag, definition);
|
|
167
291
|
return Object.assign(tag, {
|
|
168
292
|
id,
|
|
169
293
|
layer: makeLayer
|
|
@@ -178,11 +302,11 @@ var AnalyticsEngine_exports = /* @__PURE__ */ __exportAll({
|
|
|
178
302
|
AnalyticsEngineQueryError: () => AnalyticsEngineQueryError,
|
|
179
303
|
AnalyticsEngineWriteValidationError: () => AnalyticsEngineWriteValidationError,
|
|
180
304
|
QueryTag: () => QueryTag,
|
|
181
|
-
Tag: () => Tag$
|
|
305
|
+
Tag: () => Tag$16,
|
|
182
306
|
isAnalyticsEngineDataset: () => isAnalyticsEngineDataset,
|
|
183
|
-
layer: () => layer$
|
|
184
|
-
make: () => make$
|
|
185
|
-
makeClient: () => makeClient$
|
|
307
|
+
layer: () => layer$17,
|
|
308
|
+
make: () => make$16,
|
|
309
|
+
makeClient: () => makeClient$13,
|
|
186
310
|
makeQuery: () => makeQuery,
|
|
187
311
|
makeQueryClient: () => makeQueryClient,
|
|
188
312
|
queryConfig: () => queryConfig,
|
|
@@ -194,7 +318,7 @@ var AnalyticsEngine_exports = /* @__PURE__ */ __exportAll({
|
|
|
194
318
|
});
|
|
195
319
|
const expectedAnalyticsEngineDataset = "Analytics Engine dataset binding with writeDataPoint()";
|
|
196
320
|
const defaultQueryApiBaseUrl = "https://api.cloudflare.com/client/v4";
|
|
197
|
-
const textEncoder = new TextEncoder();
|
|
321
|
+
const textEncoder$1 = new TextEncoder();
|
|
198
322
|
const writeLimits = {
|
|
199
323
|
maxBlobs: 20,
|
|
200
324
|
maxDoubles: 20,
|
|
@@ -260,9 +384,9 @@ const resolveWritePolicy = (defaults, options) => ({
|
|
|
260
384
|
});
|
|
261
385
|
const fieldPath = (prefix, field) => prefix === "" ? field : `${prefix}.${field}`;
|
|
262
386
|
const indexedPath = (prefix, field, index) => `${fieldPath(prefix, field)}[${index}]`;
|
|
263
|
-
const byteLength = (value) => {
|
|
387
|
+
const byteLength$1 = (value) => {
|
|
264
388
|
if (value === null) return 0;
|
|
265
|
-
return typeof value === "string" ? textEncoder.encode(value).byteLength : value.byteLength;
|
|
389
|
+
return typeof value === "string" ? textEncoder$1.encode(value).byteLength : value.byteLength;
|
|
266
390
|
};
|
|
267
391
|
const lengthViolation = (path, label, actual, limit) => ({
|
|
268
392
|
path,
|
|
@@ -276,11 +400,11 @@ const validateDataPointLimits = (dataPoint, pathPrefix = "") => {
|
|
|
276
400
|
if (dataPoint.doubles !== void 0 && dataPoint.doubles.length > writeLimits.maxDoubles) violations.push(lengthViolation(fieldPath(pathPrefix, "doubles"), "doubles", dataPoint.doubles.length, writeLimits.maxDoubles));
|
|
277
401
|
if (dataPoint.indexes !== void 0 && dataPoint.indexes.length > writeLimits.maxIndexes) violations.push(lengthViolation(fieldPath(pathPrefix, "indexes"), "indexes", dataPoint.indexes.length, writeLimits.maxIndexes));
|
|
278
402
|
if (dataPoint.blobs !== void 0) {
|
|
279
|
-
const blobBytes = dataPoint.blobs.reduce((total, value) => total + byteLength(value), 0);
|
|
403
|
+
const blobBytes = dataPoint.blobs.reduce((total, value) => total + byteLength$1(value), 0);
|
|
280
404
|
if (blobBytes > writeLimits.maxBlobBytes) violations.push(lengthViolation(fieldPath(pathPrefix, "blobs"), "blob bytes", blobBytes, writeLimits.maxBlobBytes));
|
|
281
405
|
}
|
|
282
406
|
if (dataPoint.indexes !== void 0) for (let index = 0; index < dataPoint.indexes.length; index++) {
|
|
283
|
-
const indexBytes = byteLength(dataPoint.indexes[index] ?? null);
|
|
407
|
+
const indexBytes = byteLength$1(dataPoint.indexes[index] ?? null);
|
|
284
408
|
if (indexBytes > writeLimits.maxIndexBytes) violations.push(lengthViolation(indexedPath(pathPrefix, "indexes", index), "index bytes", indexBytes, writeLimits.maxIndexBytes));
|
|
285
409
|
}
|
|
286
410
|
return violations;
|
|
@@ -295,7 +419,8 @@ const toAnalyticsEngineDataPoint = (dataPoint) => ({
|
|
|
295
419
|
...dataPoint.blobs === void 0 ? {} : { blobs: [...dataPoint.blobs] }
|
|
296
420
|
});
|
|
297
421
|
const validateDataPoint = (binding, operation, dataPoint, pathPrefix = "") => Effect.gen(function* () {
|
|
298
|
-
const
|
|
422
|
+
const decoded = yield* decodeDataPoint(dataPoint).pipe(Effect.mapError((cause) => analyticsEngineWriteValidationError(binding, operation, [schemaViolation(pathPrefix, cause)], cause)));
|
|
423
|
+
const validated = toAnalyticsEngineDataPoint(decoded);
|
|
299
424
|
const violations = validateDataPointLimits(validated, pathPrefix);
|
|
300
425
|
if (violations.length > 0) return yield* Effect.fail(analyticsEngineWriteValidationError(binding, operation, violations));
|
|
301
426
|
return validated;
|
|
@@ -347,7 +472,8 @@ const executeQueryRequest = (definition, httpClient, sql, options) => Effect.gen
|
|
|
347
472
|
const makeQueryClientWith = (definition, httpClient) => {
|
|
348
473
|
const raw = (sql, options) => executeQueryRequest(definition, httpClient, sql, options);
|
|
349
474
|
const query = (sql, options) => Effect.gen(function* () {
|
|
350
|
-
|
|
475
|
+
const json = yield* (yield* raw(sql, options)).json.pipe(Effect.catch((cause) => Effect.fail(analyticsEngineQueryError(definition, "json", "Failed to read Analytics Engine SQL API JSON response body", { cause }))));
|
|
476
|
+
return yield* decodeQueryResponse(json);
|
|
351
477
|
});
|
|
352
478
|
const queryResult = (row, sql, options) => Effect.gen(function* () {
|
|
353
479
|
const result = yield* query(sql, options);
|
|
@@ -375,7 +501,7 @@ const isAnalyticsEngineDataset = (value) => {
|
|
|
375
501
|
if (typeof value !== "object" || value === null) return false;
|
|
376
502
|
return typeof Reflect.get(value, "writeDataPoint") === "function";
|
|
377
503
|
};
|
|
378
|
-
const makeClient$
|
|
504
|
+
const makeClient$13 = (definition, defaults) => (dataset) => {
|
|
379
505
|
const writeDataPoint = (dataPoint, options) => {
|
|
380
506
|
const policy = resolveWritePolicy(defaults, options);
|
|
381
507
|
return validateOptionalDataPoint(definition.binding, "writeDataPoint", dataPoint).pipe(Effect.matchEffect({
|
|
@@ -407,15 +533,16 @@ const queryConfig = (options) => Config.all({
|
|
|
407
533
|
const queryLayer = (tag, definition) => Layer.effect(tag, makeQueryClient(definition));
|
|
408
534
|
const queryFetchLayer = (tag, definition) => queryLayer(tag, definition).pipe(Layer.provide(FetchHttpClient.layer));
|
|
409
535
|
const queryLayerConfig = (tag, config = queryConfig()) => Layer.effect(tag, Effect.gen(function* () {
|
|
410
|
-
|
|
536
|
+
const definition = yield* config;
|
|
537
|
+
return yield* makeQueryClient(definition);
|
|
411
538
|
}));
|
|
412
539
|
const queryFetchLayerConfig = (tag, config = queryConfig()) => queryLayerConfig(tag, config).pipe(Layer.provide(FetchHttpClient.layer));
|
|
413
|
-
const layer$
|
|
414
|
-
const make$
|
|
540
|
+
const layer$17 = (tag, definition) => layer$20(tag, definition.binding, isAnalyticsEngineDataset, makeClient$13(definition, definition.write), { expected: expectedAnalyticsEngineDataset });
|
|
541
|
+
const make$16 = (id) => Tag$16()(id);
|
|
415
542
|
const makeQuery = (id) => QueryTag()(id);
|
|
416
|
-
const Tag$
|
|
543
|
+
const Tag$16 = () => (id) => {
|
|
417
544
|
const tag = Context.Service()(id);
|
|
418
|
-
const makeLayer = (definition) => layer$
|
|
545
|
+
const makeLayer = (definition) => layer$17(tag, definition);
|
|
419
546
|
return Object.assign(tag, {
|
|
420
547
|
id,
|
|
421
548
|
layer: makeLayer
|
|
@@ -439,11 +566,11 @@ const QueryTag = () => (id) => {
|
|
|
439
566
|
//#region src/BrowserRendering.ts
|
|
440
567
|
var BrowserRendering_exports = /* @__PURE__ */ __exportAll({
|
|
441
568
|
BrowserRenderingOperationError: () => BrowserRenderingOperationError,
|
|
442
|
-
Tag: () => Tag$
|
|
569
|
+
Tag: () => Tag$15,
|
|
443
570
|
isBrowserRenderingBinding: () => isBrowserRenderingBinding,
|
|
444
|
-
layer: () => layer$
|
|
445
|
-
make: () => make$
|
|
446
|
-
makeClient: () => makeClient$
|
|
571
|
+
layer: () => layer$16,
|
|
572
|
+
make: () => make$15,
|
|
573
|
+
makeClient: () => makeClient$12
|
|
447
574
|
});
|
|
448
575
|
const expectedBrowserRenderingBinding = "Browser Rendering binding resource";
|
|
449
576
|
/** Error raised when a Browser Rendering operation fails. */
|
|
@@ -480,23 +607,64 @@ const wrapBrowser = (binding, browser) => ({
|
|
|
480
607
|
disconnect: browser.disconnect === void 0 ? Effect.void : tryBrowserRenderingSync(binding, "disconnect", () => browser.disconnect())
|
|
481
608
|
});
|
|
482
609
|
const isBrowserRenderingBinding = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
|
|
483
|
-
const makeClient$
|
|
610
|
+
const makeClient$12 = (definition) => (binding) => ({
|
|
484
611
|
definition,
|
|
485
612
|
launchWith: (launch, options) => tryBrowserRenderingPromise(definition.binding, "launch", () => launch(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser))),
|
|
486
613
|
connectWith: (connect, options) => tryBrowserRenderingPromise(definition.binding, "connect", () => connect(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser))),
|
|
487
614
|
unsafeRaw: Effect.succeed(binding)
|
|
488
615
|
});
|
|
489
|
-
const layer$
|
|
490
|
-
const make$
|
|
491
|
-
const Tag$
|
|
616
|
+
const layer$16 = (tag, definition) => layer$20(tag, definition.binding, isBrowserRenderingBinding, makeClient$12(definition), { expected: expectedBrowserRenderingBinding });
|
|
617
|
+
const make$15 = (id) => Tag$15()(id);
|
|
618
|
+
const Tag$15 = () => (id) => {
|
|
492
619
|
const tag = Context.Service()(id);
|
|
493
|
-
const makeLayer = (definition) => layer$
|
|
620
|
+
const makeLayer = (definition) => layer$16(tag, definition);
|
|
494
621
|
return Object.assign(tag, {
|
|
495
622
|
id,
|
|
496
623
|
layer: makeLayer
|
|
497
624
|
});
|
|
498
625
|
};
|
|
499
626
|
//#endregion
|
|
627
|
+
//#region src/Cache.ts
|
|
628
|
+
var Cache_exports = /* @__PURE__ */ __exportAll({
|
|
629
|
+
CacheOperationError: () => CacheOperationError,
|
|
630
|
+
CacheStorage: () => CacheStorage,
|
|
631
|
+
layer: () => layer$15,
|
|
632
|
+
layerFrom: () => layerFrom,
|
|
633
|
+
makeCacheClient: () => makeCacheClient,
|
|
634
|
+
makeClient: () => makeClient$11
|
|
635
|
+
});
|
|
636
|
+
/** Error raised when a Cloudflare Cache API operation fails. */
|
|
637
|
+
var CacheOperationError = class extends Data.TaggedError("CacheOperationError") {};
|
|
638
|
+
/** Service for Cloudflare's global Cache API. */
|
|
639
|
+
var CacheStorage = class extends Context.Service()("effect-cf/CacheStorage") {};
|
|
640
|
+
const cacheError = (cache, operation, cause) => new CacheOperationError({
|
|
641
|
+
cache,
|
|
642
|
+
operation,
|
|
643
|
+
cause
|
|
644
|
+
});
|
|
645
|
+
const tryCachePromise = (cache, operation, evaluate) => Effect.tryPromise({
|
|
646
|
+
try: evaluate,
|
|
647
|
+
catch: (cause) => cacheError(cache, operation, cause)
|
|
648
|
+
});
|
|
649
|
+
/** Wraps a native Cloudflare `Cache` instance. */
|
|
650
|
+
const makeCacheClient = (cache, name = "default") => ({
|
|
651
|
+
name,
|
|
652
|
+
match: (request, options) => tryCachePromise(name, "match", () => cache.match(request, options)).pipe(Effect.map(Option.fromUndefinedOr)),
|
|
653
|
+
put: (request, response) => tryCachePromise(name, "put", () => cache.put(request, response)),
|
|
654
|
+
delete: (request, options) => tryCachePromise(name, "delete", () => cache.delete(request, options)),
|
|
655
|
+
unsafeRaw: Effect.succeed(cache)
|
|
656
|
+
});
|
|
657
|
+
/** Wraps a native Cloudflare `CacheStorage` instance. */
|
|
658
|
+
const makeClient$11 = (storage) => ({
|
|
659
|
+
default: makeCacheClient(storage.default),
|
|
660
|
+
open: (name) => tryCachePromise(name, "open", () => storage.open(name)).pipe(Effect.map((cache) => makeCacheClient(cache, name))),
|
|
661
|
+
unsafeRaw: Effect.succeed(storage)
|
|
662
|
+
});
|
|
663
|
+
/** Provides Cache API services from an explicit native `CacheStorage` instance. */
|
|
664
|
+
const layerFrom = (storage) => Layer.succeed(CacheStorage, makeClient$11(storage));
|
|
665
|
+
/** Provides Cache API services from Cloudflare's global `caches` object. */
|
|
666
|
+
const layer$15 = Layer.sync(CacheStorage, () => makeClient$11(caches));
|
|
667
|
+
//#endregion
|
|
500
668
|
//#region src/DurableObjectStorage.ts
|
|
501
669
|
var DurableObjectStorage_exports = /* @__PURE__ */ __exportAll({
|
|
502
670
|
StorageOperationError: () => StorageOperationError,
|
|
@@ -704,7 +872,7 @@ const attachment = (schema) => {
|
|
|
704
872
|
})), Effect.flatMap((encoded) => socket.serializeAttachment(encoded)));
|
|
705
873
|
const deserialize = (socket) => Effect.gen(function* () {
|
|
706
874
|
const value = yield* socket.deserializeAttachment;
|
|
707
|
-
if (value
|
|
875
|
+
if (value === null || value === void 0) return Option.none();
|
|
708
876
|
return Option.some(yield* Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError((cause) => new DurableWebSocketAttachmentError({
|
|
709
877
|
operation: "deserialize",
|
|
710
878
|
cause
|
|
@@ -789,7 +957,7 @@ const runPromiseExitPreservingTypedFailures = async (effect) => {
|
|
|
789
957
|
//#region src/CloudflareOtlp.ts
|
|
790
958
|
var CloudflareOtlp_exports = /* @__PURE__ */ __exportAll({
|
|
791
959
|
durableObjectLayer: () => durableObjectLayer,
|
|
792
|
-
layer: () => layer$
|
|
960
|
+
layer: () => layer$14,
|
|
793
961
|
layerJson: () => layerJson,
|
|
794
962
|
layerProtobuf: () => layerProtobuf,
|
|
795
963
|
workerLayer: () => workerLayer
|
|
@@ -816,8 +984,8 @@ const makeResource = (options, runtimeAttributes) => ({
|
|
|
816
984
|
}
|
|
817
985
|
});
|
|
818
986
|
const serializationLayer = (serialization) => serialization === "json" ? OtlpSerialization.layerJson : OtlpSerialization.layerProtobuf;
|
|
987
|
+
/** Merges a non-empty signal layer list; callers handle the empty case. */
|
|
819
988
|
const mergeSignalLayers = (layers) => {
|
|
820
|
-
if (layers.length === 0) return Layer.empty;
|
|
821
989
|
let merged = layers[0];
|
|
822
990
|
for (let index = 1; index < layers.length; index++) merged = Layer.mergeAll(merged, layers[index]);
|
|
823
991
|
return merged;
|
|
@@ -841,6 +1009,7 @@ const makeLayer = (options = {}, runtimeAttributes = {}) => {
|
|
|
841
1009
|
resource,
|
|
842
1010
|
headers: options.headers
|
|
843
1011
|
}));
|
|
1012
|
+
if (layers.length === 0) return Layer.empty;
|
|
844
1013
|
return mergeSignalLayers(layers).pipe(Layer.provide(cloudflareConfigProviderLayer), Layer.provide(serializationLayer(options.serialization)), Layer.provide(FetchHttpClient.layer));
|
|
845
1014
|
};
|
|
846
1015
|
/**
|
|
@@ -851,14 +1020,14 @@ const makeLayer = (options = {}, runtimeAttributes = {}) => {
|
|
|
851
1020
|
* installed as the primary `ConfigProvider`; outside Cloudflare, the ambient
|
|
852
1021
|
* Effect `ConfigProvider` remains the fallback.
|
|
853
1022
|
*/
|
|
854
|
-
const layer$
|
|
1023
|
+
const layer$14 = (options = {}) => makeLayer(options);
|
|
855
1024
|
/** Base OTLP telemetry layer forced to JSON serialization. */
|
|
856
|
-
const layerJson = (options = {}) => layer$
|
|
1025
|
+
const layerJson = (options = {}) => layer$14({
|
|
857
1026
|
...options,
|
|
858
1027
|
serialization: "json"
|
|
859
1028
|
});
|
|
860
1029
|
/** Base OTLP telemetry layer forced to protobuf serialization. */
|
|
861
|
-
const layerProtobuf = (options = {}) => layer$
|
|
1030
|
+
const layerProtobuf = (options = {}) => layer$14({
|
|
862
1031
|
...options,
|
|
863
1032
|
serialization: "protobuf"
|
|
864
1033
|
});
|
|
@@ -890,11 +1059,11 @@ var ContainerNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
|
890
1059
|
ContainerNamespace: () => ContainerNamespace,
|
|
891
1060
|
ContainerOperationError: () => ContainerOperationError,
|
|
892
1061
|
ContainerState: () => ContainerState,
|
|
893
|
-
Tag: () => Tag$
|
|
1062
|
+
Tag: () => Tag$14,
|
|
894
1063
|
isContainerNamespaceResource: () => isContainerNamespaceResource,
|
|
895
|
-
layer: () => layer$
|
|
896
|
-
make: () => make$
|
|
897
|
-
makeClient: () => makeClient$
|
|
1064
|
+
layer: () => layer$13,
|
|
1065
|
+
make: () => make$14,
|
|
1066
|
+
makeClient: () => makeClient$10
|
|
898
1067
|
});
|
|
899
1068
|
const expectedContainerNamespace = "Container namespace binding with getByName()";
|
|
900
1069
|
/** Serializable state reported by a Cloudflare Container instance. */
|
|
@@ -937,7 +1106,7 @@ const makeInstanceClient = (definition, instance, stub) => ({
|
|
|
937
1106
|
destroy: tryContainerPromise(definition, instance, "destroy", () => stub.destroy())
|
|
938
1107
|
});
|
|
939
1108
|
const isContainerNamespaceResource = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "getByName") === "function";
|
|
940
|
-
const makeClient$
|
|
1109
|
+
const makeClient$10 = (definition) => (namespace) => {
|
|
941
1110
|
const getByName = (name, options) => Effect.try({
|
|
942
1111
|
try: () => makeInstanceClient(definition, name, namespace.getByName(name, options)),
|
|
943
1112
|
catch: (cause) => new ContainerOperationError({
|
|
@@ -966,12 +1135,12 @@ const makeClient$9 = (definition) => (namespace) => {
|
|
|
966
1135
|
unsafeRaw: Effect.succeed(namespace)
|
|
967
1136
|
};
|
|
968
1137
|
};
|
|
969
|
-
const layer$
|
|
970
|
-
const make$
|
|
1138
|
+
const layer$13 = (tag, definition) => layer$20(tag, definition.binding, isContainerNamespaceResource, makeClient$10(definition), { expected: expectedContainerNamespace });
|
|
1139
|
+
const make$14 = (id) => Tag$14()(id);
|
|
971
1140
|
/** Creates a typed Effect service for a Cloudflare Container namespace. */
|
|
972
|
-
const Tag$
|
|
1141
|
+
const Tag$14 = () => (id) => {
|
|
973
1142
|
const tag = Context.Service()(id);
|
|
974
|
-
const makeLayer = (definition) => layer$
|
|
1143
|
+
const makeLayer = (definition) => layer$13(tag, definition);
|
|
975
1144
|
const getByName = (name, options) => Effect.gen(function* () {
|
|
976
1145
|
return yield* (yield* tag).getByName(name, options);
|
|
977
1146
|
});
|
|
@@ -995,12 +1164,12 @@ const Tag$13 = () => (id) => {
|
|
|
995
1164
|
unsafeRaw
|
|
996
1165
|
});
|
|
997
1166
|
};
|
|
998
|
-
const ContainerNamespace = Tag$
|
|
1167
|
+
const ContainerNamespace = Tag$14;
|
|
999
1168
|
//#endregion
|
|
1000
1169
|
//#region src/D1.ts
|
|
1001
1170
|
var D1_exports = /* @__PURE__ */ __exportAll({
|
|
1002
1171
|
Service: () => Service$1,
|
|
1003
|
-
make: () => make$
|
|
1172
|
+
make: () => make$13
|
|
1004
1173
|
});
|
|
1005
1174
|
const TypeId$2 = "effect-cf/D1";
|
|
1006
1175
|
const expectedD1Database = "D1 database binding with prepare(), batch(), and exec()";
|
|
@@ -1012,7 +1181,7 @@ const isD1Database = (value) => {
|
|
|
1012
1181
|
/**
|
|
1013
1182
|
* Creates a typed D1 service tag plus Effect helpers.
|
|
1014
1183
|
*/
|
|
1015
|
-
const make$
|
|
1184
|
+
const make$13 = (id, definition) => Service$1()(id, definition);
|
|
1016
1185
|
/**
|
|
1017
1186
|
* Builds a D1 service around a Cloudflare D1 database binding.
|
|
1018
1187
|
*
|
|
@@ -1048,8 +1217,8 @@ const Service$1 = () => (id, definition) => {
|
|
|
1048
1217
|
var QueueBinding_exports = /* @__PURE__ */ __exportAll({
|
|
1049
1218
|
QueueOperationError: () => QueueOperationError,
|
|
1050
1219
|
isQueue: () => isQueue,
|
|
1051
|
-
layer: () => layer$
|
|
1052
|
-
makeClient: () => makeClient$
|
|
1220
|
+
layer: () => layer$12,
|
|
1221
|
+
makeClient: () => makeClient$9
|
|
1053
1222
|
});
|
|
1054
1223
|
const expectedQueueProducer = "Queue producer binding with send(); optional sendBatch()/metrics()";
|
|
1055
1224
|
var QueueOperationError = class extends Data.TaggedError("QueueOperationError") {};
|
|
@@ -1066,7 +1235,7 @@ const isQueue = (value) => {
|
|
|
1066
1235
|
if (typeof value !== "object" || value === null) return false;
|
|
1067
1236
|
return typeof value.send === "function";
|
|
1068
1237
|
};
|
|
1069
|
-
const makeClient$
|
|
1238
|
+
const makeClient$9 = (definition) => {
|
|
1070
1239
|
const encodeMessage = Schema.encodeEffect(definition.message);
|
|
1071
1240
|
return (queue) => ({
|
|
1072
1241
|
send: Effect.fnUntraced(function* (message, options) {
|
|
@@ -1104,30 +1273,30 @@ const makeClient$8 = (definition) => {
|
|
|
1104
1273
|
unsafeRaw: Effect.succeed(queue)
|
|
1105
1274
|
});
|
|
1106
1275
|
};
|
|
1107
|
-
const layer$
|
|
1276
|
+
const layer$12 = (tag, definition) => layer$20(tag, definition.binding, (value) => isQueue(value), makeClient$9(definition), { expected: expectedQueueProducer });
|
|
1108
1277
|
//#endregion
|
|
1109
1278
|
//#region src/QueueDefinition.ts
|
|
1110
1279
|
var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
1111
1280
|
Queue: () => Queue$1,
|
|
1112
|
-
Tag: () => Tag$
|
|
1281
|
+
Tag: () => Tag$13,
|
|
1113
1282
|
implement: () => implement$7,
|
|
1114
|
-
make: () => make$
|
|
1283
|
+
make: () => make$12
|
|
1115
1284
|
});
|
|
1116
1285
|
const makeDefinition$4 = (id, definition) => {
|
|
1117
1286
|
const queueDefinition = {
|
|
1118
1287
|
id,
|
|
1119
1288
|
message: definition.message
|
|
1120
1289
|
};
|
|
1121
|
-
return Object.assign(queueDefinition, { make: (layer, options) => make$
|
|
1290
|
+
return Object.assign(queueDefinition, { make: (layer, options) => make$9(layer, {
|
|
1122
1291
|
...options,
|
|
1123
1292
|
queue: wrapHandler$1(queueDefinition, options.queue)
|
|
1124
1293
|
}) });
|
|
1125
1294
|
};
|
|
1126
|
-
const make$
|
|
1127
|
-
const Tag$
|
|
1295
|
+
const make$12 = (id, definition) => Tag$13()(id, definition);
|
|
1296
|
+
const Tag$13 = () => (id, definition) => {
|
|
1128
1297
|
const queueDefinition = makeDefinition$4(id, definition);
|
|
1129
1298
|
const tag = Context.Service()(id);
|
|
1130
|
-
const layer = (binding) => layer$
|
|
1299
|
+
const layer = (binding) => layer$12(tag, {
|
|
1131
1300
|
...binding,
|
|
1132
1301
|
message: definition.message
|
|
1133
1302
|
});
|
|
@@ -1154,7 +1323,7 @@ const Tag$12 = () => (id, definition) => {
|
|
|
1154
1323
|
unsafeRaw
|
|
1155
1324
|
});
|
|
1156
1325
|
};
|
|
1157
|
-
const Queue$1 = Tag$
|
|
1326
|
+
const Queue$1 = Tag$13;
|
|
1158
1327
|
const wrapHandler$1 = (definition, handler) => {
|
|
1159
1328
|
const decodeBody = Schema.decodeUnknownEffect(definition.message);
|
|
1160
1329
|
return (batch) => Effect.gen(function* () {
|
|
@@ -1166,7 +1335,7 @@ const implement$7 = (_definition, handler) => handler;
|
|
|
1166
1335
|
//#region src/Queue.ts
|
|
1167
1336
|
var Queue_exports = /* @__PURE__ */ __exportAll({
|
|
1168
1337
|
QueueMessageDecodeError: () => QueueMessageDecodeError,
|
|
1169
|
-
Tag: () => Tag$
|
|
1338
|
+
Tag: () => Tag$12,
|
|
1170
1339
|
decodeBatch: () => decodeBatch,
|
|
1171
1340
|
fromMessage: () => fromMessage,
|
|
1172
1341
|
fromMessageBatch: () => fromMessageBatch,
|
|
@@ -1204,7 +1373,7 @@ const decodeBatch = (batch, decodeBody) => Effect.gen(function* () {
|
|
|
1204
1373
|
}
|
|
1205
1374
|
return fromMessageBatch(batch, messages);
|
|
1206
1375
|
});
|
|
1207
|
-
const Tag$
|
|
1376
|
+
const Tag$12 = Tag$13;
|
|
1208
1377
|
const implement$6 = implement$7;
|
|
1209
1378
|
//#endregion
|
|
1210
1379
|
//#region src/RpcDefinition.ts
|
|
@@ -1222,7 +1391,7 @@ var RpcDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
|
1222
1391
|
decodeSuccess: () => decodeSuccess,
|
|
1223
1392
|
encodeArgs: () => encodeArgs,
|
|
1224
1393
|
encodeSuccess: () => encodeSuccess,
|
|
1225
|
-
make: () => make$
|
|
1394
|
+
make: () => make$11,
|
|
1226
1395
|
method: () => method$4,
|
|
1227
1396
|
reservedMethodNames: () => reservedMethodNames$4
|
|
1228
1397
|
});
|
|
@@ -1232,7 +1401,7 @@ var RpcArgumentDecodeError = class extends Data.TaggedError("RpcArgumentDecodeEr
|
|
|
1232
1401
|
var RpcArgumentEncodeError = class extends Data.TaggedError("RpcArgumentEncodeError") {};
|
|
1233
1402
|
var RpcSuccessDecodeError = class extends Data.TaggedError("RpcSuccessDecodeError") {};
|
|
1234
1403
|
var RpcSuccessEncodeError = class extends Data.TaggedError("RpcSuccessEncodeError") {};
|
|
1235
|
-
const reservedMethodNames$4 = new Set([
|
|
1404
|
+
const reservedMethodNames$4 = /* @__PURE__ */ new Set([
|
|
1236
1405
|
"constructor",
|
|
1237
1406
|
"fetch",
|
|
1238
1407
|
"connect",
|
|
@@ -1325,7 +1494,7 @@ const decodeSuccess = (definition, methodName, value) => {
|
|
|
1325
1494
|
cause
|
|
1326
1495
|
})));
|
|
1327
1496
|
};
|
|
1328
|
-
const make$
|
|
1497
|
+
const make$11 = (id, methods) => {
|
|
1329
1498
|
const definition = {
|
|
1330
1499
|
id,
|
|
1331
1500
|
methods
|
|
@@ -1383,8 +1552,8 @@ var ServiceBinding_exports = /* @__PURE__ */ __exportAll({
|
|
|
1383
1552
|
ServiceBindingFetchError: () => ServiceBindingFetchError,
|
|
1384
1553
|
ServiceBindingRpcError: () => ServiceBindingRpcError,
|
|
1385
1554
|
isServiceBindingClient: () => isServiceBindingClient,
|
|
1386
|
-
layer: () => layer$
|
|
1387
|
-
makeClient: () => makeClient$
|
|
1555
|
+
layer: () => layer$11,
|
|
1556
|
+
makeClient: () => makeClient$8,
|
|
1388
1557
|
makeDirectMethods: () => makeDirectMethods$1
|
|
1389
1558
|
});
|
|
1390
1559
|
const TypeId$1 = "effect-cf/ServiceBinding";
|
|
@@ -1398,7 +1567,7 @@ var ServiceBindingFetchError = class extends Data.TaggedError("ServiceBindingFet
|
|
|
1398
1567
|
*/
|
|
1399
1568
|
var ServiceBindingRpcError = class extends Data.TaggedError("ServiceBindingRpcError") {};
|
|
1400
1569
|
const isServiceBindingClient = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "fetch") === "function";
|
|
1401
|
-
const makeClient$
|
|
1570
|
+
const makeClient$8 = (definition) => {
|
|
1402
1571
|
return (service) => {
|
|
1403
1572
|
const fetch = (input, init) => Effect.tryPromise({
|
|
1404
1573
|
try: () => service.fetch(input, init),
|
|
@@ -1409,11 +1578,12 @@ const makeClient$7 = (definition) => {
|
|
|
1409
1578
|
});
|
|
1410
1579
|
const rpc = (method, ...args) => Effect.gen(function* () {
|
|
1411
1580
|
const methodName = String(method);
|
|
1412
|
-
|
|
1581
|
+
const encodedArgs = definition.definition === void 0 ? args : yield* encodeArgs(definition.definition, methodName, args).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
1413
1582
|
binding: definition.binding,
|
|
1414
1583
|
method: methodName,
|
|
1415
1584
|
cause
|
|
1416
|
-
})))
|
|
1585
|
+
})));
|
|
1586
|
+
return yield* invokeRpcMethod(service, method, encodedArgs, (cause) => new ServiceBindingRpcError({
|
|
1417
1587
|
binding: definition.binding,
|
|
1418
1588
|
method: methodName,
|
|
1419
1589
|
cause
|
|
@@ -1429,14 +1599,18 @@ const makeClient$7 = (definition) => {
|
|
|
1429
1599
|
});
|
|
1430
1600
|
const call = (method, ...args) => Effect.gen(function* () {
|
|
1431
1601
|
const methodName = String(method);
|
|
1432
|
-
|
|
1602
|
+
const value = yield* resolve(yield* rpc(method, ...args)).pipe(Effect.mapError((cause) => new ServiceBindingRpcError({
|
|
1433
1603
|
binding: definition.binding,
|
|
1434
1604
|
method: methodName,
|
|
1435
1605
|
cause
|
|
1436
|
-
})))
|
|
1606
|
+
})));
|
|
1607
|
+
return yield* decodeSuccess$2(methodName, value);
|
|
1437
1608
|
});
|
|
1438
1609
|
const scopedCall = (method, ...args) => Effect.gen(function* () {
|
|
1439
|
-
|
|
1610
|
+
const methodName = String(method);
|
|
1611
|
+
const result = yield* rpc(method, ...args);
|
|
1612
|
+
const value = yield* scoped(result);
|
|
1613
|
+
return yield* decodeSuccess$2(methodName, value);
|
|
1440
1614
|
});
|
|
1441
1615
|
const directMethods = makeDirectMethods$1(definition.definition, call);
|
|
1442
1616
|
return Object.assign(directMethods, {
|
|
@@ -1447,7 +1621,7 @@ const makeClient$7 = (definition) => {
|
|
|
1447
1621
|
});
|
|
1448
1622
|
};
|
|
1449
1623
|
};
|
|
1450
|
-
const layer$
|
|
1624
|
+
const layer$11 = (tag, definition) => layer$20(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$8(definition), { expected: expectedServiceBinding });
|
|
1451
1625
|
/**
|
|
1452
1626
|
* Creates a typed Effect service for a Worker service binding.
|
|
1453
1627
|
*
|
|
@@ -1478,7 +1652,7 @@ const layer$10 = (tag, definition) => layer$18(tag, definition.binding, (value)
|
|
|
1478
1652
|
* ```
|
|
1479
1653
|
*/
|
|
1480
1654
|
const Service = () => (id, definition) => {
|
|
1481
|
-
const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$
|
|
1655
|
+
const tag = Service$2()(id, definition.binding, (value) => isServiceBindingClient(value), makeClient$8(definition));
|
|
1482
1656
|
const fetch = (input, init) => Effect.gen(function* () {
|
|
1483
1657
|
return yield* (yield* tag).fetch(input, init);
|
|
1484
1658
|
});
|
|
@@ -1509,13 +1683,13 @@ const makeDirectMethods$1 = (rpcDefinition, call) => {
|
|
|
1509
1683
|
//#endregion
|
|
1510
1684
|
//#region src/WorkerDefinition.ts
|
|
1511
1685
|
var WorkerDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
1512
|
-
Tag: () => Tag$
|
|
1686
|
+
Tag: () => Tag$11,
|
|
1513
1687
|
Worker: () => Worker,
|
|
1514
1688
|
implement: () => implement$5,
|
|
1515
|
-
make: () => make$
|
|
1689
|
+
make: () => make$10,
|
|
1516
1690
|
method: () => method$3
|
|
1517
1691
|
});
|
|
1518
|
-
const reservedMethodNames$3 = new Set([
|
|
1692
|
+
const reservedMethodNames$3 = /* @__PURE__ */ new Set([
|
|
1519
1693
|
"constructor",
|
|
1520
1694
|
"dup",
|
|
1521
1695
|
"fetch",
|
|
@@ -1550,21 +1724,21 @@ const method$3 = method$4;
|
|
|
1550
1724
|
*/
|
|
1551
1725
|
const makeDefinition$3 = (id, methods) => {
|
|
1552
1726
|
assertNoReservedMethods("Worker", methods, reservedMethodNames$3);
|
|
1553
|
-
const definition = make$
|
|
1554
|
-
return Object.assign(definition, { make: (layer, options) => make$
|
|
1727
|
+
const definition = make$11(id, methods);
|
|
1728
|
+
return Object.assign(definition, { make: (layer, options) => make$9(layer, {
|
|
1555
1729
|
...options,
|
|
1556
1730
|
rpc: wrapHandlers$1(definition, options.rpc)
|
|
1557
1731
|
}) });
|
|
1558
1732
|
};
|
|
1559
|
-
const make$
|
|
1560
|
-
const Tag$
|
|
1733
|
+
const make$10 = (id, methods) => Tag$11()(id, methods);
|
|
1734
|
+
const Tag$11 = () => (id, methods) => {
|
|
1561
1735
|
const definition = makeDefinition$3(id, methods);
|
|
1562
1736
|
const tag = Context.Service()(id);
|
|
1563
1737
|
const bindingDefinition = (binding) => ({
|
|
1564
1738
|
...binding,
|
|
1565
1739
|
definition
|
|
1566
1740
|
});
|
|
1567
|
-
const layer = (binding) => layer$
|
|
1741
|
+
const layer = (binding) => layer$11(tag, bindingDefinition(binding));
|
|
1568
1742
|
const fetch = (input, init) => Effect.gen(function* () {
|
|
1569
1743
|
return yield* (yield* tag).fetch(input, init);
|
|
1570
1744
|
});
|
|
@@ -1589,13 +1763,15 @@ const Tag$10 = () => (id, methods) => {
|
|
|
1589
1763
|
scopedCall
|
|
1590
1764
|
});
|
|
1591
1765
|
};
|
|
1592
|
-
const Worker = Tag$
|
|
1766
|
+
const Worker = Tag$11;
|
|
1593
1767
|
const wrapHandlers$1 = (definition, handlers) => {
|
|
1594
1768
|
const wrapped = {};
|
|
1595
1769
|
for (const key of Object.keys(definition.methods)) {
|
|
1596
1770
|
const handler = handlers[key];
|
|
1597
1771
|
wrapped[key] = (...args) => Effect.gen(function* () {
|
|
1598
|
-
|
|
1772
|
+
const decodedArgs = yield* decodeArgs(definition, key, args);
|
|
1773
|
+
const value = yield* handler(...decodedArgs);
|
|
1774
|
+
return yield* encodeSuccess(definition, key, value);
|
|
1599
1775
|
});
|
|
1600
1776
|
}
|
|
1601
1777
|
return wrapped;
|
|
@@ -1613,6 +1789,8 @@ const clock = {
|
|
|
1613
1789
|
currentTimeMillis: Effect.sync(() => clock.currentTimeMillisUnsafe()),
|
|
1614
1790
|
currentTimeNanosUnsafe: () => BigInt(Date.now()) * nanosPerMilli,
|
|
1615
1791
|
currentTimeNanos: Effect.sync(() => clock.currentTimeNanosUnsafe()),
|
|
1792
|
+
monotonicTimeNanosUnsafe: () => typeof performance === "undefined" ? BigInt(Date.now()) * nanosPerMilli : BigInt(Math.round(performance.now() * 1e6)),
|
|
1793
|
+
monotonicTimeNanos: Effect.sync(() => clock.monotonicTimeNanosUnsafe()),
|
|
1616
1794
|
sleep: (duration) => {
|
|
1617
1795
|
const millis = Duration.toMillis(duration);
|
|
1618
1796
|
if (millis <= 0) return Effect.yieldNow;
|
|
@@ -1623,7 +1801,7 @@ const clock = {
|
|
|
1623
1801
|
});
|
|
1624
1802
|
}
|
|
1625
1803
|
};
|
|
1626
|
-
const layer$
|
|
1804
|
+
const layer$10 = Layer.effect(Clock.Clock, Effect.succeed(clock));
|
|
1627
1805
|
//#endregion
|
|
1628
1806
|
//#region src/internal/Entrypoint.ts
|
|
1629
1807
|
const provideEntrypointServices = (layer, services) => layer.pipe(Layer.provideMerge(services));
|
|
@@ -1665,11 +1843,11 @@ const fromExecutionContext = (ctx, runPromiseExit) => {
|
|
|
1665
1843
|
var Worker_exports = /* @__PURE__ */ __exportAll({
|
|
1666
1844
|
ExecutionContext: () => ExecutionContext,
|
|
1667
1845
|
NativeRequest: () => NativeRequest,
|
|
1668
|
-
Tag: () => Tag$
|
|
1846
|
+
Tag: () => Tag$10,
|
|
1669
1847
|
WorkerContext: () => WorkerContext,
|
|
1670
1848
|
implement: () => implement$4,
|
|
1671
1849
|
isWebSocketUpgrade: () => isWebSocketUpgrade,
|
|
1672
|
-
make: () => make$
|
|
1850
|
+
make: () => make$9,
|
|
1673
1851
|
makeFetchHandler: () => makeFetchHandler,
|
|
1674
1852
|
method: () => method$2,
|
|
1675
1853
|
renderHttpResponse: () => renderHttpResponse
|
|
@@ -1678,7 +1856,7 @@ var ExecutionContext = class extends Context.Service()("effect-cf/ExecutionConte
|
|
|
1678
1856
|
var WorkerContext = class extends Context.Service()("effect-cf/WorkerContext") {};
|
|
1679
1857
|
var NativeRequest = class extends Context.Service()("effect-cf/NativeRequest") {};
|
|
1680
1858
|
const isWebSocketUpgrade = (request) => request.headers.get("Upgrade")?.toLowerCase() === "websocket";
|
|
1681
|
-
const reservedMethodNames$2 = new Set([
|
|
1859
|
+
const reservedMethodNames$2 = /* @__PURE__ */ new Set([
|
|
1682
1860
|
"constructor",
|
|
1683
1861
|
"dup",
|
|
1684
1862
|
"fetch",
|
|
@@ -1698,14 +1876,15 @@ const RunSymbol$1 = Symbol.for("effect-cf/Worker/run");
|
|
|
1698
1876
|
const renderHttpResponse = (effect) => Effect.flatMap(effect, (response) => Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
|
|
1699
1877
|
const renderFetchSuccess = (effect) => Effect.flatMap(effect, (response) => response instanceof Response ? Effect.succeed(response) : Effect.map(Effect.context(), (context) => HttpServerResponse.toWeb(response, { context })));
|
|
1700
1878
|
const isWorkerOptions = (options) => typeof options === "object" && options !== null && ("eventLayer" in options || "fetch" in options || "queue" in options || "rpc" in options);
|
|
1701
|
-
function make$
|
|
1879
|
+
function make$9(layer, optionsOrFetch) {
|
|
1702
1880
|
const options = isWorkerOptions(optionsOrFetch) ? optionsOrFetch : { fetch: optionsOrFetch };
|
|
1703
1881
|
class EffectWorker extends WorkerEntrypoint {
|
|
1704
1882
|
runtime;
|
|
1705
1883
|
constructor(ctx, env) {
|
|
1706
1884
|
super(ctx, env);
|
|
1707
1885
|
let runWaitUntilEffect = () => Promise.reject(/* @__PURE__ */ new Error("WorkerContext runtime is not initialized"));
|
|
1708
|
-
const
|
|
1886
|
+
const services = Layer.mergeAll(layer$10, Layer.succeed(ExecutionContext, ctx), ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env))), Layer.succeed(WorkerContext, fromExecutionContext(ctx, (effect) => runWaitUntilEffect(effect))), Layer.succeed(WorkerEnvironment, env));
|
|
1887
|
+
const runtimeLayer = provideEntrypointServices(layer, services);
|
|
1709
1888
|
this.runtime = ManagedRuntime.make(runtimeLayer);
|
|
1710
1889
|
runWaitUntilEffect = (effect) => this.runtime.runPromiseExit(effect);
|
|
1711
1890
|
}
|
|
@@ -1730,10 +1909,10 @@ function make$8(layer, optionsOrFetch) {
|
|
|
1730
1909
|
return assumeEntrypointClass(EffectWorker);
|
|
1731
1910
|
}
|
|
1732
1911
|
const makeFetchHandler = (layer, options) => {
|
|
1733
|
-
const WorkerClass = make$
|
|
1912
|
+
const WorkerClass = make$9(layer, options);
|
|
1734
1913
|
return { fetch: (request, env, ctx) => Promise.resolve(new WorkerClass(ctx, env).fetch(request)) };
|
|
1735
1914
|
};
|
|
1736
|
-
const Tag$
|
|
1915
|
+
const Tag$10 = Tag$11;
|
|
1737
1916
|
const method$2 = method$3;
|
|
1738
1917
|
const implement$4 = implement$5;
|
|
1739
1918
|
//#endregion
|
|
@@ -1742,8 +1921,8 @@ var DurableObjectNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
|
1742
1921
|
DurableObjectFetchError: () => DurableObjectFetchError,
|
|
1743
1922
|
DurableObjectRpcError: () => DurableObjectRpcError,
|
|
1744
1923
|
isDurableObjectNamespaceClient: () => isDurableObjectNamespaceClient,
|
|
1745
|
-
layer: () => layer$
|
|
1746
|
-
makeClient: () => makeClient$
|
|
1924
|
+
layer: () => layer$9,
|
|
1925
|
+
makeClient: () => makeClient$7,
|
|
1747
1926
|
makeDirectMethods: () => makeDirectMethods
|
|
1748
1927
|
});
|
|
1749
1928
|
const expectedDurableObjectNamespace = "Durable Object namespace binding with getByName(), get(), idFromName(), idFromString(), newUniqueId(), and jurisdiction()";
|
|
@@ -1757,7 +1936,7 @@ var DurableObjectRpcError = class extends Data.TaggedError("DurableObjectRpcErro
|
|
|
1757
1936
|
var DurableObjectFetchError = class extends Data.TaggedError("DurableObjectFetchError") {};
|
|
1758
1937
|
const hasFunction$2 = (value, key) => typeof Reflect.get(value, key) === "function";
|
|
1759
1938
|
const isDurableObjectNamespaceClient = (value) => typeof value === "object" && value !== null && hasFunction$2(value, "getByName") && hasFunction$2(value, "get") && hasFunction$2(value, "idFromName") && hasFunction$2(value, "idFromString") && hasFunction$2(value, "newUniqueId") && hasFunction$2(value, "jurisdiction");
|
|
1760
|
-
const makeClient$
|
|
1939
|
+
const makeClient$7 = (definition) => {
|
|
1761
1940
|
return (namespace) => {
|
|
1762
1941
|
const newUniqueId = (options) => Effect.sync(() => namespace.newUniqueId(options));
|
|
1763
1942
|
const idFromName = (name) => Effect.sync(() => namespace.idFromName(name));
|
|
@@ -1774,11 +1953,12 @@ const makeClient$6 = (definition) => {
|
|
|
1774
1953
|
});
|
|
1775
1954
|
const rpc = (stub, method, ...args) => Effect.gen(function* () {
|
|
1776
1955
|
const methodName = String(method);
|
|
1777
|
-
|
|
1956
|
+
const encodedArgs = definition.definition === void 0 ? args : yield* encodeArgs(definition.definition, methodName, args).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1778
1957
|
binding: definition.binding,
|
|
1779
1958
|
method: methodName,
|
|
1780
1959
|
cause
|
|
1781
|
-
})))
|
|
1960
|
+
})));
|
|
1961
|
+
return yield* invokeRpcMethod(stub, method, encodedArgs, (cause) => new DurableObjectRpcError({
|
|
1782
1962
|
binding: definition.binding,
|
|
1783
1963
|
method: methodName,
|
|
1784
1964
|
cause
|
|
@@ -1794,14 +1974,18 @@ const makeClient$6 = (definition) => {
|
|
|
1794
1974
|
});
|
|
1795
1975
|
const call = (stub, method, ...args) => Effect.gen(function* () {
|
|
1796
1976
|
const methodName = String(method);
|
|
1797
|
-
|
|
1977
|
+
const value = yield* resolve(yield* rpc(stub, method, ...args)).pipe(Effect.mapError((cause) => new DurableObjectRpcError({
|
|
1798
1978
|
binding: definition.binding,
|
|
1799
1979
|
method: methodName,
|
|
1800
1980
|
cause
|
|
1801
|
-
})))
|
|
1981
|
+
})));
|
|
1982
|
+
return yield* decodeSuccess$1(methodName, value);
|
|
1802
1983
|
});
|
|
1803
1984
|
const scopedCall = (stub, method, ...args) => Effect.gen(function* () {
|
|
1804
|
-
|
|
1985
|
+
const methodName = String(method);
|
|
1986
|
+
const result = yield* rpc(stub, method, ...args);
|
|
1987
|
+
const value = yield* scoped(result);
|
|
1988
|
+
return yield* decodeSuccess$1(methodName, value);
|
|
1805
1989
|
});
|
|
1806
1990
|
const directMethods = makeDirectMethods(definition.definition, {
|
|
1807
1991
|
call,
|
|
@@ -1824,7 +2008,7 @@ const makeClient$6 = (definition) => {
|
|
|
1824
2008
|
});
|
|
1825
2009
|
};
|
|
1826
2010
|
};
|
|
1827
|
-
const layer$
|
|
2011
|
+
const layer$9 = (tag, definition) => layer$20(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$7(definition), { expected: expectedDurableObjectNamespace });
|
|
1828
2012
|
const makeDirectMethods = (rpcDefinition, helpers) => {
|
|
1829
2013
|
const methods = {};
|
|
1830
2014
|
if (rpcDefinition !== void 0) {
|
|
@@ -1849,12 +2033,12 @@ const makeDirectMethods = (rpcDefinition, helpers) => {
|
|
|
1849
2033
|
//#region src/DurableObjectDefinition.ts
|
|
1850
2034
|
var DurableObjectDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
1851
2035
|
DurableObject: () => DurableObject$1,
|
|
1852
|
-
Tag: () => Tag$
|
|
2036
|
+
Tag: () => Tag$9,
|
|
1853
2037
|
implement: () => implement$3,
|
|
1854
|
-
make: () => make$
|
|
2038
|
+
make: () => make$8,
|
|
1855
2039
|
method: () => method$1
|
|
1856
2040
|
});
|
|
1857
|
-
const reservedMethodNames$1 = new Set([
|
|
2041
|
+
const reservedMethodNames$1 = /* @__PURE__ */ new Set([
|
|
1858
2042
|
"constructor",
|
|
1859
2043
|
"dup",
|
|
1860
2044
|
"fetch",
|
|
@@ -1882,21 +2066,21 @@ const method$1 = method$4;
|
|
|
1882
2066
|
*/
|
|
1883
2067
|
const makeDefinition$2 = (id, methods) => {
|
|
1884
2068
|
assertNoReservedMethods("Durable Object", methods, reservedMethodNames$1);
|
|
1885
|
-
const definition = make$
|
|
1886
|
-
return Object.assign(definition, { make: (layer, options) => make$
|
|
2069
|
+
const definition = make$11(id, methods);
|
|
2070
|
+
return Object.assign(definition, { make: (layer, options) => make$7(layer, {
|
|
1887
2071
|
...options,
|
|
1888
2072
|
rpc: wrapHandlers(definition, options.rpc)
|
|
1889
2073
|
}) });
|
|
1890
2074
|
};
|
|
1891
|
-
const make$
|
|
1892
|
-
const Tag$
|
|
2075
|
+
const make$8 = (id, methods) => Tag$9()(id, methods);
|
|
2076
|
+
const Tag$9 = () => (id, methods) => {
|
|
1893
2077
|
const definition = makeDefinition$2(id, methods);
|
|
1894
2078
|
const tag = Context.Service()(id);
|
|
1895
2079
|
const bindingDefinition = (binding) => ({
|
|
1896
2080
|
...binding,
|
|
1897
2081
|
definition
|
|
1898
2082
|
});
|
|
1899
|
-
const layer = (binding) => layer$
|
|
2083
|
+
const layer = (binding) => layer$9(tag, bindingDefinition(binding));
|
|
1900
2084
|
const newUniqueId = Effect.fnUntraced(function* (options) {
|
|
1901
2085
|
return yield* (yield* tag).newUniqueId(options);
|
|
1902
2086
|
});
|
|
@@ -1954,13 +2138,15 @@ const Tag$8 = () => (id, methods) => {
|
|
|
1954
2138
|
unsafeRaw
|
|
1955
2139
|
});
|
|
1956
2140
|
};
|
|
1957
|
-
const DurableObject$1 = Tag$
|
|
2141
|
+
const DurableObject$1 = Tag$9;
|
|
1958
2142
|
const wrapHandlers = (definition, handlers) => {
|
|
1959
2143
|
const wrapped = {};
|
|
1960
2144
|
for (const key of Object.keys(definition.methods)) {
|
|
1961
2145
|
const handler = handlers[key];
|
|
1962
2146
|
wrapped[key] = (...args) => Effect.gen(function* () {
|
|
1963
|
-
|
|
2147
|
+
const decodedArgs = yield* decodeArgs(definition, key, args);
|
|
2148
|
+
const value = yield* handler(...decodedArgs);
|
|
2149
|
+
return yield* encodeSuccess(definition, key, value);
|
|
1964
2150
|
});
|
|
1965
2151
|
}
|
|
1966
2152
|
return wrapped;
|
|
@@ -1972,12 +2158,12 @@ const implement$3 = (_definition, handlers) => handlers;
|
|
|
1972
2158
|
//#endregion
|
|
1973
2159
|
//#region src/DurableObject.ts
|
|
1974
2160
|
var DurableObject_exports = /* @__PURE__ */ __exportAll({
|
|
1975
|
-
Tag: () => Tag$
|
|
2161
|
+
Tag: () => Tag$8,
|
|
1976
2162
|
implement: () => implement$2,
|
|
1977
|
-
make: () => make$
|
|
2163
|
+
make: () => make$7,
|
|
1978
2164
|
method: () => method
|
|
1979
2165
|
});
|
|
1980
|
-
const reservedMethodNames = new Set([
|
|
2166
|
+
const reservedMethodNames = /* @__PURE__ */ new Set([
|
|
1981
2167
|
"constructor",
|
|
1982
2168
|
"dup",
|
|
1983
2169
|
"fetch",
|
|
@@ -1990,12 +2176,13 @@ const RunSymbol = Symbol.for("effect-cf/DurableObject/run");
|
|
|
1990
2176
|
/**
|
|
1991
2177
|
* Creates a Durable Object class backed by a single managed Effect runtime.
|
|
1992
2178
|
*/
|
|
1993
|
-
const make$
|
|
2179
|
+
const make$7 = (layer, options = {}) => {
|
|
1994
2180
|
class EffectDurableObject extends DurableObject {
|
|
1995
2181
|
runtime;
|
|
1996
2182
|
constructor(state, env) {
|
|
1997
2183
|
super(state, env);
|
|
1998
|
-
const
|
|
2184
|
+
const services = Layer.mergeAll(layer$10, ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env))), Layer.succeed(DurableObjectState, fromDurableObjectState(state)), Layer.succeed(WorkerEnvironment, env));
|
|
2185
|
+
const runtimeLayer = provideEntrypointServices(layer, services);
|
|
1999
2186
|
this.runtime = ManagedRuntime.make(runtimeLayer);
|
|
2000
2187
|
const initialize = options.initialize;
|
|
2001
2188
|
if (initialize !== void 0) state.waitUntil(this[RunSymbol](initialize, { eventLayer: false }));
|
|
@@ -2032,7 +2219,7 @@ const make$6 = (layer, options = {}) => {
|
|
|
2032
2219
|
defineEntrypointRpcMethods("Durable Object", EffectDurableObject.prototype, options.rpc, reservedMethodNames, (self, effect) => self[RunSymbol](effect));
|
|
2033
2220
|
return assumeEntrypointClass(EffectDurableObject);
|
|
2034
2221
|
};
|
|
2035
|
-
const Tag$
|
|
2222
|
+
const Tag$8 = Tag$9;
|
|
2036
2223
|
const method = method$1;
|
|
2037
2224
|
const implement$2 = implement$3;
|
|
2038
2225
|
//#endregion
|
|
@@ -2319,7 +2506,8 @@ var DurableObjectAlarm = class DurableObjectAlarm extends Context.Service()("eff
|
|
|
2319
2506
|
const actionMode = failureAction === void 0 ? mode : getFailureActionMode(failureAction);
|
|
2320
2507
|
if (actionMode === "retry" || actionMode === "isolated") {
|
|
2321
2508
|
const actionRetryDelay = failureAction === void 0 ? void 0 : getFailureActionRetryDelay(failureAction);
|
|
2322
|
-
|
|
2509
|
+
const retryDelay = actionRetryDelay === void 0 ? yield* getFailureRetryDelay(options) : yield* toFailureRescheduleMillis(actionRetryDelay);
|
|
2510
|
+
yield* rescheduleFailedAlarm(row, retryDelay);
|
|
2323
2511
|
return "continue";
|
|
2324
2512
|
}
|
|
2325
2513
|
if (actionMode === "skip-and-advance-repeat") {
|
|
@@ -2361,7 +2549,7 @@ var DurableObjectAlarm = class DurableObjectAlarm extends Context.Service()("eff
|
|
|
2361
2549
|
//#region src/DurableObjectRpcWebSocket.ts
|
|
2362
2550
|
var DurableObjectRpcWebSocket_exports = /* @__PURE__ */ __exportAll({
|
|
2363
2551
|
DurableObjectRpcWebSocket: () => DurableObjectRpcWebSocket,
|
|
2364
|
-
layer: () => layer$
|
|
2552
|
+
layer: () => layer$8
|
|
2365
2553
|
});
|
|
2366
2554
|
const defaultAttachmentKey = "effectCloudflareRpcClientId";
|
|
2367
2555
|
const defaultTag = "effect-cf-rpc";
|
|
@@ -2372,7 +2560,7 @@ var DurableObjectRpcWebSocket = class extends Context.Service()("effect-cf/Durab
|
|
|
2372
2560
|
/**
|
|
2373
2561
|
* Builds a layer that bridges Durable Object websocket events to `RpcServer.Protocol`.
|
|
2374
2562
|
*/
|
|
2375
|
-
const layer$
|
|
2563
|
+
const layer$8 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
2376
2564
|
const tag = options.tag ?? defaultTag;
|
|
2377
2565
|
const attachmentKey = options.attachmentKey ?? defaultAttachmentKey;
|
|
2378
2566
|
const durableObjectState = yield* DurableObjectState;
|
|
@@ -2460,7 +2648,8 @@ const layer$7 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
|
2460
2648
|
}
|
|
2461
2649
|
for (const current of decoded) yield* run(connection.id, current);
|
|
2462
2650
|
}).pipe(Effect.catch((error) => {
|
|
2463
|
-
|
|
2651
|
+
const connection = register(socket);
|
|
2652
|
+
return send(connection, error);
|
|
2464
2653
|
})),
|
|
2465
2654
|
close: unregister,
|
|
2466
2655
|
error: (socket, error) => Effect.gen(function* () {
|
|
@@ -2485,7 +2674,7 @@ const writeAttachment = (socket, key, clientId) => {
|
|
|
2485
2674
|
};
|
|
2486
2675
|
//#endregion
|
|
2487
2676
|
//#region src/DurableObjectSqlite.ts
|
|
2488
|
-
var DurableObjectSqlite_exports = /* @__PURE__ */ __exportAll({ layer: () => layer$
|
|
2677
|
+
var DurableObjectSqlite_exports = /* @__PURE__ */ __exportAll({ layer: () => layer$7 });
|
|
2489
2678
|
/**
|
|
2490
2679
|
* Provides `effect/unstable/sql` from the current Durable Object SQLite storage.
|
|
2491
2680
|
*
|
|
@@ -2497,7 +2686,7 @@ var DurableObjectSqlite_exports = /* @__PURE__ */ __exportAll({ layer: () => lay
|
|
|
2497
2686
|
* );
|
|
2498
2687
|
* ```
|
|
2499
2688
|
*/
|
|
2500
|
-
const layer$
|
|
2689
|
+
const layer$7 = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
2501
2690
|
const state = yield* DurableObjectState;
|
|
2502
2691
|
return SqliteClient.layer({
|
|
2503
2692
|
...options,
|
|
@@ -2508,38 +2697,269 @@ const layer$6 = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
|
2508
2697
|
//#region src/Email.ts
|
|
2509
2698
|
var Email_exports = /* @__PURE__ */ __exportAll({
|
|
2510
2699
|
EmailOperationError: () => EmailOperationError,
|
|
2511
|
-
|
|
2700
|
+
EmailValidationError: () => EmailValidationError,
|
|
2701
|
+
Tag: () => Tag$7,
|
|
2702
|
+
emailErrorCodes: () => emailErrorCodes,
|
|
2512
2703
|
isEmailBinding: () => isEmailBinding,
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2704
|
+
isEmailMessageBuilder: () => isEmailMessageBuilder,
|
|
2705
|
+
layer: () => layer$6,
|
|
2706
|
+
make: () => make$6,
|
|
2707
|
+
makeClient: () => makeClient$6,
|
|
2708
|
+
sendLimits: () => sendLimits,
|
|
2709
|
+
validateMessage: () => validateMessage
|
|
2516
2710
|
});
|
|
2517
2711
|
const expectedSendEmailBinding = "Send Email binding with send()";
|
|
2712
|
+
const textEncoder = new TextEncoder();
|
|
2713
|
+
/** Documented Cloudflare Email Sending limits. */
|
|
2714
|
+
const sendLimits = {
|
|
2715
|
+
/** Combined `to`, `cc`, and `bcc` addresses per message. */
|
|
2716
|
+
maxRecipients: 50,
|
|
2717
|
+
maxAttachments: 32,
|
|
2718
|
+
/** Total message size, including attachments. Not enforced client side. */
|
|
2719
|
+
maxMessageBytes: 5 * 1024 * 1024,
|
|
2720
|
+
maxHeaderNameBytes: 100,
|
|
2721
|
+
maxHeaderValueBytes: 2048,
|
|
2722
|
+
maxHeadersBytes: 16 * 1024,
|
|
2723
|
+
/** Allowlisted custom headers, excluding `X-` prefixed headers. */
|
|
2724
|
+
maxAllowlistHeaders: 20
|
|
2725
|
+
};
|
|
2726
|
+
/** Error codes reported by Cloudflare Email Sending. */
|
|
2727
|
+
const emailErrorCodes = [
|
|
2728
|
+
"E_VALIDATION_ERROR",
|
|
2729
|
+
"E_FIELD_MISSING",
|
|
2730
|
+
"E_TOO_MANY_RECIPIENTS",
|
|
2731
|
+
"E_TOO_MANY_ATTACHMENTS",
|
|
2732
|
+
"E_SENDER_NOT_VERIFIED",
|
|
2733
|
+
"E_RECIPIENT_NOT_ALLOWED",
|
|
2734
|
+
"E_RECIPIENT_SUPPRESSED",
|
|
2735
|
+
"E_SENDER_DOMAIN_NOT_AVAILABLE",
|
|
2736
|
+
"E_CONTENT_TOO_LARGE",
|
|
2737
|
+
"E_DELIVERY_FAILED",
|
|
2738
|
+
"E_RATE_LIMIT_EXCEEDED",
|
|
2739
|
+
"E_DAILY_LIMIT_EXCEEDED",
|
|
2740
|
+
"E_INTERNAL_SERVER_ERROR",
|
|
2741
|
+
"E_HEADER_NOT_ALLOWED",
|
|
2742
|
+
"E_HEADER_USE_API_FIELD",
|
|
2743
|
+
"E_HEADER_VALUE_INVALID",
|
|
2744
|
+
"E_HEADER_VALUE_TOO_LONG",
|
|
2745
|
+
"E_HEADER_NAME_INVALID",
|
|
2746
|
+
"E_HEADERS_TOO_LARGE",
|
|
2747
|
+
"E_HEADERS_TOO_MANY"
|
|
2748
|
+
];
|
|
2518
2749
|
/** Error raised when a Cloudflare Send Email operation fails. */
|
|
2519
2750
|
var EmailOperationError = class extends Data.TaggedError("EmailOperationError") {};
|
|
2751
|
+
/** Error raised when a message violates documented Cloudflare Email Sending limits. */
|
|
2752
|
+
var EmailValidationError = class extends Data.TaggedError("EmailValidationError") {};
|
|
2753
|
+
const emailErrorCode = (cause) => {
|
|
2754
|
+
if (typeof cause !== "object" || cause === null) return;
|
|
2755
|
+
const code = Reflect.get(cause, "code");
|
|
2756
|
+
return typeof code === "string" ? code : void 0;
|
|
2757
|
+
};
|
|
2520
2758
|
const emailError = (binding, operation, cause) => new EmailOperationError({
|
|
2521
2759
|
binding,
|
|
2522
2760
|
operation,
|
|
2523
|
-
cause
|
|
2761
|
+
cause,
|
|
2762
|
+
code: emailErrorCode(cause)
|
|
2763
|
+
});
|
|
2764
|
+
const emailValidationError = (binding, operation, violations) => new EmailValidationError({
|
|
2765
|
+
binding,
|
|
2766
|
+
operation,
|
|
2767
|
+
violations
|
|
2524
2768
|
});
|
|
2525
2769
|
const tryEmailPromise = (binding, operation, evaluate) => Effect.tryPromise({
|
|
2526
2770
|
try: evaluate,
|
|
2527
2771
|
catch: (cause) => emailError(binding, operation, cause)
|
|
2528
2772
|
});
|
|
2773
|
+
const builderFields = [
|
|
2774
|
+
"subject",
|
|
2775
|
+
"html",
|
|
2776
|
+
"text",
|
|
2777
|
+
"cc",
|
|
2778
|
+
"bcc",
|
|
2779
|
+
"replyTo",
|
|
2780
|
+
"attachments",
|
|
2781
|
+
"headers"
|
|
2782
|
+
];
|
|
2783
|
+
/**
|
|
2784
|
+
* Distinguishes structured Email Sending messages from raw MIME `EmailMessage`
|
|
2785
|
+
* values, which only carry envelope `from` and `to` addresses.
|
|
2786
|
+
*/
|
|
2787
|
+
const isEmailMessageBuilder = (message) => {
|
|
2788
|
+
if (typeof message !== "object" || message === null) return false;
|
|
2789
|
+
return builderFields.some((field) => Reflect.get(message, field) !== void 0);
|
|
2790
|
+
};
|
|
2791
|
+
const byteLength = (value) => textEncoder.encode(value).byteLength;
|
|
2792
|
+
const limitViolation = (path, label, actual, limit) => ({
|
|
2793
|
+
path,
|
|
2794
|
+
message: `${label} exceeds Cloudflare Email Sending limit`,
|
|
2795
|
+
actual,
|
|
2796
|
+
limit
|
|
2797
|
+
});
|
|
2798
|
+
const addressList = (value) => {
|
|
2799
|
+
if (value === void 0) return [];
|
|
2800
|
+
return Array.isArray(value) ? value : [value];
|
|
2801
|
+
};
|
|
2802
|
+
const addressViolations = (path, value) => {
|
|
2803
|
+
if (typeof value === "string") return value.includes("@") ? [] : [{
|
|
2804
|
+
path,
|
|
2805
|
+
message: "Email address must contain an @ symbol"
|
|
2806
|
+
}];
|
|
2807
|
+
if (typeof value !== "object" || value === null) return [{
|
|
2808
|
+
path,
|
|
2809
|
+
message: "Email address must be a string or { name, email } object"
|
|
2810
|
+
}];
|
|
2811
|
+
const email = Reflect.get(value, "email");
|
|
2812
|
+
if (typeof email !== "string" || !email.includes("@")) return [{
|
|
2813
|
+
path: `${path}.email`,
|
|
2814
|
+
message: "Email address must contain an @ symbol"
|
|
2815
|
+
}];
|
|
2816
|
+
return [];
|
|
2817
|
+
};
|
|
2818
|
+
const recipientViolations = (field, value) => addressList(value).flatMap((address, index) => addressViolations(`${field}[${index}]`, address));
|
|
2819
|
+
const attachmentViolations = (attachments) => {
|
|
2820
|
+
const violations = [];
|
|
2821
|
+
if (attachments.length > sendLimits.maxAttachments) violations.push(limitViolation("attachments", "attachments", attachments.length, sendLimits.maxAttachments));
|
|
2822
|
+
for (let index = 0; index < attachments.length; index++) {
|
|
2823
|
+
const attachment = attachments[index];
|
|
2824
|
+
const path = `attachments[${index}]`;
|
|
2825
|
+
if (typeof attachment !== "object" || attachment === null) {
|
|
2826
|
+
violations.push({
|
|
2827
|
+
path,
|
|
2828
|
+
message: "Attachment must be an object"
|
|
2829
|
+
});
|
|
2830
|
+
continue;
|
|
2831
|
+
}
|
|
2832
|
+
if (typeof attachment.filename !== "string" || attachment.filename === "") violations.push({
|
|
2833
|
+
path: `${path}.filename`,
|
|
2834
|
+
message: "Attachment filename is required"
|
|
2835
|
+
});
|
|
2836
|
+
if (typeof attachment.type !== "string" || attachment.type === "") violations.push({
|
|
2837
|
+
path: `${path}.type`,
|
|
2838
|
+
message: "Attachment MIME type is required"
|
|
2839
|
+
});
|
|
2840
|
+
if (attachment.content === void 0 || attachment.content === null) violations.push({
|
|
2841
|
+
path: `${path}.content`,
|
|
2842
|
+
message: "Attachment content is required"
|
|
2843
|
+
});
|
|
2844
|
+
if (attachment.disposition === "inline" && typeof attachment.contentId !== "string") violations.push({
|
|
2845
|
+
path: `${path}.contentId`,
|
|
2846
|
+
message: "Inline attachments require a contentId"
|
|
2847
|
+
});
|
|
2848
|
+
}
|
|
2849
|
+
return violations;
|
|
2850
|
+
};
|
|
2851
|
+
const headerViolations = (headers) => {
|
|
2852
|
+
const violations = [];
|
|
2853
|
+
const entries = Object.entries(headers);
|
|
2854
|
+
let totalBytes = 0;
|
|
2855
|
+
let allowlistHeaders = 0;
|
|
2856
|
+
for (const [name, value] of entries) {
|
|
2857
|
+
const path = `headers["${name}"]`;
|
|
2858
|
+
const nameBytes = byteLength(name);
|
|
2859
|
+
if (nameBytes > sendLimits.maxHeaderNameBytes) violations.push(limitViolation(path, "header name bytes", nameBytes, sendLimits.maxHeaderNameBytes));
|
|
2860
|
+
if (typeof value !== "string") {
|
|
2861
|
+
violations.push({
|
|
2862
|
+
path,
|
|
2863
|
+
message: "Header value must be a string"
|
|
2864
|
+
});
|
|
2865
|
+
continue;
|
|
2866
|
+
}
|
|
2867
|
+
const valueBytes = byteLength(value);
|
|
2868
|
+
if (valueBytes > sendLimits.maxHeaderValueBytes) violations.push(limitViolation(path, "header value bytes", valueBytes, sendLimits.maxHeaderValueBytes));
|
|
2869
|
+
totalBytes += nameBytes + valueBytes;
|
|
2870
|
+
if (!name.toLowerCase().startsWith("x-")) allowlistHeaders += 1;
|
|
2871
|
+
}
|
|
2872
|
+
if (totalBytes > sendLimits.maxHeadersBytes) violations.push(limitViolation("headers", "header bytes", totalBytes, sendLimits.maxHeadersBytes));
|
|
2873
|
+
if (allowlistHeaders > sendLimits.maxAllowlistHeaders) violations.push(limitViolation("headers", "allowlisted custom headers", allowlistHeaders, sendLimits.maxAllowlistHeaders));
|
|
2874
|
+
return violations;
|
|
2875
|
+
};
|
|
2876
|
+
/**
|
|
2877
|
+
* Validates a structured message against documented Cloudflare Email Sending
|
|
2878
|
+
* limits and returns every violation found. Total message size is not checked
|
|
2879
|
+
* because the encoded MIME size is only known once Cloudflare composes it.
|
|
2880
|
+
*/
|
|
2881
|
+
const validateMessage = (message) => {
|
|
2882
|
+
const violations = [];
|
|
2883
|
+
const fields = message;
|
|
2884
|
+
if (fields.from === void 0) violations.push({
|
|
2885
|
+
path: "from",
|
|
2886
|
+
message: "A from address is required"
|
|
2887
|
+
});
|
|
2888
|
+
else violations.push(...addressViolations("from", fields.from));
|
|
2889
|
+
if (fields.replyTo !== void 0) violations.push(...addressViolations("replyTo", fields.replyTo));
|
|
2890
|
+
if (typeof fields.subject !== "string" || fields.subject === "") violations.push({
|
|
2891
|
+
path: "subject",
|
|
2892
|
+
message: "A subject is required"
|
|
2893
|
+
});
|
|
2894
|
+
if (typeof fields.text !== "string" && typeof fields.html !== "string") violations.push({
|
|
2895
|
+
path: "$",
|
|
2896
|
+
message: "A message requires either text or html content"
|
|
2897
|
+
});
|
|
2898
|
+
const recipients = addressList(fields.to).length + addressList(fields.cc).length + addressList(fields.bcc).length;
|
|
2899
|
+
if (recipients === 0) violations.push({
|
|
2900
|
+
path: "$",
|
|
2901
|
+
message: "A message requires at least one to, cc, or bcc address"
|
|
2902
|
+
});
|
|
2903
|
+
if (recipients > sendLimits.maxRecipients) violations.push(limitViolation("$", "combined to, cc, and bcc addresses", recipients, sendLimits.maxRecipients));
|
|
2904
|
+
violations.push(...recipientViolations("to", fields.to));
|
|
2905
|
+
violations.push(...recipientViolations("cc", fields.cc));
|
|
2906
|
+
violations.push(...recipientViolations("bcc", fields.bcc));
|
|
2907
|
+
if (fields.attachments !== void 0) violations.push(...attachmentViolations(fields.attachments));
|
|
2908
|
+
if (fields.headers !== void 0) violations.push(...headerViolations(fields.headers));
|
|
2909
|
+
return violations;
|
|
2910
|
+
};
|
|
2911
|
+
const validateSendInput = (binding, operation, message) => {
|
|
2912
|
+
const violations = validateMessage(message);
|
|
2913
|
+
return violations.length > 0 ? Effect.fail(emailValidationError(binding, operation, violations)) : Effect.succeed(message);
|
|
2914
|
+
};
|
|
2529
2915
|
const isEmailBinding = (value) => {
|
|
2530
2916
|
if (typeof value !== "object" || value === null) return false;
|
|
2531
2917
|
return typeof value.send === "function";
|
|
2532
2918
|
};
|
|
2533
|
-
const makeClient$
|
|
2919
|
+
const makeClient$6 = (definition, options) => (email) => {
|
|
2534
2920
|
const runtime = email;
|
|
2535
|
-
const
|
|
2921
|
+
const validate = options?.validate ?? true;
|
|
2922
|
+
const send = ((message) => {
|
|
2923
|
+
const dispatch = () => tryEmailPromise(definition.binding, "send", () => runtime.send(message));
|
|
2924
|
+
if (!validate || !isEmailMessageBuilder(message)) return dispatch();
|
|
2925
|
+
return validateSendInput(definition.binding, "send", message).pipe(Effect.flatMap(dispatch));
|
|
2926
|
+
});
|
|
2536
2927
|
return {
|
|
2537
2928
|
definition,
|
|
2538
2929
|
send,
|
|
2539
2930
|
unsafeRaw: Effect.succeed(email)
|
|
2540
2931
|
};
|
|
2541
2932
|
};
|
|
2542
|
-
const layer$
|
|
2933
|
+
const layer$6 = (tag, definition) => layer$20(tag, definition.binding, isEmailBinding, makeClient$6(definition, definition.send), { expected: expectedSendEmailBinding });
|
|
2934
|
+
const make$6 = (id) => Tag$7()(id);
|
|
2935
|
+
const Tag$7 = () => (id) => {
|
|
2936
|
+
const tag = Context.Service()(id);
|
|
2937
|
+
const makeLayer = (definition) => layer$6(tag, definition);
|
|
2938
|
+
return Object.assign(tag, {
|
|
2939
|
+
id,
|
|
2940
|
+
layer: makeLayer
|
|
2941
|
+
});
|
|
2942
|
+
};
|
|
2943
|
+
//#endregion
|
|
2944
|
+
//#region src/Hyperdrive.ts
|
|
2945
|
+
var Hyperdrive_exports = /* @__PURE__ */ __exportAll({
|
|
2946
|
+
Tag: () => Tag$6,
|
|
2947
|
+
isHyperdrive: () => isHyperdrive,
|
|
2948
|
+
layer: () => layer$5,
|
|
2949
|
+
make: () => make$5,
|
|
2950
|
+
makeClient: () => makeClient$5
|
|
2951
|
+
});
|
|
2952
|
+
const expectedHyperdrive = "Hyperdrive binding with connectionString";
|
|
2953
|
+
const isHyperdrive = (value) => {
|
|
2954
|
+
if (typeof value !== "object" || value === null) return false;
|
|
2955
|
+
return typeof value.connectionString === "string";
|
|
2956
|
+
};
|
|
2957
|
+
const makeClient$5 = (definition) => (hyperdrive) => ({
|
|
2958
|
+
definition,
|
|
2959
|
+
connectionString: hyperdrive.connectionString,
|
|
2960
|
+
unsafeRaw: Effect.succeed(hyperdrive)
|
|
2961
|
+
});
|
|
2962
|
+
const layer$5 = (tag, definition) => layer$20(tag, definition.binding, isHyperdrive, makeClient$5(definition), { expected: expectedHyperdrive });
|
|
2543
2963
|
const make$5 = (id) => Tag$6()(id);
|
|
2544
2964
|
const Tag$6 = () => (id) => {
|
|
2545
2965
|
const tag = Context.Service()(id);
|
|
@@ -2646,7 +3066,7 @@ const makeClient$4 = (definition) => (images) => {
|
|
|
2646
3066
|
unsafeRaw: Effect.succeed(images)
|
|
2647
3067
|
};
|
|
2648
3068
|
};
|
|
2649
|
-
const layer$4 = (tag, definition) => layer$
|
|
3069
|
+
const layer$4 = (tag, definition) => layer$20(tag, definition.binding, isImagesBinding, makeClient$4(definition), { expected: expectedImagesBinding });
|
|
2650
3070
|
const make$4 = (id) => Tag$5()(id);
|
|
2651
3071
|
const Tag$5 = () => (id) => {
|
|
2652
3072
|
const tag = Context.Service()(id);
|
|
@@ -2668,7 +3088,7 @@ var Kv_exports = /* @__PURE__ */ __exportAll({
|
|
|
2668
3088
|
const expectedKvNamespace = "KV namespace binding with get(), put(), delete(), getWithMetadata(), and list()";
|
|
2669
3089
|
/** Error raised when a KV operation fails. */
|
|
2670
3090
|
var KvOperationError = class extends Data.TaggedError("KvOperationError") {};
|
|
2671
|
-
const maybeString = (value) => value
|
|
3091
|
+
const maybeString = (value) => value === null || value === void 0 ? Option.none() : Option.some(value);
|
|
2672
3092
|
const maybeNumber = (value) => value === void 0 ? Option.none() : Option.some(value);
|
|
2673
3093
|
const kvError = (binding, operation, cause) => new KvOperationError({
|
|
2674
3094
|
binding,
|
|
@@ -2741,7 +3161,7 @@ const makeClient$3 = (definition) => {
|
|
|
2741
3161
|
unsafeRaw: Effect.succeed(kv)
|
|
2742
3162
|
});
|
|
2743
3163
|
};
|
|
2744
|
-
const layer$3 = (tag, definition) => layer$
|
|
3164
|
+
const layer$3 = (tag, definition) => layer$20(tag, definition.binding, isKvNamespace, makeClient$3(definition), { expected: expectedKvNamespace });
|
|
2745
3165
|
const makeDefinition$1 = (id, definition) => {
|
|
2746
3166
|
const kvDefinition = {
|
|
2747
3167
|
id,
|
|
@@ -2858,7 +3278,7 @@ const makeClient$2 = (definition) => {
|
|
|
2858
3278
|
};
|
|
2859
3279
|
};
|
|
2860
3280
|
};
|
|
2861
|
-
const layer$2 = (tag, definition) => layer$
|
|
3281
|
+
const layer$2 = (tag, definition) => layer$20(tag, definition.binding, isR2Bucket, makeClient$2(definition), { expected: expectedR2Bucket });
|
|
2862
3282
|
const make$3 = (id) => Tag$3()(id);
|
|
2863
3283
|
const Tag$3 = () => (id) => {
|
|
2864
3284
|
const tag = Context.Service()(id);
|
|
@@ -2915,7 +3335,7 @@ const makeClient$1 = (definition) => {
|
|
|
2915
3335
|
return {
|
|
2916
3336
|
status: status.status,
|
|
2917
3337
|
output,
|
|
2918
|
-
error: status.error
|
|
3338
|
+
error: status.error === null || status.error === void 0 ? Option.none() : Option.some(status.error)
|
|
2919
3339
|
};
|
|
2920
3340
|
}))),
|
|
2921
3341
|
sendEvent: (event) => operation("sendEvent", () => raw.sendEvent(event))
|
|
@@ -2924,10 +3344,11 @@ const makeClient$1 = (definition) => {
|
|
|
2924
3344
|
return (workflow) => ({
|
|
2925
3345
|
create: Effect.fnUntraced(function* (payload, options) {
|
|
2926
3346
|
const encoded = yield* encodePayload(payload);
|
|
2927
|
-
|
|
3347
|
+
const raw = yield* tryWorkflowPromise(definition.binding, "create", () => workflow.create({
|
|
2928
3348
|
...options,
|
|
2929
3349
|
params: encoded
|
|
2930
|
-
}))
|
|
3350
|
+
}));
|
|
3351
|
+
return wrapInstance(raw);
|
|
2931
3352
|
}),
|
|
2932
3353
|
createBatch: Effect.fnUntraced(function* (batch) {
|
|
2933
3354
|
const encodedBatch = [];
|
|
@@ -2944,7 +3365,7 @@ const makeClient$1 = (definition) => {
|
|
|
2944
3365
|
unsafeRaw: Effect.succeed(workflow)
|
|
2945
3366
|
});
|
|
2946
3367
|
};
|
|
2947
|
-
const layer$1 = (tag, definition) => layer$
|
|
3368
|
+
const layer$1 = (tag, definition) => layer$20(tag, definition.binding, (value) => isWorkflow(value), makeClient$1(definition), { expected: expectedWorkflow });
|
|
2948
3369
|
//#endregion
|
|
2949
3370
|
//#region src/WorkflowDefinition.ts
|
|
2950
3371
|
var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -3004,7 +3425,8 @@ const wrapHandler = (definition, handler) => {
|
|
|
3004
3425
|
...yield* WorkflowEvent$1,
|
|
3005
3426
|
payload: decodedPayload
|
|
3006
3427
|
};
|
|
3007
|
-
|
|
3428
|
+
const result = yield* handler(decodedPayload).pipe(Effect.provideService(WorkflowEvent$1, decodedEvent));
|
|
3429
|
+
return yield* encodeResult(result);
|
|
3008
3430
|
});
|
|
3009
3431
|
};
|
|
3010
3432
|
const implement$1 = (_definition, handler) => handler;
|
|
@@ -3061,7 +3483,8 @@ const make$1 = (layer, options) => {
|
|
|
3061
3483
|
constructor(ctx, env) {
|
|
3062
3484
|
super(ctx, env);
|
|
3063
3485
|
let runWaitUntilEffect = () => Promise.reject(/* @__PURE__ */ new Error("WorkerContext runtime is not initialized"));
|
|
3064
|
-
const
|
|
3486
|
+
const services = Layer.mergeAll(Layer.succeed(ExecutionContext, ctx), ConfigProvider.layer(Effect.succeed(WorkerConfig.providerFromEnv(env))), Layer.succeed(WorkerContext, fromExecutionContext(ctx, (effect) => runWaitUntilEffect(effect))), Layer.succeed(WorkerEnvironment, env));
|
|
3487
|
+
const runtimeLayer = provideEntrypointServices(layer, services);
|
|
3065
3488
|
this.runtime = ManagedRuntime.make(runtimeLayer);
|
|
3066
3489
|
runWaitUntilEffect = (effect) => this.runtime.runPromiseExit(effect);
|
|
3067
3490
|
}
|
|
@@ -3118,7 +3541,7 @@ const makeClient = (definition) => (index) => {
|
|
|
3118
3541
|
unsafeRaw: Effect.succeed(index)
|
|
3119
3542
|
};
|
|
3120
3543
|
};
|
|
3121
|
-
const layer = (tag, definition) => layer$
|
|
3544
|
+
const layer = (tag, definition) => layer$20(tag, definition.binding, isVectorizeBinding, makeClient(definition), { expected: expectedVectorizeBinding });
|
|
3122
3545
|
const make = (id) => Tag()(id);
|
|
3123
3546
|
const Tag = () => (id) => {
|
|
3124
3547
|
const tag = Context.Service()(id);
|
|
@@ -3129,4 +3552,4 @@ const Tag = () => (id) => {
|
|
|
3129
3552
|
});
|
|
3130
3553
|
};
|
|
3131
3554
|
//#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 };
|
|
3555
|
+
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 };
|