@jagreehal/workflow 1.1.0 → 1.3.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/README.md +86 -0
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +113 -8
- package/dist/core.d.ts +113 -8
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/visualize.cjs +7 -0
- package/dist/visualize.cjs.map +1 -0
- package/dist/visualize.d.cts +805 -0
- package/dist/visualize.d.ts +805 -0
- package/dist/visualize.js +7 -0
- package/dist/visualize.js.map +1 -0
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +3 -1
- package/dist/workflow.d.ts +3 -1
- package/dist/workflow.js +1 -1
- package/dist/workflow.js.map +1 -1
- package/package.json +7 -1
package/dist/core.d.cts
CHANGED
|
@@ -117,9 +117,11 @@ declare const err: <E, C = unknown>(error: E, options?: {
|
|
|
117
117
|
* ```typescript
|
|
118
118
|
* const r = someOperation();
|
|
119
119
|
* if (isOk(r)) {
|
|
120
|
-
*
|
|
120
|
+
* // Use r.value (Type is T)
|
|
121
|
+
* processValue(r.value);
|
|
121
122
|
* } else {
|
|
122
|
-
*
|
|
123
|
+
* // Handle r.error (Type is E)
|
|
124
|
+
* handleError(r.error);
|
|
123
125
|
* }
|
|
124
126
|
* ```
|
|
125
127
|
*/
|
|
@@ -155,10 +157,19 @@ declare const isErr: <T, E, C>(r: Result<T, E, C>) => r is {
|
|
|
155
157
|
*/
|
|
156
158
|
declare const isUnexpectedError: (e: unknown) => e is UnexpectedError;
|
|
157
159
|
type AnyFunction = (...args: never[]) => unknown;
|
|
160
|
+
/**
|
|
161
|
+
* Helper to extract the error type from Result or AsyncResult return values.
|
|
162
|
+
* Works even when a function is declared to return a union of both forms.
|
|
163
|
+
*/
|
|
164
|
+
type ErrorOfReturn<R> = Extract<Awaited<R>, {
|
|
165
|
+
ok: false;
|
|
166
|
+
}> extends {
|
|
167
|
+
error: infer E;
|
|
168
|
+
} ? E : never;
|
|
158
169
|
/**
|
|
159
170
|
* Extract error type from a single function's return type
|
|
160
171
|
*/
|
|
161
|
-
type ErrorOf<T extends AnyFunction> =
|
|
172
|
+
type ErrorOf<T extends AnyFunction> = ErrorOfReturn<ReturnType<T>>;
|
|
162
173
|
/**
|
|
163
174
|
* Extract union of error types from multiple functions
|
|
164
175
|
*/
|
|
@@ -186,10 +197,19 @@ type ExtractCause<T> = T extends {
|
|
|
186
197
|
ok: false;
|
|
187
198
|
cause?: infer C;
|
|
188
199
|
} ? C : never;
|
|
200
|
+
/**
|
|
201
|
+
* Helper to extract the cause type from Result or AsyncResult return values.
|
|
202
|
+
* Works even when a function is declared to return a union of both forms.
|
|
203
|
+
*/
|
|
204
|
+
type CauseOfReturn<R> = Extract<Awaited<R>, {
|
|
205
|
+
ok: false;
|
|
206
|
+
}> extends {
|
|
207
|
+
cause?: infer C;
|
|
208
|
+
} ? C : never;
|
|
189
209
|
/**
|
|
190
210
|
* Extract cause type from a function's return type
|
|
191
211
|
*/
|
|
192
|
-
type CauseOf<T extends AnyFunction> =
|
|
212
|
+
type CauseOf<T extends AnyFunction> = CauseOfReturn<ReturnType<T>>;
|
|
193
213
|
/**
|
|
194
214
|
* Options for configuring a step within a workflow.
|
|
195
215
|
* Use these to enable tracing, caching, and state persistence.
|
|
@@ -324,6 +344,61 @@ interface RunStep<E = unknown> {
|
|
|
324
344
|
name?: string;
|
|
325
345
|
key?: string;
|
|
326
346
|
}) => Promise<T>;
|
|
347
|
+
/**
|
|
348
|
+
* Execute a parallel operation (allAsync) with scope events for visualization.
|
|
349
|
+
*
|
|
350
|
+
* This wraps the operation with scope_start and scope_end events, enabling
|
|
351
|
+
* visualization of parallel execution branches.
|
|
352
|
+
*
|
|
353
|
+
* @param name - Name for this parallel block (used in visualization)
|
|
354
|
+
* @param operation - A function that returns a Result from allAsync or allSettledAsync
|
|
355
|
+
* @returns The success value (unwrapped array)
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```typescript
|
|
359
|
+
* const [user, posts] = await step.parallel('Fetch all data', () =>
|
|
360
|
+
* allAsync([fetchUser(id), fetchPosts(id)])
|
|
361
|
+
* );
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
parallel: <T, StepE extends E, StepC = unknown>(name: string, operation: () => Result<T[], StepE, StepC> | AsyncResult<T[], StepE, StepC>) => Promise<T[]>;
|
|
365
|
+
/**
|
|
366
|
+
* Execute a race operation (anyAsync) with scope events for visualization.
|
|
367
|
+
*
|
|
368
|
+
* This wraps the operation with scope_start and scope_end events, enabling
|
|
369
|
+
* visualization of racing execution branches.
|
|
370
|
+
*
|
|
371
|
+
* @param name - Name for this race block (used in visualization)
|
|
372
|
+
* @param operation - A function that returns a Result from anyAsync
|
|
373
|
+
* @returns The success value (first to succeed)
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```typescript
|
|
377
|
+
* const data = await step.race('Fastest API', () =>
|
|
378
|
+
* anyAsync([fetchFromPrimary(id), fetchFromFallback(id)])
|
|
379
|
+
* );
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
race: <T, StepE extends E, StepC = unknown>(name: string, operation: () => Result<T, StepE, StepC> | AsyncResult<T, StepE, StepC>) => Promise<T>;
|
|
383
|
+
/**
|
|
384
|
+
* Execute an allSettled operation with scope events for visualization.
|
|
385
|
+
*
|
|
386
|
+
* This wraps the operation with scope_start and scope_end events, enabling
|
|
387
|
+
* visualization of allSettled execution branches. Unlike step.parallel,
|
|
388
|
+
* allSettled collects all results even if some fail.
|
|
389
|
+
*
|
|
390
|
+
* @param name - Name for this allSettled block (used in visualization)
|
|
391
|
+
* @param operation - A function that returns a Result from allSettledAsync
|
|
392
|
+
* @returns The success value (unwrapped array)
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* const [user, posts] = await step.allSettled('Fetch all data', () =>
|
|
397
|
+
* allSettledAsync([fetchUser(id), fetchPosts(id)])
|
|
398
|
+
* );
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
allSettled: <T, StepE extends E, StepC = unknown>(name: string, operation: () => Result<T[], StepE, StepC> | AsyncResult<T[], StepE, StepC>) => Promise<T[]>;
|
|
327
402
|
}
|
|
328
403
|
/**
|
|
329
404
|
* Unified event stream for workflow execution.
|
|
@@ -333,6 +408,10 @@ interface RunStep<E = unknown> {
|
|
|
333
408
|
* preserves its original types, but the event type cannot statically represent them.
|
|
334
409
|
* Use runtime checks or the meta field to interpret cause values.
|
|
335
410
|
*/
|
|
411
|
+
/**
|
|
412
|
+
* Scope types for parallel and race operations.
|
|
413
|
+
*/
|
|
414
|
+
type ScopeType = "parallel" | "race" | "allSettled";
|
|
336
415
|
type WorkflowEvent<E> = {
|
|
337
416
|
type: "workflow_start";
|
|
338
417
|
workflowId: string;
|
|
@@ -351,12 +430,14 @@ type WorkflowEvent<E> = {
|
|
|
351
430
|
} | {
|
|
352
431
|
type: "step_start";
|
|
353
432
|
workflowId: string;
|
|
433
|
+
stepId: string;
|
|
354
434
|
stepKey?: string;
|
|
355
435
|
name?: string;
|
|
356
436
|
ts: number;
|
|
357
437
|
} | {
|
|
358
438
|
type: "step_success";
|
|
359
439
|
workflowId: string;
|
|
440
|
+
stepId: string;
|
|
360
441
|
stepKey?: string;
|
|
361
442
|
name?: string;
|
|
362
443
|
ts: number;
|
|
@@ -364,6 +445,7 @@ type WorkflowEvent<E> = {
|
|
|
364
445
|
} | {
|
|
365
446
|
type: "step_error";
|
|
366
447
|
workflowId: string;
|
|
448
|
+
stepId: string;
|
|
367
449
|
stepKey?: string;
|
|
368
450
|
name?: string;
|
|
369
451
|
ts: number;
|
|
@@ -372,6 +454,7 @@ type WorkflowEvent<E> = {
|
|
|
372
454
|
} | {
|
|
373
455
|
type: "step_aborted";
|
|
374
456
|
workflowId: string;
|
|
457
|
+
stepId: string;
|
|
375
458
|
stepKey?: string;
|
|
376
459
|
name?: string;
|
|
377
460
|
ts: number;
|
|
@@ -397,6 +480,28 @@ type WorkflowEvent<E> = {
|
|
|
397
480
|
stepKey: string;
|
|
398
481
|
name?: string;
|
|
399
482
|
ts: number;
|
|
483
|
+
} | {
|
|
484
|
+
type: "step_skipped";
|
|
485
|
+
workflowId: string;
|
|
486
|
+
stepKey?: string;
|
|
487
|
+
name?: string;
|
|
488
|
+
reason?: string;
|
|
489
|
+
decisionId?: string;
|
|
490
|
+
ts: number;
|
|
491
|
+
} | {
|
|
492
|
+
type: "scope_start";
|
|
493
|
+
workflowId: string;
|
|
494
|
+
scopeId: string;
|
|
495
|
+
scopeType: ScopeType;
|
|
496
|
+
name?: string;
|
|
497
|
+
ts: number;
|
|
498
|
+
} | {
|
|
499
|
+
type: "scope_end";
|
|
500
|
+
workflowId: string;
|
|
501
|
+
scopeId: string;
|
|
502
|
+
ts: number;
|
|
503
|
+
durationMs: number;
|
|
504
|
+
winnerId?: string;
|
|
400
505
|
};
|
|
401
506
|
type RunOptionsWithCatch<E, C = void> = {
|
|
402
507
|
/**
|
|
@@ -1041,9 +1146,9 @@ declare function mapError<T, E, F, C>(r: Result<T, E, C>, fn: (error: E) => F):
|
|
|
1041
1146
|
* });
|
|
1042
1147
|
*
|
|
1043
1148
|
* // Handle with cause
|
|
1044
|
-
* const
|
|
1045
|
-
* ok: (value) =>
|
|
1046
|
-
* err: (error, cause) =>
|
|
1149
|
+
* const response = match(result, {
|
|
1150
|
+
* ok: (value) => ({ status: 'success', data: value }),
|
|
1151
|
+
* err: (error, cause) => ({ status: 'error', error, cause }),
|
|
1047
1152
|
* });
|
|
1048
1153
|
* ```
|
|
1049
1154
|
*/
|
|
@@ -1673,4 +1778,4 @@ type AllAsyncCauses<T extends readonly MaybeAsyncResult<unknown, unknown, unknow
|
|
|
1673
1778
|
*/
|
|
1674
1779
|
declare function allSettledAsync<const T extends readonly MaybeAsyncResult<unknown, unknown, unknown>[]>(results: T): Promise<Result<AllAsyncValues<T>, SettledError<AllAsyncErrors<T> | PromiseRejectedError, AllAsyncCauses<T> | PromiseRejectionCause>[]>>;
|
|
1675
1780
|
|
|
1676
|
-
export { type AsyncResult, type CauseOf, EARLY_EXIT_SYMBOL, type EarlyExit, type EmptyInputError, type ErrorOf, type Errors, type ExtractCause, type ExtractError, type ExtractValue, type MaybeAsyncResult, type PromiseRejectedError, type PromiseRejectionCause, type Result, type RunOptions, type RunOptionsWithCatch, type RunOptionsWithoutCatch, type RunStep, type SettledError, type StepFailureMeta, type StepOptions, type UnexpectedCause, type UnexpectedError, type UnexpectedStepFailureCause, UnwrapError, type WorkflowEvent, all, allAsync, allSettled, allSettledAsync, andThen, any, anyAsync, createEarlyExit, err, from, fromNullable, fromPromise, isEarlyExit, isErr, isOk, isUnexpectedError, map, mapError, mapErrorTry, mapTry, match, ok, partition, run, tap, tapError, tryAsync, unwrap, unwrapOr, unwrapOrElse };
|
|
1781
|
+
export { type AsyncResult, type CauseOf, EARLY_EXIT_SYMBOL, type EarlyExit, type EmptyInputError, type ErrorOf, type Errors, type ExtractCause, type ExtractError, type ExtractValue, type MaybeAsyncResult, type PromiseRejectedError, type PromiseRejectionCause, type Result, type RunOptions, type RunOptionsWithCatch, type RunOptionsWithoutCatch, type RunStep, type ScopeType, type SettledError, type StepFailureMeta, type StepOptions, type UnexpectedCause, type UnexpectedError, type UnexpectedStepFailureCause, UnwrapError, type WorkflowEvent, all, allAsync, allSettled, allSettledAsync, andThen, any, anyAsync, createEarlyExit, err, from, fromNullable, fromPromise, isEarlyExit, isErr, isOk, isUnexpectedError, map, mapError, mapErrorTry, mapTry, match, ok, partition, run, tap, tapError, tryAsync, unwrap, unwrapOr, unwrapOrElse };
|
package/dist/core.d.ts
CHANGED
|
@@ -117,9 +117,11 @@ declare const err: <E, C = unknown>(error: E, options?: {
|
|
|
117
117
|
* ```typescript
|
|
118
118
|
* const r = someOperation();
|
|
119
119
|
* if (isOk(r)) {
|
|
120
|
-
*
|
|
120
|
+
* // Use r.value (Type is T)
|
|
121
|
+
* processValue(r.value);
|
|
121
122
|
* } else {
|
|
122
|
-
*
|
|
123
|
+
* // Handle r.error (Type is E)
|
|
124
|
+
* handleError(r.error);
|
|
123
125
|
* }
|
|
124
126
|
* ```
|
|
125
127
|
*/
|
|
@@ -155,10 +157,19 @@ declare const isErr: <T, E, C>(r: Result<T, E, C>) => r is {
|
|
|
155
157
|
*/
|
|
156
158
|
declare const isUnexpectedError: (e: unknown) => e is UnexpectedError;
|
|
157
159
|
type AnyFunction = (...args: never[]) => unknown;
|
|
160
|
+
/**
|
|
161
|
+
* Helper to extract the error type from Result or AsyncResult return values.
|
|
162
|
+
* Works even when a function is declared to return a union of both forms.
|
|
163
|
+
*/
|
|
164
|
+
type ErrorOfReturn<R> = Extract<Awaited<R>, {
|
|
165
|
+
ok: false;
|
|
166
|
+
}> extends {
|
|
167
|
+
error: infer E;
|
|
168
|
+
} ? E : never;
|
|
158
169
|
/**
|
|
159
170
|
* Extract error type from a single function's return type
|
|
160
171
|
*/
|
|
161
|
-
type ErrorOf<T extends AnyFunction> =
|
|
172
|
+
type ErrorOf<T extends AnyFunction> = ErrorOfReturn<ReturnType<T>>;
|
|
162
173
|
/**
|
|
163
174
|
* Extract union of error types from multiple functions
|
|
164
175
|
*/
|
|
@@ -186,10 +197,19 @@ type ExtractCause<T> = T extends {
|
|
|
186
197
|
ok: false;
|
|
187
198
|
cause?: infer C;
|
|
188
199
|
} ? C : never;
|
|
200
|
+
/**
|
|
201
|
+
* Helper to extract the cause type from Result or AsyncResult return values.
|
|
202
|
+
* Works even when a function is declared to return a union of both forms.
|
|
203
|
+
*/
|
|
204
|
+
type CauseOfReturn<R> = Extract<Awaited<R>, {
|
|
205
|
+
ok: false;
|
|
206
|
+
}> extends {
|
|
207
|
+
cause?: infer C;
|
|
208
|
+
} ? C : never;
|
|
189
209
|
/**
|
|
190
210
|
* Extract cause type from a function's return type
|
|
191
211
|
*/
|
|
192
|
-
type CauseOf<T extends AnyFunction> =
|
|
212
|
+
type CauseOf<T extends AnyFunction> = CauseOfReturn<ReturnType<T>>;
|
|
193
213
|
/**
|
|
194
214
|
* Options for configuring a step within a workflow.
|
|
195
215
|
* Use these to enable tracing, caching, and state persistence.
|
|
@@ -324,6 +344,61 @@ interface RunStep<E = unknown> {
|
|
|
324
344
|
name?: string;
|
|
325
345
|
key?: string;
|
|
326
346
|
}) => Promise<T>;
|
|
347
|
+
/**
|
|
348
|
+
* Execute a parallel operation (allAsync) with scope events for visualization.
|
|
349
|
+
*
|
|
350
|
+
* This wraps the operation with scope_start and scope_end events, enabling
|
|
351
|
+
* visualization of parallel execution branches.
|
|
352
|
+
*
|
|
353
|
+
* @param name - Name for this parallel block (used in visualization)
|
|
354
|
+
* @param operation - A function that returns a Result from allAsync or allSettledAsync
|
|
355
|
+
* @returns The success value (unwrapped array)
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```typescript
|
|
359
|
+
* const [user, posts] = await step.parallel('Fetch all data', () =>
|
|
360
|
+
* allAsync([fetchUser(id), fetchPosts(id)])
|
|
361
|
+
* );
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
parallel: <T, StepE extends E, StepC = unknown>(name: string, operation: () => Result<T[], StepE, StepC> | AsyncResult<T[], StepE, StepC>) => Promise<T[]>;
|
|
365
|
+
/**
|
|
366
|
+
* Execute a race operation (anyAsync) with scope events for visualization.
|
|
367
|
+
*
|
|
368
|
+
* This wraps the operation with scope_start and scope_end events, enabling
|
|
369
|
+
* visualization of racing execution branches.
|
|
370
|
+
*
|
|
371
|
+
* @param name - Name for this race block (used in visualization)
|
|
372
|
+
* @param operation - A function that returns a Result from anyAsync
|
|
373
|
+
* @returns The success value (first to succeed)
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```typescript
|
|
377
|
+
* const data = await step.race('Fastest API', () =>
|
|
378
|
+
* anyAsync([fetchFromPrimary(id), fetchFromFallback(id)])
|
|
379
|
+
* );
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
race: <T, StepE extends E, StepC = unknown>(name: string, operation: () => Result<T, StepE, StepC> | AsyncResult<T, StepE, StepC>) => Promise<T>;
|
|
383
|
+
/**
|
|
384
|
+
* Execute an allSettled operation with scope events for visualization.
|
|
385
|
+
*
|
|
386
|
+
* This wraps the operation with scope_start and scope_end events, enabling
|
|
387
|
+
* visualization of allSettled execution branches. Unlike step.parallel,
|
|
388
|
+
* allSettled collects all results even if some fail.
|
|
389
|
+
*
|
|
390
|
+
* @param name - Name for this allSettled block (used in visualization)
|
|
391
|
+
* @param operation - A function that returns a Result from allSettledAsync
|
|
392
|
+
* @returns The success value (unwrapped array)
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* const [user, posts] = await step.allSettled('Fetch all data', () =>
|
|
397
|
+
* allSettledAsync([fetchUser(id), fetchPosts(id)])
|
|
398
|
+
* );
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
allSettled: <T, StepE extends E, StepC = unknown>(name: string, operation: () => Result<T[], StepE, StepC> | AsyncResult<T[], StepE, StepC>) => Promise<T[]>;
|
|
327
402
|
}
|
|
328
403
|
/**
|
|
329
404
|
* Unified event stream for workflow execution.
|
|
@@ -333,6 +408,10 @@ interface RunStep<E = unknown> {
|
|
|
333
408
|
* preserves its original types, but the event type cannot statically represent them.
|
|
334
409
|
* Use runtime checks or the meta field to interpret cause values.
|
|
335
410
|
*/
|
|
411
|
+
/**
|
|
412
|
+
* Scope types for parallel and race operations.
|
|
413
|
+
*/
|
|
414
|
+
type ScopeType = "parallel" | "race" | "allSettled";
|
|
336
415
|
type WorkflowEvent<E> = {
|
|
337
416
|
type: "workflow_start";
|
|
338
417
|
workflowId: string;
|
|
@@ -351,12 +430,14 @@ type WorkflowEvent<E> = {
|
|
|
351
430
|
} | {
|
|
352
431
|
type: "step_start";
|
|
353
432
|
workflowId: string;
|
|
433
|
+
stepId: string;
|
|
354
434
|
stepKey?: string;
|
|
355
435
|
name?: string;
|
|
356
436
|
ts: number;
|
|
357
437
|
} | {
|
|
358
438
|
type: "step_success";
|
|
359
439
|
workflowId: string;
|
|
440
|
+
stepId: string;
|
|
360
441
|
stepKey?: string;
|
|
361
442
|
name?: string;
|
|
362
443
|
ts: number;
|
|
@@ -364,6 +445,7 @@ type WorkflowEvent<E> = {
|
|
|
364
445
|
} | {
|
|
365
446
|
type: "step_error";
|
|
366
447
|
workflowId: string;
|
|
448
|
+
stepId: string;
|
|
367
449
|
stepKey?: string;
|
|
368
450
|
name?: string;
|
|
369
451
|
ts: number;
|
|
@@ -372,6 +454,7 @@ type WorkflowEvent<E> = {
|
|
|
372
454
|
} | {
|
|
373
455
|
type: "step_aborted";
|
|
374
456
|
workflowId: string;
|
|
457
|
+
stepId: string;
|
|
375
458
|
stepKey?: string;
|
|
376
459
|
name?: string;
|
|
377
460
|
ts: number;
|
|
@@ -397,6 +480,28 @@ type WorkflowEvent<E> = {
|
|
|
397
480
|
stepKey: string;
|
|
398
481
|
name?: string;
|
|
399
482
|
ts: number;
|
|
483
|
+
} | {
|
|
484
|
+
type: "step_skipped";
|
|
485
|
+
workflowId: string;
|
|
486
|
+
stepKey?: string;
|
|
487
|
+
name?: string;
|
|
488
|
+
reason?: string;
|
|
489
|
+
decisionId?: string;
|
|
490
|
+
ts: number;
|
|
491
|
+
} | {
|
|
492
|
+
type: "scope_start";
|
|
493
|
+
workflowId: string;
|
|
494
|
+
scopeId: string;
|
|
495
|
+
scopeType: ScopeType;
|
|
496
|
+
name?: string;
|
|
497
|
+
ts: number;
|
|
498
|
+
} | {
|
|
499
|
+
type: "scope_end";
|
|
500
|
+
workflowId: string;
|
|
501
|
+
scopeId: string;
|
|
502
|
+
ts: number;
|
|
503
|
+
durationMs: number;
|
|
504
|
+
winnerId?: string;
|
|
400
505
|
};
|
|
401
506
|
type RunOptionsWithCatch<E, C = void> = {
|
|
402
507
|
/**
|
|
@@ -1041,9 +1146,9 @@ declare function mapError<T, E, F, C>(r: Result<T, E, C>, fn: (error: E) => F):
|
|
|
1041
1146
|
* });
|
|
1042
1147
|
*
|
|
1043
1148
|
* // Handle with cause
|
|
1044
|
-
* const
|
|
1045
|
-
* ok: (value) =>
|
|
1046
|
-
* err: (error, cause) =>
|
|
1149
|
+
* const response = match(result, {
|
|
1150
|
+
* ok: (value) => ({ status: 'success', data: value }),
|
|
1151
|
+
* err: (error, cause) => ({ status: 'error', error, cause }),
|
|
1047
1152
|
* });
|
|
1048
1153
|
* ```
|
|
1049
1154
|
*/
|
|
@@ -1673,4 +1778,4 @@ type AllAsyncCauses<T extends readonly MaybeAsyncResult<unknown, unknown, unknow
|
|
|
1673
1778
|
*/
|
|
1674
1779
|
declare function allSettledAsync<const T extends readonly MaybeAsyncResult<unknown, unknown, unknown>[]>(results: T): Promise<Result<AllAsyncValues<T>, SettledError<AllAsyncErrors<T> | PromiseRejectedError, AllAsyncCauses<T> | PromiseRejectionCause>[]>>;
|
|
1675
1780
|
|
|
1676
|
-
export { type AsyncResult, type CauseOf, EARLY_EXIT_SYMBOL, type EarlyExit, type EmptyInputError, type ErrorOf, type Errors, type ExtractCause, type ExtractError, type ExtractValue, type MaybeAsyncResult, type PromiseRejectedError, type PromiseRejectionCause, type Result, type RunOptions, type RunOptionsWithCatch, type RunOptionsWithoutCatch, type RunStep, type SettledError, type StepFailureMeta, type StepOptions, type UnexpectedCause, type UnexpectedError, type UnexpectedStepFailureCause, UnwrapError, type WorkflowEvent, all, allAsync, allSettled, allSettledAsync, andThen, any, anyAsync, createEarlyExit, err, from, fromNullable, fromPromise, isEarlyExit, isErr, isOk, isUnexpectedError, map, mapError, mapErrorTry, mapTry, match, ok, partition, run, tap, tapError, tryAsync, unwrap, unwrapOr, unwrapOrElse };
|
|
1781
|
+
export { type AsyncResult, type CauseOf, EARLY_EXIT_SYMBOL, type EarlyExit, type EmptyInputError, type ErrorOf, type Errors, type ExtractCause, type ExtractError, type ExtractValue, type MaybeAsyncResult, type PromiseRejectedError, type PromiseRejectionCause, type Result, type RunOptions, type RunOptionsWithCatch, type RunOptionsWithoutCatch, type RunStep, type ScopeType, type SettledError, type StepFailureMeta, type StepOptions, type UnexpectedCause, type UnexpectedError, type UnexpectedStepFailureCause, UnwrapError, type WorkflowEvent, all, allAsync, allSettled, allSettledAsync, andThen, any, anyAsync, createEarlyExit, err, from, fromNullable, fromPromise, isEarlyExit, isErr, isOk, isUnexpectedError, map, mapError, mapErrorTry, mapTry, match, ok, partition, run, tap, tapError, tryAsync, unwrap, unwrapOr, unwrapOrElse };
|
package/dist/core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var k=e=>({ok:!0,value:e}),i=(e,n)=>({ok:!1,error:e,...n?.cause!==void 0?{cause:n.cause}:{}}),W=e=>e.ok,Y=e=>!e.ok,D=e=>typeof e=="object"&&e!==null&&e.type==="UNEXPECTED_ERROR",b=Symbol("early-exit");function N(e,n){return{[b]:!0,error:e,meta:n}}function V(e){return typeof e=="object"&&e!==null&&e[b]===!0}var I=Symbol("mapper-exception");function j(e){return{[I]:!0,thrown:e}}function L(e){return typeof e=="object"&&e!==null&&e[I]===!0}function X(e){return typeof e=="string"?{name:e}:e??{}}async function _(e,n){let{onError:r,onEvent:o,catchUnexpected:l,workflowId:R,context:d}=n&&typeof n=="object"?n:{},u=R??crypto.randomUUID(),O=!r&&!l,c=t=>{o?.(t,d)},P=N,U=t=>V(t),h=(t,f)=>O?f?.origin==="result"?{type:"UNEXPECTED_ERROR",cause:{type:"STEP_FAILURE",origin:"result",error:t,...f.resultCause!==void 0?{cause:f.resultCause}:{}}}:f?.origin==="throw"?{type:"UNEXPECTED_ERROR",cause:{type:"STEP_FAILURE",origin:"throw",error:t,thrown:f.thrown}}:{type:"UNEXPECTED_ERROR",cause:{type:"STEP_FAILURE",origin:"result",error:t}}:t,M=t=>t.origin==="result"?t.resultCause:t.thrown,K=t=>({type:"UNEXPECTED_ERROR",cause:t.meta.origin==="result"?{type:"STEP_FAILURE",origin:"result",error:t.error,...t.meta.resultCause!==void 0?{cause:t.meta.resultCause}:{}}:{type:"STEP_FAILURE",origin:"throw",error:t.error,thrown:t.meta.thrown}});try{let t=(m,T)=>(async()=>{let{name:a,key:s}=X(T),v=o?performance.now():0;o&&c({type:"step_start",workflowId:u,stepKey:s,name:a,ts:Date.now()});let p;try{p=await(typeof m=="function"?m():m)}catch(y){let C=performance.now()-v;if(U(y))throw c({type:"step_aborted",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:C}),y;if(l){let A;try{A=l(y)}catch(F){throw j(F)}throw c({type:"step_error",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:C,error:A}),s&&c({type:"step_complete",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:C,result:i(A,{cause:y}),meta:{origin:"throw",thrown:y}}),r?.(A,a),P(A,{origin:"throw",thrown:y})}else{let A={type:"UNEXPECTED_ERROR",cause:{type:"UNCAUGHT_EXCEPTION",thrown:y}};throw c({type:"step_error",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:C,error:A}),s&&c({type:"step_complete",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:C,result:i(A,{cause:y}),meta:{origin:"throw",thrown:y}}),y}}let E=performance.now()-v;if(p.ok)return c({type:"step_success",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:E}),s&&c({type:"step_complete",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:E,result:p}),p.value;let w=h(p.error,{origin:"result",resultCause:p.cause});throw c({type:"step_error",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:E,error:w}),s&&c({type:"step_complete",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:E,result:p,meta:{origin:"result",resultCause:p.cause}}),r?.(p.error,a),P(p.error,{origin:"result",resultCause:p.cause})})();t.try=(m,T)=>{let a=T.name,s=T.key,g="error"in T?()=>T.error:T.onError,v=o;return(async()=>{let p=v?performance.now():0;o&&c({type:"step_start",workflowId:u,stepKey:s,name:a,ts:Date.now()});try{let E=await m(),w=performance.now()-p;return c({type:"step_success",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:w}),s&&c({type:"step_complete",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:w,result:k(E)}),E}catch(E){let w=g(E),y=performance.now()-p,C=h(w,{origin:"throw",thrown:E});throw c({type:"step_error",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:y,error:C}),s&&c({type:"step_complete",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:y,result:i(w,{cause:E}),meta:{origin:"throw",thrown:E}}),r?.(w,a),P(w,{origin:"throw",thrown:E})}})()},t.fromResult=(m,T)=>{let a=T.name,s=T.key,g="error"in T?()=>T.error:T.onError,v=o;return(async()=>{let p=v?performance.now():0;o&&c({type:"step_start",workflowId:u,stepKey:s,name:a,ts:Date.now()});let E=await m();if(E.ok){let w=performance.now()-p;return c({type:"step_success",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:w}),s&&c({type:"step_complete",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:w,result:k(E.value)}),E.value}else{let w=g(E.error),y=performance.now()-p,C=h(w,{origin:"result",resultCause:E.error});throw c({type:"step_error",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:y,error:C}),s&&c({type:"step_complete",workflowId:u,stepKey:s,name:a,ts:Date.now(),durationMs:y,result:i(w,{cause:E.error}),meta:{origin:"result",resultCause:E.error}}),r?.(w,a),P(w,{origin:"result",resultCause:E.error})}})()};let x=await e(t);return k(x)}catch(t){if(L(t))throw t.thrown;if(U(t)){let x=M(t.meta);if(l||r)return i(t.error,{cause:x});if(D(t.error))return i(t.error,{cause:x});let m=K(t);return i(m,{cause:x})}if(l){let x=l(t);return r?.(x,"unexpected"),i(x,{cause:t})}let f={type:"UNEXPECTED_ERROR",cause:{type:"UNCAUGHT_EXCEPTION",thrown:t}};return r?.(f,"unexpected"),i(f,{cause:t})}}_.strict=(e,n)=>_(e,n);var S=class extends Error{constructor(r,o){super(`Unwrap called on an error result: ${String(r)}`);this.error=r;this.cause=o;this.name="UnwrapError"}},J=e=>{if(e.ok)return e.value;throw new S(e.error,e.cause)},G=(e,n)=>e.ok?e.value:n,q=(e,n)=>e.ok?e.value:n(e.error,e.cause);function B(e,n){try{return k(e())}catch(r){return n?i(n(r),{cause:r}):i(r)}}async function H(e,n){try{return k(await e)}catch(r){return n?i(n(r),{cause:r}):i(r)}}async function $(e,n){try{return k(await e())}catch(r){return n?i(n(r),{cause:r}):i(r)}}function z(e,n){return e!=null?k(e):i(n())}function Q(e,n){return e.ok?k(n(e.value)):e}function Z(e,n){return e.ok?e:i(n(e.error),{cause:e.cause})}function ee(e,n){return e.ok?n.ok(e.value):n.err(e.error,e.cause)}function ne(e,n){return e.ok?n(e.value):e}function re(e,n){return e.ok&&n(e.value),e}function te(e,n){return e.ok||n(e.error,e.cause),e}function oe(e,n,r){if(!e.ok)return e;try{return k(n(e.value))}catch(o){return i(r(o),{cause:o})}}function se(e,n,r){if(e.ok)return e;try{return i(n(e.error),{cause:e.cause})}catch(o){return i(r(o),{cause:o})}}function ue(e){let n=[];for(let r of e){if(!r.ok)return r;n.push(r.value)}return k(n)}async function ae(e){return e.length===0?k([]):new Promise(n=>{let r=!1,o=e.length,l=new Array(e.length);for(let R=0;R<e.length;R++){let d=R;Promise.resolve(e[d]).catch(u=>i({type:"PROMISE_REJECTED",cause:u},{cause:{type:"PROMISE_REJECTION",reason:u}})).then(u=>{if(!r){if(!u.ok){r=!0,n(u);return}l[d]=u.value,o--,o===0&&n(k(l))}})}})}function ie(e){let n=[],r=[];for(let o of e)o.ok?n.push(o.value):r.push({error:o.error,cause:o.cause});return r.length>0?i(r):k(n)}function le(e){let n=[],r=[];for(let o of e)o.ok?n.push(o.value):r.push(o.error);return{values:n,errors:r}}function Ee(e){if(e.length===0)return i({type:"EMPTY_INPUT",message:"any() requires at least one Result"});let n=null;for(let r of e){if(r.ok)return r;n||(n=r)}return n}async function ce(e){return e.length===0?i({type:"EMPTY_INPUT",message:"anyAsync() requires at least one Result"}):new Promise(n=>{let r=!1,o=e.length,l=null;for(let R of e)Promise.resolve(R).catch(d=>i({type:"PROMISE_REJECTED",cause:d},{cause:{type:"PROMISE_REJECTION",reason:d}})).then(d=>{if(!r){if(d.ok){r=!0,n(d);return}l||(l=d),o--,o===0&&n(l)}})})}async function pe(e){let n=await Promise.all(e.map(l=>Promise.resolve(l).then(R=>({status:"result",result:R})).catch(R=>({status:"rejected",error:{type:"PROMISE_REJECTED",cause:R},cause:{type:"PROMISE_REJECTION",reason:R}})))),r=[],o=[];for(let l of n)l.status==="rejected"?o.push({error:l.error,cause:l.cause}):l.result.ok?r.push(l.result.value):o.push({error:l.result.error,cause:l.result.cause});return o.length>0?i(o):k(r)}export{b as EARLY_EXIT_SYMBOL,S as UnwrapError,ue as all,ae as allAsync,ie as allSettled,pe as allSettledAsync,ne as andThen,Ee as any,ce as anyAsync,N as createEarlyExit,i as err,B as from,z as fromNullable,H as fromPromise,V as isEarlyExit,Y as isErr,W as isOk,D as isUnexpectedError,Q as map,Z as mapError,se as mapErrorTry,oe as mapTry,ee as match,k as ok,le as partition,_ as run,re as tap,te as tapError,$ as tryAsync,J as unwrap,G as unwrapOr,q as unwrapOrElse};
|
|
1
|
+
var f=e=>({ok:!0,value:e}),l=(e,n)=>({ok:!1,error:e,...n?.cause!==void 0?{cause:n.cause}:{}}),G=e=>e.ok,q=e=>!e.ok,L=e=>typeof e=="object"&&e!==null&&e.type==="UNEXPECTED_ERROR",O=Symbol("early-exit");function X(e,n){return{[O]:!0,error:e,meta:n}}function W(e){return typeof e=="object"&&e!==null&&e[O]===!0}var K=Symbol("mapper-exception");function Y(e){return{[K]:!0,thrown:e}}function J(e){return typeof e=="object"&&e!==null&&e[K]===!0}function $(e){return typeof e=="string"?{name:e}:e??{}}async function M(e,n){let{onError:t,onEvent:u,catchUnexpected:w,workflowId:C,context:A}=n&&typeof n=="object"?n:{},a=C??crypto.randomUUID(),D=!t&&!w,g=[],F=0,I=r=>r??`step_${++F}`,c=r=>{if(r.type==="step_success"){let S=r.stepId;for(let x=g.length-1;x>=0;x--){let T=g[x];if(T.type==="race"&&!T.winnerId){T.winnerId=S;break}}}u?.(r,A)},h=X,b=r=>W(r),_=(r,S)=>D?S?.origin==="result"?{type:"UNEXPECTED_ERROR",cause:{type:"STEP_FAILURE",origin:"result",error:r,...S.resultCause!==void 0?{cause:S.resultCause}:{}}}:S?.origin==="throw"?{type:"UNEXPECTED_ERROR",cause:{type:"STEP_FAILURE",origin:"throw",error:r,thrown:S.thrown}}:{type:"UNEXPECTED_ERROR",cause:{type:"STEP_FAILURE",origin:"result",error:r}}:r,N=r=>r.origin==="result"?r.resultCause:r.thrown,V=r=>({type:"UNEXPECTED_ERROR",cause:r.meta.origin==="result"?{type:"STEP_FAILURE",origin:"result",error:r.error,...r.meta.resultCause!==void 0?{cause:r.meta.resultCause}:{}}:{type:"STEP_FAILURE",origin:"throw",error:r.error,thrown:r.meta.thrown}});try{let r=(T,k)=>(async()=>{let{name:o,key:s}=$(k),y=I(s),i=u?performance.now():0;u&&c({type:"step_start",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now()});let p;try{p=await(typeof T=="function"?T():T)}catch(R){let v=performance.now()-i;if(b(R))throw c({type:"step_aborted",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now(),durationMs:v}),R;if(w){let P;try{P=w(R)}catch(j){throw Y(j)}throw c({type:"step_error",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now(),durationMs:v,error:P}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:o,ts:Date.now(),durationMs:v,result:l(P,{cause:R}),meta:{origin:"throw",thrown:R}}),t?.(P,o),h(P,{origin:"throw",thrown:R})}else{let P={type:"UNEXPECTED_ERROR",cause:{type:"UNCAUGHT_EXCEPTION",thrown:R}};throw c({type:"step_error",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now(),durationMs:v,error:P}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:o,ts:Date.now(),durationMs:v,result:l(P,{cause:R}),meta:{origin:"throw",thrown:R}}),R}}let E=performance.now()-i;if(p.ok)return c({type:"step_success",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now(),durationMs:E}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:o,ts:Date.now(),durationMs:E,result:p}),p.value;let d=_(p.error,{origin:"result",resultCause:p.cause});throw c({type:"step_error",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now(),durationMs:E,error:d}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:o,ts:Date.now(),durationMs:E,result:p,meta:{origin:"result",resultCause:p.cause}}),t?.(p.error,o),h(p.error,{origin:"result",resultCause:p.cause})})();r.try=(T,k)=>{let o=k.name,s=k.key,y=I(s),m="error"in k?()=>k.error:k.onError,i=u;return(async()=>{let p=i?performance.now():0;u&&c({type:"step_start",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now()});try{let E=await T(),d=performance.now()-p;return c({type:"step_success",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now(),durationMs:d}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:o,ts:Date.now(),durationMs:d,result:f(E)}),E}catch(E){let d=m(E),R=performance.now()-p,v=_(d,{origin:"throw",thrown:E});throw c({type:"step_error",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now(),durationMs:R,error:v}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:o,ts:Date.now(),durationMs:R,result:l(d,{cause:E}),meta:{origin:"throw",thrown:E}}),t?.(d,o),h(d,{origin:"throw",thrown:E})}})()},r.fromResult=(T,k)=>{let o=k.name,s=k.key,y=I(s),m="error"in k?()=>k.error:k.onError,i=u;return(async()=>{let p=i?performance.now():0;u&&c({type:"step_start",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now()});let E=await T();if(E.ok){let d=performance.now()-p;return c({type:"step_success",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now(),durationMs:d}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:o,ts:Date.now(),durationMs:d,result:f(E.value)}),E.value}else{let d=m(E.error),R=performance.now()-p,v=_(d,{origin:"result",resultCause:E.error});throw c({type:"step_error",workflowId:a,stepId:y,stepKey:s,name:o,ts:Date.now(),durationMs:R,error:v}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:o,ts:Date.now(),durationMs:R,result:l(d,{cause:E.error}),meta:{origin:"result",resultCause:E.error}}),t?.(d,o),h(d,{origin:"result",resultCause:E.error})}})()},r.parallel=(T,k)=>{let o=`scope_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return(async()=>{let s=performance.now(),y=!1;g.push({scopeId:o,type:"parallel"});let m=()=>{if(y)return;y=!0;let i=g.findIndex(p=>p.scopeId===o);i!==-1&&g.splice(i,1),c({type:"scope_end",workflowId:a,scopeId:o,ts:Date.now(),durationMs:performance.now()-s})};c({type:"scope_start",workflowId:a,scopeId:o,scopeType:"parallel",name:T,ts:Date.now()});try{let i=await k();if(m(),!i.ok)throw t?.(i.error,T),h(i.error,{origin:"result",resultCause:i.cause});return i.value}catch(i){throw m(),i}})()},r.race=(T,k)=>{let o=`scope_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return(async()=>{let s=performance.now(),y=!1,m={scopeId:o,type:"race",winnerId:void 0};g.push(m);let i=()=>{if(y)return;y=!0;let p=g.findIndex(E=>E.scopeId===o);p!==-1&&g.splice(p,1),c({type:"scope_end",workflowId:a,scopeId:o,ts:Date.now(),durationMs:performance.now()-s,winnerId:m.winnerId})};c({type:"scope_start",workflowId:a,scopeId:o,scopeType:"race",name:T,ts:Date.now()});try{let p=await k();if(i(),!p.ok)throw t?.(p.error,T),h(p.error,{origin:"result",resultCause:p.cause});return p.value}catch(p){throw i(),p}})()},r.allSettled=(T,k)=>{let o=`scope_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return(async()=>{let s=performance.now(),y=!1;g.push({scopeId:o,type:"allSettled"});let m=()=>{if(y)return;y=!0;let i=g.findIndex(p=>p.scopeId===o);i!==-1&&g.splice(i,1),c({type:"scope_end",workflowId:a,scopeId:o,ts:Date.now(),durationMs:performance.now()-s})};c({type:"scope_start",workflowId:a,scopeId:o,scopeType:"allSettled",name:T,ts:Date.now()});try{let i=await k();if(m(),!i.ok)throw t?.(i.error,T),h(i.error,{origin:"result",resultCause:i.cause});return i.value}catch(i){throw m(),i}})()};let x=await e(r);return f(x)}catch(r){if(J(r))throw r.thrown;if(b(r)){let x=N(r.meta);if(w||t)return l(r.error,{cause:x});if(L(r.error))return l(r.error,{cause:x});let T=V(r);return l(T,{cause:x})}if(w){let x=w(r);return t?.(x,"unexpected"),l(x,{cause:r})}let S={type:"UNEXPECTED_ERROR",cause:{type:"UNCAUGHT_EXCEPTION",thrown:r}};return t?.(S,"unexpected"),l(S,{cause:r})}}M.strict=(e,n)=>M(e,n);var U=class extends Error{constructor(t,u){super(`Unwrap called on an error result: ${String(t)}`);this.error=t;this.cause=u;this.name="UnwrapError"}},B=e=>{if(e.ok)return e.value;throw new U(e.error,e.cause)},H=(e,n)=>e.ok?e.value:n,z=(e,n)=>e.ok?e.value:n(e.error,e.cause);function Q(e,n){try{return f(e())}catch(t){return n?l(n(t),{cause:t}):l(t)}}async function Z(e,n){try{return f(await e)}catch(t){return n?l(n(t),{cause:t}):l(t)}}async function ee(e,n){try{return f(await e())}catch(t){return n?l(n(t),{cause:t}):l(t)}}function ne(e,n){return e!=null?f(e):l(n())}function te(e,n){return e.ok?f(n(e.value)):e}function re(e,n){return e.ok?e:l(n(e.error),{cause:e.cause})}function oe(e,n){return e.ok?n.ok(e.value):n.err(e.error,e.cause)}function se(e,n){return e.ok?n(e.value):e}function ue(e,n){return e.ok&&n(e.value),e}function ae(e,n){return e.ok||n(e.error,e.cause),e}function pe(e,n,t){if(!e.ok)return e;try{return f(n(e.value))}catch(u){return l(t(u),{cause:u})}}function ie(e,n,t){if(e.ok)return e;try{return l(n(e.error),{cause:e.cause})}catch(u){return l(t(u),{cause:u})}}function ce(e){let n=[];for(let t of e){if(!t.ok)return t;n.push(t.value)}return f(n)}async function le(e){return e.length===0?f([]):new Promise(n=>{let t=!1,u=e.length,w=new Array(e.length);for(let C=0;C<e.length;C++){let A=C;Promise.resolve(e[A]).catch(a=>l({type:"PROMISE_REJECTED",cause:a},{cause:{type:"PROMISE_REJECTION",reason:a}})).then(a=>{if(!t){if(!a.ok){t=!0,n(a);return}w[A]=a.value,u--,u===0&&n(f(w))}})}})}function Ee(e){let n=[],t=[];for(let u of e)u.ok?n.push(u.value):t.push({error:u.error,cause:u.cause});return t.length>0?l(t):f(n)}function we(e){let n=[],t=[];for(let u of e)u.ok?n.push(u.value):t.push(u.error);return{values:n,errors:t}}function ye(e){if(e.length===0)return l({type:"EMPTY_INPUT",message:"any() requires at least one Result"});let n=null;for(let t of e){if(t.ok)return t;n||(n=t)}return n}async function Te(e){return e.length===0?l({type:"EMPTY_INPUT",message:"anyAsync() requires at least one Result"}):new Promise(n=>{let t=!1,u=e.length,w=null;for(let C of e)Promise.resolve(C).catch(A=>l({type:"PROMISE_REJECTED",cause:A},{cause:{type:"PROMISE_REJECTION",reason:A}})).then(A=>{if(!t){if(A.ok){t=!0,n(A);return}w||(w=A),u--,u===0&&n(w)}})})}async function ke(e){let n=await Promise.all(e.map(w=>Promise.resolve(w).then(C=>({status:"result",result:C})).catch(C=>({status:"rejected",error:{type:"PROMISE_REJECTED",cause:C},cause:{type:"PROMISE_REJECTION",reason:C}})))),t=[],u=[];for(let w of n)w.status==="rejected"?u.push({error:w.error,cause:w.cause}):w.result.ok?t.push(w.result.value):u.push({error:w.result.error,cause:w.result.cause});return u.length>0?l(u):f(t)}export{O as EARLY_EXIT_SYMBOL,U as UnwrapError,ce as all,le as allAsync,Ee as allSettled,ke as allSettledAsync,se as andThen,ye as any,Te as anyAsync,X as createEarlyExit,l as err,Q as from,ne as fromNullable,Z as fromPromise,W as isEarlyExit,q as isErr,G as isOk,L as isUnexpectedError,te as map,re as mapError,ie as mapErrorTry,pe as mapTry,oe as match,f as ok,we as partition,M as run,ue as tap,ae as tapError,ee as tryAsync,B as unwrap,H as unwrapOr,z as unwrapOrElse};
|
|
2
2
|
//# sourceMappingURL=core.js.map
|