effect-encore 0.1.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.
@@ -0,0 +1,45 @@
1
+ import { Effect, Layer } from "effect";
2
+ import { Activity, DurableDeferred, Workflow } from "@effect/workflow";
3
+
4
+ //#region src/workflow.d.ts
5
+ declare namespace workflow_d_exports {
6
+ export { Activity, DurableDeferred, WorkflowDefinition, WorkflowReceipt, WorkflowRef, makeWorkflowReceipt, workflow, workflowClient, workflowHandlers, workflowPoll };
7
+ }
8
+ interface WorkflowDefinition<Name extends string = string> {
9
+ readonly _tag: "WorkflowDefinition";
10
+ readonly name: Name;
11
+ readonly workflow: Workflow.Any;
12
+ }
13
+ interface WorkflowReceipt<Type extends string = string> {
14
+ readonly _tag: "WorkflowReceipt";
15
+ readonly workflowName: Type;
16
+ readonly executionId: string;
17
+ }
18
+ declare const makeWorkflowReceipt: <Type extends string>(workflowName: Type, executionId: string) => WorkflowReceipt<Type>;
19
+ declare const workflow: <const Name extends string>(name: Name, options: {
20
+ readonly payload: Record<string, unknown>;
21
+ readonly idempotencyKey: (payload: Record<string, unknown>) => string;
22
+ readonly success?: unknown;
23
+ readonly error?: unknown;
24
+ }) => WorkflowDefinition<Name>;
25
+ type WorkflowRef<Name extends string = string> = {
26
+ readonly call: (payload: unknown) => Effect.Effect<unknown, unknown>;
27
+ readonly cast: (payload: unknown) => Effect.Effect<WorkflowReceipt<Name>, unknown>;
28
+ readonly interrupt: () => Effect.Effect<void>;
29
+ readonly resume: () => Effect.Effect<void>;
30
+ };
31
+ declare const workflowClient: <Name extends string>(def: WorkflowDefinition<Name>) => ((executionId: string) => WorkflowRef<Name>);
32
+ declare const workflowPoll: <Name extends string>(def: WorkflowDefinition<Name>, executionId: string) => Effect.Effect<{
33
+ _tag: "Pending";
34
+ } | {
35
+ _tag: "Success";
36
+ value: unknown;
37
+ } | {
38
+ _tag: "Failure";
39
+ error: unknown;
40
+ } | {
41
+ _tag: "Suspended";
42
+ }, never, never>;
43
+ declare const workflowHandlers: <Name extends string>(def: WorkflowDefinition<Name>, handler: Function) => Layer.Layer<never, never, never>;
44
+ //#endregion
45
+ export { Activity, DurableDeferred, WorkflowDefinition, WorkflowReceipt, WorkflowRef, makeWorkflowReceipt, workflow, workflowClient, workflowHandlers, workflowPoll, workflow_d_exports };
@@ -0,0 +1,66 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { Effect } from "effect";
3
+ import { Activity, DurableDeferred, Workflow } from "@effect/workflow";
4
+ //#region src/workflow.ts
5
+ var workflow_exports = /* @__PURE__ */ __exportAll({
6
+ Activity: () => Activity,
7
+ DurableDeferred: () => DurableDeferred,
8
+ makeWorkflowReceipt: () => makeWorkflowReceipt,
9
+ workflow: () => workflow,
10
+ workflowClient: () => workflowClient,
11
+ workflowHandlers: () => workflowHandlers,
12
+ workflowPoll: () => workflowPoll
13
+ });
14
+ const makeWorkflowReceipt = (workflowName, executionId) => ({
15
+ _tag: "WorkflowReceipt",
16
+ workflowName,
17
+ executionId
18
+ });
19
+ const workflow = (name, options) => {
20
+ const wfOptions = {
21
+ name,
22
+ payload: options.payload,
23
+ idempotencyKey: options.idempotencyKey
24
+ };
25
+ if (options.success) wfOptions["success"] = options.success;
26
+ if (options.error) wfOptions["error"] = options.error;
27
+ return {
28
+ _tag: "WorkflowDefinition",
29
+ name,
30
+ workflow: Workflow.make(wfOptions)
31
+ };
32
+ };
33
+ const workflowClient = (def) => {
34
+ const wf = def.workflow;
35
+ return (_executionId) => ({
36
+ call: (payload) => wf.execute(payload),
37
+ cast: (payload) => Effect.map(wf.execute(payload, { discard: true }), (execId) => makeWorkflowReceipt(def.name, execId)),
38
+ interrupt: () => wf.interrupt(_executionId),
39
+ resume: () => wf.resume(_executionId)
40
+ });
41
+ };
42
+ const workflowPoll = (def, executionId) => {
43
+ const wf = def.workflow;
44
+ return Effect.map(wf.poll(executionId), (rawResult) => {
45
+ if (rawResult == null) return { _tag: "Pending" };
46
+ const result = rawResult;
47
+ if (result._tag === "Suspended") return { _tag: "Suspended" };
48
+ if (result._tag === "Complete") {
49
+ const exit = result.exit;
50
+ if (exit?._tag === "Success") return {
51
+ _tag: "Success",
52
+ value: exit.value
53
+ };
54
+ return {
55
+ _tag: "Failure",
56
+ error: exit?.cause
57
+ };
58
+ }
59
+ return { _tag: "Pending" };
60
+ });
61
+ };
62
+ const workflowHandlers = (def, handler) => {
63
+ return def.workflow.toLayer(handler);
64
+ };
65
+ //#endregion
66
+ export { Activity, DurableDeferred, makeWorkflowReceipt, workflow, workflowClient, workflowHandlers, workflowPoll, workflow_exports };