effect-cf 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +8 -6
- package/dist/Artifacts-BhWrdyqX.mjs +241 -0
- package/dist/ComputerArtifacts.d.mts +55 -0
- package/dist/ComputerArtifacts.mjs +95 -0
- package/dist/ComputerWorkspace.d.mts +279 -0
- package/dist/ComputerWorkspace.mjs +545 -0
- package/dist/{DurableObjectState-CEh0DVw7.mjs → DurableObjectState-Dux8KfjG.mjs} +3 -48
- package/dist/{WorkflowBinding-D5iWzCUa.d.mts → DurableObjectState-biHrHwrh.d.mts} +7 -81
- package/dist/ErrorMessage-_lg53p3W.mjs +49 -0
- package/dist/Vitest.d.mts +2 -1
- package/dist/Vitest.mjs +2 -1
- package/dist/WorkflowBinding-zlRPCXVf.d.mts +79 -0
- package/dist/index.d.mts +15 -343
- package/dist/index.mjs +66 -946
- package/package.json +12 -1
- package/src/index.ts +0 -2
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-_lg53p3W.mjs";
|
|
3
|
+
import { a as layer$19, i as Service$2, n as Artifacts_exports, r as Binding_exports } from "./Artifacts-BhWrdyqX.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-Dux8KfjG.mjs";
|
|
5
|
+
import { Clock, Config, ConfigProvider, Context, Data, DateTime, Duration, Effect, Exit, Function, 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,15 @@ 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
|
-
//#region src/Binding.ts
|
|
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
|
|
131
14
|
//#region src/WorkersAi.ts
|
|
132
15
|
var WorkersAi_exports = /* @__PURE__ */ __exportAll({
|
|
133
|
-
Tag: () => Tag$
|
|
16
|
+
Tag: () => Tag$16,
|
|
134
17
|
WorkersAiOperationError: () => WorkersAiOperationError,
|
|
135
18
|
embeddingResponse: () => embeddingResponse,
|
|
136
19
|
isWorkersAiBinding: () => isWorkersAiBinding,
|
|
137
|
-
layer: () => layer$
|
|
138
|
-
make: () => make$
|
|
139
|
-
makeClient: () => makeClient$
|
|
20
|
+
layer: () => layer$18,
|
|
21
|
+
make: () => make$18,
|
|
22
|
+
makeClient: () => makeClient$15
|
|
140
23
|
});
|
|
141
24
|
const expectedWorkersAiBinding = "Workers AI binding with run(), gateway(), and models()";
|
|
142
25
|
/** Error raised when a Workers AI operation fails. */
|
|
@@ -158,13 +41,13 @@ const tryWorkersAiSync = (binding, operation, evaluate) => Effect.try({
|
|
|
158
41
|
try: evaluate,
|
|
159
42
|
catch: (cause) => workersAiError(binding, operation, cause)
|
|
160
43
|
});
|
|
161
|
-
const hasFunction$
|
|
162
|
-
const isWorkersAiBinding = (value) => typeof value === "object" && value !== null && hasFunction$
|
|
44
|
+
const hasFunction$3 = (value, key) => typeof Reflect.get(value, key) === "function";
|
|
45
|
+
const isWorkersAiBinding = (value) => typeof value === "object" && value !== null && hasFunction$3(value, "run") && hasFunction$3(value, "gateway") && hasFunction$3(value, "models");
|
|
163
46
|
const embeddingResponse = (value) => ({
|
|
164
47
|
data: value.data ?? [],
|
|
165
48
|
shape: value.shape ?? []
|
|
166
49
|
});
|
|
167
|
-
const makeClient$
|
|
50
|
+
const makeClient$15 = (definition) => (ai) => {
|
|
168
51
|
const run = Effect.fn("WorkersAi.run")((model, input, options) => tryWorkersAiPromise(definition.binding, "run", () => ai.run(model, input, options)));
|
|
169
52
|
return {
|
|
170
53
|
definition,
|
|
@@ -176,11 +59,11 @@ const makeClient$17 = (definition) => (ai) => {
|
|
|
176
59
|
rawUnsafe: Effect.succeed(ai)
|
|
177
60
|
};
|
|
178
61
|
};
|
|
179
|
-
const layer$
|
|
180
|
-
const make$
|
|
181
|
-
const Tag$
|
|
62
|
+
const layer$18 = (tag, definition) => layer$19(tag, definition.binding, (value) => isWorkersAiBinding(value), makeClient$15(definition), { expected: expectedWorkersAiBinding });
|
|
63
|
+
const make$18 = (id) => Tag$16()(id);
|
|
64
|
+
const Tag$16 = () => (id) => {
|
|
182
65
|
const tag = Context.Service()(id);
|
|
183
|
-
const makeLayer = (definition) => layer$
|
|
66
|
+
const makeLayer = (definition) => layer$18(tag, definition);
|
|
184
67
|
return Object.assign(tag, {
|
|
185
68
|
id,
|
|
186
69
|
layer: makeLayer
|
|
@@ -190,11 +73,11 @@ const Tag$17 = () => (id) => {
|
|
|
190
73
|
//#region src/AiGateway.ts
|
|
191
74
|
var AiGateway_exports = /* @__PURE__ */ __exportAll({
|
|
192
75
|
AiGatewayOperationError: () => AiGatewayOperationError,
|
|
193
|
-
Tag: () => Tag$
|
|
76
|
+
Tag: () => Tag$15,
|
|
194
77
|
isAiGatewayBinding: () => isAiGatewayBinding,
|
|
195
|
-
layer: () => layer$
|
|
196
|
-
make: () => make$
|
|
197
|
-
makeClient: () => makeClient$
|
|
78
|
+
layer: () => layer$17,
|
|
79
|
+
make: () => make$17,
|
|
80
|
+
makeClient: () => makeClient$14,
|
|
198
81
|
makeClientFromAi: () => makeClientFromAi,
|
|
199
82
|
makeHttpClient: () => makeHttpClient
|
|
200
83
|
});
|
|
@@ -226,7 +109,7 @@ const providerUrl = (baseUrl, path = "") => {
|
|
|
226
109
|
};
|
|
227
110
|
const gatewayUrl = (definition) => `https://gateway.ai.cloudflare.com/v1/${definition.accountId}/${definition.gatewayId}/`;
|
|
228
111
|
const isAiGatewayBinding = (value) => isWorkersAiBinding(value);
|
|
229
|
-
const makeClient$
|
|
112
|
+
const makeClient$14 = (definition, gateway) => ({
|
|
230
113
|
definition,
|
|
231
114
|
run: Effect.fn("AiGateway.run")((data, options) => tryAiGatewayPromise(definition.binding, "run", () => gateway.run(Array.isArray(data) ? [...data] : data, options))),
|
|
232
115
|
getUrl: Effect.fn("AiGateway.getUrl")((provider) => tryAiGatewayPromise(definition.binding, "getUrl", () => gateway.getUrl(provider))),
|
|
@@ -246,11 +129,11 @@ const makeClientFromAi = (definition, ai) => {
|
|
|
246
129
|
const withGateway = (operation) => gateway.pipe(Effect.flatMap(operation));
|
|
247
130
|
return {
|
|
248
131
|
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$
|
|
132
|
+
run: (data, options) => withGateway((raw) => makeClient$14(definition, raw).run(data, options)),
|
|
133
|
+
getUrl: (provider) => withGateway((raw) => makeClient$14(definition, raw).getUrl(provider)),
|
|
134
|
+
fetch: (options) => withGateway((raw) => makeClient$14(definition, raw).fetch(options)),
|
|
135
|
+
patchLog: (logId, data) => withGateway((raw) => makeClient$14(definition, raw).patchLog(logId, data)),
|
|
136
|
+
getLog: (logId) => withGateway((raw) => makeClient$14(definition, raw).getLog(logId)),
|
|
254
137
|
rawUnsafe: gateway
|
|
255
138
|
};
|
|
256
139
|
};
|
|
@@ -294,11 +177,11 @@ const makeHttpClient = (definition, request = fetch) => {
|
|
|
294
177
|
rawUnsafe: Effect.fail(aiGatewayError(binding, "rawUnsafe", /* @__PURE__ */ new TypeError("HTTP AI Gateway clients have no raw binding")))
|
|
295
178
|
};
|
|
296
179
|
};
|
|
297
|
-
const layer$
|
|
298
|
-
const make$
|
|
299
|
-
const Tag$
|
|
180
|
+
const layer$17 = (tag, definition) => layer$19(tag, definition.binding, isAiGatewayBinding, (ai) => makeClientFromAi(definition, ai), { expected: expectedAiGatewayBinding });
|
|
181
|
+
const make$17 = (id) => Tag$15()(id);
|
|
182
|
+
const Tag$15 = () => (id) => {
|
|
300
183
|
const tag = Context.Service()(id);
|
|
301
|
-
const makeLayer = (definition) => layer$
|
|
184
|
+
const makeLayer = (definition) => layer$17(tag, definition);
|
|
302
185
|
return Object.assign(tag, {
|
|
303
186
|
id,
|
|
304
187
|
layer: makeLayer
|
|
@@ -313,13 +196,13 @@ var AnalyticsEngine_exports = /* @__PURE__ */ __exportAll({
|
|
|
313
196
|
AnalyticsEngineQueryError: () => AnalyticsEngineQueryError,
|
|
314
197
|
AnalyticsEngineWriteValidationError: () => AnalyticsEngineWriteValidationError,
|
|
315
198
|
QueryTag: () => QueryTag,
|
|
316
|
-
Tag: () => Tag$
|
|
199
|
+
Tag: () => Tag$14,
|
|
317
200
|
isAnalyticsEngineDataset: () => isAnalyticsEngineDataset,
|
|
318
|
-
layer: () => layer$
|
|
201
|
+
layer: () => layer$16,
|
|
319
202
|
layerFetch: () => layerFetch,
|
|
320
203
|
layerFetchConfig: () => layerFetchConfig,
|
|
321
|
-
make: () => make$
|
|
322
|
-
makeClient: () => makeClient$
|
|
204
|
+
make: () => make$16,
|
|
205
|
+
makeClient: () => makeClient$13,
|
|
323
206
|
makeQuery: () => makeQuery,
|
|
324
207
|
makeQueryClient: () => makeQueryClient,
|
|
325
208
|
queryConfig: () => queryConfig,
|
|
@@ -508,7 +391,7 @@ const isAnalyticsEngineDataset = (value) => {
|
|
|
508
391
|
if (typeof value !== "object" || value === null) return false;
|
|
509
392
|
return typeof Reflect.get(value, "writeDataPoint") === "function";
|
|
510
393
|
};
|
|
511
|
-
const makeClient$
|
|
394
|
+
const makeClient$13 = (definition, defaults) => (dataset) => {
|
|
512
395
|
return {
|
|
513
396
|
definition,
|
|
514
397
|
writeDataPoint: Effect.fn("AnalyticsEngine.writeDataPoint")((dataPoint, options) => {
|
|
@@ -538,12 +421,12 @@ const queryLayerConfig = (tag, config = queryConfig()) => Layer.effect(tag, Effe
|
|
|
538
421
|
return yield* makeQueryClient(definition);
|
|
539
422
|
}));
|
|
540
423
|
const layerFetchConfig = (tag, config = queryConfig()) => queryLayerConfig(tag, config).pipe(Layer.provide(FetchHttpClient.layer));
|
|
541
|
-
const layer$
|
|
542
|
-
const make$
|
|
424
|
+
const layer$16 = (tag, definition) => layer$19(tag, definition.binding, isAnalyticsEngineDataset, makeClient$13(definition, definition.write), { expected: expectedAnalyticsEngineDataset });
|
|
425
|
+
const make$16 = (id) => Tag$14()(id);
|
|
543
426
|
const makeQuery = (id) => QueryTag()(id);
|
|
544
|
-
const Tag$
|
|
427
|
+
const Tag$14 = () => (id) => {
|
|
545
428
|
const tag = Context.Service()(id);
|
|
546
|
-
const makeLayer = (definition) => layer$
|
|
429
|
+
const makeLayer = (definition) => layer$16(tag, definition);
|
|
547
430
|
return Object.assign(tag, {
|
|
548
431
|
id,
|
|
549
432
|
layer: makeLayer
|
|
@@ -564,125 +447,6 @@ const QueryTag = () => (id) => {
|
|
|
564
447
|
});
|
|
565
448
|
};
|
|
566
449
|
//#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
450
|
//#region src/BrowserRendering.ts
|
|
687
451
|
var BrowserRendering_exports = /* @__PURE__ */ __exportAll({
|
|
688
452
|
BrowserRenderingOperationError: () => BrowserRenderingOperationError,
|
|
@@ -690,7 +454,7 @@ var BrowserRendering_exports = /* @__PURE__ */ __exportAll({
|
|
|
690
454
|
isBrowserRenderingBinding: () => isBrowserRenderingBinding,
|
|
691
455
|
layer: () => layer$15,
|
|
692
456
|
make: () => make$15,
|
|
693
|
-
makeClient: () => makeClient$
|
|
457
|
+
makeClient: () => makeClient$12
|
|
694
458
|
});
|
|
695
459
|
const expectedBrowserRenderingBinding = "Browser Rendering binding resource";
|
|
696
460
|
/** Error raised when a Browser Rendering operation fails. */
|
|
@@ -731,13 +495,13 @@ const wrapBrowser = (binding, browser) => ({
|
|
|
731
495
|
disconnect: browser.disconnect === void 0 ? Effect.void : tryBrowserRenderingSync(binding, "disconnect", () => browser.disconnect())
|
|
732
496
|
});
|
|
733
497
|
const isBrowserRenderingBinding = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
|
|
734
|
-
const makeClient$
|
|
498
|
+
const makeClient$12 = (definition) => (binding) => ({
|
|
735
499
|
definition,
|
|
736
500
|
launchWith: (launch, options) => tryBrowserRenderingPromise(definition.binding, "launch", () => launch(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser)), Effect.withSpan("BrowserRendering.launchWith")),
|
|
737
501
|
connectWith: (connect, options) => tryBrowserRenderingPromise(definition.binding, "connect", () => connect(binding, options)).pipe(Effect.map((browser) => wrapBrowser(definition.binding, browser)), Effect.withSpan("BrowserRendering.connectWith")),
|
|
738
502
|
rawUnsafe: Effect.succeed(binding)
|
|
739
503
|
});
|
|
740
|
-
const layer$15 = (tag, definition) => layer$
|
|
504
|
+
const layer$15 = (tag, definition) => layer$19(tag, definition.binding, isBrowserRenderingBinding, makeClient$12(definition), { expected: expectedBrowserRenderingBinding });
|
|
741
505
|
const make$15 = (id) => Tag$13()(id);
|
|
742
506
|
const Tag$13 = () => (id) => {
|
|
743
507
|
const tag = Context.Service()(id);
|
|
@@ -755,7 +519,7 @@ var Cache_exports = /* @__PURE__ */ __exportAll({
|
|
|
755
519
|
layer: () => layer$14,
|
|
756
520
|
layerFrom: () => layerFrom,
|
|
757
521
|
makeCacheClient: () => makeCacheClient,
|
|
758
|
-
makeClient: () => makeClient$
|
|
522
|
+
makeClient: () => makeClient$11
|
|
759
523
|
});
|
|
760
524
|
/** Error raised when a Cloudflare Cache API operation fails. */
|
|
761
525
|
var CacheOperationError = class extends Data.TaggedError("CacheOperationError") {
|
|
@@ -774,28 +538,28 @@ const tryCachePromise = (cache, operation, evaluate) => Effect.tryPromise({
|
|
|
774
538
|
try: evaluate,
|
|
775
539
|
catch: (cause) => cacheError(cache, operation, cause)
|
|
776
540
|
});
|
|
777
|
-
const spanOptions$
|
|
541
|
+
const spanOptions$2 = (cache, operation) => ({ attributes: {
|
|
778
542
|
cache,
|
|
779
543
|
operation
|
|
780
544
|
} });
|
|
781
545
|
/** Wraps a native Cloudflare `Cache` instance. */
|
|
782
546
|
const makeCacheClient = (cache, name = "default") => ({
|
|
783
547
|
name,
|
|
784
|
-
match: Effect.fn("Cache.match", spanOptions$
|
|
785
|
-
put: Effect.fn("Cache.put", spanOptions$
|
|
786
|
-
delete: Effect.fn("Cache.delete", spanOptions$
|
|
548
|
+
match: Effect.fn("Cache.match", spanOptions$2(name, "match"))((request, options) => tryCachePromise(name, "match", () => cache.match(request, options)).pipe(Effect.map(Option.fromUndefinedOr))),
|
|
549
|
+
put: Effect.fn("Cache.put", spanOptions$2(name, "put"))((request, response) => tryCachePromise(name, "put", () => cache.put(request, response))),
|
|
550
|
+
delete: Effect.fn("Cache.delete", spanOptions$2(name, "delete"))((request, options) => tryCachePromise(name, "delete", () => cache.delete(request, options))),
|
|
787
551
|
rawUnsafe: Effect.succeed(cache)
|
|
788
552
|
});
|
|
789
553
|
/** Wraps a native Cloudflare `CacheStorage` instance. */
|
|
790
|
-
const makeClient$
|
|
554
|
+
const makeClient$11 = (storage) => ({
|
|
791
555
|
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$
|
|
556
|
+
open: (name) => tryCachePromise(name, "open", () => storage.open(name)).pipe(Effect.map((cache) => makeCacheClient(cache, name)), Effect.withSpan("Cache.open", spanOptions$2(name, "open"))),
|
|
793
557
|
rawUnsafe: Effect.succeed(storage)
|
|
794
558
|
});
|
|
795
559
|
/** Provides Cache API services from an explicit native `CacheStorage` instance. */
|
|
796
|
-
const layerFrom = (storage) => Layer.succeed(CacheStorage, makeClient$
|
|
560
|
+
const layerFrom = (storage) => Layer.succeed(CacheStorage, makeClient$11(storage));
|
|
797
561
|
/** Provides Cache API services from Cloudflare's global `caches` object. */
|
|
798
|
-
const layer$14 = Layer.sync(CacheStorage, () => makeClient$
|
|
562
|
+
const layer$14 = Layer.sync(CacheStorage, () => makeClient$11(caches));
|
|
799
563
|
//#endregion
|
|
800
564
|
//#region src/CloudflareOtlp.ts
|
|
801
565
|
/**
|
|
@@ -919,650 +683,6 @@ const layerDurableObject = (options = {}) => Layer.unwrap(Effect.map(DurableObje
|
|
|
919
683
|
"cloudflare.durable_object.id": options.includeObjectId ? state.id.toString() : void 0
|
|
920
684
|
})));
|
|
921
685
|
//#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
686
|
//#region src/ContainerNamespace.ts
|
|
1567
687
|
var ContainerNamespace_exports = /* @__PURE__ */ __exportAll({
|
|
1568
688
|
ContainerNamespace: () => ContainerNamespace,
|
|
@@ -1685,7 +805,7 @@ const makeClient$10 = (definition) => (namespace) => {
|
|
|
1685
805
|
rawUnsafe: Effect.succeed(namespace)
|
|
1686
806
|
};
|
|
1687
807
|
};
|
|
1688
|
-
const layer$12 = (tag, definition) => layer$
|
|
808
|
+
const layer$12 = (tag, definition) => layer$19(tag, definition.binding, isContainerNamespaceResource, makeClient$10(definition), { expected: expectedContainerNamespace });
|
|
1689
809
|
const make$14 = (id) => Tag$12()(id);
|
|
1690
810
|
/** Creates a typed Effect service for a Cloudflare Container namespace. */
|
|
1691
811
|
const Tag$12 = () => (id) => {
|
|
@@ -1831,7 +951,7 @@ const makeClient$9 = (definition) => {
|
|
|
1831
951
|
rawUnsafe: Effect.succeed(queue)
|
|
1832
952
|
});
|
|
1833
953
|
};
|
|
1834
|
-
const layer$11 = (tag, definition) => layer$
|
|
954
|
+
const layer$11 = (tag, definition) => layer$19(tag, definition.binding, (value) => isQueue(value), makeClient$9(definition), { expected: expectedQueueProducer });
|
|
1835
955
|
//#endregion
|
|
1836
956
|
//#region src/QueueDefinition.ts
|
|
1837
957
|
var QueueDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -2292,7 +1412,7 @@ const makeClient$8 = (definition) => {
|
|
|
2292
1412
|
});
|
|
2293
1413
|
};
|
|
2294
1414
|
};
|
|
2295
|
-
const layer$10 = (tag, definition) => layer$
|
|
1415
|
+
const layer$10 = (tag, definition) => layer$19(tag, definition.binding, (value) => isServiceBindingClient(value), makeClient$8(definition), { expected: expectedServiceBinding });
|
|
2296
1416
|
/**
|
|
2297
1417
|
* Creates a typed Effect service for a Worker service binding.
|
|
2298
1418
|
*
|
|
@@ -2693,7 +1813,7 @@ const makeClient$7 = (definition) => {
|
|
|
2693
1813
|
});
|
|
2694
1814
|
};
|
|
2695
1815
|
};
|
|
2696
|
-
const layer$9 = (tag, definition) => layer$
|
|
1816
|
+
const layer$9 = (tag, definition) => layer$19(tag, definition.binding, (value) => isDurableObjectNamespaceClient(value), makeClient$7(definition), { expected: expectedDurableObjectNamespace });
|
|
2697
1817
|
const makeDirectMethods = (rpcDefinition, helpers) => {
|
|
2698
1818
|
const methods = {};
|
|
2699
1819
|
if (rpcDefinition !== void 0) {
|
|
@@ -3629,7 +2749,7 @@ const makeClient$6 = (definition, options) => (email) => {
|
|
|
3629
2749
|
rawUnsafe: Effect.succeed(email)
|
|
3630
2750
|
};
|
|
3631
2751
|
};
|
|
3632
|
-
const layer$6 = (tag, definition) => layer$
|
|
2752
|
+
const layer$6 = (tag, definition) => layer$19(tag, definition.binding, isEmailBinding, makeClient$6(definition, definition.send), { expected: expectedSendEmailBinding });
|
|
3633
2753
|
const make$6 = (id) => Tag$7()(id);
|
|
3634
2754
|
const Tag$7 = () => (id) => {
|
|
3635
2755
|
const tag = Context.Service()(id);
|
|
@@ -3658,7 +2778,7 @@ const makeClient$5 = (definition) => (hyperdrive) => ({
|
|
|
3658
2778
|
connectionString: hyperdrive.connectionString,
|
|
3659
2779
|
rawUnsafe: Effect.succeed(hyperdrive)
|
|
3660
2780
|
});
|
|
3661
|
-
const layer$5 = (tag, definition) => layer$
|
|
2781
|
+
const layer$5 = (tag, definition) => layer$19(tag, definition.binding, isHyperdrive, makeClient$5(definition), { expected: expectedHyperdrive });
|
|
3662
2782
|
const make$5 = (id) => Tag$6()(id);
|
|
3663
2783
|
const Tag$6 = () => (id) => {
|
|
3664
2784
|
const tag = Context.Service()(id);
|
|
@@ -3697,8 +2817,8 @@ const makeSteps = (steps) => ({
|
|
|
3697
2817
|
});
|
|
3698
2818
|
/** Empty Images transformation pipeline. */
|
|
3699
2819
|
const empty = makeSteps([]);
|
|
3700
|
-
const transform = Function
|
|
3701
|
-
const draw = Function
|
|
2820
|
+
const transform = Function.dual(2, (steps, transformValue) => makeSteps([...steps.steps, Step.Transform({ transform: transformValue })]));
|
|
2821
|
+
const draw = Function.dual(2, (steps, drawValue) => makeSteps([...steps.steps, Step.Draw(drawValue)]));
|
|
3702
2822
|
const imagesError = (binding, operation, cause) => new ImagesOperationError({
|
|
3703
2823
|
binding,
|
|
3704
2824
|
operation,
|
|
@@ -3755,7 +2875,7 @@ const makeClient$4 = (definition) => (images) => {
|
|
|
3755
2875
|
rawUnsafe: Effect.succeed(images)
|
|
3756
2876
|
};
|
|
3757
2877
|
};
|
|
3758
|
-
const layer$4 = (tag, definition) => layer$
|
|
2878
|
+
const layer$4 = (tag, definition) => layer$19(tag, definition.binding, isImagesBinding, makeClient$4(definition), { expected: expectedImagesBinding });
|
|
3759
2879
|
const make$4 = (id) => Tag$5()(id);
|
|
3760
2880
|
const Tag$5 = () => (id) => {
|
|
3761
2881
|
const tag = Context.Service()(id);
|
|
@@ -3868,7 +2988,7 @@ const makeClient$3 = (definition) => {
|
|
|
3868
2988
|
rawUnsafe: Effect.succeed(kv)
|
|
3869
2989
|
});
|
|
3870
2990
|
};
|
|
3871
|
-
const layer$3 = (tag, definition) => layer$
|
|
2991
|
+
const layer$3 = (tag, definition) => layer$19(tag, definition.binding, isKvNamespace, makeClient$3(definition), { expected: expectedKvNamespace });
|
|
3872
2992
|
const makeDefinition$1 = (id, definition) => {
|
|
3873
2993
|
const kvDefinition = {
|
|
3874
2994
|
id,
|
|
@@ -3992,7 +3112,7 @@ const makeClient$2 = (definition) => {
|
|
|
3992
3112
|
};
|
|
3993
3113
|
};
|
|
3994
3114
|
};
|
|
3995
|
-
const layer$2 = (tag, definition) => layer$
|
|
3115
|
+
const layer$2 = (tag, definition) => layer$19(tag, definition.binding, isR2Bucket, makeClient$2(definition), { expected: expectedR2Bucket });
|
|
3996
3116
|
const make$3 = (id) => Tag$3()(id);
|
|
3997
3117
|
const Tag$3 = () => (id) => {
|
|
3998
3118
|
const tag = Context.Service()(id);
|
|
@@ -4050,7 +3170,7 @@ const makeClient$1 = (definition) => (index) => {
|
|
|
4050
3170
|
rawUnsafe: Effect.succeed(index)
|
|
4051
3171
|
};
|
|
4052
3172
|
};
|
|
4053
|
-
const layer$1 = (tag, definition) => layer$
|
|
3173
|
+
const layer$1 = (tag, definition) => layer$19(tag, definition.binding, isVectorizeBinding, makeClient$1(definition), { expected: expectedVectorizeBinding });
|
|
4054
3174
|
const make$2 = (id) => Tag$2()(id);
|
|
4055
3175
|
const Tag$2 = () => (id) => {
|
|
4056
3176
|
const tag = Context.Service()(id);
|
|
@@ -4216,7 +3336,7 @@ const makeClient = (definition) => {
|
|
|
4216
3336
|
rawUnsafe: Effect.succeed(workflow)
|
|
4217
3337
|
});
|
|
4218
3338
|
};
|
|
4219
|
-
const layer = (tag, definition) => layer$
|
|
3339
|
+
const layer = (tag, definition) => layer$19(tag, definition.binding, (value) => isWorkflow(value), makeClient(definition), { expected: expectedWorkflow });
|
|
4220
3340
|
//#endregion
|
|
4221
3341
|
//#region src/WorkflowDefinition.ts
|
|
4222
3342
|
var WorkflowDefinition_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -4237,7 +3357,7 @@ const make$1 = (id, definition) => Tag$1()(id, definition);
|
|
|
4237
3357
|
const Tag$1 = () => (id, definition) => {
|
|
4238
3358
|
const workflowDefinition = makeDefinition(id, definition);
|
|
4239
3359
|
const tag = Context.Service()(`effect-cf/Workflow/${id}`);
|
|
4240
|
-
const layer$
|
|
3360
|
+
const layer$20 = (binding) => layer(tag, {
|
|
4241
3361
|
...binding,
|
|
4242
3362
|
payload: definition.payload,
|
|
4243
3363
|
result: definition.result
|
|
@@ -4257,7 +3377,7 @@ const Tag$1 = () => (id, definition) => {
|
|
|
4257
3377
|
payload: workflowDefinition.payload,
|
|
4258
3378
|
result: workflowDefinition.result,
|
|
4259
3379
|
make: workflowDefinition.make,
|
|
4260
|
-
layer: layer$
|
|
3380
|
+
layer: layer$20,
|
|
4261
3381
|
create,
|
|
4262
3382
|
createBatch,
|
|
4263
3383
|
get,
|
|
@@ -4375,4 +3495,4 @@ const waitForEvent = (name, options) => Effect.flatMap(WorkflowStep$1, (workflow
|
|
|
4375
3495
|
const Tag = Tag$1;
|
|
4376
3496
|
const implement = implement$1;
|
|
4377
3497
|
//#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,
|
|
3498
|
+
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 };
|