effect-cf 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +8 -6
  3. package/dist/{Artifacts-DcoXcRP5.d.mts → Artifacts-DnHQA-Ax.d.mts} +42 -25
  4. package/dist/Artifacts-rq3hUKQE.mjs +257 -0
  5. package/dist/{Binding-COCtoJXa.d.mts → Binding-xJJJPmiD.d.mts} +6 -5
  6. package/dist/ComputerArtifacts.d.mts +55 -0
  7. package/dist/ComputerArtifacts.mjs +95 -0
  8. package/dist/ComputerWorkspace.d.mts +279 -0
  9. package/dist/ComputerWorkspace.mjs +577 -0
  10. package/dist/ComputerWorkspaceHost.d.mts +1 -1
  11. package/dist/ComputerWorkspaceHost.mjs +18 -16
  12. package/dist/{WorkflowBinding-D5iWzCUa.d.mts → DurableObjectState-B3uFY1eM.d.mts} +90 -141
  13. package/dist/{DurableObjectState-CEh0DVw7.mjs → DurableObjectState-BjkK2kwH.mjs} +4 -49
  14. package/dist/ErrorMessage-BM0K-Nik.mjs +46 -0
  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 -4
  18. package/dist/Vitest.mjs +2 -1
  19. package/dist/WorkflowBinding-wZ-yGHow.d.mts +74 -0
  20. package/dist/index.d.mts +92 -398
  21. package/dist/index.mjs +323 -1105
  22. package/package.json +12 -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 +8 -5
  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 +27 -11
  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 +91 -21
  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/index.ts +0 -2
  63. package/src/internal/Entrypoint.ts +29 -13
  64. package/src/internal/ErrorMessage.ts +7 -6
  65. package/src/internal/RpcInvocation.ts +34 -11
  66. package/src/internal/Runtime.ts +33 -22
  67. package/src/internal/WorkerContext.ts +3 -3
@@ -0,0 +1,46 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { Config, ConfigProvider, Context, Effect, Predicate } from "effect";
3
+ //#region src/Environment.ts
4
+ var Environment_exports = /* @__PURE__ */ __exportAll({
5
+ WorkerConfig: () => WorkerConfig,
6
+ WorkerEnvironment: () => WorkerEnvironment
7
+ });
8
+ /**
9
+ * Context service for reading worker bindings from the current `env` object.
10
+ */
11
+ var WorkerEnvironment = class extends Context.Service()("effect-cf/WorkerEnvironment") {};
12
+ let WorkerConfig;
13
+ (function(_WorkerConfig) {
14
+ _WorkerConfig.string = (name) => Config.string(name);
15
+ _WorkerConfig.redacted = (name) => Config.redacted(name);
16
+ _WorkerConfig.number = (name) => Config.number(name);
17
+ _WorkerConfig.integer = (name) => Config.int(name);
18
+ _WorkerConfig.boolean = (name) => Config.boolean(name);
19
+ const providerFromEnv = _WorkerConfig.providerFromEnv = (env, options) => {
20
+ const record = {};
21
+ for (const [key, value] of Object.entries(env)) if (Predicate.isString(value) || Predicate.isNumber(value) || Predicate.isBoolean(value)) record[key] = String(value);
22
+ return ConfigProvider.fromEnvRecord(record, options);
23
+ };
24
+ const providerWith = _WorkerConfig.providerWith = (makeProvider) => Effect.map(WorkerEnvironment, makeProvider);
25
+ const provider = _WorkerConfig.provider = providerWith(providerFromEnv);
26
+ _WorkerConfig.providerLayer = ConfigProvider.layer(provider);
27
+ _WorkerConfig.layerWith = (makeProvider) => ConfigProvider.layer(providerWith(makeProvider));
28
+ })(WorkerConfig || (WorkerConfig = {}));
29
+ //#endregion
30
+ //#region src/internal/ErrorMessage.ts
31
+ /**
32
+ * Renders the most useful human-readable description of an unknown `cause`
33
+ * for use in tagged error `message` getters.
34
+ */
35
+ const causeMessage = (cause) => {
36
+ if (Predicate.hasProperty(cause, "message") && Predicate.isString(cause.message) && cause.message.length > 0) return cause.message;
37
+ try {
38
+ return String(cause);
39
+ } catch {
40
+ return "unknown cause";
41
+ }
42
+ };
43
+ /** Renders a violation list as a single `path: message; ...` line. */
44
+ const violationsMessage = (violations) => violations.map((violation) => `${violation.path}: ${violation.message}`).join("; ");
45
+ //#endregion
46
+ export { WorkerEnvironment as a, WorkerConfig as i, violationsMessage as n, Environment_exports as r, causeMessage as t };
@@ -1,4 +1,4 @@
1
- import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-COCtoJXa.mjs";
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 Hyperdrive_d_exports {
4
4
  export { HyperdriveClient, HyperdriveDefinition, HyperdriveService, LayerOptions, Tag, TagClass, isHyperdrive, layer, make, makeClient };
@@ -27,7 +27,7 @@ interface TagClass<Self, Id extends string> extends Context.ServiceClass<Self, I
27
27
  readonly id: Id;
28
28
  readonly layer: (options: LayerOptions) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
29
29
  }
30
- declare const isHyperdrive: (value: unknown) => value is Hyperdrive;
30
+ declare const isHyperdrive: <Candidate>(value: Candidate) => value is Candidate & Hyperdrive;
31
31
  declare const makeClient: (definition: HyperdriveDefinition) => (hyperdrive: Hyperdrive) => HyperdriveClient;
32
32
  declare const layer: <Self>(tag: Context.Service<Self, HyperdriveClient>, definition: HyperdriveDefinition) => Layer.Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
33
33
  declare const make: <Id extends string>(id: Id) => TagClass<HyperdriveService<Id>, Id>;
@@ -1,5 +1,5 @@
1
- import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-COCtoJXa.mjs";
2
- import { n as LayerOptions, r as TagClass } from "./Hyperdrive-6p59yyVk.mjs";
1
+ import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-xJJJPmiD.mjs";
2
+ import { n as LayerOptions, r as TagClass } from "./Hyperdrive-z-9fFz15.mjs";
3
3
  import { Layer } from "effect";
4
4
  import { PgClient } from "@effect/sql-pg";
5
5
  import { SqlClient, SqlError } from "effect/unstable/sql";
package/dist/Vitest.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- import { c as WorkerEnvironment, s as WorkerEnv } from "./Binding-COCtoJXa.mjs";
2
- import { c as DurableObjectState, l as DurableObjectStateService, o as WorkflowInstanceStatusName } from "./WorkflowBinding-D5iWzCUa.mjs";
3
- import { Effect, Layer } from "effect";
1
+ import { c as WorkerEnvironment, s as WorkerEnv } from "./Binding-xJJJPmiD.mjs";
2
+ import { n as DurableObjectStateService, t as DurableObjectState } from "./DurableObjectState-B3uFY1eM.mjs";
3
+ import { o as WorkflowInstanceStatusName } from "./WorkflowBinding-wZ-yGHow.mjs";
4
+ import { Effect, Layer, Schema } from "effect";
4
5
  import { DurableObject } from "cloudflare:workers";
5
6
  import { adminSecretsStore as adminSecretsStore$1, getQueueResult, introspectWorkflow as introspectWorkflow$1, introspectWorkflowInstance as introspectWorkflowInstance$1 } from "cloudflare:test";
6
7
  //#region src/Vitest.d.ts
@@ -154,12 +155,13 @@ interface WorkflowMockEvent {
154
155
  interface WorkflowInstanceModifier {
155
156
  readonly disableSleeps: (steps?: ReadonlyArray<WorkflowStepTarget>) => Effect.Effect<void>;
156
157
  readonly disableRetryDelays: (steps?: ReadonlyArray<WorkflowStepTarget>) => Effect.Effect<void>;
157
- readonly mockStepResult: (step: WorkflowStepTarget, result: unknown) => Effect.Effect<void>;
158
+ readonly mockStepResult: (step: WorkflowStepTarget, result: WorkflowMockResult) => Effect.Effect<void>;
158
159
  readonly mockStepError: (step: WorkflowStepTarget, error: Error, times?: number) => Effect.Effect<void>;
159
160
  readonly forceStepTimeout: (step: WorkflowStepTarget, times?: number) => Effect.Effect<void>;
160
161
  readonly mockEvent: (event: WorkflowMockEvent) => Effect.Effect<void>;
161
162
  readonly forceEventTimeout: (step: WorkflowStepTarget) => Effect.Effect<void>;
162
163
  }
164
+ type WorkflowMockResult = Schema.Schema.Type<typeof Schema.Unknown>;
163
165
  /** Effect-native introspector for one Workflow instance. */
164
166
  interface WorkflowInstanceIntrospector {
165
167
  readonly raw: NativeWorkflowInstanceIntrospector;
package/dist/Vitest.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { d as WorkerConfig, f as WorkerEnvironment, r as fromDurableObjectState, t as DurableObjectState } from "./DurableObjectState-CEh0DVw7.mjs";
1
+ import { a as WorkerEnvironment, i as WorkerConfig } from "./ErrorMessage-BM0K-Nik.mjs";
2
+ import { r as fromDurableObjectState, t as DurableObjectState } from "./DurableObjectState-BjkK2kwH.mjs";
2
3
  import { ConfigProvider, Effect, Exit, Layer } from "effect";
3
4
  import { env } from "cloudflare:workers";
4
5
  import { abortAllDurableObjects as abortAllDurableObjects$1, adminSecretsStore as adminSecretsStore$1, applyD1Migrations as applyD1Migrations$1, createExecutionContext, createMessageBatch, createPagesEventContext, createScheduledController, evictAllDurableObjects as evictAllDurableObjects$1, evictDurableObject as evictDurableObject$1, getQueueResult, introspectWorkflow as introspectWorkflow$1, introspectWorkflowInstance as introspectWorkflowInstance$1, listDurableObjectIds as listDurableObjectIds$1, reset as reset$1, runDurableObjectAlarm as runDurableObjectAlarm$1, runInDurableObject as runInDurableObject$1, waitOnExecutionContext } from "cloudflare:test";
@@ -0,0 +1,74 @@
1
+ import { c as WorkerEnvironment, r as BindingValidationError, t as BindingNotFoundError } from "./Binding-xJJJPmiD.mjs";
2
+ import { x as ServiceFreeSchema } from "./DurableObjectState-B3uFY1eM.mjs";
3
+ import { Context, Effect, Option, Schema } from "effect";
4
+ declare namespace WorkflowBinding_d_exports {
5
+ export { WorkflowBindingClient, WorkflowBindingDefinition, WorkflowInstance, WorkflowInstanceCreateBatchOptions, WorkflowInstanceCreateOptions, WorkflowInstanceEvent, WorkflowInstanceRestartOptions, WorkflowInstanceStatus, WorkflowInstanceStatusName, WorkflowOperationError, WorkflowResultDecodeError, isWorkflow, layer, makeClient };
6
+ }
7
+ type WorkflowInstanceCreateOptions<Payload> = Omit<CloudflareWorkflowInstanceCreateOptions<Payload>, "params">;
8
+ type WorkflowInstanceCreateBatchOptions<Payload, EncodedPayload = unknown> = ReadonlyArray<{
9
+ readonly payload: Payload;
10
+ } & WorkflowInstanceCreateOptions<EncodedPayload>>;
11
+ type WorkflowInstanceRestartOptions = CloudflareWorkflowInstanceRestartOptions;
12
+ type WorkflowInstanceStatusName = CloudflareInstanceStatus["status"];
13
+ interface WorkflowInstanceStatus<Result> {
14
+ readonly status: WorkflowInstanceStatusName;
15
+ readonly output: Option.Option<Result>;
16
+ readonly error: Option.Option<{
17
+ readonly name: string;
18
+ readonly message: string;
19
+ }>;
20
+ }
21
+ interface WorkflowInstance<Result> {
22
+ readonly raw: CloudflareWorkflowInstance;
23
+ readonly id: string;
24
+ readonly pause: Effect.Effect<void, WorkflowOperationError>;
25
+ readonly resume: Effect.Effect<void, WorkflowOperationError>;
26
+ readonly terminate: Effect.Effect<void, WorkflowOperationError>;
27
+ readonly restart: (options?: WorkflowInstanceRestartOptions) => Effect.Effect<void, WorkflowOperationError>;
28
+ readonly status: Effect.Effect<WorkflowInstanceStatus<Result>, WorkflowOperationError | WorkflowResultDecodeError>;
29
+ readonly sendEvent: (event: WorkflowInstanceEvent) => Effect.Effect<void, WorkflowOperationError>;
30
+ }
31
+ interface WorkflowInstanceEvent {
32
+ readonly type: string;
33
+ readonly payload: unknown;
34
+ }
35
+ interface WorkflowBindingDefinition<Payload extends ServiceFreeSchema, Result extends ServiceFreeSchema> {
36
+ /** Binding name as configured in `wrangler.jsonc`. */
37
+ readonly binding: string;
38
+ /** Codec used to encode payloads passed to `Workflow.create`. */
39
+ readonly payload: Payload;
40
+ /** Codec used to decode completed workflow status output. */
41
+ readonly result: Result;
42
+ }
43
+ interface WorkflowBindingClient<Payload extends ServiceFreeSchema, Result extends ServiceFreeSchema> {
44
+ readonly create: (payload: Schema.Schema.Type<Payload>, options?: WorkflowInstanceCreateOptions<Schema.Codec.Encoded<Payload>>) => Effect.Effect<WorkflowInstance<Schema.Schema.Type<Result>>, WorkflowOperationError | Schema.SchemaError>;
45
+ readonly createBatch: (batch: WorkflowInstanceCreateBatchOptions<Schema.Schema.Type<Payload>, Schema.Codec.Encoded<Payload>>) => Effect.Effect<ReadonlyArray<WorkflowInstance<Schema.Schema.Type<Result>>>, WorkflowOperationError | Schema.SchemaError>;
46
+ readonly get: (instanceId: string) => Effect.Effect<WorkflowInstance<Schema.Schema.Type<Result>>, WorkflowOperationError>;
47
+ readonly rawUnsafe: Effect.Effect<CloudflareWorkflow<Schema.Codec.Encoded<Payload>>>;
48
+ }
49
+ declare const WorkflowOperationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
50
+ readonly _tag: "WorkflowOperationError";
51
+ } & Readonly<A>;
52
+ declare class WorkflowOperationError extends WorkflowOperationError_base<{
53
+ readonly binding: string;
54
+ readonly operation: string;
55
+ readonly cause: unknown;
56
+ }> {
57
+ get message(): string;
58
+ }
59
+ declare const WorkflowResultDecodeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
60
+ readonly _tag: "WorkflowResultDecodeError";
61
+ } & Readonly<A>;
62
+ declare class WorkflowResultDecodeError extends WorkflowResultDecodeError_base<{
63
+ readonly binding: string;
64
+ readonly instanceId: string;
65
+ readonly cause: unknown;
66
+ }> {
67
+ get message(): string;
68
+ }
69
+ type WorkflowBindingValue = Schema.Schema.Type<typeof Schema.Unknown>;
70
+ declare const isWorkflow: <Payload>(value: WorkflowBindingValue) => value is CloudflareWorkflow<Payload>;
71
+ declare const makeClient: <Payload extends ServiceFreeSchema, Result extends ServiceFreeSchema>(definition: WorkflowBindingDefinition<Payload, Result>) => ((workflow: CloudflareWorkflow<Schema.Codec.Encoded<Payload>>) => WorkflowBindingClient<Payload, Result>);
72
+ declare const layer: <Self, Payload extends ServiceFreeSchema, Result extends ServiceFreeSchema>(tag: Context.Service<Self, WorkflowBindingClient<Payload, Result>>, definition: WorkflowBindingDefinition<Payload, Result>) => import("effect/Layer").Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
73
+ //#endregion
74
+ export { WorkflowInstanceCreateOptions as a, WorkflowInstanceCreateBatchOptions as i, WorkflowBinding_d_exports as n, WorkflowInstanceStatusName as o, WorkflowInstance as r, WorkflowOperationError as s, WorkflowBindingClient as t };