effect-cf 0.27.0 → 0.28.1

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.
Files changed (67) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +6 -0
  3. package/dist/{Artifacts-DcoXcRP5.d.mts → Artifacts-DnHQA-Ax.d.mts} +42 -25
  4. package/dist/{Artifacts-BhWrdyqX.mjs → Artifacts-rq3hUKQE.mjs} +46 -30
  5. package/dist/{Binding-COCtoJXa.d.mts → Binding-xJJJPmiD.d.mts} +6 -5
  6. package/dist/ComputerArtifacts.d.mts +1 -1
  7. package/dist/ComputerArtifacts.mjs +9 -9
  8. package/dist/ComputerWorkspace.d.mts +5 -5
  9. package/dist/ComputerWorkspace.mjs +107 -75
  10. package/dist/ComputerWorkspaceHost.d.mts +1 -1
  11. package/dist/ComputerWorkspaceHost.mjs +18 -16
  12. package/dist/{DurableObjectState-Dux8KfjG.mjs → DurableObjectState-BjkK2kwH.mjs} +3 -3
  13. package/dist/{DurableObjectState-biHrHwrh.d.mts → DurableObjectState-OupNMMUl.d.mts} +89 -64
  14. package/dist/{ErrorMessage-_lg53p3W.mjs → ErrorMessage-BM0K-Nik.mjs} +1 -4
  15. package/dist/{Hyperdrive-6p59yyVk.d.mts → Hyperdrive-z-9fFz15.d.mts} +2 -2
  16. package/dist/HyperdrivePg.d.mts +2 -2
  17. package/dist/Vitest.d.mts +6 -5
  18. package/dist/Vitest.mjs +2 -2
  19. package/dist/{WorkflowBinding-zlRPCXVf.d.mts → WorkflowBinding-DUZtKCVM.d.mts} +5 -10
  20. package/dist/index.d.mts +88 -62
  21. package/dist/index.mjs +291 -181
  22. package/package.json +1 -1
  23. package/src/AiGateway.ts +62 -7
  24. package/src/AnalyticsEngine.ts +17 -13
  25. package/src/Artifacts.ts +111 -47
  26. package/src/Binding.ts +34 -23
  27. package/src/BrowserRendering.ts +72 -33
  28. package/src/CloudflareOtlp.ts +21 -11
  29. package/src/ComputerArtifacts.ts +17 -9
  30. package/src/ComputerWorkspace.ts +202 -98
  31. package/src/ComputerWorkspaceHost.ts +55 -27
  32. package/src/ContainerNamespace.ts +8 -9
  33. package/src/D1.ts +8 -14
  34. package/src/DurableObject.ts +33 -13
  35. package/src/DurableObjectAlarm.ts +17 -5
  36. package/src/DurableObjectDefinition.ts +89 -72
  37. package/src/DurableObjectNamespace.ts +26 -12
  38. package/src/DurableObjectRpcWebSocket.ts +9 -10
  39. package/src/DurableObjectState.ts +1 -0
  40. package/src/DurableObjectStorage.ts +5 -2
  41. package/src/DurableObjectWebSocket.ts +4 -1
  42. package/src/Email.ts +26 -25
  43. package/src/Hyperdrive.ts +4 -10
  44. package/src/Images.ts +12 -14
  45. package/src/Kv.ts +15 -17
  46. package/src/Queue.ts +2 -1
  47. package/src/QueueBinding.ts +7 -12
  48. package/src/QueueDefinition.ts +7 -2
  49. package/src/R2.ts +33 -24
  50. package/src/Rpc.ts +15 -21
  51. package/src/RpcDefinition.ts +33 -38
  52. package/src/ServiceBinding.ts +26 -8
  53. package/src/Vectorize.ts +45 -18
  54. package/src/Vitest.ts +9 -3
  55. package/src/WebTransport.ts +11 -5
  56. package/src/Worker.ts +97 -24
  57. package/src/WorkerDefinition.ts +143 -63
  58. package/src/WorkersAi.ts +50 -28
  59. package/src/Workflow.ts +66 -13
  60. package/src/WorkflowBinding.ts +18 -25
  61. package/src/WorkflowDefinition.ts +4 -2
  62. package/src/internal/Entrypoint.ts +29 -13
  63. package/src/internal/ErrorMessage.ts +7 -6
  64. package/src/internal/RpcInvocation.ts +34 -11
  65. package/src/internal/Runtime.ts +33 -22
  66. package/src/internal/Telemetry.ts +17 -10
  67. package/src/internal/WorkerContext.ts +3 -3
@@ -1,7 +1,7 @@
1
- import { t as DurableObjectState } from "./DurableObjectState-Dux8KfjG.mjs";
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 (typeof cause !== "object" || cause === null) return;
43
- const code = Reflect.get(cause, "code");
44
- return typeof code === "string" ? code : void 0;
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 = typeof input === "string" ? { ref: input } : input;
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
- return {
290
- ...rest,
291
- ...encoding === "utf8" ? { encoding: "utf8" } : {},
292
- ...timeoutMs === void 0 && timeoutMillis === void 0 ? {} : { timeoutMs: timeoutMs ?? timeoutMillis }
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
- return {
298
- ...rest,
299
- ...encoding === "utf8" ? { encoding: "utf8" } : {}
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 typeof chunk === "string" ? {
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 typeof chunk === "string" ? {
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": return {
348
- _tag: "Exit",
349
- id: event.id,
350
- sequence: event.seq,
351
- exitCode: event.code,
352
- ...event.result === void 0 ? {} : { value: event.result }
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(wrapRuntimeEvent));
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 = typeof source === "string" ? optionsOrValue : void 0;
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 (typeof source === "string") return client.runtime.exec(source, runtimeExecOptions(options));
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) => client.readFile(path)),
482
- readFileBytes: method("readFileBytes", (path) => path, (path) => client.readFileBytes(path)),
483
- writeFile: method("writeFile", (path, _content) => path, (path, content) => client.writeFile(path, content)),
484
- readDir: method("readDir", (path, _options) => path, (path, options) => client.readDir(path, options)),
485
- rm: method("rm", (path, _options) => path, (path, options) => client.rm(path, options)),
486
- glob: method("glob", (pattern) => pattern, (pattern) => client.glob(pattern)),
487
- mkdir: method("mkdir", (path, _options) => path, (path, options) => client.mkdir(path, options)),
488
- stat: method("stat", (path) => path, (path) => client.stat(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
  /**
@@ -1,4 +1,4 @@
1
- import { t as ArtifactsBinding } from "./Artifacts-DcoXcRP5.mjs";
1
+ import { t as ArtifactsBinding } from "./Artifacts-DnHQA-Ax.mjs";
2
2
  import { GitClientFactory } from "@cloudflare/computer/git";
3
3
  import { DurableObjectStorageLike, SyncRetryIntent, SyncRetryOptions, SyncRetryScheduler, WithWorkspaceCtor, WorkspaceAttributeValue, WorkspaceAttributes, WorkspaceObserver, WorkspaceOptions, WorkspaceRegisteredBackend, WorkspaceRetryPendingSyncResult, WorkspaceServiceProxy, WorkspaceSpan } from "@cloudflare/computer";
4
4
  import { ShellModuleGroup, WorkerShellBackendOptions, WorkerShellLoader, WorkspaceEgressPolicy } from "@cloudflare/computer/backends/worker-shell";
@@ -18,24 +18,26 @@ const toWorkspaceOptions = (config) => {
18
18
  egress: egress ?? { mode: "none" }
19
19
  }));
20
20
  }
21
- return {
21
+ const options = {
22
22
  storage: config.storage,
23
- git: config.git ?? createGitClient(),
24
- ...config.gitIdentity === void 0 ? {} : { defaultGitIdentity: config.gitIdentity },
25
- ...backends.length === 0 ? {} : { backends },
26
- ...config.sessionId === void 0 ? {} : { sessionId: config.sessionId },
27
- ...config.mounts === void 0 ? {} : { mounts: config.mounts },
28
- ...config.observer === void 0 ? {} : { observer: config.observer },
29
- ...config.retryScheduler === void 0 ? {} : { retryScheduler: config.retryScheduler },
30
- ...config.retry === void 0 ? {} : { retry: config.retry },
31
- ...config.assets === void 0 ? {} : { assets: config.assets },
32
- ...config.artifacts === void 0 ? {} : { artifacts: {
33
- binding: config.artifacts.binding,
34
- ...config.artifacts.sessionId === void 0 ? {} : { sessionId: config.artifacts.sessionId }
35
- } },
36
- ...config.now === void 0 ? {} : { now: config.now },
37
- ...config.useThink === void 0 ? {} : { useThink: config.useThink }
23
+ git: config.git ?? createGitClient()
38
24
  };
25
+ if (config.gitIdentity !== void 0) options.defaultGitIdentity = config.gitIdentity;
26
+ if (backends.length !== 0) options.backends = backends;
27
+ if (config.sessionId !== void 0) options.sessionId = config.sessionId;
28
+ if (config.mounts !== void 0) options.mounts = config.mounts;
29
+ if (config.observer !== void 0) options.observer = config.observer;
30
+ if (config.retryScheduler !== void 0) options.retryScheduler = config.retryScheduler;
31
+ if (config.retry !== void 0) options.retry = config.retry;
32
+ if (config.assets !== void 0) options.assets = config.assets;
33
+ if (config.artifacts !== void 0) {
34
+ const artifacts = { binding: config.artifacts.binding };
35
+ if (config.artifacts.sessionId !== void 0) artifacts.sessionId = config.artifacts.sessionId;
36
+ options.artifacts = artifacts;
37
+ }
38
+ if (config.now !== void 0) options.now = config.now;
39
+ if (config.useThink !== void 0) options.useThink = config.useThink;
40
+ return options;
39
41
  };
40
42
  const HostArguments = Symbol("effect-cf/ComputerWorkspaceHost/arguments");
41
43
  /**
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
- import { t as causeMessage } from "./ErrorMessage-_lg53p3W.mjs";
3
- import { Cause, Context, Data, Effect, Exit, Option, Result, Schema } from "effect";
2
+ import { t as causeMessage } from "./ErrorMessage-BM0K-Nik.mjs";
3
+ import { Cause, Context, Data, Effect, Exit, Option, Predicate, Result, Schema } from "effect";
4
4
  //#region src/DurableObjectStorage.ts
5
5
  var DurableObjectStorage_exports = /* @__PURE__ */ __exportAll({
6
6
  StorageOperationError: () => StorageOperationError,
@@ -80,7 +80,7 @@ const fromSyncKvStorage = (kv) => ({
80
80
  const fromDurableObjectTransaction = (txn) => ({
81
81
  get: (keyOrKeys, options) => Array.isArray(keyOrKeys) ? tryStoragePromise("transaction.get", () => txn.get(keyOrKeys, options)) : tryStoragePromise("transaction.get", () => txn.get(keyOrKeys, options)),
82
82
  list: (options) => tryStoragePromise("transaction.list", () => txn.list(options)),
83
- put: (keyOrEntries, valueOrOptions, maybeOptions) => tryStoragePromise("transaction.put", () => typeof keyOrEntries === "string" ? txn.put(keyOrEntries, valueOrOptions, maybeOptions) : txn.put(keyOrEntries, valueOrOptions)),
83
+ put: (keyOrEntries, valueOrOptions, maybeOptions) => tryStoragePromise("transaction.put", () => Predicate.isString(keyOrEntries) ? txn.put(keyOrEntries, valueOrOptions, maybeOptions) : txn.put(keyOrEntries, valueOrOptions)),
84
84
  delete: (keyOrKeys, options) => Array.isArray(keyOrKeys) ? tryStoragePromise("transaction.delete", () => txn.delete(keyOrKeys, options)) : tryStoragePromise("transaction.delete", () => txn.delete(keyOrKeys, options)),
85
85
  rollback: () => tryStorageSync("transaction.rollback", () => txn.rollback()),
86
86
  getAlarm: (options) => tryStoragePromise("transaction.getAlarm", () => txn.getAlarm(options)),