effect-cf 0.26.0 → 0.28.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 +16 -0
- package/README.md +8 -6
- package/dist/{Artifacts-DcoXcRP5.d.mts → Artifacts-DnHQA-Ax.d.mts} +42 -25
- package/dist/Artifacts-rq3hUKQE.mjs +257 -0
- package/dist/{Binding-COCtoJXa.d.mts → Binding-xJJJPmiD.d.mts} +6 -5
- package/dist/ComputerArtifacts.d.mts +55 -0
- package/dist/ComputerArtifacts.mjs +95 -0
- package/dist/ComputerWorkspace.d.mts +279 -0
- package/dist/ComputerWorkspace.mjs +577 -0
- package/dist/ComputerWorkspaceHost.d.mts +1 -1
- package/dist/ComputerWorkspaceHost.mjs +18 -16
- package/dist/{WorkflowBinding-D5iWzCUa.d.mts → DurableObjectState-B3uFY1eM.d.mts} +90 -141
- package/dist/{DurableObjectState-CEh0DVw7.mjs → DurableObjectState-BjkK2kwH.mjs} +4 -49
- package/dist/ErrorMessage-BM0K-Nik.mjs +46 -0
- package/dist/{Hyperdrive-6p59yyVk.d.mts → Hyperdrive-z-9fFz15.d.mts} +2 -2
- package/dist/HyperdrivePg.d.mts +2 -2
- package/dist/Vitest.d.mts +6 -4
- package/dist/Vitest.mjs +2 -1
- package/dist/WorkflowBinding-wZ-yGHow.d.mts +74 -0
- package/dist/index.d.mts +92 -398
- package/dist/index.mjs +323 -1105
- package/package.json +12 -1
- package/src/AiGateway.ts +62 -7
- package/src/AnalyticsEngine.ts +17 -13
- package/src/Artifacts.ts +111 -47
- package/src/Binding.ts +34 -23
- package/src/BrowserRendering.ts +72 -33
- package/src/CloudflareOtlp.ts +8 -5
- package/src/ComputerArtifacts.ts +17 -9
- package/src/ComputerWorkspace.ts +202 -98
- package/src/ComputerWorkspaceHost.ts +55 -27
- package/src/ContainerNamespace.ts +8 -9
- package/src/D1.ts +8 -14
- package/src/DurableObject.ts +27 -11
- package/src/DurableObjectAlarm.ts +17 -5
- package/src/DurableObjectDefinition.ts +89 -72
- package/src/DurableObjectNamespace.ts +26 -12
- package/src/DurableObjectRpcWebSocket.ts +9 -10
- package/src/DurableObjectState.ts +1 -0
- package/src/DurableObjectStorage.ts +5 -2
- package/src/DurableObjectWebSocket.ts +4 -1
- package/src/Email.ts +26 -25
- package/src/Hyperdrive.ts +4 -10
- package/src/Images.ts +12 -14
- package/src/Kv.ts +15 -17
- package/src/Queue.ts +2 -1
- package/src/QueueBinding.ts +7 -12
- package/src/QueueDefinition.ts +7 -2
- package/src/R2.ts +33 -24
- package/src/Rpc.ts +15 -21
- package/src/RpcDefinition.ts +33 -38
- package/src/ServiceBinding.ts +26 -8
- package/src/Vectorize.ts +45 -18
- package/src/Vitest.ts +9 -3
- package/src/WebTransport.ts +11 -5
- package/src/Worker.ts +91 -21
- package/src/WorkerDefinition.ts +143 -63
- package/src/WorkersAi.ts +50 -28
- package/src/Workflow.ts +66 -13
- package/src/WorkflowBinding.ts +18 -25
- package/src/WorkflowDefinition.ts +4 -2
- package/src/index.ts +0 -2
- package/src/internal/Entrypoint.ts +29 -13
- package/src/internal/ErrorMessage.ts +7 -6
- package/src/internal/RpcInvocation.ts +34 -11
- package/src/internal/Runtime.ts +33 -22
- package/src/internal/WorkerContext.ts +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { a as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { a as WorkerEnvironment, i as WorkerConfig, n as violationsMessage, r as Environment_exports, t as causeMessage } from "./ErrorMessage-BM0K-Nik.mjs";
|
|
3
|
+
import { a as layer$19, i as Service$2, n as Artifacts_exports, r as Binding_exports } from "./Artifacts-rq3hUKQE.mjs";
|
|
4
|
+
import { a as DurableObjectWebSocket_exports, i as fromExecutionContext, n as DurableObjectState_exports, o as fromWebSocket, r as fromDurableObjectState, s as DurableObjectStorage_exports, t as DurableObjectState } from "./DurableObjectState-BjkK2kwH.mjs";
|
|
5
|
+
import { Cause, Clock, Config, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Function as Function$1, Layer, ManagedRuntime, Option, Predicate, Queue, Result, Schema } from "effect";
|
|
5
6
|
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpEffect, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
6
7
|
import { OtlpExporter, OtlpLogger, OtlpMetrics, OtlpSerialization, OtlpTracer } from "effect/unstable/observability";
|
|
7
8
|
import { D1Client } from "@effect/sql-d1";
|
|
@@ -10,133 +11,16 @@ import * as RpcMessage from "effect/unstable/rpc/RpcMessage";
|
|
|
10
11
|
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
|
|
11
12
|
import * as RpcServer from "effect/unstable/rpc/RpcServer";
|
|
12
13
|
import { SqliteClient } from "@effect/sql-sqlite-do";
|
|
13
|
-
|
|
14
|
-
var Binding_exports = /* @__PURE__ */ __exportAll({
|
|
15
|
-
BindingNotFoundError: () => BindingNotFoundError,
|
|
16
|
-
BindingValidationError: () => BindingValidationError,
|
|
17
|
-
Service: () => Service$2,
|
|
18
|
-
TypeId: () => TypeId$3,
|
|
19
|
-
layer: () => layer$20
|
|
20
|
-
});
|
|
21
|
-
/** Internal type id marker used by binding helper services. */
|
|
22
|
-
const TypeId$3 = "~effect-cf/Binding";
|
|
23
|
-
/** Error raised when a configured binding does not exist on `env`. */
|
|
24
|
-
var BindingNotFoundError = class extends Data.TaggedError("BindingNotFoundError") {};
|
|
25
|
-
/** Error raised when a binding exists but does not match the expected shape. */
|
|
26
|
-
var BindingValidationError = class extends Data.TaggedError("BindingValidationError") {};
|
|
27
|
-
const defaultExpected = "Cloudflare binding resource";
|
|
28
|
-
const isPropertyTarget$1 = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
|
|
29
|
-
const getObjectName = (value) => {
|
|
30
|
-
const tag = (() => {
|
|
31
|
-
try {
|
|
32
|
-
return Object.prototype.toString.call(value).slice(8, -1);
|
|
33
|
-
} catch {
|
|
34
|
-
return typeof value;
|
|
35
|
-
}
|
|
36
|
-
})();
|
|
37
|
-
const constructorName = (() => {
|
|
38
|
-
try {
|
|
39
|
-
return "constructor" in value && typeof value.constructor === "function" && typeof value.constructor.name === "string" ? value.constructor.name : void 0;
|
|
40
|
-
} catch {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
})();
|
|
44
|
-
if (tag !== "Object") return tag;
|
|
45
|
-
if (constructorName !== void 0 && constructorName !== "" && constructorName !== "Object") return constructorName;
|
|
46
|
-
return tag;
|
|
47
|
-
};
|
|
48
|
-
const propertyNames = (value) => {
|
|
49
|
-
const names = /* @__PURE__ */ new Set();
|
|
50
|
-
for (const target of [value, Object.getPrototypeOf(value)]) {
|
|
51
|
-
if (target === null || target === Object.prototype || target === Function.prototype) continue;
|
|
52
|
-
try {
|
|
53
|
-
for (const name of Object.getOwnPropertyNames(target)) names.add(name);
|
|
54
|
-
} catch {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return [...names].filter((name) => name !== "constructor").sort();
|
|
59
|
-
};
|
|
60
|
-
const isMethod = (value, name) => {
|
|
61
|
-
try {
|
|
62
|
-
return typeof Reflect.get(value, name) === "function";
|
|
63
|
-
} catch {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const describeActual = (value) => {
|
|
68
|
-
if (value === null) return "null";
|
|
69
|
-
if (typeof value !== "object" && typeof value !== "function") return typeof value;
|
|
70
|
-
const names = propertyNames(value);
|
|
71
|
-
const methods = names.filter((name) => isMethod(value, name));
|
|
72
|
-
const properties = names.filter((name) => !methods.includes(name));
|
|
73
|
-
const details = [methods.length > 0 ? `methods ${methods.join(", ")}` : void 0, properties.length > 0 ? `properties ${properties.join(", ")}` : void 0].filter((detail) => detail !== void 0);
|
|
74
|
-
if (details.length === 0) return getObjectName(value);
|
|
75
|
-
return `${getObjectName(value)} with ${details.join("; ")}`;
|
|
76
|
-
};
|
|
77
|
-
const getBinding = (env, binding, isResource, options) => Effect.gen(function* () {
|
|
78
|
-
if (!isPropertyTarget$1(env)) {
|
|
79
|
-
const actual = describeActual(env);
|
|
80
|
-
return yield* Effect.fail(new BindingValidationError({
|
|
81
|
-
binding,
|
|
82
|
-
expected: "WorkerEnvironment object",
|
|
83
|
-
actual,
|
|
84
|
-
message: `Cloudflare binding "${binding}" failed validation. Expected WorkerEnvironment object; got ${actual}`
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
const resource = Reflect.get(env, binding);
|
|
88
|
-
if (resource === void 0) return yield* Effect.fail(new BindingNotFoundError({
|
|
89
|
-
binding,
|
|
90
|
-
message: `Cloudflare binding "${binding}" was not found in WorkerEnvironment`
|
|
91
|
-
}));
|
|
92
|
-
if (!isResource(resource)) {
|
|
93
|
-
const expected = options?.expected ?? defaultExpected;
|
|
94
|
-
const actual = describeActual(resource);
|
|
95
|
-
return yield* Effect.fail(new BindingValidationError({
|
|
96
|
-
binding,
|
|
97
|
-
expected,
|
|
98
|
-
actual,
|
|
99
|
-
message: `Cloudflare binding "${binding}" failed validation. Expected ${expected}; got ${actual}`
|
|
100
|
-
}));
|
|
101
|
-
}
|
|
102
|
-
return resource;
|
|
103
|
-
});
|
|
104
|
-
/**
|
|
105
|
-
* The overloads on {@link layer} and {@link Service} guarantee that
|
|
106
|
-
* `Service = Resource` whenever `wrap` is absent, making the fallback cast
|
|
107
|
-
* safe.
|
|
108
|
-
*/
|
|
109
|
-
const makeBindingLayer = (tag, binding, isResource, wrap, options) => Layer.effect(tag, Effect.gen(function* () {
|
|
110
|
-
const env = yield* WorkerEnvironment;
|
|
111
|
-
const resource = yield* getBinding(env, binding, isResource, options);
|
|
112
|
-
return wrap === void 0 ? resource : wrap(resource);
|
|
113
|
-
}));
|
|
114
|
-
function layer$20(tag, binding, isResource, wrap, options) {
|
|
115
|
-
return makeBindingLayer(tag, binding, isResource, wrap, options);
|
|
116
|
-
}
|
|
117
|
-
const Service$2 = () => {
|
|
118
|
-
function makeService(id, binding, isResource, wrap, options) {
|
|
119
|
-
const tag = Context.Service()(`effect-cf/Binding/${id}`);
|
|
120
|
-
const serviceLayer = makeBindingLayer(tag, binding, isResource, wrap, options);
|
|
121
|
-
return Object.assign(tag, {
|
|
122
|
-
[TypeId$3]: TypeId$3,
|
|
123
|
-
id,
|
|
124
|
-
binding,
|
|
125
|
-
layer: serviceLayer
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
return makeService;
|
|
129
|
-
};
|
|
130
|
-
//#endregion
|
|
14
|
+
import { NonRetryableError } from "cloudflare:workflows";
|
|
131
15
|
//#region src/WorkersAi.ts
|
|
132
16
|
var WorkersAi_exports = /* @__PURE__ */ __exportAll({
|
|
133
|
-
Tag: () => Tag$
|
|
17
|
+
Tag: () => Tag$16,
|
|
134
18
|
WorkersAiOperationError: () => WorkersAiOperationError,
|
|
135
19
|
embeddingResponse: () => embeddingResponse,
|
|
136
20
|
isWorkersAiBinding: () => isWorkersAiBinding,
|
|
137
|
-
layer: () => layer$
|
|
138
|
-
make: () => make$
|
|
139
|
-
makeClient: () => makeClient$
|
|
21
|
+
layer: () => layer$18,
|
|
22
|
+
make: () => make$18,
|
|
23
|
+
makeClient: () => makeClient$15
|
|
140
24
|
});
|
|
141
25
|
const expectedWorkersAiBinding = "Workers AI binding with run(), gateway(), and models()";
|
|
142
26
|
/** Error raised when a Workers AI operation fails. */
|
|
@@ -145,6 +29,7 @@ var WorkersAiOperationError = class extends Data.TaggedError("WorkersAiOperation
|
|
|
145
29
|
return `Workers AI ${this.operation} failed for binding "${this.binding}": ${causeMessage(this.cause)}`;
|
|
146
30
|
}
|
|
147
31
|
};
|
|
32
|
+
const embeddingDimensionsKey = "shape";
|
|
148
33
|
const workersAiError = (binding, operation, cause) => new WorkersAiOperationError({
|
|
149
34
|
binding,
|
|
150
35
|
operation,
|
|
@@ -158,29 +43,41 @@ const tryWorkersAiSync = (binding, operation, evaluate) => Effect.try({
|
|
|
158
43
|
try: evaluate,
|
|
159
44
|
catch: (cause) => workersAiError(binding, operation, cause)
|
|
160
45
|
});
|
|
161
|
-
const
|
|
162
|
-
const
|
|
46
|
+
const WorkersAiBindingSchema = Schema.declare((value) => Predicate.hasProperty(value, "run") && Predicate.isFunction(value.run) && Predicate.hasProperty(value, "gateway") && Predicate.isFunction(value.gateway) && Predicate.hasProperty(value, "models") && Predicate.isFunction(value.models));
|
|
47
|
+
const decodeWorkersAiBinding = Schema.decodeUnknownOption(WorkersAiBindingSchema);
|
|
48
|
+
const isWorkersAiBinding = (value) => Option.isSome(decodeWorkersAiBinding(value));
|
|
163
49
|
const embeddingResponse = (value) => ({
|
|
164
50
|
data: value.data ?? [],
|
|
165
|
-
|
|
51
|
+
[embeddingDimensionsKey]: value[embeddingDimensionsKey] ?? []
|
|
166
52
|
});
|
|
167
|
-
const
|
|
168
|
-
|
|
53
|
+
const decodeEmbeddingResponse = Schema.decodeUnknownOption(Schema.Struct({
|
|
54
|
+
data: Schema.optional(Schema.Array(Schema.Array(Schema.Number))),
|
|
55
|
+
[embeddingDimensionsKey]: Schema.optional(Schema.Array(Schema.Number))
|
|
56
|
+
}));
|
|
57
|
+
const makeClient$15 = (definition) => (ai) => {
|
|
58
|
+
const run = Effect.fn("WorkersAi.run")((model, input, options) => tryWorkersAiPromise(definition.binding, "run", () => {
|
|
59
|
+
return ai.run(model, input, options);
|
|
60
|
+
}));
|
|
169
61
|
return {
|
|
170
62
|
definition,
|
|
171
63
|
aiGatewayLogId: tryWorkersAiSync(definition.binding, "aiGatewayLogId", () => ai.aiGatewayLogId),
|
|
172
64
|
run,
|
|
173
|
-
runEmbedding: Effect.fn("WorkersAi.runEmbedding")((model, input, options) =>
|
|
65
|
+
runEmbedding: Effect.fn("WorkersAi.runEmbedding")((model, input, options) => {
|
|
66
|
+
return run(model, input, options).pipe(Effect.map((response) => Option.match(decodeEmbeddingResponse(response), {
|
|
67
|
+
onNone: () => embeddingResponse({}),
|
|
68
|
+
onSome: embeddingResponse
|
|
69
|
+
})));
|
|
70
|
+
}),
|
|
174
71
|
models: Effect.fn("WorkersAi.models")((params) => tryWorkersAiPromise(definition.binding, "models", () => ai.models(params))),
|
|
175
72
|
gateway: (gatewayId) => tryWorkersAiSync(definition.binding, "gateway", () => ai.gateway(gatewayId)),
|
|
176
73
|
rawUnsafe: Effect.succeed(ai)
|
|
177
74
|
};
|
|
178
75
|
};
|
|
179
|
-
const layer$
|
|
180
|
-
const make$
|
|
181
|
-
const Tag$
|
|
76
|
+
const layer$18 = (tag, definition) => layer$19(tag, definition.binding, (value) => isWorkersAiBinding(value), makeClient$15(definition), { expected: expectedWorkersAiBinding });
|
|
77
|
+
const make$18 = (id) => Tag$16()(id);
|
|
78
|
+
const Tag$16 = () => (id) => {
|
|
182
79
|
const tag = Context.Service()(id);
|
|
183
|
-
const makeLayer = (definition) => layer$
|
|
80
|
+
const makeLayer = (definition) => layer$18(tag, definition);
|
|
184
81
|
return Object.assign(tag, {
|
|
185
82
|
id,
|
|
186
83
|
layer: makeLayer
|
|
@@ -190,11 +87,11 @@ const Tag$17 = () => (id) => {
|
|
|
190
87
|
//#region src/AiGateway.ts
|
|
191
88
|
var AiGateway_exports = /* @__PURE__ */ __exportAll({
|
|
192
89
|
AiGatewayOperationError: () => AiGatewayOperationError,
|
|
193
|
-
Tag: () => Tag$
|
|
90
|
+
Tag: () => Tag$15,
|
|
194
91
|
isAiGatewayBinding: () => isAiGatewayBinding,
|
|
195
|
-
layer: () => layer$
|
|
196
|
-
make: () => make$
|
|
197
|
-
makeClient: () => makeClient$
|
|
92
|
+
layer: () => layer$17,
|
|
93
|
+
make: () => make$17,
|
|
94
|
+
makeClient: () => makeClient$14,
|
|
198
95
|
makeClientFromAi: () => makeClientFromAi,
|
|
199
96
|
makeHttpClient: () => makeHttpClient
|
|
200
97
|
});
|
|
@@ -205,6 +102,49 @@ var AiGatewayOperationError = class extends Data.TaggedError("AiGatewayOperation
|
|
|
205
102
|
return `AI Gateway ${this.operation} failed for binding "${this.binding}": ${causeMessage(this.cause)}`;
|
|
206
103
|
}
|
|
207
104
|
};
|
|
105
|
+
const AiGatewayMetadata = Schema.Record(Schema.String, Schema.Union([
|
|
106
|
+
Schema.String,
|
|
107
|
+
Schema.Number,
|
|
108
|
+
Schema.Boolean,
|
|
109
|
+
Schema.Null
|
|
110
|
+
]));
|
|
111
|
+
const AiGatewayHttpMetadata = Schema.Union([AiGatewayMetadata, Schema.fromJsonString(AiGatewayMetadata)]);
|
|
112
|
+
const AiGatewayLogResponse = Schema.Struct({
|
|
113
|
+
success: Schema.Literal(true),
|
|
114
|
+
result: Schema.Struct({
|
|
115
|
+
id: Schema.String,
|
|
116
|
+
provider: Schema.String,
|
|
117
|
+
model: Schema.String,
|
|
118
|
+
model_type: Schema.optional(Schema.String),
|
|
119
|
+
path: Schema.String,
|
|
120
|
+
duration: Schema.Number,
|
|
121
|
+
request_type: Schema.optional(Schema.String),
|
|
122
|
+
request_content_type: Schema.optional(Schema.String),
|
|
123
|
+
status_code: Schema.Number,
|
|
124
|
+
response_content_type: Schema.optional(Schema.String),
|
|
125
|
+
success: Schema.Boolean,
|
|
126
|
+
cached: Schema.Boolean,
|
|
127
|
+
tokens_in: Schema.optional(Schema.Number),
|
|
128
|
+
tokens_out: Schema.optional(Schema.Number),
|
|
129
|
+
metadata: Schema.optional(AiGatewayHttpMetadata),
|
|
130
|
+
step: Schema.optional(Schema.Number),
|
|
131
|
+
cost: Schema.optional(Schema.Number),
|
|
132
|
+
custom_cost: Schema.optional(Schema.Boolean),
|
|
133
|
+
request_size: Schema.Number,
|
|
134
|
+
request_head: Schema.optional(Schema.String),
|
|
135
|
+
request_head_complete: Schema.Boolean,
|
|
136
|
+
response_size: Schema.Number,
|
|
137
|
+
response_head: Schema.optional(Schema.String),
|
|
138
|
+
response_head_complete: Schema.Boolean,
|
|
139
|
+
created_at: Schema.DateFromString
|
|
140
|
+
})
|
|
141
|
+
});
|
|
142
|
+
const AiGatewayPatchLogResponse = Schema.Struct({
|
|
143
|
+
success: Schema.Literal(true),
|
|
144
|
+
result: Schema.Unknown
|
|
145
|
+
});
|
|
146
|
+
const decodeAiGatewayLogResponse = Schema.decodeUnknownPromise(AiGatewayLogResponse);
|
|
147
|
+
const decodeAiGatewayPatchLogResponse = Schema.decodeUnknownPromise(AiGatewayPatchLogResponse);
|
|
208
148
|
const aiGatewayError = (binding, operation, cause) => new AiGatewayOperationError({
|
|
209
149
|
binding,
|
|
210
150
|
operation,
|
|
@@ -225,8 +165,11 @@ const providerUrl = (baseUrl, path = "") => {
|
|
|
225
165
|
return normalizedPath === "" ? url : new URL(normalizedPath, url);
|
|
226
166
|
};
|
|
227
167
|
const gatewayUrl = (definition) => `https://gateway.ai.cloudflare.com/v1/${definition.accountId}/${definition.gatewayId}/`;
|
|
168
|
+
const ensureSuccessfulResponse = (response) => {
|
|
169
|
+
if (!response.ok) throw new Error(`AI Gateway HTTP request failed with status ${response.status}`);
|
|
170
|
+
};
|
|
228
171
|
const isAiGatewayBinding = (value) => isWorkersAiBinding(value);
|
|
229
|
-
const makeClient$
|
|
172
|
+
const makeClient$14 = (definition, gateway) => ({
|
|
230
173
|
definition,
|
|
231
174
|
run: Effect.fn("AiGateway.run")((data, options) => tryAiGatewayPromise(definition.binding, "run", () => gateway.run(Array.isArray(data) ? [...data] : data, options))),
|
|
232
175
|
getUrl: Effect.fn("AiGateway.getUrl")((provider) => tryAiGatewayPromise(definition.binding, "getUrl", () => gateway.getUrl(provider))),
|
|
@@ -246,11 +189,11 @@ const makeClientFromAi = (definition, ai) => {
|
|
|
246
189
|
const withGateway = (operation) => gateway.pipe(Effect.flatMap(operation));
|
|
247
190
|
return {
|
|
248
191
|
definition,
|
|
249
|
-
run: (data, options) => withGateway((raw) => makeClient$
|
|
250
|
-
getUrl: (provider) => withGateway((raw) => makeClient$
|
|
251
|
-
fetch: (options) => withGateway((raw) => makeClient$
|
|
252
|
-
patchLog: (logId, data) => withGateway((raw) => makeClient$
|
|
253
|
-
getLog: (logId) => withGateway((raw) => makeClient$
|
|
192
|
+
run: (data, options) => withGateway((raw) => makeClient$14(definition, raw).run(data, options)),
|
|
193
|
+
getUrl: (provider) => withGateway((raw) => makeClient$14(definition, raw).getUrl(provider)),
|
|
194
|
+
fetch: (options) => withGateway((raw) => makeClient$14(definition, raw).fetch(options)),
|
|
195
|
+
patchLog: (logId, data) => withGateway((raw) => makeClient$14(definition, raw).patchLog(logId, data)),
|
|
196
|
+
getLog: (logId) => withGateway((raw) => makeClient$14(definition, raw).getLog(logId)),
|
|
254
197
|
rawUnsafe: gateway
|
|
255
198
|
};
|
|
256
199
|
};
|
|
@@ -282,23 +225,29 @@ const makeHttpClient = (definition, request = fetch) => {
|
|
|
282
225
|
...options.init,
|
|
283
226
|
signal: mergeAbortSignals(options.init?.signal, signal)
|
|
284
227
|
}))))),
|
|
285
|
-
patchLog: Effect.fn("AiGateway.patchLog")((logId, data) => tryAiGatewayPromise(binding, "patchLog", (signal) =>
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
228
|
+
patchLog: Effect.fn("AiGateway.patchLog")((logId, data) => tryAiGatewayPromise(binding, "patchLog", async (signal) => {
|
|
229
|
+
const response = await request(providerUrl(gatewayUrl(definition), `logs/${logId}`).href, {
|
|
230
|
+
method: "PATCH",
|
|
231
|
+
body: JSON.stringify(data),
|
|
232
|
+
headers: { "content-type": "application/json" },
|
|
233
|
+
signal
|
|
234
|
+
});
|
|
235
|
+
ensureSuccessfulResponse(response);
|
|
236
|
+
await decodeAiGatewayPatchLogResponse(await response.json());
|
|
237
|
+
})),
|
|
291
238
|
getLog: Effect.fn("AiGateway.getLog")((logId) => tryAiGatewayPromise(binding, "getLog", async (signal) => {
|
|
292
|
-
|
|
239
|
+
const response = await request(providerUrl(gatewayUrl(definition), `logs/${logId}`).href, { signal });
|
|
240
|
+
ensureSuccessfulResponse(response);
|
|
241
|
+
return (await decodeAiGatewayLogResponse(await response.json())).result;
|
|
293
242
|
})),
|
|
294
243
|
rawUnsafe: Effect.fail(aiGatewayError(binding, "rawUnsafe", /* @__PURE__ */ new TypeError("HTTP AI Gateway clients have no raw binding")))
|
|
295
244
|
};
|
|
296
245
|
};
|
|
297
|
-
const layer$
|
|
298
|
-
const make$
|
|
299
|
-
const Tag$
|
|
246
|
+
const layer$17 = (tag, definition) => layer$19(tag, definition.binding, isAiGatewayBinding, (ai) => makeClientFromAi(definition, ai), { expected: expectedAiGatewayBinding });
|
|
247
|
+
const make$17 = (id) => Tag$15()(id);
|
|
248
|
+
const Tag$15 = () => (id) => {
|
|
300
249
|
const tag = Context.Service()(id);
|
|
301
|
-
const makeLayer = (definition) => layer$
|
|
250
|
+
const makeLayer = (definition) => layer$17(tag, definition);
|
|
302
251
|
return Object.assign(tag, {
|
|
303
252
|
id,
|
|
304
253
|
layer: makeLayer
|
|
@@ -313,13 +262,13 @@ var AnalyticsEngine_exports = /* @__PURE__ */ __exportAll({
|
|
|
313
262
|
AnalyticsEngineQueryError: () => AnalyticsEngineQueryError,
|
|
314
263
|
AnalyticsEngineWriteValidationError: () => AnalyticsEngineWriteValidationError,
|
|
315
264
|
QueryTag: () => QueryTag,
|
|
316
|
-
Tag: () => Tag$
|
|
265
|
+
Tag: () => Tag$14,
|
|
317
266
|
isAnalyticsEngineDataset: () => isAnalyticsEngineDataset,
|
|
318
|
-
layer: () => layer$
|
|
267
|
+
layer: () => layer$16,
|
|
319
268
|
layerFetch: () => layerFetch,
|
|
320
269
|
layerFetchConfig: () => layerFetchConfig,
|
|
321
|
-
make: () => make$
|
|
322
|
-
makeClient: () => makeClient$
|
|
270
|
+
make: () => make$16,
|
|
271
|
+
makeClient: () => makeClient$13,
|
|
323
272
|
makeQuery: () => makeQuery,
|
|
324
273
|
makeQueryClient: () => makeQueryClient,
|
|
325
274
|
queryConfig: () => queryConfig,
|
|
@@ -398,7 +347,7 @@ const fieldPath = (prefix, field) => prefix === "" ? field : `${prefix}.${field}
|
|
|
398
347
|
const indexedPath = (prefix, field, index) => `${fieldPath(prefix, field)}[${index}]`;
|
|
399
348
|
const byteLength$1 = (value) => {
|
|
400
349
|
if (value === null) return 0;
|
|
401
|
-
return
|
|
350
|
+
return Predicate.isString(value) ? textEncoder$1.encode(value).byteLength : value.byteLength;
|
|
402
351
|
};
|
|
403
352
|
const lengthViolation = (path, label, actual, limit) => ({
|
|
404
353
|
path,
|
|
@@ -425,11 +374,13 @@ const schemaViolation = (pathPrefix, cause) => ({
|
|
|
425
374
|
path: pathPrefix === "" ? "$" : pathPrefix,
|
|
426
375
|
message: cause.message
|
|
427
376
|
});
|
|
428
|
-
const toAnalyticsEngineDataPoint = (dataPoint) =>
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
377
|
+
const toAnalyticsEngineDataPoint = (dataPoint) => {
|
|
378
|
+
const result = {};
|
|
379
|
+
if (dataPoint.indexes !== void 0) result.indexes = [...dataPoint.indexes];
|
|
380
|
+
if (dataPoint.doubles !== void 0) result.doubles = [...dataPoint.doubles];
|
|
381
|
+
if (dataPoint.blobs !== void 0) result.blobs = [...dataPoint.blobs];
|
|
382
|
+
return result;
|
|
383
|
+
};
|
|
433
384
|
const validateDataPoint = (binding, operation, dataPoint, pathPrefix = "") => Effect.gen(function* () {
|
|
434
385
|
const decoded = yield* decodeDataPoint(dataPoint).pipe(Effect.mapError((cause) => analyticsEngineWriteValidationError(binding, operation, [schemaViolation(pathPrefix, cause)], cause)));
|
|
435
386
|
const validated = toAnalyticsEngineDataPoint(decoded);
|
|
@@ -504,11 +455,8 @@ const makeQueryClientWith = (definition, httpClient) => {
|
|
|
504
455
|
};
|
|
505
456
|
};
|
|
506
457
|
const makeQueryClient = (definition) => Effect.map(HttpClient.HttpClient, (httpClient) => makeQueryClientWith(definition, httpClient));
|
|
507
|
-
const isAnalyticsEngineDataset = (value) =>
|
|
508
|
-
|
|
509
|
-
return typeof Reflect.get(value, "writeDataPoint") === "function";
|
|
510
|
-
};
|
|
511
|
-
const makeClient$15 = (definition, defaults) => (dataset) => {
|
|
458
|
+
const isAnalyticsEngineDataset = (value) => Predicate.hasProperty(value, "writeDataPoint") && Predicate.isFunction(value.writeDataPoint);
|
|
459
|
+
const makeClient$13 = (definition, defaults) => (dataset) => {
|
|
512
460
|
return {
|
|
513
461
|
definition,
|
|
514
462
|
writeDataPoint: Effect.fn("AnalyticsEngine.writeDataPoint")((dataPoint, options) => {
|
|
@@ -538,12 +486,12 @@ const queryLayerConfig = (tag, config = queryConfig()) => Layer.effect(tag, Effe
|
|
|
538
486
|
return yield* makeQueryClient(definition);
|
|
539
487
|
}));
|
|
540
488
|
const layerFetchConfig = (tag, config = queryConfig()) => queryLayerConfig(tag, config).pipe(Layer.provide(FetchHttpClient.layer));
|
|
541
|
-
const layer$
|
|
542
|
-
const make$
|
|
489
|
+
const layer$16 = (tag, definition) => layer$19(tag, definition.binding, isAnalyticsEngineDataset, makeClient$13(definition, definition.write), { expected: expectedAnalyticsEngineDataset });
|
|
490
|
+
const make$16 = (id) => Tag$14()(id);
|
|
543
491
|
const makeQuery = (id) => QueryTag()(id);
|
|
544
|
-
const Tag$
|
|
492
|
+
const Tag$14 = () => (id) => {
|
|
545
493
|
const tag = Context.Service()(id);
|
|
546
|
-
const makeLayer = (definition) => layer$
|
|
494
|
+
const makeLayer = (definition) => layer$16(tag, definition);
|
|
547
495
|
return Object.assign(tag, {
|
|
548
496
|
id,
|
|
549
497
|
layer: makeLayer
|
|
@@ -564,125 +512,6 @@ const QueryTag = () => (id) => {
|
|
|
564
512
|
});
|
|
565
513
|
};
|
|
566
514
|
//#endregion
|
|
567
|
-
//#region src/Artifacts.ts
|
|
568
|
-
var Artifacts_exports = /* @__PURE__ */ __exportAll({
|
|
569
|
-
ArtifactsOperationError: () => ArtifactsOperationError,
|
|
570
|
-
Tag: () => Tag$14,
|
|
571
|
-
artifactsErrorCodes: () => artifactsErrorCodes,
|
|
572
|
-
artifactsErrorNumericCodes: () => artifactsErrorNumericCodes,
|
|
573
|
-
isArtifactsBinding: () => isArtifactsBinding,
|
|
574
|
-
isArtifactsRepoBinding: () => isArtifactsRepoBinding,
|
|
575
|
-
layer: () => layer$16,
|
|
576
|
-
make: () => make$16,
|
|
577
|
-
makeClient: () => makeClient$14
|
|
578
|
-
});
|
|
579
|
-
const expectedArtifactsBinding = "Artifacts binding with create(), get(), import(), list(), and delete()";
|
|
580
|
-
const expectedArtifactsRepo = "Artifacts repo handle with createToken(), listTokens(), revokeToken(), fork(), log(), readCommit(), and readTree()";
|
|
581
|
-
/** Documented string error codes returned by Cloudflare Artifacts. */
|
|
582
|
-
const artifactsErrorCodes = [
|
|
583
|
-
"ALREADY_EXISTS",
|
|
584
|
-
"NOT_FOUND",
|
|
585
|
-
"IMPORT_IN_PROGRESS",
|
|
586
|
-
"FORK_IN_PROGRESS",
|
|
587
|
-
"INVALID_INPUT",
|
|
588
|
-
"INVALID_REPO_NAME",
|
|
589
|
-
"INVALID_TTL",
|
|
590
|
-
"INVALID_URL",
|
|
591
|
-
"REMOTE_AUTH_REQUIRED",
|
|
592
|
-
"UPSTREAM_UNAVAILABLE",
|
|
593
|
-
"MEMORY_LIMIT",
|
|
594
|
-
"INTERNAL_ERROR"
|
|
595
|
-
];
|
|
596
|
-
/** Documented numeric error codes returned by Cloudflare Artifacts. */
|
|
597
|
-
const artifactsErrorNumericCodes = {
|
|
598
|
-
ALREADY_EXISTS: 10201,
|
|
599
|
-
NOT_FOUND: 10200,
|
|
600
|
-
IMPORT_IN_PROGRESS: 10302,
|
|
601
|
-
FORK_IN_PROGRESS: 10303,
|
|
602
|
-
INVALID_INPUT: 10100,
|
|
603
|
-
INVALID_REPO_NAME: 10101,
|
|
604
|
-
INVALID_TTL: 10103,
|
|
605
|
-
INVALID_URL: 10104,
|
|
606
|
-
REMOTE_AUTH_REQUIRED: 10106,
|
|
607
|
-
UPSTREAM_UNAVAILABLE: 10401,
|
|
608
|
-
MEMORY_LIMIT: 10402,
|
|
609
|
-
INTERNAL_ERROR: 10400
|
|
610
|
-
};
|
|
611
|
-
/** Error raised when a Cloudflare Artifacts operation fails. */
|
|
612
|
-
var ArtifactsOperationError = class extends Data.TaggedError("ArtifactsOperationError") {
|
|
613
|
-
get message() {
|
|
614
|
-
const code = this.code === void 0 ? "" : ` (${this.code})`;
|
|
615
|
-
return `Artifacts ${this.operation} failed for binding "${this.binding}"${code}: ${causeMessage(this.cause)}`;
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
const artifactsErrorDetails$1 = (cause) => {
|
|
619
|
-
if (typeof cause !== "object" || cause === null) return {};
|
|
620
|
-
const code = Reflect.get(cause, "code");
|
|
621
|
-
const numericCode = Reflect.get(cause, "numericCode");
|
|
622
|
-
return {
|
|
623
|
-
...typeof code === "string" ? { code } : {},
|
|
624
|
-
...typeof numericCode === "number" ? { numericCode } : {}
|
|
625
|
-
};
|
|
626
|
-
};
|
|
627
|
-
const artifactsError = (binding, operation, cause) => new ArtifactsOperationError({
|
|
628
|
-
binding,
|
|
629
|
-
operation,
|
|
630
|
-
cause,
|
|
631
|
-
...artifactsErrorDetails$1(cause)
|
|
632
|
-
});
|
|
633
|
-
const tryArtifactsPromise = (binding, operation, evaluate) => Effect.tryPromise({
|
|
634
|
-
try: evaluate,
|
|
635
|
-
catch: (cause) => artifactsError(binding, operation, cause)
|
|
636
|
-
});
|
|
637
|
-
const spanOptions$4 = (binding, operation) => ({ attributes: {
|
|
638
|
-
binding,
|
|
639
|
-
operation
|
|
640
|
-
} });
|
|
641
|
-
const hasFunction$3 = (value, key) => typeof Reflect.get(value, key) === "function";
|
|
642
|
-
/** Tests whether a value exposes the complete documented Artifacts repo handle API. */
|
|
643
|
-
const isArtifactsRepoBinding = (value) => typeof value === "object" && value !== null && hasFunction$3(value, "createToken") && hasFunction$3(value, "listTokens") && hasFunction$3(value, "revokeToken") && hasFunction$3(value, "fork") && hasFunction$3(value, "log") && hasFunction$3(value, "readCommit") && hasFunction$3(value, "readTree");
|
|
644
|
-
/** Tests whether a value exposes the complete documented Artifacts namespace API. */
|
|
645
|
-
const isArtifactsBinding = (value) => typeof value === "object" && value !== null && hasFunction$3(value, "create") && hasFunction$3(value, "get") && hasFunction$3(value, "import") && hasFunction$3(value, "list") && hasFunction$3(value, "delete");
|
|
646
|
-
const wrapRepo = (binding, repo) => ({
|
|
647
|
-
id: repo.id,
|
|
648
|
-
name: repo.name,
|
|
649
|
-
description: repo.description,
|
|
650
|
-
defaultBranch: repo.defaultBranch,
|
|
651
|
-
createdAt: repo.createdAt,
|
|
652
|
-
updatedAt: repo.updatedAt,
|
|
653
|
-
lastPushAt: repo.lastPushAt,
|
|
654
|
-
source: repo.source,
|
|
655
|
-
readOnly: repo.readOnly,
|
|
656
|
-
remote: repo.remote,
|
|
657
|
-
createToken: Effect.fn("Artifacts.createToken", spanOptions$4(binding, "createToken"))((scope, ttl) => tryArtifactsPromise(binding, "createToken", () => repo.createToken(scope, ttl))),
|
|
658
|
-
listTokens: tryArtifactsPromise(binding, "listTokens", () => repo.listTokens()).pipe(Effect.withSpan("Artifacts.listTokens", spanOptions$4(binding, "listTokens"))),
|
|
659
|
-
revokeToken: Effect.fn("Artifacts.revokeToken", spanOptions$4(binding, "revokeToken"))((tokenOrId) => tryArtifactsPromise(binding, "revokeToken", () => repo.revokeToken(tokenOrId))),
|
|
660
|
-
fork: Effect.fn("Artifacts.fork", spanOptions$4(binding, "fork"))((name, options) => tryArtifactsPromise(binding, "fork", () => repo.fork(name, options))),
|
|
661
|
-
log: Effect.fn("Artifacts.log", spanOptions$4(binding, "log"))((options) => tryArtifactsPromise(binding, "log", () => repo.log(options))),
|
|
662
|
-
readCommit: Effect.fn("Artifacts.readCommit", spanOptions$4(binding, "readCommit"))((hash) => tryArtifactsPromise(binding, "readCommit", () => repo.readCommit(hash))),
|
|
663
|
-
readTree: Effect.fn("Artifacts.readTree", spanOptions$4(binding, "readTree"))((hash) => tryArtifactsPromise(binding, "readTree", () => repo.readTree(hash))),
|
|
664
|
-
raw: repo
|
|
665
|
-
});
|
|
666
|
-
const makeClient$14 = (definition) => (artifacts) => ({
|
|
667
|
-
definition,
|
|
668
|
-
create: Effect.fn("Artifacts.create", spanOptions$4(definition.binding, "create"))((name, options) => tryArtifactsPromise(definition.binding, "create", () => artifacts.create(name, options))),
|
|
669
|
-
get: Effect.fn("Artifacts.get", spanOptions$4(definition.binding, "get"))((name) => tryArtifactsPromise(definition.binding, "get", () => artifacts.get(name)).pipe(Effect.flatMap((repo) => isArtifactsRepoBinding(repo) ? Effect.succeed(wrapRepo(definition.binding, repo)) : Effect.fail(artifactsError(definition.binding, "get", /* @__PURE__ */ new TypeError(`Expected ${expectedArtifactsRepo}`)))))),
|
|
670
|
-
import: Effect.fn("Artifacts.import", spanOptions$4(definition.binding, "import"))((params) => tryArtifactsPromise(definition.binding, "import", () => artifacts.import(params))),
|
|
671
|
-
list: Effect.fn("Artifacts.list", spanOptions$4(definition.binding, "list"))((options) => tryArtifactsPromise(definition.binding, "list", () => artifacts.list(options))),
|
|
672
|
-
delete: Effect.fn("Artifacts.delete", spanOptions$4(definition.binding, "delete"))((name) => tryArtifactsPromise(definition.binding, "delete", () => artifacts.delete(name))),
|
|
673
|
-
rawUnsafe: Effect.succeed(artifacts)
|
|
674
|
-
});
|
|
675
|
-
const layer$16 = (tag, definition) => layer$20(tag, definition.binding, isArtifactsBinding, makeClient$14(definition), { expected: expectedArtifactsBinding });
|
|
676
|
-
const make$16 = (id) => Tag$14()(id);
|
|
677
|
-
const Tag$14 = () => (id) => {
|
|
678
|
-
const tag = Context.Service()(id);
|
|
679
|
-
const makeLayer = (definition) => layer$16(tag, definition);
|
|
680
|
-
return Object.assign(tag, {
|
|
681
|
-
id,
|
|
682
|
-
layer: makeLayer
|
|
683
|
-
});
|
|
684
|
-
};
|
|
685
|
-
//#endregion
|
|
686
515
|
//#region src/BrowserRendering.ts
|
|
687
516
|
var BrowserRendering_exports = /* @__PURE__ */ __exportAll({
|
|
688
517
|
BrowserRenderingOperationError: () => BrowserRenderingOperationError,
|
|
@@ -690,7 +519,7 @@ var BrowserRendering_exports = /* @__PURE__ */ __exportAll({
|
|
|
690
519
|
isBrowserRenderingBinding: () => isBrowserRenderingBinding,
|
|
691
520
|
layer: () => layer$15,
|
|
692
521
|
make: () => make$15,
|
|
693
|
-
makeClient: () => makeClient$
|
|
522
|
+
makeClient: () => makeClient$12
|
|
694
523
|
});
|
|
695
524
|
const expectedBrowserRenderingBinding = "Browser Rendering binding resource";
|
|
696
525
|
/** Error raised when a Browser Rendering operation fails. */
|
|
@@ -718,9 +547,18 @@ const wrapPage = (binding, page) => ({
|
|
|
718
547
|
goto: (url, options) => page.goto === void 0 ? missingMethod(binding, "goto") : tryBrowserRenderingPromise(binding, "goto", () => page.goto(url, options)),
|
|
719
548
|
setContent: (html, options) => page.setContent === void 0 ? missingMethod(binding, "setContent") : tryBrowserRenderingPromise(binding, "setContent", () => page.setContent(html, options)),
|
|
720
549
|
content: page.content === void 0 ? missingMethod(binding, "content") : tryBrowserRenderingPromise(binding, "content", () => page.content()),
|
|
721
|
-
screenshot: (options) =>
|
|
722
|
-
|
|
723
|
-
|
|
550
|
+
screenshot: (options) => {
|
|
551
|
+
const screenshot = page.screenshot?.bind(page);
|
|
552
|
+
return screenshot === void 0 ? missingMethod(binding, "screenshot") : tryBrowserRenderingPromise(binding, "screenshot", () => screenshot(options));
|
|
553
|
+
},
|
|
554
|
+
pdf: (options) => {
|
|
555
|
+
const pdf = page.pdf?.bind(page);
|
|
556
|
+
return pdf === void 0 ? missingMethod(binding, "pdf") : tryBrowserRenderingPromise(binding, "pdf", () => pdf(options));
|
|
557
|
+
},
|
|
558
|
+
evaluate: (pageFunction, ...args) => {
|
|
559
|
+
const evaluate = page.evaluate?.bind(page);
|
|
560
|
+
return evaluate === void 0 ? missingMethod(binding, "evaluate") : tryBrowserRenderingPromise(binding, "evaluate", () => evaluate(pageFunction, ...args));
|
|
561
|
+
},
|
|
724
562
|
close: (options) => page.close === void 0 ? Effect.void : tryBrowserRenderingPromise(binding, "closePage", () => page.close(options))
|
|
725
563
|
});
|
|
726
564
|
const wrapBrowser = (binding, browser) => ({
|
|
@@ -730,14 +568,14 @@ const wrapBrowser = (binding, browser) => ({
|
|
|
730
568
|
close: browser.close === void 0 ? Effect.void : tryBrowserRenderingPromise(binding, "closeBrowser", () => browser.close()),
|
|
731
569
|
disconnect: browser.disconnect === void 0 ? Effect.void : tryBrowserRenderingSync(binding, "disconnect", () => browser.disconnect())
|
|
732
570
|
});
|
|
733
|
-
const isBrowserRenderingBinding = (value) => (
|
|
734
|
-
const makeClient$
|
|
571
|
+
const isBrowserRenderingBinding = (value) => Predicate.isObjectOrArray(value) || Predicate.isFunction(value);
|
|
572
|
+
const makeClient$12 = (definition) => (binding) => ({
|
|
735
573
|
definition,
|
|
736
574
|
launchWith: (launch, options) => tryBrowserRenderingPromise(definition.binding, "launch", () => launch(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser)), Effect.withSpan("BrowserRendering.launchWith")),
|
|
737
575
|
connectWith: (connect, options) => tryBrowserRenderingPromise(definition.binding, "connect", () => connect(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser)), Effect.withSpan("BrowserRendering.connectWith")),
|
|
738
576
|
rawUnsafe: Effect.succeed(binding)
|
|
739
577
|
});
|
|
740
|
-
const layer$15 = (tag, definition) => layer$
|
|
578
|
+
const layer$15 = (tag, definition) => layer$19(tag, definition.binding, isBrowserRenderingBinding, makeClient$12(definition), { expected: expectedBrowserRenderingBinding });
|
|
741
579
|
const make$15 = (id) => Tag$13()(id);
|
|
742
580
|
const Tag$13 = () => (id) => {
|
|
743
581
|
const tag = Context.Service()(id);
|
|
@@ -755,7 +593,7 @@ var Cache_exports = /* @__PURE__ */ __exportAll({
|
|
|
755
593
|
layer: () => layer$14,
|
|
756
594
|
layerFrom: () => layerFrom,
|
|
757
595
|
makeCacheClient: () => makeCacheClient,
|
|
758
|
-
makeClient: () => makeClient$
|
|
596
|
+
makeClient: () => makeClient$11
|
|
759
597
|
});
|
|
760
598
|
/** Error raised when a Cloudflare Cache API operation fails. */
|
|
761
599
|
var CacheOperationError = class extends Data.TaggedError("CacheOperationError") {
|
|
@@ -774,28 +612,28 @@ const tryCachePromise = (cache, operation, evaluate) => Effect.tryPromise({
|
|
|
774
612
|
try: evaluate,
|
|
775
613
|
catch: (cause) => cacheError(cache, operation, cause)
|
|
776
614
|
});
|
|
777
|
-
const spanOptions$
|
|
615
|
+
const spanOptions$2 = (cache, operation) => ({ attributes: {
|
|
778
616
|
cache,
|
|
779
617
|
operation
|
|
780
618
|
} });
|
|
781
619
|
/** Wraps a native Cloudflare `Cache` instance. */
|
|
782
620
|
const makeCacheClient = (cache, name = "default") => ({
|
|
783
621
|
name,
|
|
784
|
-
match: Effect.fn("Cache.match", spanOptions$
|
|
785
|
-
put: Effect.fn("Cache.put", spanOptions$
|
|
786
|
-
delete: Effect.fn("Cache.delete", spanOptions$
|
|
622
|
+
match: Effect.fn("Cache.match", spanOptions$2(name, "match"))((request, options) => tryCachePromise(name, "match", () => cache.match(request, options)).pipe(Effect.map(Option.fromUndefinedOr))),
|
|
623
|
+
put: Effect.fn("Cache.put", spanOptions$2(name, "put"))((request, response) => tryCachePromise(name, "put", () => cache.put(request, response))),
|
|
624
|
+
delete: Effect.fn("Cache.delete", spanOptions$2(name, "delete"))((request, options) => tryCachePromise(name, "delete", () => cache.delete(request, options))),
|
|
787
625
|
rawUnsafe: Effect.succeed(cache)
|
|
788
626
|
});
|
|
789
627
|
/** Wraps a native Cloudflare `CacheStorage` instance. */
|
|
790
|
-
const makeClient$
|
|
628
|
+
const makeClient$11 = (storage) => ({
|
|
791
629
|
default: makeCacheClient(storage.default),
|
|
792
|
-
open: (name) => tryCachePromise(name, "open", () => storage.open(name)).pipe(Effect.map((cache) => makeCacheClient(cache, name)), Effect.withSpan("Cache.open", spanOptions$
|
|
630
|
+
open: (name) => tryCachePromise(name, "open", () => storage.open(name)).pipe(Effect.map((cache) => makeCacheClient(cache, name)), Effect.withSpan("Cache.open", spanOptions$2(name, "open"))),
|
|
793
631
|
rawUnsafe: Effect.succeed(storage)
|
|
794
632
|
});
|
|
795
633
|
/** Provides Cache API services from an explicit native `CacheStorage` instance. */
|
|
796
|
-
const layerFrom = (storage) => Layer.succeed(CacheStorage, makeClient$
|
|
634
|
+
const layerFrom = (storage) => Layer.succeed(CacheStorage, makeClient$11(storage));
|
|
797
635
|
/** Provides Cache API services from Cloudflare's global `caches` object. */
|
|
798
|
-
const layer$14 = Layer.sync(CacheStorage, () => makeClient$
|
|
636
|
+
const layer$14 = Layer.sync(CacheStorage, () => makeClient$11(caches));
|
|
799
637
|
//#endregion
|
|
800
638
|
//#region src/CloudflareOtlp.ts
|
|
801
639
|
/**
|
|
@@ -919,650 +757,6 @@ const layerDurableObject = (options = {}) => Layer.unwrap(Effect.map(DurableObje
|
|
|
919
757
|
"cloudflare.durable_object.id": options.includeObjectId ? state.id.toString() : void 0
|
|
920
758
|
})));
|
|
921
759
|
//#endregion
|
|
922
|
-
//#region src/ComputerArtifacts.ts
|
|
923
|
-
var ComputerArtifacts_exports = /* @__PURE__ */ __exportAll({
|
|
924
|
-
fromClient: () => fromClient,
|
|
925
|
-
makeClient: () => makeClient$11
|
|
926
|
-
});
|
|
927
|
-
const artifactsErrorDetails = (cause) => {
|
|
928
|
-
if (typeof cause !== "object" || cause === null) return {};
|
|
929
|
-
const code = Reflect.get(cause, "code");
|
|
930
|
-
const numericCode = Reflect.get(cause, "numericCode");
|
|
931
|
-
return {
|
|
932
|
-
...typeof code === "string" ? { code } : {},
|
|
933
|
-
...typeof numericCode === "number" ? { numericCode } : {}
|
|
934
|
-
};
|
|
935
|
-
};
|
|
936
|
-
const operationError = (binding, operation, cause) => new ArtifactsOperationError({
|
|
937
|
-
binding,
|
|
938
|
-
operation,
|
|
939
|
-
cause,
|
|
940
|
-
...artifactsErrorDetails(cause)
|
|
941
|
-
});
|
|
942
|
-
const tryOperation = (binding, operation, evaluate) => Effect.tryPromise({
|
|
943
|
-
try: evaluate,
|
|
944
|
-
catch: (cause) => operationError(binding, operation, cause)
|
|
945
|
-
});
|
|
946
|
-
const spanOptions$2 = (binding, sessionId, operation) => ({ attributes: {
|
|
947
|
-
binding,
|
|
948
|
-
sessionId,
|
|
949
|
-
operation
|
|
950
|
-
} });
|
|
951
|
-
/** Wraps an already-created upstream session client. */
|
|
952
|
-
const fromClient = (client, options = {}) => {
|
|
953
|
-
const binding = options.binding ?? "ARTIFACTS";
|
|
954
|
-
const { sessionId } = client;
|
|
955
|
-
return {
|
|
956
|
-
sessionId,
|
|
957
|
-
create: Effect.fn("ComputerArtifacts.create", spanOptions$2(binding, sessionId, "create"))(function* (name, createOptions) {
|
|
958
|
-
yield* Effect.annotateCurrentSpan("repo", name);
|
|
959
|
-
return yield* tryOperation(binding, "create", () => client.create(name, createOptions));
|
|
960
|
-
}),
|
|
961
|
-
get: Effect.fn("ComputerArtifacts.get", spanOptions$2(binding, sessionId, "get"))(function* (name) {
|
|
962
|
-
yield* Effect.annotateCurrentSpan("repo", name);
|
|
963
|
-
return yield* tryOperation(binding, "get", () => client.get(name));
|
|
964
|
-
}),
|
|
965
|
-
list: tryOperation(binding, "list", () => client.list()).pipe(Effect.withSpan("ComputerArtifacts.list", spanOptions$2(binding, sessionId, "list"))),
|
|
966
|
-
import: Effect.fn("ComputerArtifacts.import", spanOptions$2(binding, sessionId, "import"))(function* (name, source, importOptions) {
|
|
967
|
-
yield* Effect.annotateCurrentSpan("repo", name);
|
|
968
|
-
return yield* tryOperation(binding, "import", () => client.import(name, source, importOptions));
|
|
969
|
-
}),
|
|
970
|
-
delete: Effect.fn("ComputerArtifacts.delete", spanOptions$2(binding, sessionId, "delete"))(function* (name) {
|
|
971
|
-
yield* Effect.annotateCurrentSpan("repo", name);
|
|
972
|
-
return yield* tryOperation(binding, "delete", () => client.delete(name));
|
|
973
|
-
}),
|
|
974
|
-
createToken: Effect.fn("ComputerArtifacts.createToken", spanOptions$2(binding, sessionId, "createToken"))(function* (name, scope, ttl) {
|
|
975
|
-
yield* Effect.annotateCurrentSpan("repo", name);
|
|
976
|
-
return yield* tryOperation(binding, "createToken", () => client.createToken(name, scope, ttl));
|
|
977
|
-
}),
|
|
978
|
-
listTokens: Effect.fn("ComputerArtifacts.listTokens", spanOptions$2(binding, sessionId, "listTokens"))(function* (name) {
|
|
979
|
-
yield* Effect.annotateCurrentSpan("repo", name);
|
|
980
|
-
return yield* tryOperation(binding, "listTokens", () => client.listTokens(name));
|
|
981
|
-
}),
|
|
982
|
-
getToken: Effect.fn("ComputerArtifacts.getToken", spanOptions$2(binding, sessionId, "getToken"))(function* (name, id) {
|
|
983
|
-
yield* Effect.annotateCurrentSpan({
|
|
984
|
-
repo: name,
|
|
985
|
-
tokenId: id
|
|
986
|
-
});
|
|
987
|
-
return yield* tryOperation(binding, "getToken", () => client.getToken(name, id));
|
|
988
|
-
}),
|
|
989
|
-
revokeToken: Effect.fn("ComputerArtifacts.revokeToken", spanOptions$2(binding, sessionId, "revokeToken"))(function* (name, tokenOrId) {
|
|
990
|
-
yield* Effect.annotateCurrentSpan("repo", name);
|
|
991
|
-
return yield* tryOperation(binding, "revokeToken", () => client.revokeToken(name, tokenOrId));
|
|
992
|
-
}),
|
|
993
|
-
cli: Effect.fn("ComputerArtifacts.cli", spanOptions$2(binding, sessionId, "cli"))(function* (input) {
|
|
994
|
-
yield* Effect.annotateCurrentSpan("argv", input.argv.join(" "));
|
|
995
|
-
return yield* tryOperation(binding, "cli", () => client.cli(input));
|
|
996
|
-
}),
|
|
997
|
-
rawUnsafe: Effect.succeed(client)
|
|
998
|
-
};
|
|
999
|
-
};
|
|
1000
|
-
/**
|
|
1001
|
-
* Creates an Effect-native session client directly from a Worker Artifacts
|
|
1002
|
-
* binding. `@cloudflare/computer` is loaded only when this Effect runs, keeping
|
|
1003
|
-
* the optional peer out of applications that do not use this integration.
|
|
1004
|
-
*/
|
|
1005
|
-
const makeClient$11 = Effect.fn("ComputerArtifacts.makeClient")(function* (bindingValue, sessionId, options = {}) {
|
|
1006
|
-
const binding = options.binding ?? "ARTIFACTS";
|
|
1007
|
-
const computerArtifacts = yield* Effect.tryPromise({
|
|
1008
|
-
try: () => import("@cloudflare/computer/artifacts"),
|
|
1009
|
-
catch: (cause) => operationError(binding, "createClient", cause)
|
|
1010
|
-
});
|
|
1011
|
-
const client = yield* Effect.try({
|
|
1012
|
-
try: () => computerArtifacts.createArtifact(bindingValue, sessionId),
|
|
1013
|
-
catch: (cause) => operationError(binding, "createClient", cause)
|
|
1014
|
-
});
|
|
1015
|
-
return fromClient(client, { binding });
|
|
1016
|
-
});
|
|
1017
|
-
//#endregion
|
|
1018
|
-
//#region src/ComputerWorkspace.ts
|
|
1019
|
-
var ComputerWorkspace_exports = /* @__PURE__ */ __exportAll({
|
|
1020
|
-
ComputerWorkspace: () => ComputerWorkspace,
|
|
1021
|
-
WorkspaceAssetsError: () => WorkspaceAssetsError,
|
|
1022
|
-
WorkspaceExecError: () => WorkspaceExecError,
|
|
1023
|
-
WorkspaceFsError: () => WorkspaceFsError,
|
|
1024
|
-
WorkspaceGitError: () => WorkspaceGitError,
|
|
1025
|
-
fromWorkspaceClient: () => fromWorkspaceClient
|
|
1026
|
-
});
|
|
1027
|
-
/**
|
|
1028
|
-
* Workspace errors use `Schema.TaggedError`, unlike most local binding errors,
|
|
1029
|
-
* because workspace operations commonly sit behind Durable Object RPC methods.
|
|
1030
|
-
* The schema form preserves the operation-family tags across that boundary.
|
|
1031
|
-
*/
|
|
1032
|
-
var WorkspaceFsError = class extends Schema.TaggedError()("WorkspaceFsError", {
|
|
1033
|
-
operation: Schema.String,
|
|
1034
|
-
path: Schema.String,
|
|
1035
|
-
message: Schema.String,
|
|
1036
|
-
code: Schema.optionalKey(Schema.String),
|
|
1037
|
-
cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
|
|
1038
|
-
}) {};
|
|
1039
|
-
/** Schema-serializable error for a workspace Git operation. */
|
|
1040
|
-
var WorkspaceGitError = class extends Schema.TaggedError()("WorkspaceGitError", {
|
|
1041
|
-
operation: Schema.String,
|
|
1042
|
-
message: Schema.String,
|
|
1043
|
-
code: Schema.optionalKey(Schema.String),
|
|
1044
|
-
cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
|
|
1045
|
-
}) {};
|
|
1046
|
-
/** Schema-serializable error for a workspace runtime operation. */
|
|
1047
|
-
var WorkspaceExecError = class extends Schema.TaggedError()("WorkspaceExecError", {
|
|
1048
|
-
operation: Schema.String,
|
|
1049
|
-
message: Schema.String,
|
|
1050
|
-
code: Schema.optionalKey(Schema.String),
|
|
1051
|
-
cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
|
|
1052
|
-
}) {};
|
|
1053
|
-
/** Schema-serializable error for a workspace Assets operation. */
|
|
1054
|
-
var WorkspaceAssetsError = class extends Schema.TaggedError()("WorkspaceAssetsError", {
|
|
1055
|
-
operation: Schema.String,
|
|
1056
|
-
path: Schema.String,
|
|
1057
|
-
message: Schema.String,
|
|
1058
|
-
code: Schema.optionalKey(Schema.String),
|
|
1059
|
-
cause: Schema.optionalKey(Schema.Defect({ includeStack: true }))
|
|
1060
|
-
}) {};
|
|
1061
|
-
const errorMessage = (cause) => cause instanceof Error ? cause.message : String(cause);
|
|
1062
|
-
const errorCode = (cause) => {
|
|
1063
|
-
if (typeof cause !== "object" || cause === null) return;
|
|
1064
|
-
const code = Reflect.get(cause, "code");
|
|
1065
|
-
return typeof code === "string" ? code : void 0;
|
|
1066
|
-
};
|
|
1067
|
-
const fsError = (operation, path, cause) => WorkspaceFsError.make({
|
|
1068
|
-
operation,
|
|
1069
|
-
path,
|
|
1070
|
-
message: errorMessage(cause),
|
|
1071
|
-
cause,
|
|
1072
|
-
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
1073
|
-
});
|
|
1074
|
-
const gitError = (operation, cause) => WorkspaceGitError.make({
|
|
1075
|
-
operation,
|
|
1076
|
-
message: errorMessage(cause),
|
|
1077
|
-
cause,
|
|
1078
|
-
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
1079
|
-
});
|
|
1080
|
-
const execError = (operation, cause) => WorkspaceExecError.make({
|
|
1081
|
-
operation,
|
|
1082
|
-
message: errorMessage(cause),
|
|
1083
|
-
cause,
|
|
1084
|
-
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
1085
|
-
});
|
|
1086
|
-
const assetsError = (operation, path, cause) => WorkspaceAssetsError.make({
|
|
1087
|
-
operation,
|
|
1088
|
-
path,
|
|
1089
|
-
message: errorMessage(cause),
|
|
1090
|
-
cause,
|
|
1091
|
-
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
1092
|
-
});
|
|
1093
|
-
const tryFs = (operation, path, evaluate) => Effect.tryPromise({
|
|
1094
|
-
try: evaluate,
|
|
1095
|
-
catch: (cause) => fsError(operation, path, cause)
|
|
1096
|
-
});
|
|
1097
|
-
const isNotFound = (error) => error.code === "ENOENT" || /ENOENT|no such/i.test(error.message);
|
|
1098
|
-
const makeFilesystem = (fsClient) => {
|
|
1099
|
-
const readFile = Effect.fn("ComputerWorkspace.fs.readFile", { attributes: {
|
|
1100
|
-
family: "fs",
|
|
1101
|
-
operation: "readFile"
|
|
1102
|
-
} })(function* (path, options = {}) {
|
|
1103
|
-
yield* Effect.annotateCurrentSpan("path", path);
|
|
1104
|
-
const { encoding = "utf8", ...readOptions } = options;
|
|
1105
|
-
if (encoding === "stream") return yield* tryFs("readFile", path, () => fsClient.readFile(path, readOptions));
|
|
1106
|
-
return yield* tryFs("readFile", path, () => fsClient.readFile(path, {
|
|
1107
|
-
...readOptions,
|
|
1108
|
-
encoding: "utf8"
|
|
1109
|
-
}));
|
|
1110
|
-
});
|
|
1111
|
-
const stat = Effect.fn("ComputerWorkspace.fs.stat", { attributes: {
|
|
1112
|
-
family: "fs",
|
|
1113
|
-
operation: "stat"
|
|
1114
|
-
} })(function* (path) {
|
|
1115
|
-
yield* Effect.annotateCurrentSpan("path", path);
|
|
1116
|
-
return yield* tryFs("stat", path, () => fsClient.stat(path));
|
|
1117
|
-
});
|
|
1118
|
-
return {
|
|
1119
|
-
readFile,
|
|
1120
|
-
stat,
|
|
1121
|
-
lstat: Effect.fn("ComputerWorkspace.fs.lstat", { attributes: {
|
|
1122
|
-
family: "fs",
|
|
1123
|
-
operation: "lstat"
|
|
1124
|
-
} })(function* (path) {
|
|
1125
|
-
yield* Effect.annotateCurrentSpan("path", path);
|
|
1126
|
-
return yield* tryFs("lstat", path, () => fsClient.lstat(path));
|
|
1127
|
-
}),
|
|
1128
|
-
exists: Effect.fn("ComputerWorkspace.fs.exists", { attributes: {
|
|
1129
|
-
family: "fs",
|
|
1130
|
-
operation: "exists"
|
|
1131
|
-
} })(function* (path) {
|
|
1132
|
-
yield* Effect.annotateCurrentSpan("path", path);
|
|
1133
|
-
return yield* stat(path).pipe(Effect.as(true), Effect.catch((error) => isNotFound(error) ? Effect.succeed(false) : Effect.fail(error)));
|
|
1134
|
-
}),
|
|
1135
|
-
readlink: Effect.fn("ComputerWorkspace.fs.readlink", { attributes: {
|
|
1136
|
-
family: "fs",
|
|
1137
|
-
operation: "readlink"
|
|
1138
|
-
} })(function* (path) {
|
|
1139
|
-
yield* Effect.annotateCurrentSpan("path", path);
|
|
1140
|
-
return yield* tryFs("readlink", path, () => fsClient.readlink(path));
|
|
1141
|
-
}),
|
|
1142
|
-
readdir: Effect.fn("ComputerWorkspace.fs.readdir", { attributes: {
|
|
1143
|
-
family: "fs",
|
|
1144
|
-
operation: "readdir"
|
|
1145
|
-
} })(function* (path, options) {
|
|
1146
|
-
yield* Effect.annotateCurrentSpan("path", path);
|
|
1147
|
-
return yield* tryFs("readdir", path, () => fsClient.readdir(path, options));
|
|
1148
|
-
}),
|
|
1149
|
-
find: Effect.fn("ComputerWorkspace.fs.find", { attributes: {
|
|
1150
|
-
family: "fs",
|
|
1151
|
-
operation: "find"
|
|
1152
|
-
} })(function* (directory, pattern, options) {
|
|
1153
|
-
yield* Effect.annotateCurrentSpan({
|
|
1154
|
-
path: directory,
|
|
1155
|
-
pattern
|
|
1156
|
-
});
|
|
1157
|
-
return yield* tryFs("find", directory, () => fsClient.find(directory, pattern, options));
|
|
1158
|
-
}),
|
|
1159
|
-
ls: Effect.fn("ComputerWorkspace.fs.ls", { attributes: {
|
|
1160
|
-
family: "fs",
|
|
1161
|
-
operation: "ls"
|
|
1162
|
-
} })(function* (prefix) {
|
|
1163
|
-
yield* Effect.annotateCurrentSpan("path", prefix);
|
|
1164
|
-
return yield* tryFs("ls", prefix, () => fsClient.ls(prefix));
|
|
1165
|
-
}),
|
|
1166
|
-
grep: Effect.fn("ComputerWorkspace.fs.grep", { attributes: {
|
|
1167
|
-
family: "fs",
|
|
1168
|
-
operation: "grep"
|
|
1169
|
-
} })(function* (pattern, path, options) {
|
|
1170
|
-
yield* Effect.annotateCurrentSpan({
|
|
1171
|
-
path,
|
|
1172
|
-
pattern
|
|
1173
|
-
});
|
|
1174
|
-
return yield* tryFs("grep", path, () => fsClient.grep(pattern, path, options));
|
|
1175
|
-
}),
|
|
1176
|
-
writeFile: Effect.fn("ComputerWorkspace.fs.writeFile", { attributes: {
|
|
1177
|
-
family: "fs",
|
|
1178
|
-
operation: "writeFile"
|
|
1179
|
-
} })(function* (path, content, options) {
|
|
1180
|
-
yield* Effect.annotateCurrentSpan("path", path);
|
|
1181
|
-
yield* tryFs("writeFile", path, () => fsClient.writeFile(path, content, options));
|
|
1182
|
-
}),
|
|
1183
|
-
mkdir: Effect.fn("ComputerWorkspace.fs.mkdir", { attributes: {
|
|
1184
|
-
family: "fs",
|
|
1185
|
-
operation: "mkdir"
|
|
1186
|
-
} })(function* (path, options) {
|
|
1187
|
-
yield* Effect.annotateCurrentSpan("path", path);
|
|
1188
|
-
yield* tryFs("mkdir", path, () => fsClient.mkdir(path, options));
|
|
1189
|
-
}),
|
|
1190
|
-
rm: Effect.fn("ComputerWorkspace.fs.rm", { attributes: {
|
|
1191
|
-
family: "fs",
|
|
1192
|
-
operation: "rm"
|
|
1193
|
-
} })(function* (path, options) {
|
|
1194
|
-
yield* Effect.annotateCurrentSpan("path", path);
|
|
1195
|
-
yield* tryFs("rm", path, () => fsClient.rm(path, options));
|
|
1196
|
-
}),
|
|
1197
|
-
chmod: Effect.fn("ComputerWorkspace.fs.chmod", { attributes: {
|
|
1198
|
-
family: "fs",
|
|
1199
|
-
operation: "chmod"
|
|
1200
|
-
} })(function* (path, mode) {
|
|
1201
|
-
yield* Effect.annotateCurrentSpan({
|
|
1202
|
-
path,
|
|
1203
|
-
mode
|
|
1204
|
-
});
|
|
1205
|
-
yield* tryFs("chmod", path, () => fsClient.chmod(path, mode));
|
|
1206
|
-
}),
|
|
1207
|
-
symlink: Effect.fn("ComputerWorkspace.fs.symlink", { attributes: {
|
|
1208
|
-
family: "fs",
|
|
1209
|
-
operation: "symlink"
|
|
1210
|
-
} })(function* (target, path) {
|
|
1211
|
-
yield* Effect.annotateCurrentSpan({
|
|
1212
|
-
path,
|
|
1213
|
-
target
|
|
1214
|
-
});
|
|
1215
|
-
yield* tryFs("symlink", path, () => fsClient.symlink(target, path));
|
|
1216
|
-
})
|
|
1217
|
-
};
|
|
1218
|
-
};
|
|
1219
|
-
const gitPerson = (person) => ({
|
|
1220
|
-
...person,
|
|
1221
|
-
timestampSeconds: person.timestamp
|
|
1222
|
-
});
|
|
1223
|
-
const gitCommit = (commit) => ({
|
|
1224
|
-
oid: commit.oid,
|
|
1225
|
-
message: commit.message,
|
|
1226
|
-
tree: commit.tree,
|
|
1227
|
-
parent: commit.parent,
|
|
1228
|
-
parents: commit.parent,
|
|
1229
|
-
author: gitPerson(commit.author),
|
|
1230
|
-
committer: gitPerson(commit.committer)
|
|
1231
|
-
});
|
|
1232
|
-
const makeGit = (gitClient) => {
|
|
1233
|
-
const method = (operation, evaluate) => Effect.fn(`ComputerWorkspace.git.${operation}`, { attributes: {
|
|
1234
|
-
family: "git",
|
|
1235
|
-
operation
|
|
1236
|
-
} })(function* (...args) {
|
|
1237
|
-
return yield* Effect.tryPromise({
|
|
1238
|
-
try: () => evaluate(...args),
|
|
1239
|
-
catch: (cause) => gitError(operation, cause)
|
|
1240
|
-
});
|
|
1241
|
-
});
|
|
1242
|
-
const log = Effect.fn("ComputerWorkspace.git.log", { attributes: {
|
|
1243
|
-
family: "git",
|
|
1244
|
-
operation: "log"
|
|
1245
|
-
} })(function* (options) {
|
|
1246
|
-
const { maxCount, ...upstreamOptions } = options ?? {};
|
|
1247
|
-
return (yield* Effect.tryPromise({
|
|
1248
|
-
try: () => gitClient.log({
|
|
1249
|
-
...upstreamOptions,
|
|
1250
|
-
...upstreamOptions.depth === void 0 && maxCount !== void 0 ? { depth: maxCount } : {}
|
|
1251
|
-
}),
|
|
1252
|
-
catch: (cause) => gitError("log", cause)
|
|
1253
|
-
})).map(gitCommit);
|
|
1254
|
-
});
|
|
1255
|
-
const revParse = Effect.fn("ComputerWorkspace.git.revParse", { attributes: {
|
|
1256
|
-
family: "git",
|
|
1257
|
-
operation: "revParse"
|
|
1258
|
-
} })(function* (input) {
|
|
1259
|
-
const options = typeof input === "string" ? { ref: input } : input;
|
|
1260
|
-
return yield* Effect.tryPromise({
|
|
1261
|
-
try: () => gitClient.revParse(options),
|
|
1262
|
-
catch: (cause) => gitError("revParse", cause)
|
|
1263
|
-
});
|
|
1264
|
-
});
|
|
1265
|
-
return {
|
|
1266
|
-
clone: method("clone", (options) => gitClient.clone(options)),
|
|
1267
|
-
diff: method("diff", (options) => gitClient.diff(options)),
|
|
1268
|
-
diffSummary: method("diffSummary", (options) => gitClient.diffSummary(options)),
|
|
1269
|
-
init: method("init", (options) => gitClient.init(options)),
|
|
1270
|
-
status: method("status", (options) => gitClient.status(options)),
|
|
1271
|
-
add: method("add", (options) => gitClient.add(options)),
|
|
1272
|
-
rm: method("rm", (options) => gitClient.rm(options)),
|
|
1273
|
-
commit: method("commit", (options) => gitClient.commit(options)),
|
|
1274
|
-
log,
|
|
1275
|
-
show: method("show", (options) => gitClient.show(options)),
|
|
1276
|
-
revParse,
|
|
1277
|
-
repoRoot: method("repoRoot", (options) => gitClient.repoRoot(options)),
|
|
1278
|
-
currentBranch: method("currentBranch", (options) => gitClient.currentBranch(options)),
|
|
1279
|
-
lsFiles: method("lsFiles", (options) => gitClient.lsFiles(options)),
|
|
1280
|
-
lsTree: method("lsTree", (options) => gitClient.lsTree(options)),
|
|
1281
|
-
branch: method("branch", (options) => gitClient.branch(options)),
|
|
1282
|
-
branchDelete: method("branchDelete", (options) => gitClient.branchDelete(options)),
|
|
1283
|
-
branchList: method("branchList", (options) => gitClient.branchList(options)),
|
|
1284
|
-
tag: method("tag", (options) => gitClient.tag(options)),
|
|
1285
|
-
tagDelete: method("tagDelete", (options) => gitClient.tagDelete(options)),
|
|
1286
|
-
tagList: method("tagList", (options) => gitClient.tagList(options)),
|
|
1287
|
-
checkout: method("checkout", (options) => gitClient.checkout(options)),
|
|
1288
|
-
fetch: method("fetch", (options) => gitClient.fetch(options)),
|
|
1289
|
-
push: method("push", (options) => gitClient.push(options)),
|
|
1290
|
-
pull: method("pull", (options) => gitClient.pull(options)),
|
|
1291
|
-
merge: method("merge", (options) => gitClient.merge(options)),
|
|
1292
|
-
remoteAdd: method("remoteAdd", (options) => gitClient.remoteAdd(options)),
|
|
1293
|
-
remoteRemove: method("remoteRemove", (options) => gitClient.remoteRemove(options)),
|
|
1294
|
-
remoteList: method("remoteList", (options) => gitClient.remoteList(options)),
|
|
1295
|
-
hashObject: method("hashObject", (options) => gitClient.hashObject(options)),
|
|
1296
|
-
catFile: method("catFile", (options) => gitClient.catFile(options)),
|
|
1297
|
-
updateRef: method("updateRef", (options) => gitClient.updateRef(options)),
|
|
1298
|
-
configGet: method("configGet", (options) => gitClient.configGet(options)),
|
|
1299
|
-
configSet: method("configSet", (options) => gitClient.configSet(options)),
|
|
1300
|
-
stashPush: method("stashPush", (options) => gitClient.stashPush(options)),
|
|
1301
|
-
stashList: method("stashList", (options) => gitClient.stashList(options)),
|
|
1302
|
-
stashPop: method("stashPop", (options) => gitClient.stashPop(options)),
|
|
1303
|
-
reset: method("reset", (options) => gitClient.reset(options)),
|
|
1304
|
-
clean: method("clean", (options) => gitClient.clean(options)),
|
|
1305
|
-
cli: method("cli", (input) => gitClient.cli(input))
|
|
1306
|
-
};
|
|
1307
|
-
};
|
|
1308
|
-
const runtimeExecOptions = (options) => {
|
|
1309
|
-
const { encoding = "utf8", timeoutMillis, timeoutMs, ...rest } = options ?? {};
|
|
1310
|
-
return {
|
|
1311
|
-
...rest,
|
|
1312
|
-
...encoding === "utf8" ? { encoding: "utf8" } : {},
|
|
1313
|
-
...timeoutMs === void 0 && timeoutMillis === void 0 ? {} : { timeoutMs: timeoutMs ?? timeoutMillis }
|
|
1314
|
-
};
|
|
1315
|
-
};
|
|
1316
|
-
const runtimeGetOptions = (options) => {
|
|
1317
|
-
const { encoding = "utf8", ...rest } = options ?? {};
|
|
1318
|
-
return {
|
|
1319
|
-
...rest,
|
|
1320
|
-
...encoding === "utf8" ? { encoding: "utf8" } : {}
|
|
1321
|
-
};
|
|
1322
|
-
};
|
|
1323
|
-
const wrapRuntimeResult = (result) => ({
|
|
1324
|
-
status: result.status,
|
|
1325
|
-
exitCode: result.exitCode,
|
|
1326
|
-
stdout: result.stdout,
|
|
1327
|
-
stderr: result.stderr,
|
|
1328
|
-
...result.value === void 0 ? {} : { value: result.value },
|
|
1329
|
-
pushed: result.pushed,
|
|
1330
|
-
pulled: result.pulled,
|
|
1331
|
-
skipped: result.skipped,
|
|
1332
|
-
sync: result.sync
|
|
1333
|
-
});
|
|
1334
|
-
const wrapRuntimeEvent = (event) => {
|
|
1335
|
-
switch (event.name) {
|
|
1336
|
-
case "stdout": {
|
|
1337
|
-
const chunk = event.value;
|
|
1338
|
-
return typeof chunk === "string" ? {
|
|
1339
|
-
_tag: "Stdout",
|
|
1340
|
-
id: event.id,
|
|
1341
|
-
sequence: event.seq,
|
|
1342
|
-
chunk,
|
|
1343
|
-
text: chunk
|
|
1344
|
-
} : {
|
|
1345
|
-
_tag: "Stdout",
|
|
1346
|
-
id: event.id,
|
|
1347
|
-
sequence: event.seq,
|
|
1348
|
-
chunk,
|
|
1349
|
-
bytes: chunk
|
|
1350
|
-
};
|
|
1351
|
-
}
|
|
1352
|
-
case "stderr": {
|
|
1353
|
-
const chunk = event.value;
|
|
1354
|
-
return typeof chunk === "string" ? {
|
|
1355
|
-
_tag: "Stderr",
|
|
1356
|
-
id: event.id,
|
|
1357
|
-
sequence: event.seq,
|
|
1358
|
-
chunk,
|
|
1359
|
-
text: chunk
|
|
1360
|
-
} : {
|
|
1361
|
-
_tag: "Stderr",
|
|
1362
|
-
id: event.id,
|
|
1363
|
-
sequence: event.seq,
|
|
1364
|
-
chunk,
|
|
1365
|
-
bytes: chunk
|
|
1366
|
-
};
|
|
1367
|
-
}
|
|
1368
|
-
case "exit": return {
|
|
1369
|
-
_tag: "Exit",
|
|
1370
|
-
id: event.id,
|
|
1371
|
-
sequence: event.seq,
|
|
1372
|
-
exitCode: event.code,
|
|
1373
|
-
...event.result === void 0 ? {} : { value: event.result }
|
|
1374
|
-
};
|
|
1375
|
-
}
|
|
1376
|
-
};
|
|
1377
|
-
const wrapRun = (handle) => {
|
|
1378
|
-
const events = Stream.fromReadableStream({
|
|
1379
|
-
evaluate: () => handle,
|
|
1380
|
-
onError: (cause) => execError("events", cause)
|
|
1381
|
-
}).pipe(Stream.map(wrapRuntimeEvent));
|
|
1382
|
-
const result = Effect.tryPromise({
|
|
1383
|
-
try: () => handle.result(),
|
|
1384
|
-
catch: (cause) => execError("result", cause)
|
|
1385
|
-
}).pipe(Effect.map(wrapRuntimeResult));
|
|
1386
|
-
const kill = Effect.fn("ComputerWorkspace.runtime.run.kill", { attributes: {
|
|
1387
|
-
family: "runtime",
|
|
1388
|
-
operation: "run.kill",
|
|
1389
|
-
runId: handle.id
|
|
1390
|
-
} })(function* (signal) {
|
|
1391
|
-
yield* Effect.tryPromise({
|
|
1392
|
-
try: () => handle.kill(signal),
|
|
1393
|
-
catch: (cause) => execError("run.kill", cause)
|
|
1394
|
-
});
|
|
1395
|
-
});
|
|
1396
|
-
return {
|
|
1397
|
-
id: handle.id,
|
|
1398
|
-
backend: handle.backend,
|
|
1399
|
-
events,
|
|
1400
|
-
result,
|
|
1401
|
-
kill
|
|
1402
|
-
};
|
|
1403
|
-
};
|
|
1404
|
-
const releaseRun = (handle) => Effect.sync(() => handle[Symbol.dispose]());
|
|
1405
|
-
const makeRuntime = (client) => {
|
|
1406
|
-
const execImplementation = Effect.fn("ComputerWorkspace.runtime.exec", { attributes: {
|
|
1407
|
-
family: "runtime",
|
|
1408
|
-
operation: "exec"
|
|
1409
|
-
} })(function* (source, optionsOrValue, ...remainingValues) {
|
|
1410
|
-
const options = typeof source === "string" ? optionsOrValue : void 0;
|
|
1411
|
-
yield* Effect.annotateCurrentSpan({
|
|
1412
|
-
backend: options?.backend,
|
|
1413
|
-
runId: options?.id
|
|
1414
|
-
});
|
|
1415
|
-
const handle = yield* Effect.acquireRelease(Effect.tryPromise({
|
|
1416
|
-
try: () => {
|
|
1417
|
-
if (typeof source === "string") return client.runtime.exec(source, runtimeExecOptions(options));
|
|
1418
|
-
const values = optionsOrValue === void 0 ? remainingValues : [optionsOrValue, ...remainingValues];
|
|
1419
|
-
return client.runtime.exec(source, ...values);
|
|
1420
|
-
},
|
|
1421
|
-
catch: (cause) => execError("exec", cause)
|
|
1422
|
-
}), releaseRun);
|
|
1423
|
-
return wrapRun(handle);
|
|
1424
|
-
});
|
|
1425
|
-
const exec = execImplementation;
|
|
1426
|
-
const getExec = Effect.fn("ComputerWorkspace.runtime.getExec", { attributes: {
|
|
1427
|
-
family: "runtime",
|
|
1428
|
-
operation: "getExec"
|
|
1429
|
-
} })(function* (id, options) {
|
|
1430
|
-
yield* Effect.annotateCurrentSpan({
|
|
1431
|
-
backend: options?.backend,
|
|
1432
|
-
runId: id
|
|
1433
|
-
});
|
|
1434
|
-
const handle = yield* Effect.acquireRelease(Effect.tryPromise({
|
|
1435
|
-
try: () => client.runtime.getExec(id, runtimeGetOptions(options)),
|
|
1436
|
-
catch: (cause) => execError("getExec", cause)
|
|
1437
|
-
}), releaseRun);
|
|
1438
|
-
return wrapRun(handle);
|
|
1439
|
-
});
|
|
1440
|
-
const killExec = Effect.fn("ComputerWorkspace.runtime.killExec", { attributes: {
|
|
1441
|
-
family: "runtime",
|
|
1442
|
-
operation: "killExec"
|
|
1443
|
-
} })(function* (id, options) {
|
|
1444
|
-
yield* Effect.annotateCurrentSpan({
|
|
1445
|
-
backend: options?.backend,
|
|
1446
|
-
runId: id
|
|
1447
|
-
});
|
|
1448
|
-
yield* Effect.tryPromise({
|
|
1449
|
-
try: () => client.runtime.killExec(id, options),
|
|
1450
|
-
catch: (cause) => execError("killExec", cause)
|
|
1451
|
-
});
|
|
1452
|
-
});
|
|
1453
|
-
const disposeExec = Effect.fn("ComputerWorkspace.runtime.disposeExec", { attributes: {
|
|
1454
|
-
family: "runtime",
|
|
1455
|
-
operation: "disposeExec"
|
|
1456
|
-
} })(function* (id, options) {
|
|
1457
|
-
yield* Effect.annotateCurrentSpan({
|
|
1458
|
-
backend: options?.backend,
|
|
1459
|
-
runId: id
|
|
1460
|
-
});
|
|
1461
|
-
yield* Effect.tryPromise({
|
|
1462
|
-
try: () => client.runtime.disposeExec(id, options),
|
|
1463
|
-
catch: (cause) => execError("disposeExec", cause)
|
|
1464
|
-
});
|
|
1465
|
-
});
|
|
1466
|
-
return {
|
|
1467
|
-
exec,
|
|
1468
|
-
execCollect: Effect.fn("ComputerWorkspace.runtime.execCollect", { attributes: {
|
|
1469
|
-
family: "runtime",
|
|
1470
|
-
operation: "execCollect"
|
|
1471
|
-
} })(function* (source, optionsOrValue, ...remainingValues) {
|
|
1472
|
-
return yield* Effect.scoped(Effect.gen(function* () {
|
|
1473
|
-
return yield* (yield* execImplementation(source, optionsOrValue, ...remainingValues)).result;
|
|
1474
|
-
}));
|
|
1475
|
-
}),
|
|
1476
|
-
getExec,
|
|
1477
|
-
killExec,
|
|
1478
|
-
disposeExec
|
|
1479
|
-
};
|
|
1480
|
-
};
|
|
1481
|
-
const makeAssets = (client) => client === void 0 ? void 0 : { share: Effect.fn("ComputerWorkspace.assets.share", { attributes: {
|
|
1482
|
-
family: "assets",
|
|
1483
|
-
operation: "share"
|
|
1484
|
-
} })(function* (path, options) {
|
|
1485
|
-
yield* Effect.annotateCurrentSpan("path", path);
|
|
1486
|
-
return yield* Effect.tryPromise({
|
|
1487
|
-
try: () => client.share(path, options),
|
|
1488
|
-
catch: (cause) => assetsError("share", path, cause)
|
|
1489
|
-
});
|
|
1490
|
-
}) };
|
|
1491
|
-
const makeThink = (client) => {
|
|
1492
|
-
if (client.readFile === void 0 || client.readFileBytes === void 0 || client.writeFile === void 0 || client.readDir === void 0 || client.rm === void 0 || client.glob === void 0 || client.mkdir === void 0 || client.stat === void 0) return;
|
|
1493
|
-
const method = (operation, pathOf, evaluate) => Effect.fn(`ComputerWorkspace.think.${operation}`, { attributes: {
|
|
1494
|
-
family: "think",
|
|
1495
|
-
operation
|
|
1496
|
-
} })(function* (...args) {
|
|
1497
|
-
const path = pathOf(...args);
|
|
1498
|
-
yield* Effect.annotateCurrentSpan("path", path);
|
|
1499
|
-
return yield* tryFs(`think.${operation}`, path, () => evaluate(...args));
|
|
1500
|
-
});
|
|
1501
|
-
return {
|
|
1502
|
-
readFile: method("readFile", (path) => path, (path) => client.readFile(path)),
|
|
1503
|
-
readFileBytes: method("readFileBytes", (path) => path, (path) => client.readFileBytes(path)),
|
|
1504
|
-
writeFile: method("writeFile", (path, _content) => path, (path, content) => client.writeFile(path, content)),
|
|
1505
|
-
readDir: method("readDir", (path, _options) => path, (path, options) => client.readDir(path, options)),
|
|
1506
|
-
rm: method("rm", (path, _options) => path, (path, options) => client.rm(path, options)),
|
|
1507
|
-
glob: method("glob", (pattern) => pattern, (pattern) => client.glob(pattern)),
|
|
1508
|
-
mkdir: method("mkdir", (path, _options) => path, (path, options) => client.mkdir(path, options)),
|
|
1509
|
-
stat: method("stat", (path) => path, (path) => client.stat(path))
|
|
1510
|
-
};
|
|
1511
|
-
};
|
|
1512
|
-
/**
|
|
1513
|
-
* Wraps a client whose lifetime is owned by the caller. Prefer
|
|
1514
|
-
* {@link ComputerWorkspace.layer} in Durable Objects so the parent client and
|
|
1515
|
-
* every runtime handle are disposed by Effect `Scope`.
|
|
1516
|
-
*/
|
|
1517
|
-
const fromWorkspaceClient = (client) => {
|
|
1518
|
-
const fs = makeFilesystem(client.fs);
|
|
1519
|
-
const git = makeGit(client.git);
|
|
1520
|
-
const runtime = makeRuntime(client);
|
|
1521
|
-
return {
|
|
1522
|
-
fs,
|
|
1523
|
-
git,
|
|
1524
|
-
runtime,
|
|
1525
|
-
artifacts: fromClient(client.artifacts, { binding: "ComputerWorkspace.artifacts" }),
|
|
1526
|
-
assets: makeAssets(client.assets),
|
|
1527
|
-
think: makeThink(client),
|
|
1528
|
-
readFile: fs.readFile,
|
|
1529
|
-
stat: fs.stat,
|
|
1530
|
-
lstat: fs.lstat,
|
|
1531
|
-
exists: fs.exists,
|
|
1532
|
-
readlink: fs.readlink,
|
|
1533
|
-
readdir: fs.readdir,
|
|
1534
|
-
listDirectory: fs.readdir,
|
|
1535
|
-
find: fs.find,
|
|
1536
|
-
ls: fs.ls,
|
|
1537
|
-
grep: fs.grep,
|
|
1538
|
-
writeFile: fs.writeFile,
|
|
1539
|
-
mkdir: fs.mkdir,
|
|
1540
|
-
rm: fs.rm,
|
|
1541
|
-
removePath: fs.rm,
|
|
1542
|
-
chmod: fs.chmod,
|
|
1543
|
-
symlink: fs.symlink,
|
|
1544
|
-
exec: runtime.exec,
|
|
1545
|
-
execCollect: runtime.execCollect,
|
|
1546
|
-
getExec: runtime.getExec,
|
|
1547
|
-
killExec: runtime.killExec,
|
|
1548
|
-
disposeExec: runtime.disposeExec
|
|
1549
|
-
};
|
|
1550
|
-
};
|
|
1551
|
-
/** Effect service for the workspace owned by the enclosing Durable Object. */
|
|
1552
|
-
var ComputerWorkspace = class ComputerWorkspace extends Context.Service()("effect-cf/ComputerWorkspace") {
|
|
1553
|
-
/**
|
|
1554
|
-
* Acquires the single workspace registered by `withComputerWorkspace` and
|
|
1555
|
-
* releases its RPC client when the layer scope closes.
|
|
1556
|
-
*/
|
|
1557
|
-
static layer = Layer.effect(ComputerWorkspace, Effect.gen(function* () {
|
|
1558
|
-
const host = lookup((yield* DurableObjectState).raw);
|
|
1559
|
-
if (host === void 0) return yield* Effect.die("ComputerWorkspace.layer requires a Durable Object class built with withComputerWorkspace");
|
|
1560
|
-
const computer = yield* Effect.promise(() => import("@cloudflare/computer"));
|
|
1561
|
-
const client = yield* Effect.acquireRelease(Effect.promise(() => computer.getWorkspace(host)), (workspace) => Effect.sync(() => workspace[Symbol.dispose]()));
|
|
1562
|
-
return ComputerWorkspace.of(fromWorkspaceClient(client));
|
|
1563
|
-
}));
|
|
1564
|
-
};
|
|
1565
|
-
//#endregion
|
|
1566
760
|
//#region src/ContainerNamespace.ts
|
|
1567
761
|
var ContainerNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
1568
762
|
ContainerNamespace: () => ContainerNamespace,
|
|
@@ -1648,7 +842,7 @@ const makeInstanceClient = (definition, instance, stub) => {
|
|
|
1648
842
|
removeDeniedHost: hostnameOperation("removeDeniedHost")
|
|
1649
843
|
};
|
|
1650
844
|
};
|
|
1651
|
-
const isContainerNamespaceResource = (value) =>
|
|
845
|
+
const isContainerNamespaceResource = (value) => Predicate.hasProperty(value, "getByName") && Predicate.isFunction(value.getByName);
|
|
1652
846
|
const makeClient$10 = (definition) => (namespace) => {
|
|
1653
847
|
const getByName = (name, options) => Effect.try({
|
|
1654
848
|
try: () => makeInstanceClient(definition, name, namespace.getByName(name, options)),
|
|
@@ -1685,7 +879,7 @@ const makeClient$10 = (definition) => (namespace) => {
|
|
|
1685
879
|
rawUnsafe: Effect.succeed(namespace)
|
|
1686
880
|
};
|
|
1687
881
|
};
|
|
1688
|
-
const layer$12 = (tag, definition) => layer$
|
|
882
|
+
const layer$12 = (tag, definition) => layer$19(tag, definition.binding, (value) => isContainerNamespaceResource(value), makeClient$10(definition), { expected: expectedContainerNamespace });
|
|
1689
883
|
const make$14 = (id) => Tag$12()(id);
|
|
1690
884
|
/** Creates a typed Effect service for a Cloudflare Container namespace. */
|
|
1691
885
|
const Tag$12 = () => (id) => {
|
|
@@ -1728,11 +922,7 @@ var D1_exports = /* @__PURE__ */ __exportAll({
|
|
|
1728
922
|
});
|
|
1729
923
|
const TypeId$2 = "~effect-cf/D1";
|
|
1730
924
|
const expectedD1Database = "D1 database binding with prepare(), batch(), and exec()";
|
|
1731
|
-
const isD1Database = (value) =>
|
|
1732
|
-
if (typeof value !== "object" || value === null) return false;
|
|
1733
|
-
const resource = value;
|
|
1734
|
-
return typeof resource.prepare === "function" && typeof resource.batch === "function" && typeof resource.exec === "function";
|
|
1735
|
-
};
|
|
925
|
+
const isD1Database = (value) => Predicate.hasProperty(value, "prepare") && Predicate.isFunction(value.prepare) && Predicate.hasProperty(value, "batch") && Predicate.isFunction(value.batch) && Predicate.hasProperty(value, "exec") && Predicate.isFunction(value.exec);
|
|
1736
926
|
/**
|
|
1737
927
|
* Creates a typed D1 service tag plus Effect helpers.
|
|
1738
928
|
*/
|
|
@@ -1786,10 +976,7 @@ const tryQueuePromise = (binding, operation, evaluate) => Effect.tryPromise({
|
|
|
1786
976
|
message: `Cloudflare queue binding "${binding}" operation "${operation}" failed`
|
|
1787
977
|
})
|
|
1788
978
|
});
|
|
1789
|
-
const isQueue = (value) =>
|
|
1790
|
-
if (typeof value !== "object" || value === null) return false;
|
|
1791
|
-
return typeof value.send === "function";
|
|
1792
|
-
};
|
|
979
|
+
const isQueue = (value) => Predicate.hasProperty(value, "send") && Predicate.isFunction(value.send);
|
|
1793
980
|
const makeClient$9 = (definition) => {
|
|
1794
981
|
const encodeMessage = Schema.encodeEffect(definition.message);
|
|
1795
982
|
return (queue) => ({
|
|
@@ -1831,7 +1018,7 @@ const makeClient$9 = (definition) => {
|
|
|
1831
1018
|
rawUnsafe: Effect.succeed(queue)
|
|
1832
1019
|
});
|
|
1833
1020
|
};
|
|
1834
|
-
const layer$11 = (tag, definition) => layer$
|
|
1021
|
+
const layer$11 = (tag, definition) => layer$19(tag, definition.binding, (value) => isQueue(value), makeClient$9(definition), { expected: expectedQueueProducer });
|
|
1835
1022
|
//#endregion
|
|
1836
1023
|
//#region src/QueueDefinition.ts
|
|
1837
1024
|
var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -2022,7 +1209,7 @@ const encodeWireError = (error) => {
|
|
|
2022
1209
|
const decodeWireError = (cause) => {
|
|
2023
1210
|
if (!(cause instanceof Error)) return cause;
|
|
2024
1211
|
try {
|
|
2025
|
-
const parsed = JSON.parse(cause.message);
|
|
1212
|
+
const parsed = Schema.decodeUnknownSync(Schema.Unknown)(JSON.parse(cause.message));
|
|
2026
1213
|
if (!Predicate.hasProperty(parsed, wireErrorKey)) return cause;
|
|
2027
1214
|
return Schema.decodeUnknownSync(WireErrorSchema)(parsed[wireErrorKey]);
|
|
2028
1215
|
} catch {
|
|
@@ -2115,6 +1302,10 @@ const make$11 = (id, methods) => {
|
|
|
2115
1302
|
};
|
|
2116
1303
|
//#endregion
|
|
2117
1304
|
//#region src/internal/Entrypoint.ts
|
|
1305
|
+
const invokeEntrypointRpcMethod = (self, method, args, run, onExit) => {
|
|
1306
|
+
const handler = Effect.suspend(() => method(...args)).pipe(Effect.mapError(encodeWireError));
|
|
1307
|
+
return run(self, onExit === void 0 ? handler : handler.pipe(Effect.onExit(() => onExit(self))));
|
|
1308
|
+
};
|
|
2118
1309
|
const provideEntrypointServices = (layer, services) => layer.pipe(Layer.provideMerge(services));
|
|
2119
1310
|
const defineEntrypointRpcMethods = (target, prototype, rpc, reservedMethodNames, run, onExit) => {
|
|
2120
1311
|
const methods = rpc ?? {};
|
|
@@ -2122,12 +1313,13 @@ const defineEntrypointRpcMethods = (target, prototype, rpc, reservedMethodNames,
|
|
|
2122
1313
|
for (const [key, method] of Object.entries(methods)) Object.defineProperty(prototype, key, {
|
|
2123
1314
|
enumerable: true,
|
|
2124
1315
|
value(...args) {
|
|
2125
|
-
|
|
2126
|
-
return run(this, onExit === void 0 ? handler : handler.pipe(Effect.onExit(() => onExit(this))));
|
|
1316
|
+
return invokeEntrypointRpcMethod(this, method, args, run, onExit);
|
|
2127
1317
|
}
|
|
2128
1318
|
});
|
|
2129
1319
|
};
|
|
2130
|
-
const assumeEntrypointClass = (entrypoint) =>
|
|
1320
|
+
const assumeEntrypointClass = (entrypoint) => {
|
|
1321
|
+
return entrypoint;
|
|
1322
|
+
};
|
|
2131
1323
|
//#endregion
|
|
2132
1324
|
//#region src/internal/Runtime.ts
|
|
2133
1325
|
/**
|
|
@@ -2143,18 +1335,11 @@ const makeEntrypointRuntime = (layer, env, services) => {
|
|
|
2143
1335
|
const entrypointServices = Layer.mergeAll(services, ConfigProvider.layer(WorkerConfig.providerFromEnv(env)), Layer.succeed(WorkerEnvironment, env));
|
|
2144
1336
|
return ManagedRuntime.make(provideEntrypointServices(layer, entrypointServices));
|
|
2145
1337
|
};
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
* `REvent` requirement satisfied by the event layer; TypeScript cannot reduce
|
|
2152
|
-
* `Exclude<...>` over the generic union.
|
|
2153
|
-
*/
|
|
2154
|
-
const runEventPromise = (runtime, effect, eventLayer) => {
|
|
2155
|
-
const withEventLayer = eventLayer === void 0 ? effect : effect.pipe(Effect.provide(eventLayer, { local: true }));
|
|
2156
|
-
return runtime.runPromise(Effect.scoped(withEventLayer));
|
|
2157
|
-
};
|
|
1338
|
+
function runEventPromise(...args) {
|
|
1339
|
+
const [runtime, effect, eventLayer] = args;
|
|
1340
|
+
if (eventLayer === void 0) return runtime.runPromise(Effect.scoped(effect));
|
|
1341
|
+
return runtime.runPromise(Effect.scoped(effect.pipe(Effect.provide(eventLayer, { local: true }))));
|
|
1342
|
+
}
|
|
2158
1343
|
//#endregion
|
|
2159
1344
|
//#region src/internal/Telemetry.ts
|
|
2160
1345
|
const logFlushFailure = Effect.logError("Telemetry flush failed").pipe(Effect.ignoreCause);
|
|
@@ -2177,25 +1362,30 @@ var Rpc_exports = /* @__PURE__ */ __exportAll({
|
|
|
2177
1362
|
resolve: () => resolve,
|
|
2178
1363
|
scoped: () => scoped
|
|
2179
1364
|
});
|
|
2180
|
-
const isDisposable = (value) => (
|
|
1365
|
+
const isDisposable = (value) => Predicate.hasProperty(value, Symbol.dispose) && Predicate.isFunction(value[Symbol.dispose]);
|
|
2181
1366
|
const dispose = (value) => Effect.sync(() => {
|
|
2182
1367
|
if (isDisposable(value)) value[Symbol.dispose]();
|
|
2183
1368
|
});
|
|
2184
|
-
const resolve = (value) => isPromiseLike(value) ? Effect.tryPromise({
|
|
2185
|
-
try: () => value,
|
|
1369
|
+
const resolve = (value) => Predicate.isPromiseLike(value) ? Effect.tryPromise({
|
|
1370
|
+
try: () => Promise.resolve(value),
|
|
2186
1371
|
catch: (cause) => decodeWireError(cause)
|
|
2187
|
-
}) : Effect.sync(() =>
|
|
1372
|
+
}) : Effect.sync(() => {
|
|
1373
|
+
return value;
|
|
1374
|
+
});
|
|
2188
1375
|
const scoped = (value) => Effect.acquireRelease(resolve(value), (resolved) => dispose(resolved));
|
|
2189
|
-
const isPromiseLike = (value) => (typeof value === "object" || typeof value === "function") && value !== null && "then" in value && typeof value.then === "function";
|
|
2190
1376
|
//#endregion
|
|
2191
1377
|
//#region src/internal/RpcInvocation.ts
|
|
2192
|
-
const
|
|
1378
|
+
const invokeWithReceiver = (value, receiver, args) => {
|
|
1379
|
+
return Function.prototype.apply.call(value, receiver, args);
|
|
1380
|
+
};
|
|
2193
1381
|
const lookupRpcMethod = (target, method, makeError) => Effect.try({
|
|
2194
1382
|
try: () => {
|
|
2195
|
-
if (!
|
|
2196
|
-
const
|
|
2197
|
-
|
|
2198
|
-
|
|
1383
|
+
if (!Predicate.isObjectKeyword(target)) throw new TypeError(`RPC target is not object-like`);
|
|
1384
|
+
const receiver = target;
|
|
1385
|
+
const value = receiver[method];
|
|
1386
|
+
if (!Predicate.isFunction(value)) throw new TypeError(`RPC method "${String(method)}" is not callable`);
|
|
1387
|
+
const callable = value;
|
|
1388
|
+
return (...args) => invokeWithReceiver(callable, receiver, args);
|
|
2199
1389
|
},
|
|
2200
1390
|
catch: makeError
|
|
2201
1391
|
});
|
|
@@ -2235,7 +1425,9 @@ var ServiceBindingRpcError = class extends Data.TaggedError("ServiceBindingRpcEr
|
|
|
2235
1425
|
return `Service binding "${this.binding}" RPC method "${this.method}" failed: ${causeMessage(this.cause)}`;
|
|
2236
1426
|
}
|
|
2237
1427
|
};
|
|
2238
|
-
const
|
|
1428
|
+
const ServiceBindingSchema = Schema.declare((value) => Predicate.hasProperty(value, "fetch") && Predicate.isFunction(value.fetch));
|
|
1429
|
+
const decodeServiceBinding = Schema.decodeUnknownOption(ServiceBindingSchema);
|
|
1430
|
+
const isServiceBindingClient = (value) => Option.isSome(decodeServiceBinding(value));
|
|
2239
1431
|
const makeClient$8 = (definition) => {
|
|
2240
1432
|
return (service) => {
|
|
2241
1433
|
const fetch = Effect.fn("ServiceBinding.fetch")(function* (input, init) {
|
|
@@ -2292,7 +1484,7 @@ const makeClient$8 = (definition) => {
|
|
|
2292
1484
|
});
|
|
2293
1485
|
};
|
|
2294
1486
|
};
|
|
2295
|
-
const layer$10 = (tag, definition) => layer$
|
|
1487
|
+
const layer$10 = (tag, definition) => layer$19(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$8(definition), { expected: expectedServiceBinding });
|
|
2296
1488
|
/**
|
|
2297
1489
|
* Creates a typed Effect service for a Worker service binding.
|
|
2298
1490
|
*
|
|
@@ -2348,7 +1540,10 @@ const Service = () => (id, definition) => {
|
|
|
2348
1540
|
};
|
|
2349
1541
|
const makeDirectMethods$1 = (rpcDefinition, call) => {
|
|
2350
1542
|
const methods = {};
|
|
2351
|
-
if (rpcDefinition !== void 0)
|
|
1543
|
+
if (rpcDefinition !== void 0) {
|
|
1544
|
+
const invoke = call;
|
|
1545
|
+
for (const methodName of Object.keys(rpcDefinition.methods)) methods[methodName] = (...args) => invoke(methodName, ...args);
|
|
1546
|
+
}
|
|
2352
1547
|
return methods;
|
|
2353
1548
|
};
|
|
2354
1549
|
//#endregion
|
|
@@ -2376,6 +1571,9 @@ const reservedMethodNames$3 = /* @__PURE__ */ new Set([
|
|
|
2376
1571
|
"webSocketClose",
|
|
2377
1572
|
"webSocketError"
|
|
2378
1573
|
]);
|
|
1574
|
+
const assumeTagClass = (value) => {
|
|
1575
|
+
return value;
|
|
1576
|
+
};
|
|
2379
1577
|
/**
|
|
2380
1578
|
* Defines a single RPC method schema in a worker definition.
|
|
2381
1579
|
*/
|
|
@@ -2396,10 +1594,14 @@ const method$1 = method$2;
|
|
|
2396
1594
|
const makeDefinition$3 = (id, methods) => {
|
|
2397
1595
|
assertNoReservedMethods("Worker", methods, reservedMethodNames$3);
|
|
2398
1596
|
const definition = make$11(id, methods);
|
|
2399
|
-
return Object.assign(definition, { make: (layer, options) =>
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
1597
|
+
return Object.assign(definition, { make: (layer, options) => {
|
|
1598
|
+
const workerOptions = {
|
|
1599
|
+
...options,
|
|
1600
|
+
rpc: wrapHandlers$1(definition, options.rpc)
|
|
1601
|
+
};
|
|
1602
|
+
if (workerOptions.eventLayer === void 0) return make$9(layer, workerOptions);
|
|
1603
|
+
return make$9(layer, workerOptions);
|
|
1604
|
+
} });
|
|
2403
1605
|
};
|
|
2404
1606
|
const make$10 = (id, methods) => Tag$9()(id, methods);
|
|
2405
1607
|
const Tag$9 = () => (id, methods) => {
|
|
@@ -2423,7 +1625,7 @@ const Tag$9 = () => (id, methods) => {
|
|
|
2423
1625
|
return yield* (yield* tag).scopedCall(method, ...args);
|
|
2424
1626
|
});
|
|
2425
1627
|
const directMethods = makeDirectMethods$1(definition, call);
|
|
2426
|
-
return Object.assign(tag, directMethods, {
|
|
1628
|
+
return assumeTagClass(Object.assign(tag, directMethods, {
|
|
2427
1629
|
id: definition.id,
|
|
2428
1630
|
methods: definition.methods,
|
|
2429
1631
|
make: definition.make,
|
|
@@ -2432,11 +1634,11 @@ const Tag$9 = () => (id, methods) => {
|
|
|
2432
1634
|
rpc,
|
|
2433
1635
|
call,
|
|
2434
1636
|
scopedCall
|
|
2435
|
-
});
|
|
1637
|
+
}));
|
|
2436
1638
|
};
|
|
2437
1639
|
const Worker = Tag$9;
|
|
2438
1640
|
const wrapHandlers$1 = (definition, handlers) => {
|
|
2439
|
-
const wrapped =
|
|
1641
|
+
const wrapped = Object.create(null);
|
|
2440
1642
|
for (const key of Object.keys(definition.methods)) {
|
|
2441
1643
|
const handler = handlers[key];
|
|
2442
1644
|
wrapped[key] = (...args) => Effect.gen(function* () {
|
|
@@ -2546,8 +1748,10 @@ function make$9(layer, optionsOrFetch) {
|
|
|
2546
1748
|
super(ctx, env);
|
|
2547
1749
|
this.runtime = makeEntrypointRuntime(layer, env, Layer.mergeAll(Layer.succeed(ExecutionContext, ctx), Layer.succeed(WorkerContext, fromExecutionContext(ctx))));
|
|
2548
1750
|
}
|
|
2549
|
-
[RunSymbol$1](effect
|
|
2550
|
-
|
|
1751
|
+
[RunSymbol$1](effect) {
|
|
1752
|
+
const eventLayer = options.eventLayer;
|
|
1753
|
+
if (eventLayer === void 0) return runEventPromise(this.runtime, effect);
|
|
1754
|
+
return runEventPromise(this.runtime, effect, eventLayer);
|
|
2551
1755
|
}
|
|
2552
1756
|
fetch(request) {
|
|
2553
1757
|
return this[FetchSymbol](request);
|
|
@@ -2569,19 +1773,8 @@ function make$9(layer, optionsOrFetch) {
|
|
|
2569
1773
|
defineEntrypointRpcMethods("Worker", EffectWorker.prototype, options.rpc, reservedMethodNames$2, (self, effect) => self[RunSymbol$1](effect), () => scheduleTelemetryFlush$1);
|
|
2570
1774
|
return assumeEntrypointClass(EffectWorker);
|
|
2571
1775
|
}
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
* {@link make}.
|
|
2575
|
-
*
|
|
2576
|
-
* The Effect runtime is cached per `env` identity, so the user layer builds
|
|
2577
|
-
* once per isolate instead of once per request. `ExecutionContext`-backed
|
|
2578
|
-
* services (`Worker.ExecutionContext`, `Worker.WorkerContext`) are still
|
|
2579
|
-
* provided fresh for every request. Layer finalizers do not run when the
|
|
2580
|
-
* isolate is evicted; Cloudflare provides no shutdown hook. Use `eventLayer`
|
|
2581
|
-
* for resources that must be finalized per event.
|
|
2582
|
-
*/
|
|
2583
|
-
const makeFetchHandler = (layer, options) => {
|
|
2584
|
-
const WorkerClass = make$9(layer, options);
|
|
1776
|
+
function makeFetchHandler(layer, options) {
|
|
1777
|
+
const WorkerClass = options.eventLayer === void 0 ? make$9(layer, options) : make$9(layer, options);
|
|
2585
1778
|
const instances = /* @__PURE__ */ new WeakMap();
|
|
2586
1779
|
return { fetch: (request, env, ctx) => {
|
|
2587
1780
|
let instance = instances.get(env);
|
|
@@ -2591,7 +1784,7 @@ const makeFetchHandler = (layer, options) => {
|
|
|
2591
1784
|
}
|
|
2592
1785
|
return instance[FetchSymbol](request, ctx);
|
|
2593
1786
|
} };
|
|
2594
|
-
}
|
|
1787
|
+
}
|
|
2595
1788
|
//#endregion
|
|
2596
1789
|
//#region src/DurableObjectNamespace.ts
|
|
2597
1790
|
var DurableObjectNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -2619,8 +1812,8 @@ var DurableObjectFetchError = class extends Data.TaggedError("DurableObjectFetch
|
|
|
2619
1812
|
return `Durable Object fetch failed for binding "${this.binding}": ${causeMessage(this.cause)}`;
|
|
2620
1813
|
}
|
|
2621
1814
|
};
|
|
2622
|
-
const hasFunction$
|
|
2623
|
-
const isDurableObjectNamespaceClient = (value) =>
|
|
1815
|
+
const hasFunction$1 = (value, key) => Predicate.hasProperty(value, key) && Predicate.isFunction(value[key]);
|
|
1816
|
+
const isDurableObjectNamespaceClient = (value) => hasFunction$1(value, "getByName") && hasFunction$1(value, "get") && hasFunction$1(value, "idFromName") && hasFunction$1(value, "idFromString") && hasFunction$1(value, "newUniqueId") && hasFunction$1(value, "jurisdiction");
|
|
2624
1817
|
const makeClient$7 = (definition) => {
|
|
2625
1818
|
return (namespace) => {
|
|
2626
1819
|
const newUniqueId = (options) => Effect.sync(() => namespace.newUniqueId(options));
|
|
@@ -2693,7 +1886,7 @@ const makeClient$7 = (definition) => {
|
|
|
2693
1886
|
});
|
|
2694
1887
|
};
|
|
2695
1888
|
};
|
|
2696
|
-
const layer$9 = (tag, definition) => layer$
|
|
1889
|
+
const layer$9 = (tag, definition) => layer$19(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$7(definition), { expected: expectedDurableObjectNamespace });
|
|
2697
1890
|
const makeDirectMethods = (rpcDefinition, helpers) => {
|
|
2698
1891
|
const methods = {};
|
|
2699
1892
|
if (rpcDefinition !== void 0) {
|
|
@@ -2732,10 +1925,9 @@ const reservedMethodNames$1 = /* @__PURE__ */ new Set([
|
|
|
2732
1925
|
"webSocketClose",
|
|
2733
1926
|
"webSocketError"
|
|
2734
1927
|
]);
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
const method = method$2;
|
|
1928
|
+
function method(definition) {
|
|
1929
|
+
return method$2(definition);
|
|
1930
|
+
}
|
|
2739
1931
|
/**
|
|
2740
1932
|
* Creates a Durable Object RPC definition plus implementation/binding helpers.
|
|
2741
1933
|
*
|
|
@@ -2788,14 +1980,17 @@ const Tag$8 = () => (id, methods) => {
|
|
|
2788
1980
|
const fetch = Effect.fn("DurableObject.fetch")(function* (stub, input, init) {
|
|
2789
1981
|
return yield* (yield* tag).fetch(stub, input, init);
|
|
2790
1982
|
});
|
|
2791
|
-
const rpc = Effect.fn("DurableObject.rpc")(function* (stub,
|
|
2792
|
-
|
|
1983
|
+
const rpc = Effect.fn("DurableObject.rpc")(function* (stub, methodName, ...args) {
|
|
1984
|
+
const invokeRpc = (yield* tag).rpc;
|
|
1985
|
+
return yield* invokeRpc(stub, methodName, ...args);
|
|
2793
1986
|
});
|
|
2794
|
-
const call = Effect.fn("DurableObject.call")(function* (stub,
|
|
2795
|
-
|
|
1987
|
+
const call = Effect.fn("DurableObject.call")(function* (stub, methodName, ...args) {
|
|
1988
|
+
const invokeCall = (yield* tag).call;
|
|
1989
|
+
return yield* invokeCall(stub, methodName, ...args);
|
|
2796
1990
|
});
|
|
2797
|
-
const scopedCall = Effect.fn("DurableObject.scopedCall")(function* (stub,
|
|
2798
|
-
|
|
1991
|
+
const scopedCall = Effect.fn("DurableObject.scopedCall")(function* (stub, methodName, ...args) {
|
|
1992
|
+
const invokeScopedCall = (yield* tag).scopedCall;
|
|
1993
|
+
return yield* invokeScopedCall(stub, methodName, ...args);
|
|
2799
1994
|
});
|
|
2800
1995
|
const rawUnsafe = Effect.fnUntraced(function* () {
|
|
2801
1996
|
return yield* (yield* tag).rawUnsafe;
|
|
@@ -2826,7 +2021,7 @@ const Tag$8 = () => (id, methods) => {
|
|
|
2826
2021
|
};
|
|
2827
2022
|
const DurableObject$1 = Tag$8;
|
|
2828
2023
|
const wrapHandlers = (definition, handlers) => {
|
|
2829
|
-
const wrapped =
|
|
2024
|
+
const wrapped = Object.create(Object.prototype);
|
|
2830
2025
|
for (const key of Object.keys(definition.methods)) {
|
|
2831
2026
|
const handler = handlers[key];
|
|
2832
2027
|
wrapped[key] = (...args) => Effect.gen(function* () {
|
|
@@ -2873,7 +2068,9 @@ const make$7 = (layer, options = {}) => {
|
|
|
2873
2068
|
if (initialize !== void 0) state.waitUntil(this[RunSymbol](initialize, { eventLayer: false }));
|
|
2874
2069
|
}
|
|
2875
2070
|
[RunSymbol](effect, runOptions = {}) {
|
|
2876
|
-
|
|
2071
|
+
const eventLayer = runOptions.eventLayer === false ? void 0 : options.eventLayer;
|
|
2072
|
+
if (eventLayer === void 0) return runEventPromise(this.runtime, effect);
|
|
2073
|
+
return runEventPromise(this.runtime, effect, eventLayer);
|
|
2877
2074
|
}
|
|
2878
2075
|
fetch(request) {
|
|
2879
2076
|
const fetchHandler = options.fetch;
|
|
@@ -2895,8 +2092,8 @@ const make$7 = (layer, options = {}) => {
|
|
|
2895
2092
|
webSocketClose(socket, code, reason, wasClean) {
|
|
2896
2093
|
if (options.webSocketClose !== void 0) return this[RunSymbol](options.webSocketClose(fromWebSocket(socket), code, reason, wasClean));
|
|
2897
2094
|
}
|
|
2898
|
-
webSocketError(socket,
|
|
2899
|
-
if (options.webSocketError !== void 0) return this[RunSymbol](options.webSocketError(fromWebSocket(socket),
|
|
2095
|
+
webSocketError(socket, cause) {
|
|
2096
|
+
if (options.webSocketError !== void 0) return this[RunSymbol](options.webSocketError(fromWebSocket(socket), cause));
|
|
2900
2097
|
}
|
|
2901
2098
|
}
|
|
2902
2099
|
defineEntrypointRpcMethods("Durable Object", EffectDurableObject.prototype, options.rpc, reservedMethodNames, (self, effect) => self[RunSymbol](effect), () => scheduleTelemetryFlush);
|
|
@@ -3032,12 +2229,12 @@ const toFailureRescheduleMillis = (input) => Effect.try({
|
|
|
3032
2229
|
catch: (cause) => new InvalidProcessDueAlarmsOptionsError({ cause })
|
|
3033
2230
|
});
|
|
3034
2231
|
const getFailureRetryDelay = (options) => toFailureRescheduleMillis(options?.retryFailedAfter ?? DEFAULT_PROCESS_DUE_ALARMS_FAILURE_RESCHEDULE_AFTER);
|
|
3035
|
-
const getFailureActionMode = (action) =>
|
|
3036
|
-
const getFailureActionRetryDelay = (action) =>
|
|
2232
|
+
const getFailureActionMode = (action) => Predicate.isString(action) ? action : action.mode;
|
|
2233
|
+
const getFailureActionRetryDelay = (action) => Predicate.isString(action) || action.mode !== "retry" ? void 0 : action.retryFailedAfter;
|
|
3037
2234
|
const processDue = (handle, options = {}) => Effect.gen(function* () {
|
|
3038
2235
|
return yield* (yield* DurableObjectAlarm).processDueAlarms(handle, options);
|
|
3039
2236
|
});
|
|
3040
|
-
const isAlarmDefinitionConfig = (definition) =>
|
|
2237
|
+
const isAlarmDefinitionConfig = (definition) => Predicate.isObject(definition) && "payload" in definition;
|
|
3041
2238
|
const getAlarmDefinitionSchema = (definition) => isAlarmDefinitionConfig(definition) ? definition.payload : definition;
|
|
3042
2239
|
const getAlarmDefinitionFailureAction = (definition) => {
|
|
3043
2240
|
if (definition === void 0 || !isAlarmDefinitionConfig(definition)) return;
|
|
@@ -3350,21 +2547,21 @@ const layer$8 = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
|
3350
2547
|
return Predicate.isTagged(cause, "MaxBufferSizeExceeded") ? Effect.ignore(connection.socket.close(1009, String(cause))) : send(connection, RpcMessage.ResponseDefectEncoded(cause));
|
|
3351
2548
|
})),
|
|
3352
2549
|
close: unregister,
|
|
3353
|
-
error: (socket,
|
|
3354
|
-
yield* Effect.logDebug("Durable Object RPC websocket error",
|
|
2550
|
+
error: (socket, cause) => Effect.gen(function* () {
|
|
2551
|
+
yield* Effect.logDebug("Durable Object RPC websocket error", cause);
|
|
3355
2552
|
yield* unregister(socket);
|
|
3356
2553
|
})
|
|
3357
2554
|
});
|
|
3358
2555
|
return Context.mergeAll(Context.make(RpcServer.Protocol, protocol), Context.make(DurableObjectRpcWebSocket, service));
|
|
3359
2556
|
}));
|
|
3360
|
-
const normalizeMessage = (message) =>
|
|
2557
|
+
const normalizeMessage = (message) => Predicate.isString(message) ? message : new Uint8Array(message);
|
|
3361
2558
|
const readAttachment = (socket, key) => {
|
|
3362
2559
|
const value = socket.deserializeAttachment();
|
|
3363
|
-
if (value
|
|
2560
|
+
if (Predicate.isObjectOrArray(value) && Predicate.hasProperty(value, key) && Predicate.isNumber(value[key])) return value[key];
|
|
3364
2561
|
};
|
|
3365
2562
|
const writeAttachment = (socket, key, clientId) => {
|
|
3366
2563
|
const current = socket.deserializeAttachment();
|
|
3367
|
-
const attachment =
|
|
2564
|
+
const attachment = Predicate.isObject(current) ? current : {};
|
|
3368
2565
|
socket.serializeAttachment({
|
|
3369
2566
|
...attachment,
|
|
3370
2567
|
[key]: clientId
|
|
@@ -3470,9 +2667,9 @@ var EmailValidationError = class extends Data.TaggedError("EmailValidationError"
|
|
|
3470
2667
|
* error and strips non-standard properties.
|
|
3471
2668
|
*/
|
|
3472
2669
|
const emailErrorCode = (cause) => {
|
|
3473
|
-
if (
|
|
3474
|
-
const code =
|
|
3475
|
-
return
|
|
2670
|
+
if (!Predicate.isObject(cause)) return;
|
|
2671
|
+
const code = Predicate.hasProperty(cause, "code") ? cause.code : void 0;
|
|
2672
|
+
return Predicate.isString(code) ? code : void 0;
|
|
3476
2673
|
};
|
|
3477
2674
|
const emailError = (binding, operation, cause) => new EmailOperationError({
|
|
3478
2675
|
binding,
|
|
@@ -3501,16 +2698,16 @@ const addressList = (value) => {
|
|
|
3501
2698
|
return Array.isArray(value) ? value : [value];
|
|
3502
2699
|
};
|
|
3503
2700
|
const addressViolations = (path, value) => {
|
|
3504
|
-
if (
|
|
2701
|
+
if (Predicate.isString(value)) return value.includes("@") ? [] : [{
|
|
3505
2702
|
path,
|
|
3506
2703
|
message: "Email address must contain an @ symbol"
|
|
3507
2704
|
}];
|
|
3508
|
-
if (
|
|
2705
|
+
if (!Predicate.isObject(value)) return [{
|
|
3509
2706
|
path,
|
|
3510
2707
|
message: "Email address must be a string or { name, email } object"
|
|
3511
2708
|
}];
|
|
3512
|
-
const email =
|
|
3513
|
-
if (
|
|
2709
|
+
const email = Predicate.hasProperty(value, "email") ? value.email : void 0;
|
|
2710
|
+
if (!Predicate.isString(email) || !email.includes("@")) return [{
|
|
3514
2711
|
path: `${path}.email`,
|
|
3515
2712
|
message: "Email address must contain an @ symbol"
|
|
3516
2713
|
}];
|
|
@@ -3523,18 +2720,18 @@ const attachmentViolations = (attachments) => {
|
|
|
3523
2720
|
for (let index = 0; index < attachments.length; index++) {
|
|
3524
2721
|
const attachment = attachments[index];
|
|
3525
2722
|
const path = `attachments[${index}]`;
|
|
3526
|
-
if (
|
|
2723
|
+
if (!Predicate.isObject(attachment)) {
|
|
3527
2724
|
violations.push({
|
|
3528
2725
|
path,
|
|
3529
2726
|
message: "Attachment must be an object"
|
|
3530
2727
|
});
|
|
3531
2728
|
continue;
|
|
3532
2729
|
}
|
|
3533
|
-
if (
|
|
2730
|
+
if (!Predicate.isString(attachment.filename) || attachment.filename === "") violations.push({
|
|
3534
2731
|
path: `${path}.filename`,
|
|
3535
2732
|
message: "Attachment filename is required"
|
|
3536
2733
|
});
|
|
3537
|
-
if (
|
|
2734
|
+
if (!Predicate.isString(attachment.type) || attachment.type === "") violations.push({
|
|
3538
2735
|
path: `${path}.type`,
|
|
3539
2736
|
message: "Attachment MIME type is required"
|
|
3540
2737
|
});
|
|
@@ -3542,7 +2739,7 @@ const attachmentViolations = (attachments) => {
|
|
|
3542
2739
|
path: `${path}.content`,
|
|
3543
2740
|
message: "Attachment content is required"
|
|
3544
2741
|
});
|
|
3545
|
-
if (attachment.disposition === "inline" &&
|
|
2742
|
+
if (attachment.disposition === "inline" && !Predicate.isString(attachment.contentId)) violations.push({
|
|
3546
2743
|
path: `${path}.contentId`,
|
|
3547
2744
|
message: "Inline attachments require a contentId"
|
|
3548
2745
|
});
|
|
@@ -3558,7 +2755,7 @@ const headerViolations = (headers) => {
|
|
|
3558
2755
|
const path = `headers["${name}"]`;
|
|
3559
2756
|
const nameBytes = byteLength(name);
|
|
3560
2757
|
if (nameBytes > sendLimits.maxHeaderNameBytes) violations.push(limitViolation(path, "header name bytes", nameBytes, sendLimits.maxHeaderNameBytes));
|
|
3561
|
-
if (
|
|
2758
|
+
if (!Predicate.isString(value)) {
|
|
3562
2759
|
violations.push({
|
|
3563
2760
|
path,
|
|
3564
2761
|
message: "Header value must be a string"
|
|
@@ -3588,11 +2785,11 @@ const validateMessage = (message) => {
|
|
|
3588
2785
|
});
|
|
3589
2786
|
else violations.push(...addressViolations("from", fields.from));
|
|
3590
2787
|
if (fields.replyTo !== void 0) violations.push(...addressViolations("replyTo", fields.replyTo));
|
|
3591
|
-
if (
|
|
2788
|
+
if (!Predicate.isString(fields.subject) || fields.subject === "") violations.push({
|
|
3592
2789
|
path: "subject",
|
|
3593
2790
|
message: "A subject is required"
|
|
3594
2791
|
});
|
|
3595
|
-
if (
|
|
2792
|
+
if (!Predicate.isString(fields.text) && !Predicate.isString(fields.html)) violations.push({
|
|
3596
2793
|
path: "$",
|
|
3597
2794
|
message: "A message requires either text or html content"
|
|
3598
2795
|
});
|
|
@@ -3613,10 +2810,7 @@ const validateSendInput = (binding, operation, message) => {
|
|
|
3613
2810
|
const violations = validateMessage(message);
|
|
3614
2811
|
return violations.length > 0 ? Effect.fail(emailValidationError(binding, operation, violations)) : Effect.succeed(message);
|
|
3615
2812
|
};
|
|
3616
|
-
const isEmailBinding = (value) =>
|
|
3617
|
-
if (typeof value !== "object" || value === null) return false;
|
|
3618
|
-
return typeof value.send === "function";
|
|
3619
|
-
};
|
|
2813
|
+
const isEmailBinding = (value) => Predicate.hasProperty(value, "send") && Predicate.isFunction(value.send);
|
|
3620
2814
|
const makeClient$6 = (definition, options) => (email) => {
|
|
3621
2815
|
const runtime = email;
|
|
3622
2816
|
const validate = options?.validate ?? true;
|
|
@@ -3629,7 +2823,7 @@ const makeClient$6 = (definition, options) => (email) => {
|
|
|
3629
2823
|
rawUnsafe: Effect.succeed(email)
|
|
3630
2824
|
};
|
|
3631
2825
|
};
|
|
3632
|
-
const layer$6 = (tag, definition) => layer$
|
|
2826
|
+
const layer$6 = (tag, definition) => layer$19(tag, definition.binding, isEmailBinding, makeClient$6(definition, definition.send), { expected: expectedSendEmailBinding });
|
|
3633
2827
|
const make$6 = (id) => Tag$7()(id);
|
|
3634
2828
|
const Tag$7 = () => (id) => {
|
|
3635
2829
|
const tag = Context.Service()(id);
|
|
@@ -3649,16 +2843,13 @@ var Hyperdrive_exports = /* @__PURE__ */ __exportAll({
|
|
|
3649
2843
|
makeClient: () => makeClient$5
|
|
3650
2844
|
});
|
|
3651
2845
|
const expectedHyperdrive = "Hyperdrive binding with connectionString";
|
|
3652
|
-
const isHyperdrive = (value) =>
|
|
3653
|
-
if (typeof value !== "object" || value === null) return false;
|
|
3654
|
-
return typeof value.connectionString === "string";
|
|
3655
|
-
};
|
|
2846
|
+
const isHyperdrive = (value) => Predicate.hasProperty(value, "connectionString") && Predicate.isString(value.connectionString);
|
|
3656
2847
|
const makeClient$5 = (definition) => (hyperdrive) => ({
|
|
3657
2848
|
definition,
|
|
3658
2849
|
connectionString: hyperdrive.connectionString,
|
|
3659
2850
|
rawUnsafe: Effect.succeed(hyperdrive)
|
|
3660
2851
|
});
|
|
3661
|
-
const layer$5 = (tag, definition) => layer$
|
|
2852
|
+
const layer$5 = (tag, definition) => layer$19(tag, definition.binding, isHyperdrive, makeClient$5(definition), { expected: expectedHyperdrive });
|
|
3662
2853
|
const make$5 = (id) => Tag$6()(id);
|
|
3663
2854
|
const Tag$6 = () => (id) => {
|
|
3664
2855
|
const tag = Context.Service()(id);
|
|
@@ -3713,9 +2904,9 @@ const tryImagesSync = (binding, operation, evaluate) => Effect.try({
|
|
|
3713
2904
|
catch: (cause) => imagesError(binding, operation, cause)
|
|
3714
2905
|
});
|
|
3715
2906
|
const maybe = (value) => value === null ? Option.none() : Option.some(value);
|
|
3716
|
-
const hasFunction
|
|
3717
|
-
const isHostedImagesBinding = (value) =>
|
|
3718
|
-
const isImagesBinding = (value) =>
|
|
2907
|
+
const hasFunction = (value, key) => Predicate.hasProperty(value, key) && Predicate.isFunction(value[key]);
|
|
2908
|
+
const isHostedImagesBinding = (value) => hasFunction(value, "image") && hasFunction(value, "upload") && hasFunction(value, "list");
|
|
2909
|
+
const isImagesBinding = (value) => hasFunction(value, "info") && hasFunction(value, "input");
|
|
3719
2910
|
const wrapResult = (binding, result) => ({
|
|
3720
2911
|
raw: result,
|
|
3721
2912
|
response: tryImagesSync(binding, "response", () => result.response()),
|
|
@@ -3755,7 +2946,7 @@ const makeClient$4 = (definition) => (images) => {
|
|
|
3755
2946
|
rawUnsafe: Effect.succeed(images)
|
|
3756
2947
|
};
|
|
3757
2948
|
};
|
|
3758
|
-
const layer$4 = (tag, definition) => layer$
|
|
2949
|
+
const layer$4 = (tag, definition) => layer$19(tag, definition.binding, isImagesBinding, makeClient$4(definition), { expected: expectedImagesBinding });
|
|
3759
2950
|
const make$4 = (id) => Tag$5()(id);
|
|
3760
2951
|
const Tag$5 = () => (id) => {
|
|
3761
2952
|
const tag = Context.Service()(id);
|
|
@@ -3790,11 +2981,7 @@ const tryKvPromise = (binding, operation, evaluate) => Effect.tryPromise({
|
|
|
3790
2981
|
try: evaluate,
|
|
3791
2982
|
catch: (cause) => kvError(binding, operation, cause)
|
|
3792
2983
|
});
|
|
3793
|
-
const isKvNamespace = (value) =>
|
|
3794
|
-
if (typeof value !== "object" || value === null) return false;
|
|
3795
|
-
const resource = value;
|
|
3796
|
-
return typeof resource.get === "function" && typeof resource.put === "function" && typeof resource.delete === "function" && typeof resource.getWithMetadata === "function" && typeof resource.list === "function";
|
|
3797
|
-
};
|
|
2984
|
+
const isKvNamespace = (value) => Predicate.hasProperty(value, "get") && Predicate.isFunction(value.get) && Predicate.hasProperty(value, "put") && Predicate.isFunction(value.put) && Predicate.hasProperty(value, "delete") && Predicate.isFunction(value.delete) && Predicate.hasProperty(value, "getWithMetadata") && Predicate.isFunction(value.getWithMetadata) && Predicate.hasProperty(value, "list") && Predicate.isFunction(value.list);
|
|
3798
2985
|
const makeClient$3 = (definition) => {
|
|
3799
2986
|
const encodeKey = Schema.encodeEffect(definition.key);
|
|
3800
2987
|
const decodeKey = Schema.decodeUnknownEffect(definition.key);
|
|
@@ -3868,7 +3055,7 @@ const makeClient$3 = (definition) => {
|
|
|
3868
3055
|
rawUnsafe: Effect.succeed(kv)
|
|
3869
3056
|
});
|
|
3870
3057
|
};
|
|
3871
|
-
const layer$3 = (tag, definition) => layer$
|
|
3058
|
+
const layer$3 = (tag, definition) => layer$19(tag, definition.binding, isKvNamespace, makeClient$3(definition), { expected: expectedKvNamespace });
|
|
3872
3059
|
const makeDefinition$1 = (id, definition) => {
|
|
3873
3060
|
const kvDefinition = {
|
|
3874
3061
|
id,
|
|
@@ -3926,7 +3113,7 @@ const spanOptions$1 = (binding, operation) => ({ attributes: {
|
|
|
3926
3113
|
binding,
|
|
3927
3114
|
operation
|
|
3928
3115
|
} });
|
|
3929
|
-
const isR2ObjectBody = (value) => "body" in value &&
|
|
3116
|
+
const isR2ObjectBody = (value) => "body" in value && Predicate.isFunction(value.arrayBuffer) && Predicate.isFunction(value.bytes) && Predicate.isFunction(value.text) && Predicate.isFunction(value.json) && Predicate.isFunction(value.blob);
|
|
3930
3117
|
const wrapObjectBody = (binding, object) => ({
|
|
3931
3118
|
key: object.key,
|
|
3932
3119
|
version: object.version,
|
|
@@ -3956,11 +3143,9 @@ const wrapGetResult = (binding, object) => {
|
|
|
3956
3143
|
if (object === null || !isR2ObjectBody(object)) return object;
|
|
3957
3144
|
return wrapObjectBody(binding, object);
|
|
3958
3145
|
};
|
|
3959
|
-
const
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
return typeof resource.head === "function" && typeof resource.get === "function" && typeof resource.put === "function" && typeof resource.createMultipartUpload === "function" && typeof resource.resumeMultipartUpload === "function" && typeof resource.delete === "function" && typeof resource.list === "function";
|
|
3963
|
-
};
|
|
3146
|
+
const R2BucketSchema = Schema.declare((value) => Predicate.hasProperty(value, "head") && Predicate.isFunction(value.head) && Predicate.hasProperty(value, "get") && Predicate.isFunction(value.get) && Predicate.hasProperty(value, "put") && Predicate.isFunction(value.put) && Predicate.hasProperty(value, "createMultipartUpload") && Predicate.isFunction(value.createMultipartUpload) && Predicate.hasProperty(value, "resumeMultipartUpload") && Predicate.isFunction(value.resumeMultipartUpload) && Predicate.hasProperty(value, "delete") && Predicate.isFunction(value.delete) && Predicate.hasProperty(value, "list") && Predicate.isFunction(value.list));
|
|
3147
|
+
const decodeR2Bucket = Schema.decodeUnknownOption(R2BucketSchema);
|
|
3148
|
+
const isR2Bucket = (value) => Option.isSome(decodeR2Bucket(value));
|
|
3964
3149
|
const makeClient$2 = (definition) => {
|
|
3965
3150
|
const wrapUpload = (upload) => ({
|
|
3966
3151
|
raw: upload,
|
|
@@ -3984,7 +3169,7 @@ const makeClient$2 = (definition) => {
|
|
|
3984
3169
|
createMultipartUpload: Effect.fn("R2.createMultipartUpload", spanOptions$1(definition.binding, "createMultipartUpload"))((key, options) => tryR2Promise(definition.binding, "createMultipartUpload", () => bucket.createMultipartUpload(key, options)).pipe(Effect.map(wrapUpload))),
|
|
3985
3170
|
resumeMultipartUpload: Effect.fn("R2.resumeMultipartUpload", spanOptions$1(definition.binding, "resumeMultipartUpload"))((key, uploadId) => tryR2Sync(definition.binding, "resumeMultipartUpload", () => wrapUpload(bucket.resumeMultipartUpload(key, uploadId)))),
|
|
3986
3171
|
delete: Effect.fn("R2.delete", spanOptions$1(definition.binding, "delete"))((keys) => {
|
|
3987
|
-
const nativeKeys =
|
|
3172
|
+
const nativeKeys = Predicate.isString(keys) ? keys : [...keys];
|
|
3988
3173
|
return tryR2Promise(definition.binding, "delete", () => bucket.delete(nativeKeys));
|
|
3989
3174
|
}),
|
|
3990
3175
|
list: Effect.fn("R2.list", spanOptions$1(definition.binding, "list"))((options) => tryR2Promise(definition.binding, "list", () => bucket.list(options))),
|
|
@@ -3992,7 +3177,7 @@ const makeClient$2 = (definition) => {
|
|
|
3992
3177
|
};
|
|
3993
3178
|
};
|
|
3994
3179
|
};
|
|
3995
|
-
const layer$2 = (tag, definition) => layer$
|
|
3180
|
+
const layer$2 = (tag, definition) => layer$19(tag, definition.binding, isR2Bucket, makeClient$2(definition), { expected: expectedR2Bucket });
|
|
3996
3181
|
const make$3 = (id) => Tag$3()(id);
|
|
3997
3182
|
const Tag$3 = () => (id) => {
|
|
3998
3183
|
const tag = Context.Service()(id);
|
|
@@ -4032,16 +3217,25 @@ const spanOptions = (binding, operation) => ({ attributes: {
|
|
|
4032
3217
|
binding,
|
|
4033
3218
|
operation
|
|
4034
3219
|
} });
|
|
4035
|
-
const
|
|
4036
|
-
|
|
3220
|
+
const invokeVectorizeMethod = (method, receiver, args) => {
|
|
3221
|
+
return Function.prototype.apply.call(method, receiver, args);
|
|
3222
|
+
};
|
|
3223
|
+
const VectorizeBindingSchema = Schema.declare((value) => Predicate.hasProperty(value, "describe") && Predicate.isFunction(value.describe) && Predicate.hasProperty(value, "query") && Predicate.isFunction(value.query) && Predicate.hasProperty(value, "insert") && Predicate.isFunction(value.insert) && Predicate.hasProperty(value, "upsert") && Predicate.isFunction(value.upsert) && Predicate.hasProperty(value, "deleteByIds") && Predicate.isFunction(value.deleteByIds) && Predicate.hasProperty(value, "getByIds") && Predicate.isFunction(value.getByIds));
|
|
3224
|
+
const decodeVectorizeBinding = Schema.decodeUnknownOption(VectorizeBindingSchema);
|
|
3225
|
+
const isVectorizeBinding = (value) => Option.isSome(decodeVectorizeBinding(value));
|
|
4037
3226
|
const makeClient$1 = (definition) => (index) => {
|
|
4038
3227
|
const runtime = index;
|
|
4039
3228
|
const deleteByIds = Effect.fn("Vectorize.deleteByIds", spanOptions(definition.binding, "deleteByIds"))((ids) => tryVectorizePromise(definition.binding, "deleteByIds", () => runtime.deleteByIds([...ids])));
|
|
4040
3229
|
return {
|
|
4041
3230
|
definition,
|
|
4042
3231
|
describe: tryVectorizePromise(definition.binding, "describe", () => runtime.describe()).pipe(Effect.withSpan("Vectorize.describe", spanOptions(definition.binding, "describe"))),
|
|
4043
|
-
query: Effect.fn("Vectorize.query", spanOptions(definition.binding, "query"))((vector, options) => tryVectorizePromise(definition.binding, "query", () =>
|
|
4044
|
-
|
|
3232
|
+
query: Effect.fn("Vectorize.query", spanOptions(definition.binding, "query"))((vector, options) => tryVectorizePromise(definition.binding, "query", () => {
|
|
3233
|
+
return runtime.query(vector, options);
|
|
3234
|
+
})),
|
|
3235
|
+
queryById: Effect.fn("Vectorize.queryById", spanOptions(definition.binding, "queryById"))((vectorId, options) => runtime.queryById !== void 0 ? tryVectorizePromise(definition.binding, "queryById", () => {
|
|
3236
|
+
const queryById = runtime.queryById;
|
|
3237
|
+
return queryById === void 0 ? Promise.reject(/* @__PURE__ */ new TypeError("Vectorize binding does not expose queryById()")) : invokeVectorizeMethod(queryById, runtime, [vectorId, options]);
|
|
3238
|
+
}) : Effect.fail(vectorizeError(definition.binding, "queryById", /* @__PURE__ */ new TypeError("Vectorize binding does not expose queryById()")))),
|
|
4045
3239
|
insert: Effect.fn("Vectorize.insert", spanOptions(definition.binding, "insert"))((vectors) => tryVectorizePromise(definition.binding, "insert", () => runtime.insert([...vectors]))),
|
|
4046
3240
|
upsert: Effect.fn("Vectorize.upsert", spanOptions(definition.binding, "upsert"))((vectors) => tryVectorizePromise(definition.binding, "upsert", () => runtime.upsert([...vectors]))),
|
|
4047
3241
|
deleteByIds,
|
|
@@ -4050,7 +3244,7 @@ const makeClient$1 = (definition) => (index) => {
|
|
|
4050
3244
|
rawUnsafe: Effect.succeed(index)
|
|
4051
3245
|
};
|
|
4052
3246
|
};
|
|
4053
|
-
const layer$1 = (tag, definition) => layer$
|
|
3247
|
+
const layer$1 = (tag, definition) => layer$19(tag, definition.binding, isVectorizeBinding, makeClient$1(definition), { expected: expectedVectorizeBinding });
|
|
4054
3248
|
const make$2 = (id) => Tag$2()(id);
|
|
4055
3249
|
const Tag$2 = () => (id) => {
|
|
4056
3250
|
const tag = Context.Service()(id);
|
|
@@ -4106,10 +3300,13 @@ const inboundTransport = (request) => Result.getSuccess(decodeInboundTransport(r
|
|
|
4106
3300
|
*/
|
|
4107
3301
|
const isHttp3 = (transport) => transport.clientQuicRtt !== void 0 || transport.httpProtocol === "HTTP/3";
|
|
4108
3302
|
/** Feature-detects the WebTransport capabilities of the current runtime. */
|
|
4109
|
-
const capabilities = Effect.sync(() =>
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
3303
|
+
const capabilities = Effect.sync(() => {
|
|
3304
|
+
const runtime = globalThis;
|
|
3305
|
+
return {
|
|
3306
|
+
inboundSessions: false,
|
|
3307
|
+
outboundSessions: Predicate.hasProperty(runtime, "WebTransport") && Predicate.isFunction(runtime["WebTransport"])
|
|
3308
|
+
};
|
|
3309
|
+
});
|
|
4113
3310
|
/** Raised when a WebTransport capability is unavailable in this runtime. */
|
|
4114
3311
|
var WebTransportUnsupportedError = class extends Data.TaggedError("WebTransportUnsupportedError") {
|
|
4115
3312
|
get message() {
|
|
@@ -4154,11 +3351,9 @@ const tryWorkflowPromise = (binding, operation, evaluate) => Effect.tryPromise({
|
|
|
4154
3351
|
try: evaluate,
|
|
4155
3352
|
catch: (cause) => workflowError(binding, operation, cause)
|
|
4156
3353
|
});
|
|
4157
|
-
const
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
return typeof resource.create === "function" && typeof resource.createBatch === "function" && typeof resource.get === "function";
|
|
4161
|
-
};
|
|
3354
|
+
const WorkflowBindingSchema = Schema.declare((value) => Predicate.hasProperty(value, "create") && Predicate.isFunction(value.create) && Predicate.hasProperty(value, "createBatch") && Predicate.isFunction(value.createBatch) && Predicate.hasProperty(value, "get") && Predicate.isFunction(value.get));
|
|
3355
|
+
const decodeWorkflowBinding = Schema.decodeUnknownOption(WorkflowBindingSchema);
|
|
3356
|
+
const isWorkflow = (value) => Option.isSome(decodeWorkflowBinding(value));
|
|
4162
3357
|
const makeClient = (definition) => {
|
|
4163
3358
|
const encodePayload = Schema.encodeEffect(definition.payload);
|
|
4164
3359
|
const decodeResult = Schema.decodeUnknownEffect(definition.result);
|
|
@@ -4216,7 +3411,7 @@ const makeClient = (definition) => {
|
|
|
4216
3411
|
rawUnsafe: Effect.succeed(workflow)
|
|
4217
3412
|
});
|
|
4218
3413
|
};
|
|
4219
|
-
const layer = (tag, definition) => layer$
|
|
3414
|
+
const layer = (tag, definition) => layer$19(tag, definition.binding, (value) => isWorkflow(value), makeClient(definition), { expected: expectedWorkflow });
|
|
4220
3415
|
//#endregion
|
|
4221
3416
|
//#region src/WorkflowDefinition.ts
|
|
4222
3417
|
var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -4237,7 +3432,7 @@ const make$1 = (id, definition) => Tag$1()(id, definition);
|
|
|
4237
3432
|
const Tag$1 = () => (id, definition) => {
|
|
4238
3433
|
const workflowDefinition = makeDefinition(id, definition);
|
|
4239
3434
|
const tag = Context.Service()(`effect-cf/Workflow/${id}`);
|
|
4240
|
-
const layer$
|
|
3435
|
+
const layer$20 = (binding) => layer(tag, {
|
|
4241
3436
|
...binding,
|
|
4242
3437
|
payload: definition.payload,
|
|
4243
3438
|
result: definition.result
|
|
@@ -4257,7 +3452,7 @@ const Tag$1 = () => (id, definition) => {
|
|
|
4257
3452
|
payload: workflowDefinition.payload,
|
|
4258
3453
|
result: workflowDefinition.result,
|
|
4259
3454
|
make: workflowDefinition.make,
|
|
4260
|
-
layer: layer$
|
|
3455
|
+
layer: layer$20,
|
|
4261
3456
|
create,
|
|
4262
3457
|
createBatch,
|
|
4263
3458
|
get,
|
|
@@ -4291,6 +3486,7 @@ var Workflow_exports = /* @__PURE__ */ __exportAll({
|
|
|
4291
3486
|
WorkflowStep: () => WorkflowStep$1,
|
|
4292
3487
|
WorkflowStepContext: () => WorkflowStepContext$1,
|
|
4293
3488
|
WorkflowStepError: () => WorkflowStepError,
|
|
3489
|
+
WorkflowStepNonRetryableError: () => WorkflowStepNonRetryableError,
|
|
4294
3490
|
implement: () => implement,
|
|
4295
3491
|
make: () => make,
|
|
4296
3492
|
sleep: () => sleep,
|
|
@@ -4306,6 +3502,17 @@ var WorkflowStepError = class extends Data.TaggedError("WorkflowStepError") {
|
|
|
4306
3502
|
return `Workflow ${this.operation} failed${step}: ${causeMessage(this.cause)}`;
|
|
4307
3503
|
}
|
|
4308
3504
|
};
|
|
3505
|
+
/**
|
|
3506
|
+
* Typed step failure that Cloudflare must treat as terminal instead of retrying.
|
|
3507
|
+
*
|
|
3508
|
+
* The workflow boundary converts this value into Cloudflare's native
|
|
3509
|
+
* `NonRetryableError` while preserving the original cause and its message.
|
|
3510
|
+
*/
|
|
3511
|
+
var WorkflowStepNonRetryableError = class extends Data.TaggedError("WorkflowStepNonRetryableError") {
|
|
3512
|
+
get message() {
|
|
3513
|
+
return `Workflow step failed without retry: ${causeMessage(this.cause)}`;
|
|
3514
|
+
}
|
|
3515
|
+
};
|
|
4309
3516
|
var WorkflowStep$1 = class extends Context.Service()("effect-cf/WorkflowStep") {};
|
|
4310
3517
|
var WorkflowStepContext$1 = class extends Context.Service()("effect-cf/WorkflowStepContext") {};
|
|
4311
3518
|
const fromWorkflowEvent = (event) => ({
|
|
@@ -4315,11 +3522,20 @@ const fromWorkflowEvent = (event) => ({
|
|
|
4315
3522
|
instanceId: event.instanceId,
|
|
4316
3523
|
workflowName: event.workflowName
|
|
4317
3524
|
});
|
|
3525
|
+
const toCloudflareNonRetryableError = (error) => {
|
|
3526
|
+
const cloudflareError = new NonRetryableError(error.message);
|
|
3527
|
+
cloudflareError.cause = error.cause;
|
|
3528
|
+
return cloudflareError;
|
|
3529
|
+
};
|
|
3530
|
+
const exposeCloudflareNonRetryableError = (effect) => Effect.catchCause(effect, (cause) => {
|
|
3531
|
+
const error = Cause.findErrorOption(cause);
|
|
3532
|
+
return Option.isSome(error) && error.value instanceof WorkflowStepNonRetryableError ? Effect.die(toCloudflareNonRetryableError(error.value)) : Effect.failCause(cause);
|
|
3533
|
+
});
|
|
4318
3534
|
const fromWorkflowStep = (step, runPromise) => ({
|
|
4319
3535
|
raw: step,
|
|
4320
3536
|
do: (name, effect, config) => Effect.context().pipe(Effect.flatMap((context) => Effect.tryPromise({
|
|
4321
3537
|
try: () => {
|
|
4322
|
-
const run = (stepContext) => runPromise(Effect.scoped(Effect.provideService(Effect.provideContext(effect, context), WorkflowStepContext$1, stepContext)));
|
|
3538
|
+
const run = (stepContext) => runPromise(exposeCloudflareNonRetryableError(Effect.scoped(Effect.provideService(Effect.provideContext(effect, context), WorkflowStepContext$1, stepContext))));
|
|
4323
3539
|
const rawStep = step;
|
|
4324
3540
|
return config === void 0 ? rawStep.do(name, run) : rawStep.do(name, config, run);
|
|
4325
3541
|
},
|
|
@@ -4346,7 +3562,9 @@ const fromWorkflowStep = (step, runPromise) => ({
|
|
|
4346
3562
|
})
|
|
4347
3563
|
}),
|
|
4348
3564
|
waitForEvent: (name, options) => Effect.tryPromise({
|
|
4349
|
-
try: () =>
|
|
3565
|
+
try: () => {
|
|
3566
|
+
return step.waitForEvent(name, options);
|
|
3567
|
+
},
|
|
4350
3568
|
catch: (cause) => new WorkflowStepError({
|
|
4351
3569
|
step: name,
|
|
4352
3570
|
operation: "waitForEvent",
|
|
@@ -4375,4 +3593,4 @@ const waitForEvent = (name, options) => Effect.flatMap(WorkflowStep$1, (workflow
|
|
|
4375
3593
|
const Tag = Tag$1;
|
|
4376
3594
|
const implement = implement$1;
|
|
4377
3595
|
//#endregion
|
|
4378
|
-
export { AiGateway_exports as AiGateway, AnalyticsEngine_exports as AnalyticsEngine, Artifacts_exports as Artifacts, Binding_exports as Binding, BrowserRendering_exports as BrowserRendering, Cache_exports as Cache, CloudflareOtlp_exports as CloudflareOtlp,
|
|
3596
|
+
export { AiGateway_exports as AiGateway, AnalyticsEngine_exports as AnalyticsEngine, Artifacts_exports as Artifacts, 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, Environment_exports as Environment, 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, WebTransport_exports as WebTransport, 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 };
|