@tasker-systems/tasker 0.1.5 → 0.1.7

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.
@@ -1,3 +1,3 @@
1
- export { y as ErrorCallback, n as EventName, o as EventNames, d as EventPoller, z as EventPollerConfig, f as EventSystem, F as EventSystemConfig, G as EventSystemStats, A as MetricsCallback, p as MetricsEventName, q as MetricsEventNames, M as MetricsPayload, P as PollerCyclePayload, r as PollerEventName, s as PollerEventNames, C as PollerState, g as StepCompletionSentPayload, D as StepEventCallback, t as StepEventName, u as StepEventNames, h as StepExecutionCompletedPayload, i as StepExecutionFailedPayload, j as StepExecutionReceivedPayload, k as StepExecutionStartedPayload, T as TaskerEventEmitter, l as TaskerEventMap, W as WorkerErrorPayload, v as WorkerEventName, w as WorkerEventNames, m as WorkerEventPayload, x as createEventPoller } from '../index-Bvdub2HH.js';
1
+ export { y as ErrorCallback, n as EventName, o as EventNames, d as EventPoller, z as EventPollerConfig, f as EventSystem, F as EventSystemConfig, G as EventSystemStats, A as MetricsCallback, p as MetricsEventName, q as MetricsEventNames, M as MetricsPayload, P as PollerCyclePayload, r as PollerEventName, s as PollerEventNames, C as PollerState, g as StepCompletionSentPayload, D as StepEventCallback, t as StepEventName, u as StepEventNames, h as StepExecutionCompletedPayload, i as StepExecutionFailedPayload, j as StepExecutionReceivedPayload, k as StepExecutionStartedPayload, T as TaskerEventEmitter, l as TaskerEventMap, W as WorkerErrorPayload, v as WorkerEventName, w as WorkerEventNames, m as WorkerEventPayload, x as createEventPoller } from '../index-CRCYa9Xk.js';
2
2
  import 'eventemitter3';
3
3
  import '../ffi/index.js';
@@ -948,6 +948,10 @@ declare abstract class StepHandler {
948
948
  /**
949
949
  * Version string for the handler.
950
950
  * Default: "1.0.0"
951
+ *
952
+ * Currently a no-op — not yet wired through FFI bridges to
953
+ * StepExecutionMetadata. Reserved for future observability
954
+ * and compatibility tracking.
951
955
  */
952
956
  static handlerVersion: string;
953
957
  /**
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NapiModule, FfiLayer, FfiDomainEvent, FfiLayerConfig } from './ffi/index.js';
2
2
  export { BootstrapConfig as FfiBootstrapConfig, BootstrapResult as FfiBootstrapResult, FfiDispatchMetrics, LogFields as FfiLogFields, FfiStepEvent, StopResult as FfiStopResult, WorkerStatus as FfiWorkerStatus, NapiBackoffHint, NapiCheckpointYieldData, NapiClientResult, NapiDependencyResult, NapiDispatchMetrics, NapiDomainEvent, NapiDomainEventMetadata, NapiListTasksParams, NapiOrchestrationMetadata, NapiStepDefinition, NapiStepEvent, NapiStepExecutionError, NapiStepExecutionMetadata, NapiStepExecutionResult, NapiTaskInfo, NapiTaskRequest, NapiWorkflowStep, StepExecutionResult } from './ffi/index.js';
3
- import { S as StepHandlerResult, a as StepHandler, B as BatchWorkerConfig, b as StepContext, E as ExecutableHandler, c as StepHandlerClass, T as TaskerEventEmitter, d as EventPoller, e as StepExecutionSubscriber, f as EventSystem } from './index-Bvdub2HH.js';
4
- export { y as ErrorCallback, I as ErrorType, n as EventName, o as EventNames, z as EventPollerConfig, F as EventSystemConfig, G as EventSystemStats, A as MetricsCallback, p as MetricsEventName, q as MetricsEventNames, M as MetricsPayload, P as PollerCyclePayload, r as PollerEventName, s as PollerEventNames, C as PollerState, g as StepCompletionSentPayload, L as StepContextParams, D as StepEventCallback, t as StepEventName, u as StepEventNames, h as StepExecutionCompletedPayload, i as StepExecutionFailedPayload, j as StepExecutionReceivedPayload, k as StepExecutionStartedPayload, H as StepExecutionSubscriberConfig, N as StepHandlerResultParams, l as TaskerEventMap, W as WorkerErrorPayload, v as WorkerEventName, w as WorkerEventNames, m as WorkerEventPayload, x as createEventPoller, J as isStandardErrorType, K as isTypicallyRetryable } from './index-Bvdub2HH.js';
3
+ import { S as StepHandlerResult, a as StepHandler, B as BatchWorkerConfig, b as StepContext, c as StepHandlerClass, E as ExecutableHandler, T as TaskerEventEmitter, d as EventPoller, e as StepExecutionSubscriber, f as EventSystem } from './index-CRCYa9Xk.js';
4
+ export { y as ErrorCallback, I as ErrorType, n as EventName, o as EventNames, z as EventPollerConfig, F as EventSystemConfig, G as EventSystemStats, A as MetricsCallback, p as MetricsEventName, q as MetricsEventNames, M as MetricsPayload, P as PollerCyclePayload, r as PollerEventName, s as PollerEventNames, C as PollerState, g as StepCompletionSentPayload, L as StepContextParams, D as StepEventCallback, t as StepEventName, u as StepEventNames, h as StepExecutionCompletedPayload, i as StepExecutionFailedPayload, j as StepExecutionReceivedPayload, k as StepExecutionStartedPayload, H as StepExecutionSubscriberConfig, N as StepHandlerResultParams, l as TaskerEventMap, W as WorkerErrorPayload, v as WorkerEventName, w as WorkerEventNames, m as WorkerEventPayload, x as createEventPoller, J as isStandardErrorType, K as isTypicallyRetryable } from './index-CRCYa9Xk.js';
5
5
  import { Logger } from 'pino';
6
6
  import 'eventemitter3';
7
7
 
@@ -2629,6 +2629,257 @@ declare function ffiEventToDomainEvent(ffiEvent: FfiDomainEvent): DomainEvent;
2629
2629
  */
2630
2630
  declare function createFfiPollAdapter(module: NapiModule): () => DomainEvent | null;
2631
2631
 
2632
+ /**
2633
+ * Functional/factory API for step handlers (TAS-294).
2634
+ *
2635
+ * This module provides factory-function alternatives to the class-based handler API.
2636
+ * It reduces boilerplate for common handler patterns while preserving full access
2637
+ * to the underlying StepContext for advanced use cases.
2638
+ *
2639
+ * Factory functions auto-wrap return values and classify exceptions:
2640
+ * - Record return → StepHandlerResult.success(record)
2641
+ * - StepHandlerResult return → pass through unchanged
2642
+ * - PermanentError thrown → StepHandlerResult.failure(retryable=false)
2643
+ * - RetryableError thrown → StepHandlerResult.failure(retryable=true)
2644
+ * - Other errors → StepHandlerResult.failure(retryable=true)
2645
+ *
2646
+ * @example
2647
+ * ```typescript
2648
+ * import { defineHandler, PermanentError } from 'tasker-core';
2649
+ *
2650
+ * const ProcessPayment = defineHandler('process_payment', {
2651
+ * depends: { cart: 'validate_cart' },
2652
+ * inputs: { paymentInfo: 'payment_info' },
2653
+ * }, async ({ cart, paymentInfo, context }) => {
2654
+ * if (!paymentInfo) throw new PermanentError('Payment info required');
2655
+ * const result = await chargeCard(paymentInfo, cart.total);
2656
+ * return { paymentId: result.id, amount: cart.total };
2657
+ * });
2658
+ * ```
2659
+ *
2660
+ * @module handler/functional
2661
+ */
2662
+
2663
+ /**
2664
+ * Base error for permanent, non-retryable failures.
2665
+ *
2666
+ * Throw this in functional handlers when the error will not succeed on retry.
2667
+ *
2668
+ * @example
2669
+ * ```typescript
2670
+ * throw new PermanentError('Invalid account number');
2671
+ * ```
2672
+ */
2673
+ declare class PermanentError extends Error {
2674
+ readonly retryable = false;
2675
+ readonly metadata: Record<string, unknown>;
2676
+ constructor(message: string, metadata?: Record<string, unknown>);
2677
+ }
2678
+ /**
2679
+ * Base error for transient, retryable failures.
2680
+ *
2681
+ * Throw this in functional handlers when a retry might succeed.
2682
+ *
2683
+ * @example
2684
+ * ```typescript
2685
+ * throw new RetryableError('Service temporarily unavailable');
2686
+ * ```
2687
+ */
2688
+ declare class RetryableError extends Error {
2689
+ readonly retryable = true;
2690
+ readonly metadata: Record<string, unknown>;
2691
+ constructor(message: string, metadata?: Record<string, unknown>);
2692
+ }
2693
+ /**
2694
+ * Options for defineHandler and related factory functions.
2695
+ */
2696
+ interface HandlerOptions {
2697
+ /** Mapping of parameter names to dependency step names */
2698
+ depends?: Record<string, string>;
2699
+ /** Mapping of parameter names to input data keys */
2700
+ inputs?: Record<string, string>;
2701
+ /** Handler version (default: "1.0.0") */
2702
+ version?: string;
2703
+ }
2704
+ /**
2705
+ * The injected arguments object passed to functional handlers.
2706
+ *
2707
+ * Contains declared dependencies, inputs, and always includes `context`.
2708
+ */
2709
+ type HandlerArgs = Record<string, unknown> & {
2710
+ context: StepContext;
2711
+ };
2712
+ /**
2713
+ * Handler function signature.
2714
+ */
2715
+ type HandlerFn = (args: HandlerArgs) => Promise<Record<string, unknown> | StepHandlerResult | undefined>;
2716
+ /**
2717
+ * Helper for decision handler return values.
2718
+ *
2719
+ * @example
2720
+ * ```typescript
2721
+ * const RouteOrder = defineDecisionHandler('route_order', {
2722
+ * depends: { order: 'validate_order' },
2723
+ * }, async ({ order }) => {
2724
+ * if (order.tier === 'premium') {
2725
+ * return Decision.route(['process_premium'], { tier: 'premium' });
2726
+ * }
2727
+ * return Decision.route(['process_standard']);
2728
+ * });
2729
+ * ```
2730
+ */
2731
+ declare class Decision {
2732
+ readonly type: 'create_steps' | 'no_branches';
2733
+ readonly steps: string[];
2734
+ readonly reason?: string | undefined;
2735
+ readonly routingContext: Record<string, unknown>;
2736
+ private constructor();
2737
+ /**
2738
+ * Route to the specified steps.
2739
+ */
2740
+ static route(steps: string[], routingContext?: Record<string, unknown>): Decision;
2741
+ /**
2742
+ * Skip all branches.
2743
+ */
2744
+ static skip(reason: string, routingContext?: Record<string, unknown>): Decision;
2745
+ }
2746
+ /**
2747
+ * Configuration returned by batch analyzer handlers.
2748
+ */
2749
+ interface BatchConfig {
2750
+ totalItems: number;
2751
+ batchSize: number;
2752
+ metadata?: Record<string, unknown>;
2753
+ }
2754
+ /**
2755
+ * Define a step handler from a function.
2756
+ *
2757
+ * Returns a StepHandler subclass that can be registered with HandlerRegistry.
2758
+ * The function receives injected dependencies, inputs, and context.
2759
+ * Return values are auto-wrapped as success results, and exceptions are
2760
+ * auto-classified as failure results.
2761
+ *
2762
+ * @param name - Handler name (must match step definition)
2763
+ * @param options - Dependencies, inputs, and version
2764
+ * @param fn - Handler function
2765
+ * @returns StepHandler subclass
2766
+ *
2767
+ * @example
2768
+ * ```typescript
2769
+ * const ProcessPayment = defineHandler('process_payment', {
2770
+ * depends: { cart: 'validate_cart' },
2771
+ * inputs: { paymentInfo: 'payment_info' },
2772
+ * }, async ({ cart, paymentInfo, context }) => {
2773
+ * if (!paymentInfo) throw new PermanentError('Payment info required');
2774
+ * const result = await chargeCard(paymentInfo, cart.total);
2775
+ * return { paymentId: result.id, amount: cart.total };
2776
+ * });
2777
+ *
2778
+ * // Register:
2779
+ * registry.register(ProcessPayment);
2780
+ * ```
2781
+ */
2782
+ declare function defineHandler(name: string, options: HandlerOptions, fn: HandlerFn): StepHandlerClass;
2783
+ /**
2784
+ * Define a decision handler from a function.
2785
+ *
2786
+ * The function should return a `Decision.route(...)` or `Decision.skip(...)`.
2787
+ *
2788
+ * @param name - Handler name
2789
+ * @param options - Dependencies, inputs, and version
2790
+ * @param fn - Handler function returning a Decision
2791
+ * @returns StepHandler subclass
2792
+ *
2793
+ * @example
2794
+ * ```typescript
2795
+ * const RouteOrder = defineDecisionHandler('route_order', {
2796
+ * depends: { order: 'validate_order' },
2797
+ * }, async ({ order }) => {
2798
+ * if (order.tier === 'premium') {
2799
+ * return Decision.route(['process_premium'], { tier: 'premium' });
2800
+ * }
2801
+ * return Decision.route(['process_standard']);
2802
+ * });
2803
+ * ```
2804
+ */
2805
+ declare function defineDecisionHandler(name: string, options: HandlerOptions, fn: (args: HandlerArgs) => Promise<Decision | StepHandlerResult>): StepHandlerClass;
2806
+ /**
2807
+ * Define a batch analyzer handler.
2808
+ *
2809
+ * The function should return a `BatchConfig` with `totalItems` and `batchSize`.
2810
+ * Cursor configs are generated automatically.
2811
+ *
2812
+ * @param name - Handler name
2813
+ * @param options - Handler options plus `workerTemplate`
2814
+ * @param fn - Handler function returning a BatchConfig
2815
+ * @returns StepHandler subclass
2816
+ */
2817
+ declare function defineBatchAnalyzer(name: string, options: HandlerOptions & {
2818
+ workerTemplate: string;
2819
+ }, fn: (args: HandlerArgs) => Promise<BatchConfig | StepHandlerResult>): StepHandlerClass;
2820
+ /**
2821
+ * Define a batch worker handler.
2822
+ *
2823
+ * The function receives a `batchContext` parameter extracted from the step
2824
+ * context, containing cursor configuration for this worker's partition.
2825
+ *
2826
+ * @param name - Handler name
2827
+ * @param options - Dependencies, inputs, and version
2828
+ * @param fn - Handler function receiving batch context
2829
+ * @returns StepHandler subclass
2830
+ */
2831
+ declare function defineBatchWorker(name: string, options: HandlerOptions, fn: (args: HandlerArgs & {
2832
+ batchContext: BatchWorkerContext | null;
2833
+ }) => Promise<Record<string, unknown> | StepHandlerResult | undefined>): StepHandlerClass;
2834
+ /**
2835
+ * Options for defineApiHandler.
2836
+ */
2837
+ interface ApiHandlerOptions extends HandlerOptions {
2838
+ /** Base URL for API calls */
2839
+ baseUrl: string;
2840
+ /** Default request timeout in milliseconds (default: 30000) */
2841
+ defaultTimeout?: number;
2842
+ /** Default headers to include in all requests */
2843
+ defaultHeaders?: Record<string, string>;
2844
+ }
2845
+ /**
2846
+ * The injected arguments for API handlers, including the `api` object
2847
+ * with pre-configured HTTP methods and result helpers.
2848
+ *
2849
+ * `api` is the handler instance itself with API methods applied (matching
2850
+ * the Python/Ruby pattern where `api=self`).
2851
+ */
2852
+ type ApiHandlerArgs = HandlerArgs & {
2853
+ api: APICapable;
2854
+ };
2855
+ /**
2856
+ * Define an API handler with HTTP client functionality.
2857
+ *
2858
+ * The function receives an `api` object providing pre-configured HTTP methods
2859
+ * (get, post, put, patch, delete, request) and result helpers (apiSuccess,
2860
+ * apiFailure, connectionError, timeoutError) from the APIMixin.
2861
+ *
2862
+ * @param name - Handler name (must match step definition)
2863
+ * @param options - Dependencies, inputs, version, and API configuration
2864
+ * @param fn - Handler function receiving api and other injected args
2865
+ * @returns StepHandler subclass
2866
+ *
2867
+ * @example
2868
+ * ```typescript
2869
+ * const FetchUser = defineApiHandler('fetch_user', {
2870
+ * baseUrl: 'https://api.example.com',
2871
+ * depends: { userId: 'validate_user' },
2872
+ * }, async ({ userId, api }) => {
2873
+ * const response = await api.get(`/users/${userId}`);
2874
+ * if (response.ok) {
2875
+ * return api.apiSuccess(response);
2876
+ * }
2877
+ * return api.apiFailure(response);
2878
+ * });
2879
+ * ```
2880
+ */
2881
+ declare function defineApiHandler(name: string, options: ApiHandlerOptions, fn: (args: ApiHandlerArgs) => Promise<Record<string, unknown> | StepHandlerResult | undefined>): StepHandlerClass;
2882
+
2632
2883
  /**
2633
2884
  * TAS-93: Handler definition type for resolver chain.
2634
2885
  *
@@ -3691,12 +3942,18 @@ declare class HandlerSystem {
3691
3942
  * Try to import an index file from the handler path.
3692
3943
  */
3693
3944
  private tryImportIndexFile;
3945
+ /**
3946
+ * TAS-294: Try to import the dsl_examples index file.
3947
+ * This is separate from tryImportIndexFile because dsl_examples/ is a sibling
3948
+ * directory to examples/, and both need to be loaded.
3949
+ */
3950
+ private tryImportDslExamplesIndex;
3694
3951
  /**
3695
3952
  * Register handlers from a module's exports.
3696
3953
  */
3697
3954
  private registerHandlersFromModule;
3698
3955
  /**
3699
- * Register handlers from ALL_EXAMPLE_HANDLERS array.
3956
+ * Register handlers from a named handler array.
3700
3957
  */
3701
3958
  private registerFromHandlerArray;
3702
3959
  /**
@@ -4104,4 +4361,4 @@ declare class WorkerServer {
4104
4361
  private cleanupOnError;
4105
4362
  }
4106
4363
 
4107
- export { type APICapable, APIMixin, ApiHandler, ApiResponse, BasePublisher, type BaseResolver, BaseSubscriber, type BatchAggregationResult, type BatchAnalyzerOutcome, type BatchMetadata, type BatchProcessingOutcome, type BatchWorkerContext, type BatchWorkerOutcome, type Batchable, BatchableMixin, type BootstrapConfig, type BootstrapResult, ClassLookupResolver, type CreateBatchesOutcome, type CreateTaskOptions, type CursorConfig, type DecisionCapable, DecisionHandler, DecisionMixin, type DecisionPointOutcome, DecisionType, DefaultPublisher, type DomainEvent, type DomainEventCallback, type DomainEventErrorCallback, type DomainEventMetadata, type DomainEventPollerConfig, DuplicatePublisherError, type EventDeclaration, EventPoller, EventSystem, ExecutableHandler, ExplicitMappingResolver, type FailureStrategy, FfiDomainEvent, FfiLayer, FfiLayerConfig, type HandlerDefinition, type HandlerEntry, type HandlerFactory, HandlerRegistry, type HandlerSpec, HandlerSystem, InProcessDomainEventPoller, type ListTasksOptions, type LogFields, MethodDispatchError, MethodDispatchWrapper, NapiModule, type NoBatchesOutcome, NoResolverMatchError, type PollerStats, type PublishContext, PublisherNotFoundError, PublisherRegistry, PublisherValidationError, RegistryFrozenError, RegistryResolver, type RegistryResolverStatic, ResolutionError, ResolverChain, type ResolverConfig, ResolverNotFoundError, type RustBatchWorkerInputs, type RustCursorConfig, type ServerComponents, type HealthCheckResult as ServerHealthCheckResult, type ServerState, type ServerStatus, ShutdownController, type ShutdownHandler, StepContext, type StepEventContext, StepExecutionSubscriber, StepHandler, StepHandlerClass, StepHandlerResult, type StepResult, type StopResult, type SubscriberClass, SubscriberRegistry, type SubscriberStats, TaskerClient, TaskerClientError, TaskerEventEmitter, WorkerServer, type WorkerServerConfig, type WorkerStatus, aggregateBatchResults, applyAPI, applyBatchable, applyDecision, bootstrapWorker, createBatchWorkerContext, createBatches, createDomainEvent, createFfiPollAdapter, createLogger, createStepEventContext, effectiveMethod, ffiEventToDomainEvent, fromCallable, fromDto, getRustVersion, getVersion, getWorkerStatus, hasResolverHint, healthCheck, isCreateBatches, isNoBatches, isWorkerRunning, logDebug, logError, logInfo, logTrace, logWarn, noBatches, normalizeToDefinition, stopWorker, transitionToGracefulShutdown, usesMethodDispatch };
4364
+ export { type APICapable, APIMixin, ApiHandler, type ApiHandlerArgs, type ApiHandlerOptions, ApiResponse, BasePublisher, type BaseResolver, BaseSubscriber, type BatchAggregationResult, type BatchAnalyzerOutcome, type BatchConfig, type BatchMetadata, type BatchProcessingOutcome, type BatchWorkerContext, type BatchWorkerOutcome, type Batchable, BatchableMixin, type BootstrapConfig, type BootstrapResult, ClassLookupResolver, type CreateBatchesOutcome, type CreateTaskOptions, type CursorConfig, Decision, type DecisionCapable, DecisionHandler, DecisionMixin, type DecisionPointOutcome, DecisionType, DefaultPublisher, type DomainEvent, type DomainEventCallback, type DomainEventErrorCallback, type DomainEventMetadata, type DomainEventPollerConfig, DuplicatePublisherError, type EventDeclaration, EventPoller, EventSystem, ExecutableHandler, ExplicitMappingResolver, type FailureStrategy, FfiDomainEvent, FfiLayer, FfiLayerConfig, type HandlerArgs, type HandlerDefinition, type HandlerEntry, type HandlerFactory, type HandlerFn, type HandlerOptions, HandlerRegistry, type HandlerSpec, HandlerSystem, InProcessDomainEventPoller, type ListTasksOptions, type LogFields, MethodDispatchError, MethodDispatchWrapper, NapiModule, type NoBatchesOutcome, NoResolverMatchError, PermanentError, type PollerStats, type PublishContext, PublisherNotFoundError, PublisherRegistry, PublisherValidationError, RegistryFrozenError, RegistryResolver, type RegistryResolverStatic, ResolutionError, ResolverChain, type ResolverConfig, ResolverNotFoundError, RetryableError, type RustBatchWorkerInputs, type RustCursorConfig, type ServerComponents, type HealthCheckResult as ServerHealthCheckResult, type ServerState, type ServerStatus, ShutdownController, type ShutdownHandler, StepContext, type StepEventContext, StepExecutionSubscriber, StepHandler, StepHandlerClass, StepHandlerResult, type StepResult, type StopResult, type SubscriberClass, SubscriberRegistry, type SubscriberStats, TaskerClient, TaskerClientError, TaskerEventEmitter, WorkerServer, type WorkerServerConfig, type WorkerStatus, aggregateBatchResults, applyAPI, applyBatchable, applyDecision, bootstrapWorker, createBatchWorkerContext, createBatches, createDomainEvent, createFfiPollAdapter, createLogger, createStepEventContext, defineApiHandler, defineBatchAnalyzer, defineBatchWorker, defineDecisionHandler, defineHandler, effectiveMethod, ffiEventToDomainEvent, fromCallable, fromDto, getRustVersion, getVersion, getWorkerStatus, hasResolverHint, healthCheck, isCreateBatches, isNoBatches, isWorkerRunning, logDebug, logError, logInfo, logTrace, logWarn, noBatches, normalizeToDefinition, stopWorker, transitionToGracefulShutdown, usesMethodDispatch };