effect-cf 0.27.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 +10 -0
- package/dist/{Artifacts-DcoXcRP5.d.mts → Artifacts-DnHQA-Ax.d.mts} +42 -25
- package/dist/{Artifacts-BhWrdyqX.mjs → Artifacts-rq3hUKQE.mjs} +46 -30
- package/dist/{Binding-COCtoJXa.d.mts → Binding-xJJJPmiD.d.mts} +6 -5
- package/dist/ComputerArtifacts.d.mts +1 -1
- package/dist/ComputerArtifacts.mjs +9 -9
- package/dist/ComputerWorkspace.d.mts +5 -5
- package/dist/ComputerWorkspace.mjs +107 -75
- package/dist/ComputerWorkspaceHost.d.mts +1 -1
- package/dist/ComputerWorkspaceHost.mjs +18 -16
- package/dist/{DurableObjectState-biHrHwrh.d.mts → DurableObjectState-B3uFY1eM.d.mts} +85 -62
- package/dist/{DurableObjectState-Dux8KfjG.mjs → DurableObjectState-BjkK2kwH.mjs} +3 -3
- package/dist/{ErrorMessage-_lg53p3W.mjs → ErrorMessage-BM0K-Nik.mjs} +1 -4
- 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 -5
- package/dist/Vitest.mjs +2 -2
- package/dist/{WorkflowBinding-zlRPCXVf.d.mts → WorkflowBinding-wZ-yGHow.d.mts} +5 -10
- package/dist/index.d.mts +82 -60
- package/dist/index.mjs +268 -170
- package/package.json +1 -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/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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# effect-cf
|
|
2
2
|
|
|
3
|
+
## 0.28.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#104](https://github.com/danieljvdm/effect-cf/pull/104) [`4aadbd0`](https://github.com/danieljvdm/effect-cf/commit/4aadbd0b6e76449bac190dbc5abb4c20486c8761) Thanks [@danieljvdm](https://github.com/danieljvdm)! - Allow workflow step Effects to fail terminally with `WorkflowStepNonRetryableError`, which is rethrown to Cloudflare as its native `NonRetryableError`.
|
|
8
|
+
|
|
9
|
+
- [#104](https://github.com/danieljvdm/effect-cf/pull/104) [`4aadbd0`](https://github.com/danieljvdm/effect-cf/commit/4aadbd0b6e76449bac190dbc5abb4c20486c8761) Thanks [@danieljvdm](https://github.com/danieljvdm)! - Support method-only remote Artifacts repository bindings with a typed `info()` client operation and live commit history shapes.
|
|
10
|
+
|
|
11
|
+
- [#102](https://github.com/danieljvdm/effect-cf/pull/102) [`1b32c54`](https://github.com/danieljvdm/effect-cf/commit/1b32c54757bf404c2454389b0386e0996974cdc6) Thanks [@danieljvdm](https://github.com/danieljvdm)! - Harden Cloudflare and WebTransport runtime boundaries with receiver-safe invocation, truthful return types, validated external data, and stricter event-layer requirements.
|
|
12
|
+
|
|
3
13
|
## 0.27.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-
|
|
1
|
+
import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-xJJJPmiD.mjs";
|
|
2
2
|
import { Context, Effect, Layer } from "effect";
|
|
3
3
|
declare namespace Artifacts_d_exports {
|
|
4
|
-
export { ArtifactsBinding, ArtifactsClient, ArtifactsCommit, ArtifactsCreateOptions, ArtifactsCreateRepoResult, ArtifactsCreateTokenResult, ArtifactsDefinition, ArtifactsErrorCode, ArtifactsForkOptions, ArtifactsImportParams, ArtifactsImportSource, ArtifactsImportTarget, ArtifactsImportTargetOptions, ArtifactsListOptions, ArtifactsLogOptions, ArtifactsLogResult, ArtifactsOperation, ArtifactsOperationError, ArtifactsRepoBinding, ArtifactsRepoClient, ArtifactsRepoInfo, ArtifactsRepoListEntry, ArtifactsRepoListResult, ArtifactsRepoStatus, ArtifactsService, ArtifactsTokenInfo, ArtifactsTokenListResult, ArtifactsTokenScope, ArtifactsTokenState, ArtifactsTree, Cursor, LayerOptions, RepoName, Tag, TagClass, artifactsErrorCodes, artifactsErrorNumericCodes, isArtifactsBinding, isArtifactsRepoBinding, layer, make, makeClient };
|
|
4
|
+
export { ArtifactsBinding, ArtifactsClient, ArtifactsCommit, ArtifactsCommitIdentity, ArtifactsCreateOptions, ArtifactsCreateRepoResult, ArtifactsCreateTokenResult, ArtifactsDefinition, ArtifactsErrorCode, ArtifactsForkOptions, ArtifactsImportParams, ArtifactsImportSource, ArtifactsImportTarget, ArtifactsImportTargetOptions, ArtifactsListOptions, ArtifactsLogOptions, ArtifactsLogResult, ArtifactsOperation, ArtifactsOperationError, ArtifactsRepoBinding, ArtifactsRepoClient, ArtifactsRepoInfo, ArtifactsRepoListEntry, ArtifactsRepoListResult, ArtifactsRepoStatus, ArtifactsService, ArtifactsTokenInfo, ArtifactsTokenListResult, ArtifactsTokenScope, ArtifactsTokenState, ArtifactsTree, Cursor, LayerOptions, RepoName, Tag, TagClass, artifactsErrorCodes, artifactsErrorNumericCodes, isArtifactsBinding, isArtifactsRepoBinding, layer, make, makeClient };
|
|
5
5
|
}
|
|
6
6
|
/** Artifacts operation represented by {@link ArtifactsOperationError}. */
|
|
7
|
-
type ArtifactsOperation = "createClient" | "create" | "get" | "import" | "list" | "delete" | "createToken" | "listTokens" | "getToken" | "revokeToken" | "fork" | "log" | "readCommit" | "readTree" | "cli";
|
|
7
|
+
type ArtifactsOperation = "createClient" | "create" | "get" | "import" | "list" | "delete" | "createToken" | "listTokens" | "getToken" | "revokeToken" | "fork" | "info" | "log" | "readCommit" | "readTree" | "cli";
|
|
8
8
|
/** Documented string error codes returned by Cloudflare Artifacts. */
|
|
9
9
|
declare const artifactsErrorCodes: readonly ["ALREADY_EXISTS", "NOT_FOUND", "IMPORT_IN_PROGRESS", "FORK_IN_PROGRESS", "INVALID_INPUT", "INVALID_REPO_NAME", "INVALID_TTL", "INVALID_URL", "REMOTE_AUTH_REQUIRED", "UPSTREAM_UNAVAILABLE", "MEMORY_LIMIT", "INTERNAL_ERROR"];
|
|
10
10
|
/** Documented numeric error codes returned by Cloudflare Artifacts. */
|
|
@@ -74,32 +74,34 @@ type ArtifactsCreateTokenResult = CloudflareArtifactsCreateTokenResult;
|
|
|
74
74
|
type ArtifactsTokenInfo = CloudflareArtifactsTokenInfo;
|
|
75
75
|
/** Repository token list result. */
|
|
76
76
|
type ArtifactsTokenListResult = CloudflareArtifactsTokenListResult;
|
|
77
|
-
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* publish its fields in the binding reference or Workers type declarations.
|
|
82
|
-
*/
|
|
83
|
-
interface ArtifactsLogResult {
|
|
84
|
-
readonly [field: string]: unknown;
|
|
77
|
+
/** Identity recorded for a Git commit author or committer. */
|
|
78
|
+
interface ArtifactsCommitIdentity {
|
|
79
|
+
readonly name: string;
|
|
80
|
+
readonly email: string;
|
|
85
81
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Parsed Git commit returned by `readCommit()`.
|
|
88
|
-
*
|
|
89
|
-
* Cloudflare currently documents this generated type by name but does not
|
|
90
|
-
* publish its fields in the binding reference or Workers type declarations.
|
|
91
|
-
*/
|
|
82
|
+
/** Parsed Git commit returned by `readCommit()` and `log()`. */
|
|
92
83
|
interface ArtifactsCommit {
|
|
93
|
-
readonly
|
|
94
|
-
|
|
84
|
+
readonly hash: string;
|
|
85
|
+
readonly treeHash: string;
|
|
86
|
+
readonly message: string;
|
|
87
|
+
readonly author: ArtifactsCommitIdentity;
|
|
88
|
+
readonly committer: ArtifactsCommitIdentity;
|
|
89
|
+
readonly parents: ReadonlyArray<string>;
|
|
90
|
+
/** Unix timestamp in seconds. */
|
|
91
|
+
readonly authoredAt: number;
|
|
92
|
+
/** Unix timestamp in seconds. */
|
|
93
|
+
readonly committedAt: number;
|
|
94
|
+
}
|
|
95
|
+
/** Bare commit array returned by `log()`. */
|
|
96
|
+
type ArtifactsLogResult = ReadonlyArray<ArtifactsCommit>;
|
|
95
97
|
/**
|
|
96
98
|
* Parsed Git tree returned by `readTree()`.
|
|
97
99
|
*
|
|
98
100
|
* Cloudflare currently documents this generated type by name but does not
|
|
99
101
|
* publish its fields in the binding reference or Workers type declarations.
|
|
100
102
|
*/
|
|
101
|
-
interface ArtifactsTree {
|
|
102
|
-
readonly [field: string]:
|
|
103
|
+
interface ArtifactsTree<Field = unknown> {
|
|
104
|
+
readonly [field: string]: Field;
|
|
103
105
|
}
|
|
104
106
|
/** Options for `Artifacts.create()`. */
|
|
105
107
|
interface ArtifactsCreateOptions {
|
|
@@ -155,7 +157,15 @@ interface ArtifactsLogOptions {
|
|
|
155
157
|
readonly offset?: number;
|
|
156
158
|
}
|
|
157
159
|
/** Runtime repository handle, including methods absent from current shipped Workers types. */
|
|
158
|
-
interface ArtifactsRepoBinding extends ArtifactsRepoInfo {
|
|
160
|
+
interface ArtifactsRepoBinding extends Partial<ArtifactsRepoInfo> {
|
|
161
|
+
/**
|
|
162
|
+
* Read repository metadata.
|
|
163
|
+
*
|
|
164
|
+
* Remote bindings expose method-only RPC handles and provide metadata only
|
|
165
|
+
* through this method. It is optional solely for compatibility with older
|
|
166
|
+
* local handles that expose metadata as data properties.
|
|
167
|
+
*/
|
|
168
|
+
readonly info?: () => Promise<ArtifactsRepoInfo>;
|
|
159
169
|
/**
|
|
160
170
|
* Create a Git token for the repository.
|
|
161
171
|
*
|
|
@@ -178,8 +188,15 @@ interface ArtifactsBinding {
|
|
|
178
188
|
readonly list: (options?: ArtifactsListOptions) => Promise<ArtifactsRepoListResult>;
|
|
179
189
|
readonly delete: (name: RepoName) => Promise<boolean>;
|
|
180
190
|
}
|
|
181
|
-
/**
|
|
191
|
+
/**
|
|
192
|
+
* Effect wrapper around a repository handle returned by `Artifacts.get()`.
|
|
193
|
+
*
|
|
194
|
+
* The inherited metadata is the snapshot read while resolving the client.
|
|
195
|
+
* Use `info()` to refresh it from the repository handle.
|
|
196
|
+
*/
|
|
182
197
|
interface ArtifactsRepoClient extends ArtifactsRepoInfo {
|
|
198
|
+
/** Read and validate the repository's current metadata. */
|
|
199
|
+
readonly info: () => Effect.Effect<ArtifactsRepoInfo, ArtifactsOperationError>;
|
|
183
200
|
/**
|
|
184
201
|
* Create a Git token for the repository.
|
|
185
202
|
*
|
|
@@ -220,9 +237,9 @@ interface TagClass<Self, Id extends string> extends Context.ServiceClass<Self, I
|
|
|
220
237
|
readonly layer: (options: LayerOptions) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
221
238
|
}
|
|
222
239
|
/** Tests whether a value exposes the complete documented Artifacts repo handle API. */
|
|
223
|
-
declare const isArtifactsRepoBinding: (value:
|
|
240
|
+
declare const isArtifactsRepoBinding: <Candidate>(value: Candidate) => value is Candidate & ArtifactsRepoBinding;
|
|
224
241
|
/** Tests whether a value exposes the complete documented Artifacts namespace API. */
|
|
225
|
-
declare const isArtifactsBinding: (value:
|
|
242
|
+
declare const isArtifactsBinding: <Candidate>(value: Candidate) => value is Candidate & ArtifactsBinding;
|
|
226
243
|
declare const makeClient: (definition: ArtifactsDefinition) => (artifacts: ArtifactsBinding) => ArtifactsClient;
|
|
227
244
|
declare const layer: <Self>(tag: Context.Service<Self, ArtifactsClient>, definition: ArtifactsDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
228
245
|
declare const make: <Id extends string>(id: Id) => TagClass<ArtifactsService<Id>, Id>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { a as WorkerEnvironment, t as causeMessage } from "./ErrorMessage-
|
|
3
|
-
import { Context, Data, Effect, Layer } from "effect";
|
|
2
|
+
import { a as WorkerEnvironment, t as causeMessage } from "./ErrorMessage-BM0K-Nik.mjs";
|
|
3
|
+
import { Context, Data, Effect, Layer, Predicate, Schema } from "effect";
|
|
4
4
|
//#region src/Binding.ts
|
|
5
5
|
var Binding_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
BindingNotFoundError: () => BindingNotFoundError,
|
|
@@ -16,18 +16,18 @@ var BindingNotFoundError = class extends Data.TaggedError("BindingNotFoundError"
|
|
|
16
16
|
/** Error raised when a binding exists but does not match the expected shape. */
|
|
17
17
|
var BindingValidationError = class extends Data.TaggedError("BindingValidationError") {};
|
|
18
18
|
const defaultExpected = "Cloudflare binding resource";
|
|
19
|
-
const isPropertyTarget = (value) => (
|
|
19
|
+
const isPropertyTarget = (value) => Predicate.isObjectOrArray(value) || Predicate.isFunction(value);
|
|
20
20
|
const getObjectName = (value) => {
|
|
21
21
|
const tag = (() => {
|
|
22
22
|
try {
|
|
23
23
|
return Object.prototype.toString.call(value).slice(8, -1);
|
|
24
24
|
} catch {
|
|
25
|
-
return
|
|
25
|
+
return Predicate.isFunction(value) ? "function" : "object";
|
|
26
26
|
}
|
|
27
27
|
})();
|
|
28
28
|
const constructorName = (() => {
|
|
29
29
|
try {
|
|
30
|
-
return "constructor" in value &&
|
|
30
|
+
return "constructor" in value && Predicate.isFunction(value.constructor) && Predicate.isString(value.constructor.name) ? value.constructor.name : void 0;
|
|
31
31
|
} catch {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
@@ -50,14 +50,21 @@ const propertyNames = (value) => {
|
|
|
50
50
|
};
|
|
51
51
|
const isMethod = (value, name) => {
|
|
52
52
|
try {
|
|
53
|
-
return
|
|
53
|
+
return Predicate.hasProperty(value, name) && Predicate.isFunction(value[name]);
|
|
54
54
|
} catch {
|
|
55
55
|
return false;
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
const describeActual = (value) => {
|
|
59
59
|
if (value === null) return "null";
|
|
60
|
-
if (
|
|
60
|
+
if (!isPropertyTarget(value)) {
|
|
61
|
+
if (Predicate.isString(value)) return "string";
|
|
62
|
+
if (Predicate.isNumber(value)) return "number";
|
|
63
|
+
if (Predicate.isBoolean(value)) return "boolean";
|
|
64
|
+
if (Predicate.isBigInt(value)) return "bigint";
|
|
65
|
+
if (Predicate.isSymbol(value)) return "symbol";
|
|
66
|
+
return "undefined";
|
|
67
|
+
}
|
|
61
68
|
const names = propertyNames(value);
|
|
62
69
|
const methods = names.filter((name) => isMethod(value, name));
|
|
63
70
|
const properties = names.filter((name) => !methods.includes(name));
|
|
@@ -75,7 +82,7 @@ const getBinding = (env, binding, isResource, options) => Effect.gen(function* (
|
|
|
75
82
|
message: `Cloudflare binding "${binding}" failed validation. Expected WorkerEnvironment object; got ${actual}`
|
|
76
83
|
}));
|
|
77
84
|
}
|
|
78
|
-
const resource =
|
|
85
|
+
const resource = Predicate.hasProperty(env, binding) ? env[binding] : void 0;
|
|
79
86
|
if (resource === void 0) return yield* Effect.fail(new BindingNotFoundError({
|
|
80
87
|
binding,
|
|
81
88
|
message: `Cloudflare binding "${binding}" was not found in WorkerEnvironment`
|
|
@@ -171,13 +178,13 @@ var ArtifactsOperationError = class extends Data.TaggedError("ArtifactsOperation
|
|
|
171
178
|
}
|
|
172
179
|
};
|
|
173
180
|
const artifactsErrorDetails = (cause) => {
|
|
174
|
-
if (
|
|
175
|
-
const code =
|
|
176
|
-
const numericCode =
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
if (!Predicate.isObject(cause)) return {};
|
|
182
|
+
const code = Predicate.hasProperty(cause, "code") ? cause.code : void 0;
|
|
183
|
+
const numericCode = Predicate.hasProperty(cause, "numericCode") ? cause.numericCode : void 0;
|
|
184
|
+
const details = {};
|
|
185
|
+
if (Predicate.isString(code)) details.code = code;
|
|
186
|
+
if (Predicate.isNumber(numericCode)) details.numericCode = numericCode;
|
|
187
|
+
return details;
|
|
181
188
|
};
|
|
182
189
|
const artifactsError = (binding, operation, cause) => new ArtifactsOperationError({
|
|
183
190
|
binding,
|
|
@@ -193,22 +200,31 @@ const spanOptions = (binding, operation) => ({ attributes: {
|
|
|
193
200
|
binding,
|
|
194
201
|
operation
|
|
195
202
|
} });
|
|
196
|
-
const hasFunction = (value, key) =>
|
|
203
|
+
const hasFunction = (value, key) => Predicate.hasProperty(value, key) && Predicate.isFunction(value[key]);
|
|
204
|
+
const ArtifactsRepoInfoSchema = Schema.Struct({
|
|
205
|
+
id: Schema.String,
|
|
206
|
+
name: Schema.String,
|
|
207
|
+
description: Schema.NullOr(Schema.String),
|
|
208
|
+
defaultBranch: Schema.String,
|
|
209
|
+
createdAt: Schema.String,
|
|
210
|
+
updatedAt: Schema.String,
|
|
211
|
+
lastPushAt: Schema.NullOr(Schema.String),
|
|
212
|
+
source: Schema.NullOr(Schema.String),
|
|
213
|
+
readOnly: Schema.Boolean,
|
|
214
|
+
remote: Schema.String
|
|
215
|
+
});
|
|
216
|
+
const decodeRepoInfo = (binding, value) => Schema.decodeUnknownEffect(ArtifactsRepoInfoSchema)(value).pipe(Effect.mapError((cause) => artifactsError(binding, "info", cause)));
|
|
217
|
+
const readRepoInfo = (binding, repo) => {
|
|
218
|
+
if (hasFunction(repo, "info")) return tryArtifactsPromise(binding, "info", () => repo.info()).pipe(Effect.flatMap((info) => decodeRepoInfo(binding, info)), Effect.withSpan("Artifacts.info", spanOptions(binding, "info")));
|
|
219
|
+
return decodeRepoInfo(binding, repo).pipe(Effect.withSpan("Artifacts.info", spanOptions(binding, "info")));
|
|
220
|
+
};
|
|
197
221
|
/** Tests whether a value exposes the complete documented Artifacts repo handle API. */
|
|
198
|
-
const isArtifactsRepoBinding = (value) =>
|
|
222
|
+
const isArtifactsRepoBinding = (value) => hasFunction(value, "createToken") && hasFunction(value, "listTokens") && hasFunction(value, "revokeToken") && hasFunction(value, "fork") && hasFunction(value, "log") && hasFunction(value, "readCommit") && hasFunction(value, "readTree");
|
|
199
223
|
/** Tests whether a value exposes the complete documented Artifacts namespace API. */
|
|
200
|
-
const isArtifactsBinding = (value) =>
|
|
201
|
-
const wrapRepo = (binding, repo) => ({
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
description: repo.description,
|
|
205
|
-
defaultBranch: repo.defaultBranch,
|
|
206
|
-
createdAt: repo.createdAt,
|
|
207
|
-
updatedAt: repo.updatedAt,
|
|
208
|
-
lastPushAt: repo.lastPushAt,
|
|
209
|
-
source: repo.source,
|
|
210
|
-
readOnly: repo.readOnly,
|
|
211
|
-
remote: repo.remote,
|
|
224
|
+
const isArtifactsBinding = (value) => hasFunction(value, "create") && hasFunction(value, "get") && hasFunction(value, "import") && hasFunction(value, "list") && hasFunction(value, "delete");
|
|
225
|
+
const wrapRepo = (binding, repo, info) => ({
|
|
226
|
+
...info,
|
|
227
|
+
info: () => readRepoInfo(binding, repo),
|
|
212
228
|
createToken: Effect.fn("Artifacts.createToken", spanOptions(binding, "createToken"))((scope, ttl) => tryArtifactsPromise(binding, "createToken", () => repo.createToken(scope, ttl))),
|
|
213
229
|
listTokens: tryArtifactsPromise(binding, "listTokens", () => repo.listTokens()).pipe(Effect.withSpan("Artifacts.listTokens", spanOptions(binding, "listTokens"))),
|
|
214
230
|
revokeToken: Effect.fn("Artifacts.revokeToken", spanOptions(binding, "revokeToken"))((tokenOrId) => tryArtifactsPromise(binding, "revokeToken", () => repo.revokeToken(tokenOrId))),
|
|
@@ -221,7 +237,7 @@ const wrapRepo = (binding, repo) => ({
|
|
|
221
237
|
const makeClient = (definition) => (artifacts) => ({
|
|
222
238
|
definition,
|
|
223
239
|
create: Effect.fn("Artifacts.create", spanOptions(definition.binding, "create"))((name, options) => tryArtifactsPromise(definition.binding, "create", () => artifacts.create(name, options))),
|
|
224
|
-
get: Effect.fn("Artifacts.get", spanOptions(definition.binding, "get"))((name) => tryArtifactsPromise(definition.binding, "get", () => artifacts.get(name)).pipe(Effect.flatMap((repo) => isArtifactsRepoBinding(repo) ? Effect.
|
|
240
|
+
get: Effect.fn("Artifacts.get", spanOptions(definition.binding, "get"))((name) => tryArtifactsPromise(definition.binding, "get", () => artifacts.get(name)).pipe(Effect.flatMap((repo) => isArtifactsRepoBinding(repo) ? readRepoInfo(definition.binding, repo).pipe(Effect.map((info) => wrapRepo(definition.binding, repo, info))) : Effect.fail(artifactsError(definition.binding, "get", /* @__PURE__ */ new TypeError(`Expected ${expectedArtifactsRepo}`)))))),
|
|
225
241
|
import: Effect.fn("Artifacts.import", spanOptions(definition.binding, "import"))((params) => tryArtifactsPromise(definition.binding, "import", () => artifacts.import(params))),
|
|
226
242
|
list: Effect.fn("Artifacts.list", spanOptions(definition.binding, "list"))((options) => tryArtifactsPromise(definition.binding, "list", () => artifacts.list(options))),
|
|
227
243
|
delete: Effect.fn("Artifacts.delete", spanOptions(definition.binding, "delete"))((name) => tryArtifactsPromise(definition.binding, "delete", () => artifacts.delete(name))),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config, ConfigProvider, Context, Effect, Layer } from "effect";
|
|
1
|
+
import { Config, ConfigProvider, Context, Effect, Layer, Predicate } from "effect";
|
|
2
2
|
declare namespace Environment_d_exports {
|
|
3
3
|
export { WorkerConfig, WorkerEnv, WorkerEnvironment };
|
|
4
4
|
}
|
|
@@ -116,6 +116,7 @@ declare class BindingValidationError extends BindingValidationError_base<{
|
|
|
116
116
|
interface ValidationOptions {
|
|
117
117
|
readonly expected?: string;
|
|
118
118
|
}
|
|
119
|
+
type BindingCandidate = Parameters<typeof Predicate.isUnknown>[0];
|
|
119
120
|
/**
|
|
120
121
|
* Creates a Context tag + layer for reading and validating a Cloudflare binding.
|
|
121
122
|
*
|
|
@@ -128,11 +129,11 @@ interface BindingService<Self, Id extends string, Service> extends Context.Servi
|
|
|
128
129
|
readonly binding: string;
|
|
129
130
|
readonly layer: Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
130
131
|
}
|
|
131
|
-
declare function layer<Self, Resource>(tag: Context.Service<Self, Resource>, binding: string, isResource: (value:
|
|
132
|
-
declare function layer<Self, Resource, Service>(tag: Context.Service<Self, Service>, binding: string, isResource: (value:
|
|
132
|
+
declare function layer<Self, Resource>(tag: Context.Service<Self, Resource>, binding: string, isResource: (value: BindingCandidate) => value is Resource, wrap?: undefined, options?: ValidationOptions): Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
133
|
+
declare function layer<Self, Resource, Service>(tag: Context.Service<Self, Service>, binding: string, isResource: (value: BindingCandidate) => value is Resource, wrap: (resource: Resource) => Service, options?: ValidationOptions): Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
133
134
|
declare const Service: <Self>() => {
|
|
134
|
-
<Id extends string, Resource>(id: Id, binding: string, isResource: (value:
|
|
135
|
-
<Id extends string, Resource, Service>(id: Id, binding: string, isResource: (value:
|
|
135
|
+
<Id extends string, Resource>(id: Id, binding: string, isResource: (value: BindingCandidate) => value is Resource, wrap?: undefined, options?: ValidationOptions): BindingService<Self, Id, Resource>;
|
|
136
|
+
<Id extends string, Resource, Service>(id: Id, binding: string, isResource: (value: BindingCandidate) => value is Resource, wrap: (resource: Resource) => Service, options?: ValidationOptions): BindingService<Self, Id, Service>;
|
|
136
137
|
};
|
|
137
138
|
//#endregion
|
|
138
139
|
export { Environment_d_exports as a, WorkerEnvironment as c, Binding_d_exports as i, BindingService as n, WorkerConfig as o, BindingValidationError as r, WorkerEnv as s, BindingNotFoundError as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ArtifactsOperationError, c as ArtifactsTokenListResult, i as ArtifactsCreateTokenResult, n as ArtifactsCreateOptions, o as ArtifactsRepoInfo, r as ArtifactsCreateRepoResult, s as ArtifactsTokenInfo, t as ArtifactsBinding, u as RepoName } from "./Artifacts-
|
|
1
|
+
import { a as ArtifactsOperationError, c as ArtifactsTokenListResult, i as ArtifactsCreateTokenResult, n as ArtifactsCreateOptions, o as ArtifactsRepoInfo, r as ArtifactsCreateRepoResult, s as ArtifactsTokenInfo, t as ArtifactsBinding, u as RepoName } from "./Artifacts-DnHQA-Ax.mjs";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import { ArtifactClient, ArtifactImportOptions, ArtifactImportSource, ArtifactRepoSummary, ArtifactScope, ArtifactsCLIInput, ArtifactsCLIResult, RemoteAddFn } from "@cloudflare/computer/artifacts";
|
|
4
4
|
//#region src/ComputerArtifacts.d.ts
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { t as ArtifactsOperationError } from "./Artifacts-
|
|
2
|
-
import { Effect } from "effect";
|
|
1
|
+
import { t as ArtifactsOperationError } from "./Artifacts-rq3hUKQE.mjs";
|
|
2
|
+
import { Effect, Predicate } from "effect";
|
|
3
3
|
//#region src/ComputerArtifacts.ts
|
|
4
4
|
const artifactsErrorDetails = (cause) => {
|
|
5
|
-
if (
|
|
6
|
-
const code =
|
|
7
|
-
const numericCode =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
if (!Predicate.isObject(cause)) return {};
|
|
6
|
+
const code = Predicate.hasProperty(cause, "code") ? cause.code : void 0;
|
|
7
|
+
const numericCode = Predicate.hasProperty(cause, "numericCode") ? cause.numericCode : void 0;
|
|
8
|
+
const details = {};
|
|
9
|
+
if (Predicate.isString(code)) details.code = code;
|
|
10
|
+
if (Predicate.isNumber(numericCode)) details.numericCode = numericCode;
|
|
11
|
+
return details;
|
|
12
12
|
};
|
|
13
13
|
const operationError = (binding, operation, cause) => new ArtifactsOperationError({
|
|
14
14
|
binding,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComputerArtifactsClient } from "./ComputerArtifacts.mjs";
|
|
2
|
-
import { t as DurableObjectState } from "./DurableObjectState-
|
|
2
|
+
import { t as DurableObjectState } from "./DurableObjectState-B3uFY1eM.mjs";
|
|
3
3
|
import { Context, Effect, Layer, Schema, Scope, Stream } from "effect";
|
|
4
4
|
import { CommitView, GitClient, GitCloneOptions, GitCommitOptions, GitDiffOptions, GitFetchOptions, GitLogOptions, GitUpdateRefOptions } from "@cloudflare/computer/git";
|
|
5
5
|
import { ExecSyncResult, RuntimeExecOptions, RuntimeGetOptions, RuntimeKillOptions, ShellValue, SkippedEntry, ThinkWorkspaceCompatibility, WorkspaceClient, WorkspaceRuntimeResult, WorkspaceRuntimeValue as WorkspaceRuntimeValue$1 } from "@cloudflare/computer";
|
|
@@ -229,7 +229,7 @@ type EffectThinkMethod<Method> = Method extends ((...args: infer Args) => Promis
|
|
|
229
229
|
/** Effect wrapper of the optional Think compatibility surface. */
|
|
230
230
|
type ComputerWorkspaceThink = { readonly [Name in keyof ThinkWorkspaceCompatibility]: EffectThinkMethod<ThinkWorkspaceCompatibility[Name]>; };
|
|
231
231
|
/** Effect service over every client surface exposed by Cloudflare Computer. */
|
|
232
|
-
interface
|
|
232
|
+
interface ComputerWorkspaceService {
|
|
233
233
|
readonly fs: ComputerWorkspaceFilesystem;
|
|
234
234
|
readonly git: ComputerWorkspaceGit;
|
|
235
235
|
readonly runtime: ComputerWorkspaceRuntime;
|
|
@@ -265,8 +265,8 @@ interface ComputerWorkspaceShape {
|
|
|
265
265
|
* {@link ComputerWorkspace.layer} in Durable Objects so the parent client and
|
|
266
266
|
* every runtime handle are disposed by Effect `Scope`.
|
|
267
267
|
*/
|
|
268
|
-
declare const fromWorkspaceClient: (client: WorkspaceClient) =>
|
|
269
|
-
declare const ComputerWorkspace_base: Context.ServiceClass<ComputerWorkspace, "effect-cf/ComputerWorkspace",
|
|
268
|
+
declare const fromWorkspaceClient: (client: WorkspaceClient) => ComputerWorkspaceService;
|
|
269
|
+
declare const ComputerWorkspace_base: Context.ServiceClass<ComputerWorkspace, "effect-cf/ComputerWorkspace", ComputerWorkspaceService>;
|
|
270
270
|
/** Effect service for the workspace owned by the enclosing Durable Object. */
|
|
271
271
|
declare class ComputerWorkspace extends ComputerWorkspace_base {
|
|
272
272
|
/**
|
|
@@ -276,4 +276,4 @@ declare class ComputerWorkspace extends ComputerWorkspace_base {
|
|
|
276
276
|
static readonly layer: Layer.Layer<ComputerWorkspace, never, DurableObjectState>;
|
|
277
277
|
}
|
|
278
278
|
//#endregion
|
|
279
|
-
export { ComputerWorkspace, ComputerWorkspaceAssets, ComputerWorkspaceFilesystem, ComputerWorkspaceGit, ComputerWorkspaceRuntime, ComputerWorkspaceShape, ComputerWorkspaceThink, ListDirectoryOptions, ReadTextFileOptions, RemovePathOptions, WorkspaceAssetsError, WorkspaceDirectoryEntry, WorkspaceEntryStat, WorkspaceExec, WorkspaceExecChunk, WorkspaceExecCollect, WorkspaceExecEncoding, WorkspaceExecError, WorkspaceExecEvent, WorkspaceExecOptions, WorkspaceExecResult, WorkspaceExecRun, WorkspaceExecSignal, WorkspaceExecSkippedEntry, WorkspaceExecSyncResult, WorkspaceFindOptions, WorkspaceFoundEntry, WorkspaceFsError, WorkspaceGetExec, WorkspaceGetExecOptions, WorkspaceGitCheckoutOptions, WorkspaceGitCloneOptions, WorkspaceGitCommit, WorkspaceGitCommitOptions, WorkspaceGitDiffOptions, WorkspaceGitError, WorkspaceGitFetchOptions, WorkspaceGitFetchResult, WorkspaceGitLogOptions, WorkspaceGitPerson, WorkspaceGitUpdateRefOptions, WorkspaceGrepMatch, WorkspaceGrepOptions, WorkspaceMkdirOptions, WorkspaceReadEncoding, WorkspaceReadFile, WorkspaceReadFileOptions, WorkspaceRuntimeValue, WorkspaceWriteFileContent, WorkspaceWriteFileOptions, fromWorkspaceClient };
|
|
279
|
+
export { ComputerWorkspace, ComputerWorkspaceAssets, ComputerWorkspaceFilesystem, ComputerWorkspaceGit, ComputerWorkspaceRuntime, ComputerWorkspaceService, type ComputerWorkspaceService as ComputerWorkspaceShape, ComputerWorkspaceThink, ListDirectoryOptions, ReadTextFileOptions, RemovePathOptions, WorkspaceAssetsError, WorkspaceDirectoryEntry, WorkspaceEntryStat, WorkspaceExec, WorkspaceExecChunk, WorkspaceExecCollect, WorkspaceExecEncoding, WorkspaceExecError, WorkspaceExecEvent, WorkspaceExecOptions, WorkspaceExecResult, WorkspaceExecRun, WorkspaceExecSignal, WorkspaceExecSkippedEntry, WorkspaceExecSyncResult, WorkspaceFindOptions, WorkspaceFoundEntry, WorkspaceFsError, WorkspaceGetExec, WorkspaceGetExecOptions, WorkspaceGitCheckoutOptions, WorkspaceGitCloneOptions, WorkspaceGitCommit, WorkspaceGitCommitOptions, WorkspaceGitDiffOptions, WorkspaceGitError, WorkspaceGitFetchOptions, WorkspaceGitFetchResult, WorkspaceGitLogOptions, WorkspaceGitPerson, WorkspaceGitUpdateRefOptions, WorkspaceGrepMatch, WorkspaceGrepOptions, WorkspaceMkdirOptions, WorkspaceReadEncoding, WorkspaceReadFile, WorkspaceReadFileOptions, WorkspaceRuntimeValue, WorkspaceWriteFileContent, WorkspaceWriteFileOptions, fromWorkspaceClient };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as DurableObjectState } from "./DurableObjectState-
|
|
1
|
+
import { t as DurableObjectState } from "./DurableObjectState-BjkK2kwH.mjs";
|
|
2
2
|
import { fromClient } from "./ComputerArtifacts.mjs";
|
|
3
3
|
import { t as lookup } from "./ComputerWorkspaceHostRegistry-CY5Fv4Ng.mjs";
|
|
4
|
-
import { Context, Effect, Layer, Schema, Stream } from "effect";
|
|
4
|
+
import { Context, Effect, Layer, Predicate, Schema, Stream } from "effect";
|
|
5
5
|
//#region src/ComputerWorkspace.ts
|
|
6
6
|
/**
|
|
7
7
|
* Workspace errors use `Schema.TaggedError`, unlike most local binding errors,
|
|
@@ -39,36 +39,50 @@ var WorkspaceAssetsError = class extends Schema.TaggedError()("WorkspaceAssetsEr
|
|
|
39
39
|
}) {};
|
|
40
40
|
const errorMessage = (cause) => cause instanceof Error ? cause.message : String(cause);
|
|
41
41
|
const errorCode = (cause) => {
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if (Predicate.hasProperty(cause, "code") && Predicate.isString(cause.code)) return cause.code;
|
|
43
|
+
};
|
|
44
|
+
const fsError = (operation, path, cause) => {
|
|
45
|
+
const properties = {
|
|
46
|
+
operation,
|
|
47
|
+
path,
|
|
48
|
+
message: errorMessage(cause),
|
|
49
|
+
cause
|
|
50
|
+
};
|
|
51
|
+
const code = errorCode(cause);
|
|
52
|
+
if (code !== void 0) properties.code = code;
|
|
53
|
+
return WorkspaceFsError.make(properties);
|
|
54
|
+
};
|
|
55
|
+
const gitError = (operation, cause) => {
|
|
56
|
+
const properties = {
|
|
57
|
+
operation,
|
|
58
|
+
message: errorMessage(cause),
|
|
59
|
+
cause
|
|
60
|
+
};
|
|
61
|
+
const code = errorCode(cause);
|
|
62
|
+
if (code !== void 0) properties.code = code;
|
|
63
|
+
return WorkspaceGitError.make(properties);
|
|
64
|
+
};
|
|
65
|
+
const execError = (operation, cause) => {
|
|
66
|
+
const properties = {
|
|
67
|
+
operation,
|
|
68
|
+
message: errorMessage(cause),
|
|
69
|
+
cause
|
|
70
|
+
};
|
|
71
|
+
const code = errorCode(cause);
|
|
72
|
+
if (code !== void 0) properties.code = code;
|
|
73
|
+
return WorkspaceExecError.make(properties);
|
|
74
|
+
};
|
|
75
|
+
const assetsError = (operation, path, cause) => {
|
|
76
|
+
const properties = {
|
|
77
|
+
operation,
|
|
78
|
+
path,
|
|
79
|
+
message: errorMessage(cause),
|
|
80
|
+
cause
|
|
81
|
+
};
|
|
82
|
+
const code = errorCode(cause);
|
|
83
|
+
if (code !== void 0) properties.code = code;
|
|
84
|
+
return WorkspaceAssetsError.make(properties);
|
|
45
85
|
};
|
|
46
|
-
const fsError = (operation, path, cause) => WorkspaceFsError.make({
|
|
47
|
-
operation,
|
|
48
|
-
path,
|
|
49
|
-
message: errorMessage(cause),
|
|
50
|
-
cause,
|
|
51
|
-
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
52
|
-
});
|
|
53
|
-
const gitError = (operation, cause) => WorkspaceGitError.make({
|
|
54
|
-
operation,
|
|
55
|
-
message: errorMessage(cause),
|
|
56
|
-
cause,
|
|
57
|
-
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
58
|
-
});
|
|
59
|
-
const execError = (operation, cause) => WorkspaceExecError.make({
|
|
60
|
-
operation,
|
|
61
|
-
message: errorMessage(cause),
|
|
62
|
-
cause,
|
|
63
|
-
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
64
|
-
});
|
|
65
|
-
const assetsError = (operation, path, cause) => WorkspaceAssetsError.make({
|
|
66
|
-
operation,
|
|
67
|
-
path,
|
|
68
|
-
message: errorMessage(cause),
|
|
69
|
-
cause,
|
|
70
|
-
...errorCode(cause) === void 0 ? {} : { code: errorCode(cause) }
|
|
71
|
-
});
|
|
72
86
|
const tryFs = (operation, path, evaluate) => Effect.tryPromise({
|
|
73
87
|
try: evaluate,
|
|
74
88
|
catch: (cause) => fsError(operation, path, cause)
|
|
@@ -223,11 +237,10 @@ const makeGit = (gitClient) => {
|
|
|
223
237
|
operation: "log"
|
|
224
238
|
} })(function* (options) {
|
|
225
239
|
const { maxCount, ...upstreamOptions } = options ?? {};
|
|
240
|
+
const logOptions = { ...upstreamOptions };
|
|
241
|
+
if (logOptions.depth === void 0 && maxCount !== void 0) logOptions.depth = maxCount;
|
|
226
242
|
return (yield* Effect.tryPromise({
|
|
227
|
-
try: () => gitClient.log(
|
|
228
|
-
...upstreamOptions,
|
|
229
|
-
...upstreamOptions.depth === void 0 && maxCount !== void 0 ? { depth: maxCount } : {}
|
|
230
|
-
}),
|
|
243
|
+
try: () => gitClient.log(logOptions),
|
|
231
244
|
catch: (cause) => gitError("log", cause)
|
|
232
245
|
})).map(gitCommit);
|
|
233
246
|
});
|
|
@@ -235,7 +248,7 @@ const makeGit = (gitClient) => {
|
|
|
235
248
|
family: "git",
|
|
236
249
|
operation: "revParse"
|
|
237
250
|
} })(function* (input) {
|
|
238
|
-
const options =
|
|
251
|
+
const options = Predicate.isString(input) ? { ref: input } : input;
|
|
239
252
|
return yield* Effect.tryPromise({
|
|
240
253
|
try: () => gitClient.revParse(options),
|
|
241
254
|
catch: (cause) => gitError("revParse", cause)
|
|
@@ -286,35 +299,41 @@ const makeGit = (gitClient) => {
|
|
|
286
299
|
};
|
|
287
300
|
const runtimeExecOptions = (options) => {
|
|
288
301
|
const { encoding = "utf8", timeoutMillis, timeoutMs, ...rest } = options ?? {};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
302
|
+
const runtimeOptions = { ...rest };
|
|
303
|
+
if (encoding === "utf8") runtimeOptions.encoding = "utf8";
|
|
304
|
+
const selectedTimeout = timeoutMs ?? timeoutMillis;
|
|
305
|
+
if (selectedTimeout !== void 0) runtimeOptions.timeoutMs = selectedTimeout;
|
|
306
|
+
return runtimeOptions;
|
|
294
307
|
};
|
|
295
308
|
const runtimeGetOptions = (options) => {
|
|
296
309
|
const { encoding = "utf8", ...rest } = options ?? {};
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
310
|
+
const runtimeOptions = { ...rest };
|
|
311
|
+
if (encoding === "utf8") runtimeOptions.encoding = "utf8";
|
|
312
|
+
return runtimeOptions;
|
|
313
|
+
};
|
|
314
|
+
const wrapRuntimeResult = (result) => {
|
|
315
|
+
const stdout = result.stdout;
|
|
316
|
+
const stderr = result.stderr;
|
|
317
|
+
const wrapped = {
|
|
318
|
+
status: result.status,
|
|
319
|
+
exitCode: result.exitCode,
|
|
320
|
+
stdout,
|
|
321
|
+
stderr,
|
|
322
|
+
pushed: result.pushed,
|
|
323
|
+
pulled: result.pulled,
|
|
324
|
+
skipped: result.skipped,
|
|
325
|
+
sync: result.sync
|
|
326
|
+
};
|
|
327
|
+
return result.value === void 0 ? wrapped : {
|
|
328
|
+
...wrapped,
|
|
329
|
+
value: result.value
|
|
300
330
|
};
|
|
301
331
|
};
|
|
302
|
-
const wrapRuntimeResult = (result) => ({
|
|
303
|
-
status: result.status,
|
|
304
|
-
exitCode: result.exitCode,
|
|
305
|
-
stdout: result.stdout,
|
|
306
|
-
stderr: result.stderr,
|
|
307
|
-
...result.value === void 0 ? {} : { value: result.value },
|
|
308
|
-
pushed: result.pushed,
|
|
309
|
-
pulled: result.pulled,
|
|
310
|
-
skipped: result.skipped,
|
|
311
|
-
sync: result.sync
|
|
312
|
-
});
|
|
313
332
|
const wrapRuntimeEvent = (event) => {
|
|
314
333
|
switch (event.name) {
|
|
315
334
|
case "stdout": {
|
|
316
335
|
const chunk = event.value;
|
|
317
|
-
return
|
|
336
|
+
return Predicate.isString(chunk) ? {
|
|
318
337
|
_tag: "Stdout",
|
|
319
338
|
id: event.id,
|
|
320
339
|
sequence: event.seq,
|
|
@@ -330,7 +349,7 @@ const wrapRuntimeEvent = (event) => {
|
|
|
330
349
|
}
|
|
331
350
|
case "stderr": {
|
|
332
351
|
const chunk = event.value;
|
|
333
|
-
return
|
|
352
|
+
return Predicate.isString(chunk) ? {
|
|
334
353
|
_tag: "Stderr",
|
|
335
354
|
id: event.id,
|
|
336
355
|
sequence: event.seq,
|
|
@@ -344,20 +363,25 @@ const wrapRuntimeEvent = (event) => {
|
|
|
344
363
|
bytes: chunk
|
|
345
364
|
};
|
|
346
365
|
}
|
|
347
|
-
case "exit":
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
366
|
+
case "exit":
|
|
367
|
+
const exitEvent = {
|
|
368
|
+
_tag: "Exit",
|
|
369
|
+
id: event.id,
|
|
370
|
+
sequence: event.seq,
|
|
371
|
+
exitCode: event.code
|
|
372
|
+
};
|
|
373
|
+
return event.result === void 0 ? exitEvent : {
|
|
374
|
+
...exitEvent,
|
|
375
|
+
value: event.result
|
|
376
|
+
};
|
|
354
377
|
}
|
|
355
378
|
};
|
|
356
379
|
const wrapRun = (handle) => {
|
|
380
|
+
const mapRuntimeEvent = wrapRuntimeEvent;
|
|
357
381
|
const events = Stream.fromReadableStream({
|
|
358
382
|
evaluate: () => handle,
|
|
359
383
|
onError: (cause) => execError("events", cause)
|
|
360
|
-
}).pipe(Stream.map(
|
|
384
|
+
}).pipe(Stream.map(mapRuntimeEvent));
|
|
361
385
|
const result = Effect.tryPromise({
|
|
362
386
|
try: () => handle.result(),
|
|
363
387
|
catch: (cause) => execError("result", cause)
|
|
@@ -386,14 +410,14 @@ const makeRuntime = (client) => {
|
|
|
386
410
|
family: "runtime",
|
|
387
411
|
operation: "exec"
|
|
388
412
|
} })(function* (source, optionsOrValue, ...remainingValues) {
|
|
389
|
-
const options =
|
|
413
|
+
const options = Predicate.isString(source) ? optionsOrValue : void 0;
|
|
390
414
|
yield* Effect.annotateCurrentSpan({
|
|
391
415
|
backend: options?.backend,
|
|
392
416
|
runId: options?.id
|
|
393
417
|
});
|
|
394
418
|
const handle = yield* Effect.acquireRelease(Effect.tryPromise({
|
|
395
419
|
try: () => {
|
|
396
|
-
if (
|
|
420
|
+
if (Predicate.isString(source)) return client.runtime.exec(source, runtimeExecOptions(options));
|
|
397
421
|
const values = optionsOrValue === void 0 ? remainingValues : [optionsOrValue, ...remainingValues];
|
|
398
422
|
return client.runtime.exec(source, ...values);
|
|
399
423
|
},
|
|
@@ -477,15 +501,23 @@ const makeThink = (client) => {
|
|
|
477
501
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
478
502
|
return yield* tryFs(`think.${operation}`, path, () => evaluate(...args));
|
|
479
503
|
});
|
|
504
|
+
const readFile = client.readFile.bind(client);
|
|
505
|
+
const readFileBytes = client.readFileBytes.bind(client);
|
|
506
|
+
const writeFile = client.writeFile.bind(client);
|
|
507
|
+
const readDir = client.readDir.bind(client);
|
|
508
|
+
const rm = client.rm.bind(client);
|
|
509
|
+
const glob = client.glob.bind(client);
|
|
510
|
+
const mkdir = client.mkdir.bind(client);
|
|
511
|
+
const stat = client.stat.bind(client);
|
|
480
512
|
return {
|
|
481
|
-
readFile: method("readFile", (path) => path, (path) =>
|
|
482
|
-
readFileBytes: method("readFileBytes", (path) => path, (path) =>
|
|
483
|
-
writeFile: method("writeFile", (path, _content) => path, (path, content) =>
|
|
484
|
-
readDir: method("readDir", (path, _options) => path, (path, options) =>
|
|
485
|
-
rm: method("rm", (path, _options) => path, (path, options) =>
|
|
486
|
-
glob: method("glob", (pattern) => pattern, (pattern) =>
|
|
487
|
-
mkdir: method("mkdir", (path, _options) => path, (path, options) =>
|
|
488
|
-
stat: method("stat", (path) => path, (path) =>
|
|
513
|
+
readFile: method("readFile", (path) => path, (path) => readFile(path)),
|
|
514
|
+
readFileBytes: method("readFileBytes", (path) => path, (path) => readFileBytes(path)),
|
|
515
|
+
writeFile: method("writeFile", (path, _content) => path, (path, content) => writeFile(path, content)),
|
|
516
|
+
readDir: method("readDir", (path, _options) => path, (path, options) => readDir(path, options)),
|
|
517
|
+
rm: method("rm", (path, _options) => path, (path, options) => rm(path, options)),
|
|
518
|
+
glob: method("glob", (pattern) => pattern, (pattern) => glob(pattern)),
|
|
519
|
+
mkdir: method("mkdir", (path, _options) => path, (path, options) => mkdir(path, options)),
|
|
520
|
+
stat: method("stat", (path) => path, (path) => stat(path))
|
|
489
521
|
};
|
|
490
522
|
};
|
|
491
523
|
/**
|