awaitly 1.35.0 → 2.0.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/dist/{duration.d.ts → di-BDlT7InM.d.cts} +15 -1
- package/dist/{duration.d.cts → di-BbFFfO8y.d.ts} +15 -1
- package/dist/errors-DtXvrCiO.d.cts +708 -0
- package/dist/errors-DtXvrCiO.d.ts +708 -0
- package/dist/index.cjs +4594 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1970 -141
- package/dist/index.d.ts +1970 -141
- package/dist/index.js +4398 -1
- package/dist/index.js.map +1 -1
- package/dist/result.cjs +641 -1
- package/dist/result.cjs.map +1 -1
- package/dist/result.d.cts +29 -4
- package/dist/result.d.ts +29 -4
- package/dist/result.js +561 -1
- package/dist/result.js.map +1 -1
- package/dist/testing.cjs +4202 -8
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +2 -6
- package/dist/testing.d.ts +2 -6
- package/dist/testing.js +4154 -8
- package/dist/testing.js.map +1 -1
- package/dist/{run-entry-DGs0tySr.d.cts → types-B8NfNRGX.d.ts} +1078 -1502
- package/dist/{run-entry-BOuNyVoO.d.ts → types-BZ2f4MRR.d.cts} +1078 -1502
- package/dist/workflow.cjs +7096 -6
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +3346 -22
- package/dist/workflow.d.ts +3346 -22
- package/dist/workflow.js +6929 -6
- package/dist/workflow.js.map +1 -1
- package/package.json +3 -168
- package/dist/adapters.cjs +0 -7
- package/dist/adapters.cjs.map +0 -1
- package/dist/adapters.d.cts +0 -179
- package/dist/adapters.d.ts +0 -179
- package/dist/adapters.js +0 -7
- package/dist/adapters.js.map +0 -1
- package/dist/batch.cjs +0 -7
- package/dist/batch.cjs.map +0 -1
- package/dist/batch.d.cts +0 -200
- package/dist/batch.d.ts +0 -200
- package/dist/batch.js +0 -7
- package/dist/batch.js.map +0 -1
- package/dist/bind-deps.cjs +0 -2
- package/dist/bind-deps.cjs.map +0 -1
- package/dist/bind-deps.d.cts +0 -28
- package/dist/bind-deps.d.ts +0 -28
- package/dist/bind-deps.js +0 -2
- package/dist/bind-deps.js.map +0 -1
- package/dist/cache.cjs +0 -2
- package/dist/cache.cjs.map +0 -1
- package/dist/cache.d.cts +0 -269
- package/dist/cache.d.ts +0 -269
- package/dist/cache.js +0 -2
- package/dist/cache.js.map +0 -1
- package/dist/circuit-breaker.cjs +0 -7
- package/dist/circuit-breaker.cjs.map +0 -1
- package/dist/circuit-breaker.d.cts +0 -211
- package/dist/circuit-breaker.d.ts +0 -211
- package/dist/circuit-breaker.js +0 -7
- package/dist/circuit-breaker.js.map +0 -1
- package/dist/conditional.cjs +0 -2
- package/dist/conditional.cjs.map +0 -1
- package/dist/conditional.d.cts +0 -252
- package/dist/conditional.d.ts +0 -252
- package/dist/conditional.js +0 -2
- package/dist/conditional.js.map +0 -1
- package/dist/core.cjs +0 -7
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.cts +0 -5
- package/dist/core.d.ts +0 -5
- package/dist/core.js +0 -7
- package/dist/core.js.map +0 -1
- package/dist/di-By77n4Fa.d.ts +0 -15
- package/dist/di-OJfsohf-.d.cts +0 -15
- package/dist/diagnostics.cjs +0 -8
- package/dist/diagnostics.cjs.map +0 -1
- package/dist/diagnostics.d.cts +0 -68
- package/dist/diagnostics.d.ts +0 -68
- package/dist/diagnostics.js +0 -8
- package/dist/diagnostics.js.map +0 -1
- package/dist/durable.cjs +0 -11
- package/dist/durable.cjs.map +0 -1
- package/dist/durable.d.cts +0 -9
- package/dist/durable.d.ts +0 -9
- package/dist/durable.js +0 -11
- package/dist/durable.js.map +0 -1
- package/dist/duration.cjs +0 -2
- package/dist/duration.cjs.map +0 -1
- package/dist/duration.js +0 -2
- package/dist/duration.js.map +0 -1
- package/dist/engine.cjs +0 -11
- package/dist/engine.cjs.map +0 -1
- package/dist/engine.d.cts +0 -115
- package/dist/engine.d.ts +0 -115
- package/dist/engine.js +0 -11
- package/dist/engine.js.map +0 -1
- package/dist/errors.cjs +0 -2
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts +0 -361
- package/dist/errors.d.ts +0 -361
- package/dist/errors.js +0 -2
- package/dist/errors.js.map +0 -1
- package/dist/fetch.cjs +0 -7
- package/dist/fetch.cjs.map +0 -1
- package/dist/fetch.d.cts +0 -86
- package/dist/fetch.d.ts +0 -86
- package/dist/fetch.js +0 -7
- package/dist/fetch.js.map +0 -1
- package/dist/flow.cjs +0 -7
- package/dist/flow.cjs.map +0 -1
- package/dist/flow.d.cts +0 -163
- package/dist/flow.d.ts +0 -163
- package/dist/flow.js +0 -7
- package/dist/flow.js.map +0 -1
- package/dist/functional.cjs +0 -2
- package/dist/functional.cjs.map +0 -1
- package/dist/functional.d.cts +0 -444
- package/dist/functional.d.ts +0 -444
- package/dist/functional.js +0 -2
- package/dist/functional.js.map +0 -1
- package/dist/guards-4sV7mTqj.d.cts +0 -72
- package/dist/guards-BIX05ALH.d.ts +0 -72
- package/dist/hitl-DFn4Xa_l.d.cts +0 -468
- package/dist/hitl-DU5VpKq7.d.ts +0 -468
- package/dist/hitl.cjs +0 -7
- package/dist/hitl.cjs.map +0 -1
- package/dist/hitl.d.cts +0 -442
- package/dist/hitl.d.ts +0 -442
- package/dist/hitl.js +0 -7
- package/dist/hitl.js.map +0 -1
- package/dist/index-CnvBryQB.d.ts +0 -417
- package/dist/index-DEZEf8Fs.d.cts +0 -417
- package/dist/match-entry-DjI2bLpD.d.cts +0 -209
- package/dist/match-entry-DjI2bLpD.d.ts +0 -209
- package/dist/match.cjs +0 -2
- package/dist/match.cjs.map +0 -1
- package/dist/match.d.cts +0 -1
- package/dist/match.d.ts +0 -1
- package/dist/match.js +0 -2
- package/dist/match.js.map +0 -1
- package/dist/otel.cjs +0 -2
- package/dist/otel.cjs.map +0 -1
- package/dist/otel.d.cts +0 -188
- package/dist/otel.d.ts +0 -188
- package/dist/otel.js +0 -2
- package/dist/otel.js.map +0 -1
- package/dist/persistence-entry-B-8PjnSR.d.cts +0 -831
- package/dist/persistence-entry-D8zRkLiT.d.ts +0 -831
- package/dist/persistence.cjs +0 -2
- package/dist/persistence.cjs.map +0 -1
- package/dist/persistence.d.cts +0 -7
- package/dist/persistence.d.ts +0 -7
- package/dist/persistence.js +0 -2
- package/dist/persistence.js.map +0 -1
- package/dist/policies.cjs +0 -2
- package/dist/policies.cjs.map +0 -1
- package/dist/policies.d.cts +0 -379
- package/dist/policies.d.ts +0 -379
- package/dist/policies.js +0 -2
- package/dist/policies.js.map +0 -1
- package/dist/ratelimit.cjs +0 -7
- package/dist/ratelimit.cjs.map +0 -1
- package/dist/ratelimit.d.cts +0 -458
- package/dist/ratelimit.d.ts +0 -458
- package/dist/ratelimit.js +0 -7
- package/dist/ratelimit.js.map +0 -1
- package/dist/reliability.cjs +0 -11
- package/dist/reliability.cjs.map +0 -1
- package/dist/reliability.d.cts +0 -11
- package/dist/reliability.d.ts +0 -11
- package/dist/reliability.js +0 -11
- package/dist/reliability.js.map +0 -1
- package/dist/resolver.cjs +0 -7
- package/dist/resolver.cjs.map +0 -1
- package/dist/resolver.d.cts +0 -68
- package/dist/resolver.d.ts +0 -68
- package/dist/resolver.js +0 -7
- package/dist/resolver.js.map +0 -1
- package/dist/resource.cjs +0 -7
- package/dist/resource.cjs.map +0 -1
- package/dist/resource.d.cts +0 -174
- package/dist/resource.d.ts +0 -174
- package/dist/resource.js +0 -7
- package/dist/resource.js.map +0 -1
- package/dist/result/retry.cjs +0 -2
- package/dist/result/retry.cjs.map +0 -1
- package/dist/result/retry.d.cts +0 -70
- package/dist/result/retry.d.ts +0 -70
- package/dist/result/retry.js +0 -2
- package/dist/result/retry.js.map +0 -1
- package/dist/retry.cjs +0 -2
- package/dist/retry.cjs.map +0 -1
- package/dist/retry.d.cts +0 -388
- package/dist/retry.d.ts +0 -388
- package/dist/retry.js +0 -2
- package/dist/retry.js.map +0 -1
- package/dist/run.cjs +0 -7
- package/dist/run.cjs.map +0 -1
- package/dist/run.d.cts +0 -4
- package/dist/run.d.ts +0 -4
- package/dist/run.js +0 -7
- package/dist/run.js.map +0 -1
- package/dist/saga.cjs +0 -11
- package/dist/saga.cjs.map +0 -1
- package/dist/saga.d.cts +0 -164
- package/dist/saga.d.ts +0 -164
- package/dist/saga.js +0 -11
- package/dist/saga.js.map +0 -1
- package/dist/singleflight.cjs +0 -2
- package/dist/singleflight.cjs.map +0 -1
- package/dist/singleflight.d.cts +0 -145
- package/dist/singleflight.d.ts +0 -145
- package/dist/singleflight.js +0 -2
- package/dist/singleflight.js.map +0 -1
- package/dist/slugs.cjs +0 -2
- package/dist/slugs.cjs.map +0 -1
- package/dist/slugs.d.cts +0 -67
- package/dist/slugs.d.ts +0 -67
- package/dist/slugs.js +0 -2
- package/dist/slugs.js.map +0 -1
- package/dist/streaming.cjs +0 -9
- package/dist/streaming.cjs.map +0 -1
- package/dist/streaming.d.cts +0 -596
- package/dist/streaming.d.ts +0 -596
- package/dist/streaming.js +0 -9
- package/dist/streaming.js.map +0 -1
- package/dist/tagged-error.cjs +0 -2
- package/dist/tagged-error.cjs.map +0 -1
- package/dist/tagged-error.d.cts +0 -275
- package/dist/tagged-error.d.ts +0 -275
- package/dist/tagged-error.js +0 -2
- package/dist/tagged-error.js.map +0 -1
- package/dist/types-BziYHFkD.d.ts +0 -323
- package/dist/types-C5jLEUqY.d.cts +0 -323
- package/dist/webhook.cjs +0 -7
- package/dist/webhook.cjs.map +0 -1
- package/dist/webhook.d.cts +0 -499
- package/dist/webhook.d.ts +0 -499
- package/dist/webhook.js +0 -7
- package/dist/webhook.js.map +0 -1
package/dist/conditional.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var w=(o,n)=>{for(var t in n)d(o,t,{get:n[t],enumerable:!0})},x=(o,n,t,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of f(n))!O.call(o,i)&&i!==t&&d(o,i,{get:()=>n[i],enumerable:!(e=c(n,i))||e.enumerable});return o};var y=o=>x(d({},"__esModule",{value:!0}),o);var k={};w(k,{createConditionalHelpers:()=>u,unless:()=>s,unlessOr:()=>C,when:()=>a,whenOr:()=>r});module.exports=y(k);function l(){return`decision_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function p(o,n,t){if(!o?.onEvent)return;let e={type:"step_skipped",workflowId:o.workflowId,stepKey:n?.key,name:n?.name,reason:n?.reason,decisionId:t,ts:Date.now()},i=e.context!==void 0||o.context===void 0?e:{...e,context:o.context};o.onEvent(i)}function a(o,n,t,e){if(o)return n();let i=l();p(e,t,i)}function s(o,n,t,e){return a(!o,n,t,e)}function r(o,n,t,e,i){if(o)return n();let T=l();return p(i,e,T),t}function C(o,n,t,e,i){return r(!o,n,t,e,i)}function u(o){return{when:(n,t,e)=>a(n,t,e,o),unless:(n,t,e)=>s(n,t,e,o),whenOr:(n,t,e,i)=>r(n,t,e,i,o),unlessOr:(n,t,e,i)=>C(n,t,e,i,o)}}0&&(module.exports={createConditionalHelpers,unless,unlessOr,when,whenOr});
|
|
2
|
-
//# sourceMappingURL=conditional.cjs.map
|
package/dist/conditional.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/conditional-entry.ts","../src/conditional.ts"],"sourcesContent":["/**\n * awaitly/conditional\n *\n * Conditional execution helpers: when/unless for cleaner branching logic.\n *\n * @example\n * ```typescript\n * import { when, unless } from 'awaitly/conditional';\n *\n * const result = await workflow(async ({ step }) => {\n * const user = await step(fetchUser(id));\n * await when(user.isAdmin, () => step(logAdminAccess(user)));\n * return user;\n * });\n * ```\n */\n\nexport {\n // Types\n type ConditionalOptions,\n type ConditionalContext,\n\n // Functions\n when,\n unless,\n whenOr,\n unlessOr,\n createConditionalHelpers,\n} from \"./conditional\";\n","/**\n * awaitly/conditional\n *\n * Conditional step execution helpers for workflows.\n * These helpers allow you to conditionally execute steps based on runtime conditions,\n * with proper event emission for skipped steps.\n */\n\nimport type { WorkflowEvent } from \"./core\";\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Options for conditional execution.\n */\nexport type ConditionalOptions = {\n /**\n * Human-readable name for the conditional step.\n * Used in step_skipped events for debugging and visualization.\n */\n name?: string;\n\n /**\n * Stable identity key for the conditional step.\n * Used in step_skipped events for tracking and visualization.\n */\n key?: string;\n\n /**\n * Optional reason explaining why the step was skipped.\n * Included in step_skipped events.\n */\n reason?: string;\n};\n\n/**\n * Context for conditional execution, used to emit events.\n */\nexport type ConditionalContext<C = unknown> = {\n /**\n * The workflow ID for event emission.\n */\n workflowId: string;\n\n /**\n * Event emitter function.\n */\n onEvent?: (event: WorkflowEvent<unknown, C>) => void;\n\n /**\n * Optional context value to include in emitted events.\n * When provided, this context is automatically added to step_skipped events.\n */\n context?: C;\n};\n\n/**\n * Type for operations that can be either sync or async.\n */\ntype MaybeAsync<T> = T | Promise<T>;\n\n/**\n * Type for the operation function passed to conditional helpers.\n */\ntype Operation<T> = () => MaybeAsync<T>;\n\n// =============================================================================\n// Internal Helpers\n// =============================================================================\n\n/**\n * Generate a unique decision ID for tracking conditional decisions.\n * @internal\n */\nfunction generateDecisionId(): string {\n return `decision_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;\n}\n\n/**\n * Emit a step_skipped event.\n * @internal\n */\nfunction emitSkipped<C = unknown>(\n ctx: ConditionalContext<C> | undefined,\n options: ConditionalOptions | undefined,\n decisionId: string\n): void {\n if (!ctx?.onEvent) return;\n\n // Create event with context if provided (similar to emitEvent logic)\n const event: WorkflowEvent<unknown, C> = {\n type: \"step_skipped\",\n workflowId: ctx.workflowId,\n stepKey: options?.key,\n name: options?.name,\n reason: options?.reason,\n decisionId,\n ts: Date.now(),\n };\n\n // Add context to event only if:\n // 1. Event doesn't already have context (preserves replayed events)\n // 2. Context is actually provided (don't add context: undefined property)\n const eventWithContext =\n event.context !== undefined || ctx.context === undefined\n ? event\n : ({ ...event, context: ctx.context } as WorkflowEvent<unknown, C>);\n\n ctx.onEvent(eventWithContext);\n}\n\n// =============================================================================\n// Conditional Helpers\n// =============================================================================\n\n/**\n * Run a step only if condition is true, return undefined if skipped.\n *\n * Use this when you want to conditionally execute a step and handle\n * the undefined case yourself. For a version with a default value,\n * use `whenOr`.\n *\n * @param condition - Boolean condition to evaluate\n * @param operation - Function that performs the step (only called if condition is true)\n * @param options - Optional configuration for the conditional step\n * @param ctx - Optional context for event emission\n * @returns The result of the operation if condition is true, undefined otherwise\n *\n * @example\n * ```typescript\n * const result = await workflow(async ({ step }) => {\n * const user = await step('fetchUser', () => fetchUser(id));\n *\n * // Only runs if user is premium\n * const premium = await when(\n * user.isPremium,\n * () => step('fetchPremiumData', () => fetchPremiumData(user.id)),\n * { name: 'check-premium', reason: 'User is not premium' }\n * );\n *\n * return { user, premium };\n * });\n * ```\n */\nexport function when<T, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): Promise<T | undefined>;\n\n/**\n * Synchronous overload for when the operation returns a non-Promise value.\n */\nexport function when<T, C = unknown>(\n condition: boolean,\n operation: () => T,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): T | undefined | Promise<T | undefined>;\n\nexport function when<T, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): MaybeAsync<T | undefined> {\n if (condition) {\n return operation();\n }\n\n const decisionId = generateDecisionId();\n emitSkipped(ctx, options, decisionId);\n return undefined;\n}\n\n/**\n * Run a step only if condition is false, return undefined if skipped.\n *\n * Use this when you want to conditionally execute a step when a condition\n * is NOT met. For a version with a default value, use `unlessOr`.\n *\n * @param condition - Boolean condition to evaluate\n * @param operation - Function that performs the step (only called if condition is false)\n * @param options - Optional configuration for the conditional step\n * @param ctx - Optional context for event emission\n * @returns The result of the operation if condition is false, undefined otherwise\n *\n * @example\n * ```typescript\n * const result = await workflow(async ({ step }) => {\n * const user = await step(fetchUser(id));\n *\n * // Only runs if user is NOT verified\n * const verification = await unless(\n * user.isVerified,\n * () => step(() => sendVerificationEmail(user.email), { name: 'send-verification' }),\n * { name: 'check-verification', reason: 'User is already verified' }\n * );\n *\n * return { user, verification };\n * });\n * ```\n */\nexport function unless<T, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): Promise<T | undefined>;\n\n/**\n * Synchronous overload for unless when the operation returns a non-Promise value.\n */\nexport function unless<T, C = unknown>(\n condition: boolean,\n operation: () => T,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): T | undefined | Promise<T | undefined>;\n\nexport function unless<T, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): MaybeAsync<T | undefined> {\n return when(!condition, operation, options, ctx);\n}\n\n/**\n * Run a step only if condition is true, return default value if skipped.\n *\n * Use this when you want to conditionally execute a step and provide\n * a fallback value when the condition is not met.\n *\n * @param condition - Boolean condition to evaluate\n * @param operation - Function that performs the step (only called if condition is true)\n * @param defaultValue - Value to return if condition is false\n * @param options - Optional configuration for the conditional step\n * @param ctx - Optional context for event emission\n * @returns The result of the operation if condition is true, defaultValue otherwise\n *\n * @example\n * ```typescript\n * const result = await workflow(async ({ step }) => {\n * const user = await step(fetchUser(id));\n *\n * // Get premium limits or use default for non-premium users\n * const limits = await whenOr(\n * user.isPremium,\n * () => step(() => fetchPremiumLimits(user.id), { name: 'premium-limits' }),\n * { maxRequests: 100, maxStorage: 1000 }, // default for non-premium\n * { name: 'check-premium-limits', reason: 'Using default limits for non-premium user' }\n * );\n *\n * return { user, limits };\n * });\n * ```\n */\nexport function whenOr<T, D, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): Promise<T | D>;\n\n/**\n * Synchronous overload for whenOr when the operation returns a non-Promise value.\n */\nexport function whenOr<T, D, C = unknown>(\n condition: boolean,\n operation: () => T,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): T | D | Promise<T | D>;\n\nexport function whenOr<T, D, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): MaybeAsync<T | D> {\n if (condition) {\n return operation();\n }\n\n const decisionId = generateDecisionId();\n emitSkipped(ctx, options, decisionId);\n return defaultValue;\n}\n\n/**\n * Run a step only if condition is false, return default value if skipped.\n *\n * Use this when you want to conditionally execute a step when a condition\n * is NOT met, with a fallback value for when the condition is true.\n *\n * @param condition - Boolean condition to evaluate\n * @param operation - Function that performs the step (only called if condition is false)\n * @param defaultValue - Value to return if condition is true\n * @param options - Optional configuration for the conditional step\n * @param ctx - Optional context for event emission\n * @returns The result of the operation if condition is false, defaultValue otherwise\n *\n * @example\n * ```typescript\n * const result = await workflow(async ({ step }) => {\n * const user = await step(fetchUser(id));\n *\n * // Generate new token if user is NOT authenticated, otherwise use existing\n * const token = await unlessOr(\n * user.isAuthenticated,\n * () => step(() => generateNewToken(user.id), { name: 'generate-token' }),\n * user.existingToken, // use existing token if authenticated\n * { name: 'check-auth-for-token', reason: 'Using existing token for authenticated user' }\n * );\n *\n * return { user, token };\n * });\n * ```\n */\nexport function unlessOr<T, D, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): Promise<T | D>;\n\n/**\n * Synchronous overload for unlessOr when the operation returns a non-Promise value.\n */\nexport function unlessOr<T, D, C = unknown>(\n condition: boolean,\n operation: () => T,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): T | D | Promise<T | D>;\n\nexport function unlessOr<T, D, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): MaybeAsync<T | D> {\n return whenOr(!condition, operation, defaultValue, options, ctx);\n}\n\n// =============================================================================\n// Factory Functions for Workflow Integration\n// =============================================================================\n\n/**\n * Create a set of conditional helpers bound to a workflow context.\n *\n * Use this factory when you want to automatically emit step_skipped events\n * to the workflow's event stream without passing context manually.\n *\n * @param ctx - The workflow context containing workflowId, onEvent, and optional context\n * @returns Object with bound when, unless, whenOr, and unlessOr functions\n *\n * @example\n * ```typescript\n * // With run() - context is automatically included in events\n * const result = await run(async ({ step }) => {\n * const ctx = { workflowId, onEvent, context: requestContext };\n * const { when, whenOr } = createConditionalHelpers(ctx);\n *\n * const user = await step(fetchUser(id));\n *\n * const premium = await when(\n * user.isPremium,\n * () => step(() => fetchPremiumData(user.id)),\n * { name: 'premium-data' }\n * );\n *\n * return { user, premium };\n * }, { onEvent, workflowId, context: requestContext });\n * \n * // With createWorkflow - access context from onEvent callback\n * const workflow = createWorkflow({ fetchUser }, {\n * createContext: () => ({ requestId: 'req-123' }),\n * onEvent: (event, ctx) => {\n * // ctx is available here, can be passed to conditional helpers\n * }\n * });\n * ```\n */\nexport function createConditionalHelpers<C = unknown>(ctx: ConditionalContext<C>) {\n return {\n /**\n * Run a step only if condition is true, return undefined if skipped.\n */\n when: <T>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions\n ): MaybeAsync<T | undefined> => when(condition, operation, options, ctx),\n\n /**\n * Run a step only if condition is false, return undefined if skipped.\n */\n unless: <T>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions\n ): MaybeAsync<T | undefined> => unless(condition, operation, options, ctx),\n\n /**\n * Run a step only if condition is true, return default value if skipped.\n */\n whenOr: <T, D>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions\n ): MaybeAsync<T | D> => whenOr(condition, operation, defaultValue, options, ctx),\n\n /**\n * Run a step only if condition is false, return default value if skipped.\n */\n unlessOr: <T, D>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions\n ): MaybeAsync<T | D> => unlessOr(condition, operation, defaultValue, options, ctx),\n };\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,EAAA,WAAAC,EAAA,aAAAC,EAAA,SAAAC,EAAA,WAAAC,IAAA,eAAAC,EAAAP,GC4EA,SAASQ,GAA6B,CACpC,MAAO,YAAY,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,EAAG,CAAC,CAAC,EACzE,CAMA,SAASC,EACPC,EACAC,EACAC,EACM,CACN,GAAI,CAACF,GAAK,QAAS,OAGnB,IAAMG,EAAmC,CACvC,KAAM,eACN,WAAYH,EAAI,WAChB,QAASC,GAAS,IAClB,KAAMA,GAAS,KACf,OAAQA,GAAS,OACjB,WAAAC,EACA,GAAI,KAAK,IAAI,CACf,EAKME,EACJD,EAAM,UAAY,QAAaH,EAAI,UAAY,OAC3CG,EACC,CAAE,GAAGA,EAAO,QAASH,EAAI,OAAQ,EAExCA,EAAI,QAAQI,CAAgB,CAC9B,CAoDO,SAASC,EACdC,EACAC,EACAN,EACAD,EAC2B,CAC3B,GAAIM,EACF,OAAOC,EAAU,EAGnB,IAAML,EAAaJ,EAAmB,EACtCC,EAAYC,EAAKC,EAASC,CAAU,CAEtC,CA+CO,SAASM,EACdF,EACAC,EACAN,EACAD,EAC2B,CAC3B,OAAOK,EAAK,CAACC,EAAWC,EAAWN,EAASD,CAAG,CACjD,CAmDO,SAASS,EACdH,EACAC,EACAG,EACAT,EACAD,EACmB,CACnB,GAAIM,EACF,OAAOC,EAAU,EAGnB,IAAML,EAAaJ,EAAmB,EACtC,OAAAC,EAAYC,EAAKC,EAASC,CAAU,EAC7BQ,CACT,CAmDO,SAASC,EACdL,EACAC,EACAG,EACAT,EACAD,EACmB,CACnB,OAAOS,EAAO,CAACH,EAAWC,EAAWG,EAAcT,EAASD,CAAG,CACjE,CA0CO,SAASY,EAAsCZ,EAA4B,CAChF,MAAO,CAIL,KAAM,CACJM,EACAC,EACAN,IAC8BI,EAAKC,EAAWC,EAAWN,EAASD,CAAG,EAKvE,OAAQ,CACNM,EACAC,EACAN,IAC8BO,EAAOF,EAAWC,EAAWN,EAASD,CAAG,EAKzE,OAAQ,CACNM,EACAC,EACAG,EACAT,IACsBQ,EAAOH,EAAWC,EAAWG,EAAcT,EAASD,CAAG,EAK/E,SAAU,CACRM,EACAC,EACAG,EACAT,IACsBU,EAASL,EAAWC,EAAWG,EAAcT,EAASD,CAAG,CACnF,CACF","names":["conditional_entry_exports","__export","createConditionalHelpers","unless","unlessOr","when","whenOr","__toCommonJS","generateDecisionId","emitSkipped","ctx","options","decisionId","event","eventWithContext","when","condition","operation","unless","whenOr","defaultValue","unlessOr","createConditionalHelpers"]}
|
package/dist/conditional.d.cts
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import { ae as WorkflowEvent } from './run-entry-DGs0tySr.cjs';
|
|
2
|
-
import './errors.cjs';
|
|
3
|
-
import './tagged-error.cjs';
|
|
4
|
-
import './slugs.cjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* awaitly/conditional
|
|
8
|
-
*
|
|
9
|
-
* Conditional step execution helpers for workflows.
|
|
10
|
-
* These helpers allow you to conditionally execute steps based on runtime conditions,
|
|
11
|
-
* with proper event emission for skipped steps.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Options for conditional execution.
|
|
16
|
-
*/
|
|
17
|
-
type ConditionalOptions = {
|
|
18
|
-
/**
|
|
19
|
-
* Human-readable name for the conditional step.
|
|
20
|
-
* Used in step_skipped events for debugging and visualization.
|
|
21
|
-
*/
|
|
22
|
-
name?: string;
|
|
23
|
-
/**
|
|
24
|
-
* Stable identity key for the conditional step.
|
|
25
|
-
* Used in step_skipped events for tracking and visualization.
|
|
26
|
-
*/
|
|
27
|
-
key?: string;
|
|
28
|
-
/**
|
|
29
|
-
* Optional reason explaining why the step was skipped.
|
|
30
|
-
* Included in step_skipped events.
|
|
31
|
-
*/
|
|
32
|
-
reason?: string;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Context for conditional execution, used to emit events.
|
|
36
|
-
*/
|
|
37
|
-
type ConditionalContext<C = unknown> = {
|
|
38
|
-
/**
|
|
39
|
-
* The workflow ID for event emission.
|
|
40
|
-
*/
|
|
41
|
-
workflowId: string;
|
|
42
|
-
/**
|
|
43
|
-
* Event emitter function.
|
|
44
|
-
*/
|
|
45
|
-
onEvent?: (event: WorkflowEvent<unknown, C>) => void;
|
|
46
|
-
/**
|
|
47
|
-
* Optional context value to include in emitted events.
|
|
48
|
-
* When provided, this context is automatically added to step_skipped events.
|
|
49
|
-
*/
|
|
50
|
-
context?: C;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Type for operations that can be either sync or async.
|
|
54
|
-
*/
|
|
55
|
-
type MaybeAsync<T> = T | Promise<T>;
|
|
56
|
-
/**
|
|
57
|
-
* Type for the operation function passed to conditional helpers.
|
|
58
|
-
*/
|
|
59
|
-
type Operation<T> = () => MaybeAsync<T>;
|
|
60
|
-
/**
|
|
61
|
-
* Run a step only if condition is true, return undefined if skipped.
|
|
62
|
-
*
|
|
63
|
-
* Use this when you want to conditionally execute a step and handle
|
|
64
|
-
* the undefined case yourself. For a version with a default value,
|
|
65
|
-
* use `whenOr`.
|
|
66
|
-
*
|
|
67
|
-
* @param condition - Boolean condition to evaluate
|
|
68
|
-
* @param operation - Function that performs the step (only called if condition is true)
|
|
69
|
-
* @param options - Optional configuration for the conditional step
|
|
70
|
-
* @param ctx - Optional context for event emission
|
|
71
|
-
* @returns The result of the operation if condition is true, undefined otherwise
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* const result = await workflow(async ({ step }) => {
|
|
76
|
-
* const user = await step('fetchUser', () => fetchUser(id));
|
|
77
|
-
*
|
|
78
|
-
* // Only runs if user is premium
|
|
79
|
-
* const premium = await when(
|
|
80
|
-
* user.isPremium,
|
|
81
|
-
* () => step('fetchPremiumData', () => fetchPremiumData(user.id)),
|
|
82
|
-
* { name: 'check-premium', reason: 'User is not premium' }
|
|
83
|
-
* );
|
|
84
|
-
*
|
|
85
|
-
* return { user, premium };
|
|
86
|
-
* });
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
declare function when<T, C = unknown>(condition: boolean, operation: Operation<T>, options?: ConditionalOptions, ctx?: ConditionalContext<C>): Promise<T | undefined>;
|
|
90
|
-
/**
|
|
91
|
-
* Synchronous overload for when the operation returns a non-Promise value.
|
|
92
|
-
*/
|
|
93
|
-
declare function when<T, C = unknown>(condition: boolean, operation: () => T, options?: ConditionalOptions, ctx?: ConditionalContext<C>): T | undefined | Promise<T | undefined>;
|
|
94
|
-
/**
|
|
95
|
-
* Run a step only if condition is false, return undefined if skipped.
|
|
96
|
-
*
|
|
97
|
-
* Use this when you want to conditionally execute a step when a condition
|
|
98
|
-
* is NOT met. For a version with a default value, use `unlessOr`.
|
|
99
|
-
*
|
|
100
|
-
* @param condition - Boolean condition to evaluate
|
|
101
|
-
* @param operation - Function that performs the step (only called if condition is false)
|
|
102
|
-
* @param options - Optional configuration for the conditional step
|
|
103
|
-
* @param ctx - Optional context for event emission
|
|
104
|
-
* @returns The result of the operation if condition is false, undefined otherwise
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* const result = await workflow(async ({ step }) => {
|
|
109
|
-
* const user = await step(fetchUser(id));
|
|
110
|
-
*
|
|
111
|
-
* // Only runs if user is NOT verified
|
|
112
|
-
* const verification = await unless(
|
|
113
|
-
* user.isVerified,
|
|
114
|
-
* () => step(() => sendVerificationEmail(user.email), { name: 'send-verification' }),
|
|
115
|
-
* { name: 'check-verification', reason: 'User is already verified' }
|
|
116
|
-
* );
|
|
117
|
-
*
|
|
118
|
-
* return { user, verification };
|
|
119
|
-
* });
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
declare function unless<T, C = unknown>(condition: boolean, operation: Operation<T>, options?: ConditionalOptions, ctx?: ConditionalContext<C>): Promise<T | undefined>;
|
|
123
|
-
/**
|
|
124
|
-
* Synchronous overload for unless when the operation returns a non-Promise value.
|
|
125
|
-
*/
|
|
126
|
-
declare function unless<T, C = unknown>(condition: boolean, operation: () => T, options?: ConditionalOptions, ctx?: ConditionalContext<C>): T | undefined | Promise<T | undefined>;
|
|
127
|
-
/**
|
|
128
|
-
* Run a step only if condition is true, return default value if skipped.
|
|
129
|
-
*
|
|
130
|
-
* Use this when you want to conditionally execute a step and provide
|
|
131
|
-
* a fallback value when the condition is not met.
|
|
132
|
-
*
|
|
133
|
-
* @param condition - Boolean condition to evaluate
|
|
134
|
-
* @param operation - Function that performs the step (only called if condition is true)
|
|
135
|
-
* @param defaultValue - Value to return if condition is false
|
|
136
|
-
* @param options - Optional configuration for the conditional step
|
|
137
|
-
* @param ctx - Optional context for event emission
|
|
138
|
-
* @returns The result of the operation if condition is true, defaultValue otherwise
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```typescript
|
|
142
|
-
* const result = await workflow(async ({ step }) => {
|
|
143
|
-
* const user = await step(fetchUser(id));
|
|
144
|
-
*
|
|
145
|
-
* // Get premium limits or use default for non-premium users
|
|
146
|
-
* const limits = await whenOr(
|
|
147
|
-
* user.isPremium,
|
|
148
|
-
* () => step(() => fetchPremiumLimits(user.id), { name: 'premium-limits' }),
|
|
149
|
-
* { maxRequests: 100, maxStorage: 1000 }, // default for non-premium
|
|
150
|
-
* { name: 'check-premium-limits', reason: 'Using default limits for non-premium user' }
|
|
151
|
-
* );
|
|
152
|
-
*
|
|
153
|
-
* return { user, limits };
|
|
154
|
-
* });
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
declare function whenOr<T, D, C = unknown>(condition: boolean, operation: Operation<T>, defaultValue: D, options?: ConditionalOptions, ctx?: ConditionalContext<C>): Promise<T | D>;
|
|
158
|
-
/**
|
|
159
|
-
* Synchronous overload for whenOr when the operation returns a non-Promise value.
|
|
160
|
-
*/
|
|
161
|
-
declare function whenOr<T, D, C = unknown>(condition: boolean, operation: () => T, defaultValue: D, options?: ConditionalOptions, ctx?: ConditionalContext<C>): T | D | Promise<T | D>;
|
|
162
|
-
/**
|
|
163
|
-
* Run a step only if condition is false, return default value if skipped.
|
|
164
|
-
*
|
|
165
|
-
* Use this when you want to conditionally execute a step when a condition
|
|
166
|
-
* is NOT met, with a fallback value for when the condition is true.
|
|
167
|
-
*
|
|
168
|
-
* @param condition - Boolean condition to evaluate
|
|
169
|
-
* @param operation - Function that performs the step (only called if condition is false)
|
|
170
|
-
* @param defaultValue - Value to return if condition is true
|
|
171
|
-
* @param options - Optional configuration for the conditional step
|
|
172
|
-
* @param ctx - Optional context for event emission
|
|
173
|
-
* @returns The result of the operation if condition is false, defaultValue otherwise
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```typescript
|
|
177
|
-
* const result = await workflow(async ({ step }) => {
|
|
178
|
-
* const user = await step(fetchUser(id));
|
|
179
|
-
*
|
|
180
|
-
* // Generate new token if user is NOT authenticated, otherwise use existing
|
|
181
|
-
* const token = await unlessOr(
|
|
182
|
-
* user.isAuthenticated,
|
|
183
|
-
* () => step(() => generateNewToken(user.id), { name: 'generate-token' }),
|
|
184
|
-
* user.existingToken, // use existing token if authenticated
|
|
185
|
-
* { name: 'check-auth-for-token', reason: 'Using existing token for authenticated user' }
|
|
186
|
-
* );
|
|
187
|
-
*
|
|
188
|
-
* return { user, token };
|
|
189
|
-
* });
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
|
-
declare function unlessOr<T, D, C = unknown>(condition: boolean, operation: Operation<T>, defaultValue: D, options?: ConditionalOptions, ctx?: ConditionalContext<C>): Promise<T | D>;
|
|
193
|
-
/**
|
|
194
|
-
* Synchronous overload for unlessOr when the operation returns a non-Promise value.
|
|
195
|
-
*/
|
|
196
|
-
declare function unlessOr<T, D, C = unknown>(condition: boolean, operation: () => T, defaultValue: D, options?: ConditionalOptions, ctx?: ConditionalContext<C>): T | D | Promise<T | D>;
|
|
197
|
-
/**
|
|
198
|
-
* Create a set of conditional helpers bound to a workflow context.
|
|
199
|
-
*
|
|
200
|
-
* Use this factory when you want to automatically emit step_skipped events
|
|
201
|
-
* to the workflow's event stream without passing context manually.
|
|
202
|
-
*
|
|
203
|
-
* @param ctx - The workflow context containing workflowId, onEvent, and optional context
|
|
204
|
-
* @returns Object with bound when, unless, whenOr, and unlessOr functions
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* // With run() - context is automatically included in events
|
|
209
|
-
* const result = await run(async ({ step }) => {
|
|
210
|
-
* const ctx = { workflowId, onEvent, context: requestContext };
|
|
211
|
-
* const { when, whenOr } = createConditionalHelpers(ctx);
|
|
212
|
-
*
|
|
213
|
-
* const user = await step(fetchUser(id));
|
|
214
|
-
*
|
|
215
|
-
* const premium = await when(
|
|
216
|
-
* user.isPremium,
|
|
217
|
-
* () => step(() => fetchPremiumData(user.id)),
|
|
218
|
-
* { name: 'premium-data' }
|
|
219
|
-
* );
|
|
220
|
-
*
|
|
221
|
-
* return { user, premium };
|
|
222
|
-
* }, { onEvent, workflowId, context: requestContext });
|
|
223
|
-
*
|
|
224
|
-
* // With createWorkflow - access context from onEvent callback
|
|
225
|
-
* const workflow = createWorkflow({ fetchUser }, {
|
|
226
|
-
* createContext: () => ({ requestId: 'req-123' }),
|
|
227
|
-
* onEvent: (event, ctx) => {
|
|
228
|
-
* // ctx is available here, can be passed to conditional helpers
|
|
229
|
-
* }
|
|
230
|
-
* });
|
|
231
|
-
* ```
|
|
232
|
-
*/
|
|
233
|
-
declare function createConditionalHelpers<C = unknown>(ctx: ConditionalContext<C>): {
|
|
234
|
-
/**
|
|
235
|
-
* Run a step only if condition is true, return undefined if skipped.
|
|
236
|
-
*/
|
|
237
|
-
when: <T>(condition: boolean, operation: Operation<T>, options?: ConditionalOptions) => MaybeAsync<T | undefined>;
|
|
238
|
-
/**
|
|
239
|
-
* Run a step only if condition is false, return undefined if skipped.
|
|
240
|
-
*/
|
|
241
|
-
unless: <T>(condition: boolean, operation: Operation<T>, options?: ConditionalOptions) => MaybeAsync<T | undefined>;
|
|
242
|
-
/**
|
|
243
|
-
* Run a step only if condition is true, return default value if skipped.
|
|
244
|
-
*/
|
|
245
|
-
whenOr: <T, D>(condition: boolean, operation: Operation<T>, defaultValue: D, options?: ConditionalOptions) => MaybeAsync<T | D>;
|
|
246
|
-
/**
|
|
247
|
-
* Run a step only if condition is false, return default value if skipped.
|
|
248
|
-
*/
|
|
249
|
-
unlessOr: <T, D>(condition: boolean, operation: Operation<T>, defaultValue: D, options?: ConditionalOptions) => MaybeAsync<T | D>;
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
export { type ConditionalContext, type ConditionalOptions, createConditionalHelpers, unless, unlessOr, when, whenOr };
|
package/dist/conditional.d.ts
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import { ae as WorkflowEvent } from './run-entry-BOuNyVoO.js';
|
|
2
|
-
import './errors.js';
|
|
3
|
-
import './tagged-error.js';
|
|
4
|
-
import './slugs.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* awaitly/conditional
|
|
8
|
-
*
|
|
9
|
-
* Conditional step execution helpers for workflows.
|
|
10
|
-
* These helpers allow you to conditionally execute steps based on runtime conditions,
|
|
11
|
-
* with proper event emission for skipped steps.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Options for conditional execution.
|
|
16
|
-
*/
|
|
17
|
-
type ConditionalOptions = {
|
|
18
|
-
/**
|
|
19
|
-
* Human-readable name for the conditional step.
|
|
20
|
-
* Used in step_skipped events for debugging and visualization.
|
|
21
|
-
*/
|
|
22
|
-
name?: string;
|
|
23
|
-
/**
|
|
24
|
-
* Stable identity key for the conditional step.
|
|
25
|
-
* Used in step_skipped events for tracking and visualization.
|
|
26
|
-
*/
|
|
27
|
-
key?: string;
|
|
28
|
-
/**
|
|
29
|
-
* Optional reason explaining why the step was skipped.
|
|
30
|
-
* Included in step_skipped events.
|
|
31
|
-
*/
|
|
32
|
-
reason?: string;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Context for conditional execution, used to emit events.
|
|
36
|
-
*/
|
|
37
|
-
type ConditionalContext<C = unknown> = {
|
|
38
|
-
/**
|
|
39
|
-
* The workflow ID for event emission.
|
|
40
|
-
*/
|
|
41
|
-
workflowId: string;
|
|
42
|
-
/**
|
|
43
|
-
* Event emitter function.
|
|
44
|
-
*/
|
|
45
|
-
onEvent?: (event: WorkflowEvent<unknown, C>) => void;
|
|
46
|
-
/**
|
|
47
|
-
* Optional context value to include in emitted events.
|
|
48
|
-
* When provided, this context is automatically added to step_skipped events.
|
|
49
|
-
*/
|
|
50
|
-
context?: C;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Type for operations that can be either sync or async.
|
|
54
|
-
*/
|
|
55
|
-
type MaybeAsync<T> = T | Promise<T>;
|
|
56
|
-
/**
|
|
57
|
-
* Type for the operation function passed to conditional helpers.
|
|
58
|
-
*/
|
|
59
|
-
type Operation<T> = () => MaybeAsync<T>;
|
|
60
|
-
/**
|
|
61
|
-
* Run a step only if condition is true, return undefined if skipped.
|
|
62
|
-
*
|
|
63
|
-
* Use this when you want to conditionally execute a step and handle
|
|
64
|
-
* the undefined case yourself. For a version with a default value,
|
|
65
|
-
* use `whenOr`.
|
|
66
|
-
*
|
|
67
|
-
* @param condition - Boolean condition to evaluate
|
|
68
|
-
* @param operation - Function that performs the step (only called if condition is true)
|
|
69
|
-
* @param options - Optional configuration for the conditional step
|
|
70
|
-
* @param ctx - Optional context for event emission
|
|
71
|
-
* @returns The result of the operation if condition is true, undefined otherwise
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* const result = await workflow(async ({ step }) => {
|
|
76
|
-
* const user = await step('fetchUser', () => fetchUser(id));
|
|
77
|
-
*
|
|
78
|
-
* // Only runs if user is premium
|
|
79
|
-
* const premium = await when(
|
|
80
|
-
* user.isPremium,
|
|
81
|
-
* () => step('fetchPremiumData', () => fetchPremiumData(user.id)),
|
|
82
|
-
* { name: 'check-premium', reason: 'User is not premium' }
|
|
83
|
-
* );
|
|
84
|
-
*
|
|
85
|
-
* return { user, premium };
|
|
86
|
-
* });
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
declare function when<T, C = unknown>(condition: boolean, operation: Operation<T>, options?: ConditionalOptions, ctx?: ConditionalContext<C>): Promise<T | undefined>;
|
|
90
|
-
/**
|
|
91
|
-
* Synchronous overload for when the operation returns a non-Promise value.
|
|
92
|
-
*/
|
|
93
|
-
declare function when<T, C = unknown>(condition: boolean, operation: () => T, options?: ConditionalOptions, ctx?: ConditionalContext<C>): T | undefined | Promise<T | undefined>;
|
|
94
|
-
/**
|
|
95
|
-
* Run a step only if condition is false, return undefined if skipped.
|
|
96
|
-
*
|
|
97
|
-
* Use this when you want to conditionally execute a step when a condition
|
|
98
|
-
* is NOT met. For a version with a default value, use `unlessOr`.
|
|
99
|
-
*
|
|
100
|
-
* @param condition - Boolean condition to evaluate
|
|
101
|
-
* @param operation - Function that performs the step (only called if condition is false)
|
|
102
|
-
* @param options - Optional configuration for the conditional step
|
|
103
|
-
* @param ctx - Optional context for event emission
|
|
104
|
-
* @returns The result of the operation if condition is false, undefined otherwise
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* const result = await workflow(async ({ step }) => {
|
|
109
|
-
* const user = await step(fetchUser(id));
|
|
110
|
-
*
|
|
111
|
-
* // Only runs if user is NOT verified
|
|
112
|
-
* const verification = await unless(
|
|
113
|
-
* user.isVerified,
|
|
114
|
-
* () => step(() => sendVerificationEmail(user.email), { name: 'send-verification' }),
|
|
115
|
-
* { name: 'check-verification', reason: 'User is already verified' }
|
|
116
|
-
* );
|
|
117
|
-
*
|
|
118
|
-
* return { user, verification };
|
|
119
|
-
* });
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
declare function unless<T, C = unknown>(condition: boolean, operation: Operation<T>, options?: ConditionalOptions, ctx?: ConditionalContext<C>): Promise<T | undefined>;
|
|
123
|
-
/**
|
|
124
|
-
* Synchronous overload for unless when the operation returns a non-Promise value.
|
|
125
|
-
*/
|
|
126
|
-
declare function unless<T, C = unknown>(condition: boolean, operation: () => T, options?: ConditionalOptions, ctx?: ConditionalContext<C>): T | undefined | Promise<T | undefined>;
|
|
127
|
-
/**
|
|
128
|
-
* Run a step only if condition is true, return default value if skipped.
|
|
129
|
-
*
|
|
130
|
-
* Use this when you want to conditionally execute a step and provide
|
|
131
|
-
* a fallback value when the condition is not met.
|
|
132
|
-
*
|
|
133
|
-
* @param condition - Boolean condition to evaluate
|
|
134
|
-
* @param operation - Function that performs the step (only called if condition is true)
|
|
135
|
-
* @param defaultValue - Value to return if condition is false
|
|
136
|
-
* @param options - Optional configuration for the conditional step
|
|
137
|
-
* @param ctx - Optional context for event emission
|
|
138
|
-
* @returns The result of the operation if condition is true, defaultValue otherwise
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```typescript
|
|
142
|
-
* const result = await workflow(async ({ step }) => {
|
|
143
|
-
* const user = await step(fetchUser(id));
|
|
144
|
-
*
|
|
145
|
-
* // Get premium limits or use default for non-premium users
|
|
146
|
-
* const limits = await whenOr(
|
|
147
|
-
* user.isPremium,
|
|
148
|
-
* () => step(() => fetchPremiumLimits(user.id), { name: 'premium-limits' }),
|
|
149
|
-
* { maxRequests: 100, maxStorage: 1000 }, // default for non-premium
|
|
150
|
-
* { name: 'check-premium-limits', reason: 'Using default limits for non-premium user' }
|
|
151
|
-
* );
|
|
152
|
-
*
|
|
153
|
-
* return { user, limits };
|
|
154
|
-
* });
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
declare function whenOr<T, D, C = unknown>(condition: boolean, operation: Operation<T>, defaultValue: D, options?: ConditionalOptions, ctx?: ConditionalContext<C>): Promise<T | D>;
|
|
158
|
-
/**
|
|
159
|
-
* Synchronous overload for whenOr when the operation returns a non-Promise value.
|
|
160
|
-
*/
|
|
161
|
-
declare function whenOr<T, D, C = unknown>(condition: boolean, operation: () => T, defaultValue: D, options?: ConditionalOptions, ctx?: ConditionalContext<C>): T | D | Promise<T | D>;
|
|
162
|
-
/**
|
|
163
|
-
* Run a step only if condition is false, return default value if skipped.
|
|
164
|
-
*
|
|
165
|
-
* Use this when you want to conditionally execute a step when a condition
|
|
166
|
-
* is NOT met, with a fallback value for when the condition is true.
|
|
167
|
-
*
|
|
168
|
-
* @param condition - Boolean condition to evaluate
|
|
169
|
-
* @param operation - Function that performs the step (only called if condition is false)
|
|
170
|
-
* @param defaultValue - Value to return if condition is true
|
|
171
|
-
* @param options - Optional configuration for the conditional step
|
|
172
|
-
* @param ctx - Optional context for event emission
|
|
173
|
-
* @returns The result of the operation if condition is false, defaultValue otherwise
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```typescript
|
|
177
|
-
* const result = await workflow(async ({ step }) => {
|
|
178
|
-
* const user = await step(fetchUser(id));
|
|
179
|
-
*
|
|
180
|
-
* // Generate new token if user is NOT authenticated, otherwise use existing
|
|
181
|
-
* const token = await unlessOr(
|
|
182
|
-
* user.isAuthenticated,
|
|
183
|
-
* () => step(() => generateNewToken(user.id), { name: 'generate-token' }),
|
|
184
|
-
* user.existingToken, // use existing token if authenticated
|
|
185
|
-
* { name: 'check-auth-for-token', reason: 'Using existing token for authenticated user' }
|
|
186
|
-
* );
|
|
187
|
-
*
|
|
188
|
-
* return { user, token };
|
|
189
|
-
* });
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
|
-
declare function unlessOr<T, D, C = unknown>(condition: boolean, operation: Operation<T>, defaultValue: D, options?: ConditionalOptions, ctx?: ConditionalContext<C>): Promise<T | D>;
|
|
193
|
-
/**
|
|
194
|
-
* Synchronous overload for unlessOr when the operation returns a non-Promise value.
|
|
195
|
-
*/
|
|
196
|
-
declare function unlessOr<T, D, C = unknown>(condition: boolean, operation: () => T, defaultValue: D, options?: ConditionalOptions, ctx?: ConditionalContext<C>): T | D | Promise<T | D>;
|
|
197
|
-
/**
|
|
198
|
-
* Create a set of conditional helpers bound to a workflow context.
|
|
199
|
-
*
|
|
200
|
-
* Use this factory when you want to automatically emit step_skipped events
|
|
201
|
-
* to the workflow's event stream without passing context manually.
|
|
202
|
-
*
|
|
203
|
-
* @param ctx - The workflow context containing workflowId, onEvent, and optional context
|
|
204
|
-
* @returns Object with bound when, unless, whenOr, and unlessOr functions
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* // With run() - context is automatically included in events
|
|
209
|
-
* const result = await run(async ({ step }) => {
|
|
210
|
-
* const ctx = { workflowId, onEvent, context: requestContext };
|
|
211
|
-
* const { when, whenOr } = createConditionalHelpers(ctx);
|
|
212
|
-
*
|
|
213
|
-
* const user = await step(fetchUser(id));
|
|
214
|
-
*
|
|
215
|
-
* const premium = await when(
|
|
216
|
-
* user.isPremium,
|
|
217
|
-
* () => step(() => fetchPremiumData(user.id)),
|
|
218
|
-
* { name: 'premium-data' }
|
|
219
|
-
* );
|
|
220
|
-
*
|
|
221
|
-
* return { user, premium };
|
|
222
|
-
* }, { onEvent, workflowId, context: requestContext });
|
|
223
|
-
*
|
|
224
|
-
* // With createWorkflow - access context from onEvent callback
|
|
225
|
-
* const workflow = createWorkflow({ fetchUser }, {
|
|
226
|
-
* createContext: () => ({ requestId: 'req-123' }),
|
|
227
|
-
* onEvent: (event, ctx) => {
|
|
228
|
-
* // ctx is available here, can be passed to conditional helpers
|
|
229
|
-
* }
|
|
230
|
-
* });
|
|
231
|
-
* ```
|
|
232
|
-
*/
|
|
233
|
-
declare function createConditionalHelpers<C = unknown>(ctx: ConditionalContext<C>): {
|
|
234
|
-
/**
|
|
235
|
-
* Run a step only if condition is true, return undefined if skipped.
|
|
236
|
-
*/
|
|
237
|
-
when: <T>(condition: boolean, operation: Operation<T>, options?: ConditionalOptions) => MaybeAsync<T | undefined>;
|
|
238
|
-
/**
|
|
239
|
-
* Run a step only if condition is false, return undefined if skipped.
|
|
240
|
-
*/
|
|
241
|
-
unless: <T>(condition: boolean, operation: Operation<T>, options?: ConditionalOptions) => MaybeAsync<T | undefined>;
|
|
242
|
-
/**
|
|
243
|
-
* Run a step only if condition is true, return default value if skipped.
|
|
244
|
-
*/
|
|
245
|
-
whenOr: <T, D>(condition: boolean, operation: Operation<T>, defaultValue: D, options?: ConditionalOptions) => MaybeAsync<T | D>;
|
|
246
|
-
/**
|
|
247
|
-
* Run a step only if condition is false, return default value if skipped.
|
|
248
|
-
*/
|
|
249
|
-
unlessOr: <T, D>(condition: boolean, operation: Operation<T>, defaultValue: D, options?: ConditionalOptions) => MaybeAsync<T | D>;
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
export { type ConditionalContext, type ConditionalOptions, createConditionalHelpers, unless, unlessOr, when, whenOr };
|
package/dist/conditional.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function d(){return`decision_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function s(t,n,e){if(!t?.onEvent)return;let o={type:"step_skipped",workflowId:t.workflowId,stepKey:n?.key,name:n?.name,reason:n?.reason,decisionId:e,ts:Date.now()},i=o.context!==void 0||t.context===void 0?o:{...o,context:t.context};t.onEvent(i)}function a(t,n,e,o){if(t)return n();let i=d();s(o,e,i)}function C(t,n,e,o){return a(!t,n,e,o)}function r(t,n,e,o,i){if(t)return n();let p=d();return s(i,o,p),e}function l(t,n,e,o,i){return r(!t,n,e,o,i)}function u(t){return{when:(n,e,o)=>a(n,e,o,t),unless:(n,e,o)=>C(n,e,o,t),whenOr:(n,e,o,i)=>r(n,e,o,i,t),unlessOr:(n,e,o,i)=>l(n,e,o,i,t)}}export{u as createConditionalHelpers,C as unless,l as unlessOr,a as when,r as whenOr};
|
|
2
|
-
//# sourceMappingURL=conditional.js.map
|
package/dist/conditional.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/conditional.ts"],"sourcesContent":["/**\n * awaitly/conditional\n *\n * Conditional step execution helpers for workflows.\n * These helpers allow you to conditionally execute steps based on runtime conditions,\n * with proper event emission for skipped steps.\n */\n\nimport type { WorkflowEvent } from \"./core\";\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Options for conditional execution.\n */\nexport type ConditionalOptions = {\n /**\n * Human-readable name for the conditional step.\n * Used in step_skipped events for debugging and visualization.\n */\n name?: string;\n\n /**\n * Stable identity key for the conditional step.\n * Used in step_skipped events for tracking and visualization.\n */\n key?: string;\n\n /**\n * Optional reason explaining why the step was skipped.\n * Included in step_skipped events.\n */\n reason?: string;\n};\n\n/**\n * Context for conditional execution, used to emit events.\n */\nexport type ConditionalContext<C = unknown> = {\n /**\n * The workflow ID for event emission.\n */\n workflowId: string;\n\n /**\n * Event emitter function.\n */\n onEvent?: (event: WorkflowEvent<unknown, C>) => void;\n\n /**\n * Optional context value to include in emitted events.\n * When provided, this context is automatically added to step_skipped events.\n */\n context?: C;\n};\n\n/**\n * Type for operations that can be either sync or async.\n */\ntype MaybeAsync<T> = T | Promise<T>;\n\n/**\n * Type for the operation function passed to conditional helpers.\n */\ntype Operation<T> = () => MaybeAsync<T>;\n\n// =============================================================================\n// Internal Helpers\n// =============================================================================\n\n/**\n * Generate a unique decision ID for tracking conditional decisions.\n * @internal\n */\nfunction generateDecisionId(): string {\n return `decision_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;\n}\n\n/**\n * Emit a step_skipped event.\n * @internal\n */\nfunction emitSkipped<C = unknown>(\n ctx: ConditionalContext<C> | undefined,\n options: ConditionalOptions | undefined,\n decisionId: string\n): void {\n if (!ctx?.onEvent) return;\n\n // Create event with context if provided (similar to emitEvent logic)\n const event: WorkflowEvent<unknown, C> = {\n type: \"step_skipped\",\n workflowId: ctx.workflowId,\n stepKey: options?.key,\n name: options?.name,\n reason: options?.reason,\n decisionId,\n ts: Date.now(),\n };\n\n // Add context to event only if:\n // 1. Event doesn't already have context (preserves replayed events)\n // 2. Context is actually provided (don't add context: undefined property)\n const eventWithContext =\n event.context !== undefined || ctx.context === undefined\n ? event\n : ({ ...event, context: ctx.context } as WorkflowEvent<unknown, C>);\n\n ctx.onEvent(eventWithContext);\n}\n\n// =============================================================================\n// Conditional Helpers\n// =============================================================================\n\n/**\n * Run a step only if condition is true, return undefined if skipped.\n *\n * Use this when you want to conditionally execute a step and handle\n * the undefined case yourself. For a version with a default value,\n * use `whenOr`.\n *\n * @param condition - Boolean condition to evaluate\n * @param operation - Function that performs the step (only called if condition is true)\n * @param options - Optional configuration for the conditional step\n * @param ctx - Optional context for event emission\n * @returns The result of the operation if condition is true, undefined otherwise\n *\n * @example\n * ```typescript\n * const result = await workflow(async ({ step }) => {\n * const user = await step('fetchUser', () => fetchUser(id));\n *\n * // Only runs if user is premium\n * const premium = await when(\n * user.isPremium,\n * () => step('fetchPremiumData', () => fetchPremiumData(user.id)),\n * { name: 'check-premium', reason: 'User is not premium' }\n * );\n *\n * return { user, premium };\n * });\n * ```\n */\nexport function when<T, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): Promise<T | undefined>;\n\n/**\n * Synchronous overload for when the operation returns a non-Promise value.\n */\nexport function when<T, C = unknown>(\n condition: boolean,\n operation: () => T,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): T | undefined | Promise<T | undefined>;\n\nexport function when<T, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): MaybeAsync<T | undefined> {\n if (condition) {\n return operation();\n }\n\n const decisionId = generateDecisionId();\n emitSkipped(ctx, options, decisionId);\n return undefined;\n}\n\n/**\n * Run a step only if condition is false, return undefined if skipped.\n *\n * Use this when you want to conditionally execute a step when a condition\n * is NOT met. For a version with a default value, use `unlessOr`.\n *\n * @param condition - Boolean condition to evaluate\n * @param operation - Function that performs the step (only called if condition is false)\n * @param options - Optional configuration for the conditional step\n * @param ctx - Optional context for event emission\n * @returns The result of the operation if condition is false, undefined otherwise\n *\n * @example\n * ```typescript\n * const result = await workflow(async ({ step }) => {\n * const user = await step(fetchUser(id));\n *\n * // Only runs if user is NOT verified\n * const verification = await unless(\n * user.isVerified,\n * () => step(() => sendVerificationEmail(user.email), { name: 'send-verification' }),\n * { name: 'check-verification', reason: 'User is already verified' }\n * );\n *\n * return { user, verification };\n * });\n * ```\n */\nexport function unless<T, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): Promise<T | undefined>;\n\n/**\n * Synchronous overload for unless when the operation returns a non-Promise value.\n */\nexport function unless<T, C = unknown>(\n condition: boolean,\n operation: () => T,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): T | undefined | Promise<T | undefined>;\n\nexport function unless<T, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): MaybeAsync<T | undefined> {\n return when(!condition, operation, options, ctx);\n}\n\n/**\n * Run a step only if condition is true, return default value if skipped.\n *\n * Use this when you want to conditionally execute a step and provide\n * a fallback value when the condition is not met.\n *\n * @param condition - Boolean condition to evaluate\n * @param operation - Function that performs the step (only called if condition is true)\n * @param defaultValue - Value to return if condition is false\n * @param options - Optional configuration for the conditional step\n * @param ctx - Optional context for event emission\n * @returns The result of the operation if condition is true, defaultValue otherwise\n *\n * @example\n * ```typescript\n * const result = await workflow(async ({ step }) => {\n * const user = await step(fetchUser(id));\n *\n * // Get premium limits or use default for non-premium users\n * const limits = await whenOr(\n * user.isPremium,\n * () => step(() => fetchPremiumLimits(user.id), { name: 'premium-limits' }),\n * { maxRequests: 100, maxStorage: 1000 }, // default for non-premium\n * { name: 'check-premium-limits', reason: 'Using default limits for non-premium user' }\n * );\n *\n * return { user, limits };\n * });\n * ```\n */\nexport function whenOr<T, D, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): Promise<T | D>;\n\n/**\n * Synchronous overload for whenOr when the operation returns a non-Promise value.\n */\nexport function whenOr<T, D, C = unknown>(\n condition: boolean,\n operation: () => T,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): T | D | Promise<T | D>;\n\nexport function whenOr<T, D, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): MaybeAsync<T | D> {\n if (condition) {\n return operation();\n }\n\n const decisionId = generateDecisionId();\n emitSkipped(ctx, options, decisionId);\n return defaultValue;\n}\n\n/**\n * Run a step only if condition is false, return default value if skipped.\n *\n * Use this when you want to conditionally execute a step when a condition\n * is NOT met, with a fallback value for when the condition is true.\n *\n * @param condition - Boolean condition to evaluate\n * @param operation - Function that performs the step (only called if condition is false)\n * @param defaultValue - Value to return if condition is true\n * @param options - Optional configuration for the conditional step\n * @param ctx - Optional context for event emission\n * @returns The result of the operation if condition is false, defaultValue otherwise\n *\n * @example\n * ```typescript\n * const result = await workflow(async ({ step }) => {\n * const user = await step(fetchUser(id));\n *\n * // Generate new token if user is NOT authenticated, otherwise use existing\n * const token = await unlessOr(\n * user.isAuthenticated,\n * () => step(() => generateNewToken(user.id), { name: 'generate-token' }),\n * user.existingToken, // use existing token if authenticated\n * { name: 'check-auth-for-token', reason: 'Using existing token for authenticated user' }\n * );\n *\n * return { user, token };\n * });\n * ```\n */\nexport function unlessOr<T, D, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): Promise<T | D>;\n\n/**\n * Synchronous overload for unlessOr when the operation returns a non-Promise value.\n */\nexport function unlessOr<T, D, C = unknown>(\n condition: boolean,\n operation: () => T,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): T | D | Promise<T | D>;\n\nexport function unlessOr<T, D, C = unknown>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions,\n ctx?: ConditionalContext<C>\n): MaybeAsync<T | D> {\n return whenOr(!condition, operation, defaultValue, options, ctx);\n}\n\n// =============================================================================\n// Factory Functions for Workflow Integration\n// =============================================================================\n\n/**\n * Create a set of conditional helpers bound to a workflow context.\n *\n * Use this factory when you want to automatically emit step_skipped events\n * to the workflow's event stream without passing context manually.\n *\n * @param ctx - The workflow context containing workflowId, onEvent, and optional context\n * @returns Object with bound when, unless, whenOr, and unlessOr functions\n *\n * @example\n * ```typescript\n * // With run() - context is automatically included in events\n * const result = await run(async ({ step }) => {\n * const ctx = { workflowId, onEvent, context: requestContext };\n * const { when, whenOr } = createConditionalHelpers(ctx);\n *\n * const user = await step(fetchUser(id));\n *\n * const premium = await when(\n * user.isPremium,\n * () => step(() => fetchPremiumData(user.id)),\n * { name: 'premium-data' }\n * );\n *\n * return { user, premium };\n * }, { onEvent, workflowId, context: requestContext });\n * \n * // With createWorkflow - access context from onEvent callback\n * const workflow = createWorkflow({ fetchUser }, {\n * createContext: () => ({ requestId: 'req-123' }),\n * onEvent: (event, ctx) => {\n * // ctx is available here, can be passed to conditional helpers\n * }\n * });\n * ```\n */\nexport function createConditionalHelpers<C = unknown>(ctx: ConditionalContext<C>) {\n return {\n /**\n * Run a step only if condition is true, return undefined if skipped.\n */\n when: <T>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions\n ): MaybeAsync<T | undefined> => when(condition, operation, options, ctx),\n\n /**\n * Run a step only if condition is false, return undefined if skipped.\n */\n unless: <T>(\n condition: boolean,\n operation: Operation<T>,\n options?: ConditionalOptions\n ): MaybeAsync<T | undefined> => unless(condition, operation, options, ctx),\n\n /**\n * Run a step only if condition is true, return default value if skipped.\n */\n whenOr: <T, D>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions\n ): MaybeAsync<T | D> => whenOr(condition, operation, defaultValue, options, ctx),\n\n /**\n * Run a step only if condition is false, return default value if skipped.\n */\n unlessOr: <T, D>(\n condition: boolean,\n operation: Operation<T>,\n defaultValue: D,\n options?: ConditionalOptions\n ): MaybeAsync<T | D> => unlessOr(condition, operation, defaultValue, options, ctx),\n };\n}\n"],"mappings":"AA4EA,SAASA,GAA6B,CACpC,MAAO,YAAY,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,EAAG,CAAC,CAAC,EACzE,CAMA,SAASC,EACPC,EACAC,EACAC,EACM,CACN,GAAI,CAACF,GAAK,QAAS,OAGnB,IAAMG,EAAmC,CACvC,KAAM,eACN,WAAYH,EAAI,WAChB,QAASC,GAAS,IAClB,KAAMA,GAAS,KACf,OAAQA,GAAS,OACjB,WAAAC,EACA,GAAI,KAAK,IAAI,CACf,EAKME,EACJD,EAAM,UAAY,QAAaH,EAAI,UAAY,OAC3CG,EACC,CAAE,GAAGA,EAAO,QAASH,EAAI,OAAQ,EAExCA,EAAI,QAAQI,CAAgB,CAC9B,CAoDO,SAASC,EACdC,EACAC,EACAN,EACAD,EAC2B,CAC3B,GAAIM,EACF,OAAOC,EAAU,EAGnB,IAAML,EAAaJ,EAAmB,EACtCC,EAAYC,EAAKC,EAASC,CAAU,CAEtC,CA+CO,SAASM,EACdF,EACAC,EACAN,EACAD,EAC2B,CAC3B,OAAOK,EAAK,CAACC,EAAWC,EAAWN,EAASD,CAAG,CACjD,CAmDO,SAASS,EACdH,EACAC,EACAG,EACAT,EACAD,EACmB,CACnB,GAAIM,EACF,OAAOC,EAAU,EAGnB,IAAML,EAAaJ,EAAmB,EACtC,OAAAC,EAAYC,EAAKC,EAASC,CAAU,EAC7BQ,CACT,CAmDO,SAASC,EACdL,EACAC,EACAG,EACAT,EACAD,EACmB,CACnB,OAAOS,EAAO,CAACH,EAAWC,EAAWG,EAAcT,EAASD,CAAG,CACjE,CA0CO,SAASY,EAAsCZ,EAA4B,CAChF,MAAO,CAIL,KAAM,CACJM,EACAC,EACAN,IAC8BI,EAAKC,EAAWC,EAAWN,EAASD,CAAG,EAKvE,OAAQ,CACNM,EACAC,EACAN,IAC8BO,EAAOF,EAAWC,EAAWN,EAASD,CAAG,EAKzE,OAAQ,CACNM,EACAC,EACAG,EACAT,IACsBQ,EAAOH,EAAWC,EAAWG,EAAcT,EAASD,CAAG,EAK/E,SAAU,CACRM,EACAC,EACAG,EACAT,IACsBU,EAASL,EAAWC,EAAWG,EAAcT,EAASD,CAAG,CACnF,CACF","names":["generateDecisionId","emitSkipped","ctx","options","decisionId","event","eventWithContext","when","condition","operation","unless","whenOr","defaultValue","unlessOr","createConditionalHelpers"]}
|