@temporal-contract/client 0.0.3 → 0.0.4

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/dist/index.d.cts CHANGED
@@ -1,71 +1,118 @@
1
1
  import { ClientOptions, WorkflowHandle, WorkflowOptions, WorkflowStartOptions } from "@temporalio/client";
2
2
  import { ClientInferInput, ClientInferOutput, ClientInferWorkflowQueries, ClientInferWorkflowSignals, ClientInferWorkflowUpdates, ContractDefinition, WorkflowDefinition } from "@temporal-contract/contract";
3
+ import { AsyncData, Future, Future as Future$1, Option, Result, Result as Result$1 } from "@swan-io/boxed";
3
4
  import { StandardSchemaV1 } from "@standard-schema/spec";
4
5
 
6
+ //#region src/errors.d.ts
7
+ /**
8
+ * Base class for all typed client errors with boxed pattern
9
+ */
10
+ declare class TypedClientError extends Error {
11
+ constructor(message: string);
12
+ }
13
+ /**
14
+ * Thrown when a workflow is not found in the contract
15
+ */
16
+ declare class WorkflowNotFoundError extends TypedClientError {
17
+ readonly workflowName: string;
18
+ readonly availableWorkflows: string[];
19
+ constructor(workflowName: string, availableWorkflows: string[]);
20
+ }
21
+ /**
22
+ * Thrown when workflow input or output validation fails
23
+ */
24
+ declare class WorkflowValidationError extends TypedClientError {
25
+ readonly workflowName: string;
26
+ readonly direction: "input" | "output";
27
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
28
+ constructor(workflowName: string, direction: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
29
+ }
30
+ /**
31
+ * Thrown when query input or output validation fails
32
+ */
33
+ declare class QueryValidationError extends TypedClientError {
34
+ readonly queryName: string;
35
+ readonly direction: "input" | "output";
36
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
37
+ constructor(queryName: string, direction: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
38
+ }
39
+ /**
40
+ * Thrown when signal input validation fails
41
+ */
42
+ declare class SignalValidationError extends TypedClientError {
43
+ readonly signalName: string;
44
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
45
+ constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
46
+ }
47
+ /**
48
+ * Thrown when update input or output validation fails
49
+ */
50
+ declare class UpdateValidationError extends TypedClientError {
51
+ readonly updateName: string;
52
+ readonly direction: "input" | "output";
53
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
54
+ constructor(updateName: string, direction: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
55
+ }
56
+ //#endregion
5
57
  //#region src/client.d.ts
6
-
7
58
  /**
8
59
  * Extended options for starting workflows with Temporal-specific features
9
60
  * Combines required workflowId with optional Temporal workflow options
10
61
  */
11
62
  type TypedWorkflowStartOptions = Pick<WorkflowStartOptions, "workflowId" | "workflowIdReusePolicy" | "workflowExecutionTimeout" | "workflowRunTimeout" | "workflowTaskTimeout" | "retry" | "memo" | "searchAttributes" | "cronSchedule"> & Pick<WorkflowOptions, "workflowId">;
12
63
  /**
13
- * Typed workflow handle with validated results, queries, signals and updates
64
+ * Typed workflow handle with validated results using Result/Future pattern
14
65
  */
15
66
  interface TypedWorkflowHandle<TWorkflow extends WorkflowDefinition> {
16
67
  workflowId: string;
17
68
  /**
18
- * Type-safe queries based on workflow definition
69
+ * Type-safe queries based on workflow definition with Result pattern
70
+ * Each query returns Future<Result<T, Error>> instead of Promise<T>
71
+ */
72
+ queries: { [K in keyof ClientInferWorkflowQueries<TWorkflow>]: ClientInferWorkflowQueries<TWorkflow>[K] extends ((...args: infer Args) => Promise<infer R>) ? (...args: Args) => Future$1<Result$1<R, TypedClientError>> : never };
73
+ /**
74
+ * Type-safe signals based on workflow definition with Result pattern
75
+ * Each signal returns Future<Result<void, Error>> instead of Promise<void>
76
+ */
77
+ signals: { [K in keyof ClientInferWorkflowSignals<TWorkflow>]: ClientInferWorkflowSignals<TWorkflow>[K] extends ((...args: infer Args) => Promise<void>) ? (...args: Args) => Future$1<Result$1<void, TypedClientError>> : never };
78
+ /**
79
+ * Type-safe updates based on workflow definition with Result pattern
80
+ * Each update returns Future<Result<T, Error>> instead of Promise<T>
19
81
  */
20
- queries: ClientInferWorkflowQueries<TWorkflow>;
82
+ updates: { [K in keyof ClientInferWorkflowUpdates<TWorkflow>]: ClientInferWorkflowUpdates<TWorkflow>[K] extends ((...args: infer Args) => Promise<infer R>) ? (...args: Args) => Future$1<Result$1<R, TypedClientError>> : never };
21
83
  /**
22
- * Type-safe signals based on workflow definition
84
+ * Get workflow result with Result pattern
23
85
  */
24
- signals: ClientInferWorkflowSignals<TWorkflow>;
86
+ result: () => Future$1<Result$1<ClientInferOutput<TWorkflow>, TypedClientError>>;
25
87
  /**
26
- * Type-safe updates based on workflow definition
88
+ * Terminate workflow with Result pattern
27
89
  */
28
- updates: ClientInferWorkflowUpdates<TWorkflow>;
29
- result: () => Promise<ClientInferOutput<TWorkflow>>;
30
- terminate: (reason?: string) => Promise<void>;
31
- cancel: () => Promise<void>;
90
+ terminate: (reason?: string) => Future$1<Result$1<void, TypedClientError>>;
91
+ /**
92
+ * Cancel workflow with Result pattern
93
+ */
94
+ cancel: () => Future$1<Result$1<void, TypedClientError>>;
32
95
  /**
33
96
  * Get workflow execution description including status and metadata
34
- *
35
- * @example
36
- * ```ts
37
- * const handle = await client.getHandle('processOrder', 'order-123');
38
- * const description = await handle.describe();
39
- * console.log(description.workflowExecutionInfo.status); // RUNNING, COMPLETED, etc.
40
- * ```
41
97
  */
42
- describe: () => ReturnType<WorkflowHandle["describe"]>;
98
+ describe: () => Future$1<Result$1<Awaited<ReturnType<WorkflowHandle["describe"]>>, TypedClientError>>;
43
99
  /**
44
100
  * Fetch the workflow execution history
45
- *
46
- * @example
47
- * ```ts
48
- * const handle = await client.getHandle('processOrder', 'order-123');
49
- * const history = handle.fetchHistory();
50
- * for await (const event of history) {
51
- * console.log(event);
52
- * }
53
- * ```
54
101
  */
55
102
  fetchHistory: () => ReturnType<WorkflowHandle["fetchHistory"]>;
56
103
  }
57
104
  /**
58
- * Typed Temporal client based on a contract
105
+ * Typed Temporal client with Result/Future pattern based on a contract
59
106
  *
60
107
  * Provides type-safe methods to start and execute workflows
61
- * defined in the contract.
108
+ * defined in the contract, with explicit error handling using Result pattern.
62
109
  */
63
110
  declare class TypedClient<TContract extends ContractDefinition> {
64
111
  private readonly contract;
65
112
  private readonly client;
66
113
  private constructor();
67
114
  /**
68
- * Create a typed Temporal client from a contract
115
+ * Create a typed Temporal client with boxed pattern from a contract
69
116
  *
70
117
  * @example
71
118
  * ```ts
@@ -77,24 +124,35 @@ declare class TypedClient<TContract extends ContractDefinition> {
77
124
  *
78
125
  * const result = await client.executeWorkflow('processOrder', {
79
126
  * workflowId: 'order-123',
80
- * args: [...],
127
+ * args: { ... },
128
+ * }).toPromise();
129
+ *
130
+ * result.match({
131
+ * Ok: (output) => console.log('Success:', output),
132
+ * Error: (error) => console.error('Failed:', error),
81
133
  * });
82
134
  * ```
83
135
  */
84
136
  static create<TContract extends ContractDefinition>(contract: TContract, options: ClientOptions): TypedClient<TContract>;
85
137
  /**
86
- * Start a workflow and return a typed handle
138
+ * Start a workflow and return a typed handle with Future pattern
87
139
  *
88
140
  * @example
89
141
  * ```ts
90
- * const handle = await client.startWorkflow('processOrder', {
142
+ * const handleResult = await client.startWorkflow('processOrder', {
91
143
  * workflowId: 'order-123',
92
- * args: ['ORD-123', 'CUST-456', [{ productId: 'PROD-1', quantity: 2 }]],
144
+ * args: { orderId: 'ORD-123' },
93
145
  * workflowExecutionTimeout: '1 day',
94
146
  * retry: { maximumAttempts: 3 },
95
- * });
147
+ * }).toPromise();
96
148
  *
97
- * const result = await handle.result();
149
+ * handleResult.match({
150
+ * Ok: async (handle) => {
151
+ * const result = await handle.result().toPromise();
152
+ * // ... handle result
153
+ * },
154
+ * Error: (error) => console.error('Failed to start:', error),
155
+ * });
98
156
  * ```
99
157
  */
100
158
  startWorkflow<TWorkflowName extends keyof TContract["workflows"]>(workflowName: TWorkflowName, {
@@ -102,20 +160,23 @@ declare class TypedClient<TContract extends ContractDefinition> {
102
160
  ...temporalOptions
103
161
  }: TypedWorkflowStartOptions & {
104
162
  args: ClientInferInput<TContract["workflows"][TWorkflowName]>;
105
- }): Promise<TypedWorkflowHandle<TContract["workflows"][TWorkflowName]>>;
163
+ }): Future$1<Result$1<TypedWorkflowHandle<TContract["workflows"][TWorkflowName]>, TypedClientError>>;
106
164
  /**
107
- * Execute a workflow (start and wait for result)
165
+ * Execute a workflow (start and wait for result) with Future/Result pattern
108
166
  *
109
167
  * @example
110
168
  * ```ts
111
169
  * const result = await client.executeWorkflow('processOrder', {
112
170
  * workflowId: 'order-123',
113
- * args: ['ORD-123', 'CUST-456', [{ productId: 'PROD-1', quantity: 2 }]],
171
+ * args: { orderId: 'ORD-123' },
114
172
  * workflowExecutionTimeout: '1 day',
115
173
  * retry: { maximumAttempts: 3 },
116
- * });
174
+ * }).toPromise();
117
175
  *
118
- * console.log(result.status); // fully typed!
176
+ * result.match({
177
+ * Ok: (output) => console.log('Order processed:', output.status),
178
+ * Error: (error) => console.error('Processing failed:', error),
179
+ * });
119
180
  * ```
120
181
  */
121
182
  executeWorkflow<TWorkflowName extends keyof TContract["workflows"]>(workflowName: TWorkflowName, {
@@ -123,69 +184,24 @@ declare class TypedClient<TContract extends ContractDefinition> {
123
184
  ...temporalOptions
124
185
  }: TypedWorkflowStartOptions & {
125
186
  args: ClientInferInput<TContract["workflows"][TWorkflowName]>;
126
- }): Promise<ClientInferOutput<TContract["workflows"][TWorkflowName]>>;
187
+ }): Future$1<Result$1<ClientInferOutput<TContract["workflows"][TWorkflowName]>, TypedClientError>>;
127
188
  /**
128
- * Get a handle to an existing workflow
189
+ * Get a handle to an existing workflow with Future/Result pattern
129
190
  *
130
191
  * @example
131
192
  * ```ts
132
- * const handle = await client.getHandle('processOrder', 'order-123');
133
- * const result = await handle.result();
193
+ * const handleResult = await client.getHandle('processOrder', 'order-123').toPromise();
194
+ * handleResult.match({
195
+ * Ok: async (handle) => {
196
+ * const result = await handle.result().toPromise();
197
+ * // ... handle result
198
+ * },
199
+ * Error: (error) => console.error('Failed to get handle:', error),
200
+ * });
134
201
  * ```
135
202
  */
136
- getHandle<TWorkflowName extends keyof TContract["workflows"]>(workflowName: TWorkflowName, workflowId: string): Promise<TypedWorkflowHandle<TContract["workflows"][TWorkflowName]>>;
203
+ getHandle<TWorkflowName extends keyof TContract["workflows"]>(workflowName: TWorkflowName, workflowId: string): Future$1<Result$1<TypedWorkflowHandle<TContract["workflows"][TWorkflowName]>, TypedClientError>>;
137
204
  private createTypedHandle;
138
205
  }
139
206
  //#endregion
140
- //#region src/errors.d.ts
141
- /**
142
- * Base error class for typed client errors
143
- */
144
- declare class TypedClientError extends Error {
145
- constructor(message: string);
146
- }
147
- /**
148
- * Error thrown when a workflow is not found in the contract
149
- */
150
- declare class WorkflowNotFoundError extends TypedClientError {
151
- readonly workflowName: string;
152
- readonly availableWorkflows: readonly string[];
153
- constructor(workflowName: string, availableWorkflows?: readonly string[]);
154
- }
155
- /**
156
- * Error thrown when workflow input or output validation fails
157
- */
158
- declare class WorkflowValidationError extends TypedClientError {
159
- readonly workflowName: string;
160
- readonly phase: "input" | "output";
161
- readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
162
- constructor(workflowName: string, phase: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
163
- }
164
- /**
165
- * Error thrown when query input or output validation fails
166
- */
167
- declare class QueryValidationError extends TypedClientError {
168
- readonly queryName: string;
169
- readonly phase: "input" | "output";
170
- readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
171
- constructor(queryName: string, phase: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
172
- }
173
- /**
174
- * Error thrown when signal input validation fails
175
- */
176
- declare class SignalValidationError extends TypedClientError {
177
- readonly signalName: string;
178
- readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
179
- constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
180
- }
181
- /**
182
- * Error thrown when update input or output validation fails
183
- */
184
- declare class UpdateValidationError extends TypedClientError {
185
- readonly updateName: string;
186
- readonly phase: "input" | "output";
187
- readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
188
- constructor(updateName: string, phase: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
189
- }
190
- //#endregion
191
- export { QueryValidationError, SignalValidationError, TypedClient, TypedClientError, type TypedWorkflowHandle, type TypedWorkflowStartOptions, UpdateValidationError, WorkflowNotFoundError, WorkflowValidationError };
207
+ export { AsyncData, Future, Option, QueryValidationError, Result, SignalValidationError, TypedClient, TypedClientError, type TypedWorkflowHandle, type TypedWorkflowStartOptions, UpdateValidationError, WorkflowNotFoundError, WorkflowValidationError };
package/dist/index.d.mts CHANGED
@@ -1,71 +1,118 @@
1
1
  import { ClientOptions, WorkflowHandle, WorkflowOptions, WorkflowStartOptions } from "@temporalio/client";
2
+ import { AsyncData, Future, Future as Future$1, Option, Result, Result as Result$1 } from "@swan-io/boxed";
2
3
  import { ClientInferInput, ClientInferOutput, ClientInferWorkflowQueries, ClientInferWorkflowSignals, ClientInferWorkflowUpdates, ContractDefinition, WorkflowDefinition } from "@temporal-contract/contract";
3
4
  import { StandardSchemaV1 } from "@standard-schema/spec";
4
5
 
6
+ //#region src/errors.d.ts
7
+ /**
8
+ * Base class for all typed client errors with boxed pattern
9
+ */
10
+ declare class TypedClientError extends Error {
11
+ constructor(message: string);
12
+ }
13
+ /**
14
+ * Thrown when a workflow is not found in the contract
15
+ */
16
+ declare class WorkflowNotFoundError extends TypedClientError {
17
+ readonly workflowName: string;
18
+ readonly availableWorkflows: string[];
19
+ constructor(workflowName: string, availableWorkflows: string[]);
20
+ }
21
+ /**
22
+ * Thrown when workflow input or output validation fails
23
+ */
24
+ declare class WorkflowValidationError extends TypedClientError {
25
+ readonly workflowName: string;
26
+ readonly direction: "input" | "output";
27
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
28
+ constructor(workflowName: string, direction: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
29
+ }
30
+ /**
31
+ * Thrown when query input or output validation fails
32
+ */
33
+ declare class QueryValidationError extends TypedClientError {
34
+ readonly queryName: string;
35
+ readonly direction: "input" | "output";
36
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
37
+ constructor(queryName: string, direction: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
38
+ }
39
+ /**
40
+ * Thrown when signal input validation fails
41
+ */
42
+ declare class SignalValidationError extends TypedClientError {
43
+ readonly signalName: string;
44
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
45
+ constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
46
+ }
47
+ /**
48
+ * Thrown when update input or output validation fails
49
+ */
50
+ declare class UpdateValidationError extends TypedClientError {
51
+ readonly updateName: string;
52
+ readonly direction: "input" | "output";
53
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
54
+ constructor(updateName: string, direction: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
55
+ }
56
+ //#endregion
5
57
  //#region src/client.d.ts
6
-
7
58
  /**
8
59
  * Extended options for starting workflows with Temporal-specific features
9
60
  * Combines required workflowId with optional Temporal workflow options
10
61
  */
11
62
  type TypedWorkflowStartOptions = Pick<WorkflowStartOptions, "workflowId" | "workflowIdReusePolicy" | "workflowExecutionTimeout" | "workflowRunTimeout" | "workflowTaskTimeout" | "retry" | "memo" | "searchAttributes" | "cronSchedule"> & Pick<WorkflowOptions, "workflowId">;
12
63
  /**
13
- * Typed workflow handle with validated results, queries, signals and updates
64
+ * Typed workflow handle with validated results using Result/Future pattern
14
65
  */
15
66
  interface TypedWorkflowHandle<TWorkflow extends WorkflowDefinition> {
16
67
  workflowId: string;
17
68
  /**
18
- * Type-safe queries based on workflow definition
69
+ * Type-safe queries based on workflow definition with Result pattern
70
+ * Each query returns Future<Result<T, Error>> instead of Promise<T>
71
+ */
72
+ queries: { [K in keyof ClientInferWorkflowQueries<TWorkflow>]: ClientInferWorkflowQueries<TWorkflow>[K] extends ((...args: infer Args) => Promise<infer R>) ? (...args: Args) => Future$1<Result$1<R, TypedClientError>> : never };
73
+ /**
74
+ * Type-safe signals based on workflow definition with Result pattern
75
+ * Each signal returns Future<Result<void, Error>> instead of Promise<void>
76
+ */
77
+ signals: { [K in keyof ClientInferWorkflowSignals<TWorkflow>]: ClientInferWorkflowSignals<TWorkflow>[K] extends ((...args: infer Args) => Promise<void>) ? (...args: Args) => Future$1<Result$1<void, TypedClientError>> : never };
78
+ /**
79
+ * Type-safe updates based on workflow definition with Result pattern
80
+ * Each update returns Future<Result<T, Error>> instead of Promise<T>
19
81
  */
20
- queries: ClientInferWorkflowQueries<TWorkflow>;
82
+ updates: { [K in keyof ClientInferWorkflowUpdates<TWorkflow>]: ClientInferWorkflowUpdates<TWorkflow>[K] extends ((...args: infer Args) => Promise<infer R>) ? (...args: Args) => Future$1<Result$1<R, TypedClientError>> : never };
21
83
  /**
22
- * Type-safe signals based on workflow definition
84
+ * Get workflow result with Result pattern
23
85
  */
24
- signals: ClientInferWorkflowSignals<TWorkflow>;
86
+ result: () => Future$1<Result$1<ClientInferOutput<TWorkflow>, TypedClientError>>;
25
87
  /**
26
- * Type-safe updates based on workflow definition
88
+ * Terminate workflow with Result pattern
27
89
  */
28
- updates: ClientInferWorkflowUpdates<TWorkflow>;
29
- result: () => Promise<ClientInferOutput<TWorkflow>>;
30
- terminate: (reason?: string) => Promise<void>;
31
- cancel: () => Promise<void>;
90
+ terminate: (reason?: string) => Future$1<Result$1<void, TypedClientError>>;
91
+ /**
92
+ * Cancel workflow with Result pattern
93
+ */
94
+ cancel: () => Future$1<Result$1<void, TypedClientError>>;
32
95
  /**
33
96
  * Get workflow execution description including status and metadata
34
- *
35
- * @example
36
- * ```ts
37
- * const handle = await client.getHandle('processOrder', 'order-123');
38
- * const description = await handle.describe();
39
- * console.log(description.workflowExecutionInfo.status); // RUNNING, COMPLETED, etc.
40
- * ```
41
97
  */
42
- describe: () => ReturnType<WorkflowHandle["describe"]>;
98
+ describe: () => Future$1<Result$1<Awaited<ReturnType<WorkflowHandle["describe"]>>, TypedClientError>>;
43
99
  /**
44
100
  * Fetch the workflow execution history
45
- *
46
- * @example
47
- * ```ts
48
- * const handle = await client.getHandle('processOrder', 'order-123');
49
- * const history = handle.fetchHistory();
50
- * for await (const event of history) {
51
- * console.log(event);
52
- * }
53
- * ```
54
101
  */
55
102
  fetchHistory: () => ReturnType<WorkflowHandle["fetchHistory"]>;
56
103
  }
57
104
  /**
58
- * Typed Temporal client based on a contract
105
+ * Typed Temporal client with Result/Future pattern based on a contract
59
106
  *
60
107
  * Provides type-safe methods to start and execute workflows
61
- * defined in the contract.
108
+ * defined in the contract, with explicit error handling using Result pattern.
62
109
  */
63
110
  declare class TypedClient<TContract extends ContractDefinition> {
64
111
  private readonly contract;
65
112
  private readonly client;
66
113
  private constructor();
67
114
  /**
68
- * Create a typed Temporal client from a contract
115
+ * Create a typed Temporal client with boxed pattern from a contract
69
116
  *
70
117
  * @example
71
118
  * ```ts
@@ -77,24 +124,35 @@ declare class TypedClient<TContract extends ContractDefinition> {
77
124
  *
78
125
  * const result = await client.executeWorkflow('processOrder', {
79
126
  * workflowId: 'order-123',
80
- * args: [...],
127
+ * args: { ... },
128
+ * }).toPromise();
129
+ *
130
+ * result.match({
131
+ * Ok: (output) => console.log('Success:', output),
132
+ * Error: (error) => console.error('Failed:', error),
81
133
  * });
82
134
  * ```
83
135
  */
84
136
  static create<TContract extends ContractDefinition>(contract: TContract, options: ClientOptions): TypedClient<TContract>;
85
137
  /**
86
- * Start a workflow and return a typed handle
138
+ * Start a workflow and return a typed handle with Future pattern
87
139
  *
88
140
  * @example
89
141
  * ```ts
90
- * const handle = await client.startWorkflow('processOrder', {
142
+ * const handleResult = await client.startWorkflow('processOrder', {
91
143
  * workflowId: 'order-123',
92
- * args: ['ORD-123', 'CUST-456', [{ productId: 'PROD-1', quantity: 2 }]],
144
+ * args: { orderId: 'ORD-123' },
93
145
  * workflowExecutionTimeout: '1 day',
94
146
  * retry: { maximumAttempts: 3 },
95
- * });
147
+ * }).toPromise();
96
148
  *
97
- * const result = await handle.result();
149
+ * handleResult.match({
150
+ * Ok: async (handle) => {
151
+ * const result = await handle.result().toPromise();
152
+ * // ... handle result
153
+ * },
154
+ * Error: (error) => console.error('Failed to start:', error),
155
+ * });
98
156
  * ```
99
157
  */
100
158
  startWorkflow<TWorkflowName extends keyof TContract["workflows"]>(workflowName: TWorkflowName, {
@@ -102,20 +160,23 @@ declare class TypedClient<TContract extends ContractDefinition> {
102
160
  ...temporalOptions
103
161
  }: TypedWorkflowStartOptions & {
104
162
  args: ClientInferInput<TContract["workflows"][TWorkflowName]>;
105
- }): Promise<TypedWorkflowHandle<TContract["workflows"][TWorkflowName]>>;
163
+ }): Future$1<Result$1<TypedWorkflowHandle<TContract["workflows"][TWorkflowName]>, TypedClientError>>;
106
164
  /**
107
- * Execute a workflow (start and wait for result)
165
+ * Execute a workflow (start and wait for result) with Future/Result pattern
108
166
  *
109
167
  * @example
110
168
  * ```ts
111
169
  * const result = await client.executeWorkflow('processOrder', {
112
170
  * workflowId: 'order-123',
113
- * args: ['ORD-123', 'CUST-456', [{ productId: 'PROD-1', quantity: 2 }]],
171
+ * args: { orderId: 'ORD-123' },
114
172
  * workflowExecutionTimeout: '1 day',
115
173
  * retry: { maximumAttempts: 3 },
116
- * });
174
+ * }).toPromise();
117
175
  *
118
- * console.log(result.status); // fully typed!
176
+ * result.match({
177
+ * Ok: (output) => console.log('Order processed:', output.status),
178
+ * Error: (error) => console.error('Processing failed:', error),
179
+ * });
119
180
  * ```
120
181
  */
121
182
  executeWorkflow<TWorkflowName extends keyof TContract["workflows"]>(workflowName: TWorkflowName, {
@@ -123,69 +184,24 @@ declare class TypedClient<TContract extends ContractDefinition> {
123
184
  ...temporalOptions
124
185
  }: TypedWorkflowStartOptions & {
125
186
  args: ClientInferInput<TContract["workflows"][TWorkflowName]>;
126
- }): Promise<ClientInferOutput<TContract["workflows"][TWorkflowName]>>;
187
+ }): Future$1<Result$1<ClientInferOutput<TContract["workflows"][TWorkflowName]>, TypedClientError>>;
127
188
  /**
128
- * Get a handle to an existing workflow
189
+ * Get a handle to an existing workflow with Future/Result pattern
129
190
  *
130
191
  * @example
131
192
  * ```ts
132
- * const handle = await client.getHandle('processOrder', 'order-123');
133
- * const result = await handle.result();
193
+ * const handleResult = await client.getHandle('processOrder', 'order-123').toPromise();
194
+ * handleResult.match({
195
+ * Ok: async (handle) => {
196
+ * const result = await handle.result().toPromise();
197
+ * // ... handle result
198
+ * },
199
+ * Error: (error) => console.error('Failed to get handle:', error),
200
+ * });
134
201
  * ```
135
202
  */
136
- getHandle<TWorkflowName extends keyof TContract["workflows"]>(workflowName: TWorkflowName, workflowId: string): Promise<TypedWorkflowHandle<TContract["workflows"][TWorkflowName]>>;
203
+ getHandle<TWorkflowName extends keyof TContract["workflows"]>(workflowName: TWorkflowName, workflowId: string): Future$1<Result$1<TypedWorkflowHandle<TContract["workflows"][TWorkflowName]>, TypedClientError>>;
137
204
  private createTypedHandle;
138
205
  }
139
206
  //#endregion
140
- //#region src/errors.d.ts
141
- /**
142
- * Base error class for typed client errors
143
- */
144
- declare class TypedClientError extends Error {
145
- constructor(message: string);
146
- }
147
- /**
148
- * Error thrown when a workflow is not found in the contract
149
- */
150
- declare class WorkflowNotFoundError extends TypedClientError {
151
- readonly workflowName: string;
152
- readonly availableWorkflows: readonly string[];
153
- constructor(workflowName: string, availableWorkflows?: readonly string[]);
154
- }
155
- /**
156
- * Error thrown when workflow input or output validation fails
157
- */
158
- declare class WorkflowValidationError extends TypedClientError {
159
- readonly workflowName: string;
160
- readonly phase: "input" | "output";
161
- readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
162
- constructor(workflowName: string, phase: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
163
- }
164
- /**
165
- * Error thrown when query input or output validation fails
166
- */
167
- declare class QueryValidationError extends TypedClientError {
168
- readonly queryName: string;
169
- readonly phase: "input" | "output";
170
- readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
171
- constructor(queryName: string, phase: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
172
- }
173
- /**
174
- * Error thrown when signal input validation fails
175
- */
176
- declare class SignalValidationError extends TypedClientError {
177
- readonly signalName: string;
178
- readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
179
- constructor(signalName: string, issues: ReadonlyArray<StandardSchemaV1.Issue>);
180
- }
181
- /**
182
- * Error thrown when update input or output validation fails
183
- */
184
- declare class UpdateValidationError extends TypedClientError {
185
- readonly updateName: string;
186
- readonly phase: "input" | "output";
187
- readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
188
- constructor(updateName: string, phase: "input" | "output", issues: ReadonlyArray<StandardSchemaV1.Issue>);
189
- }
190
- //#endregion
191
- export { QueryValidationError, SignalValidationError, TypedClient, TypedClientError, type TypedWorkflowHandle, type TypedWorkflowStartOptions, UpdateValidationError, WorkflowNotFoundError, WorkflowValidationError };
207
+ export { AsyncData, Future, Option, QueryValidationError, Result, SignalValidationError, TypedClient, TypedClientError, type TypedWorkflowHandle, type TypedWorkflowStartOptions, UpdateValidationError, WorkflowNotFoundError, WorkflowValidationError };