Stone.js API
    Preparing search index...

    Node Cli Adapter for Stone.js.

    The NodeCliAdapter provides seamless integration between Stone.js applications and the Node Cli environment. It processes incoming events from Node Cli, transforms them into IncomingEvent instances, and returns a RawResponse.

    This adapter ensures compatibility with Node Cli's execution model and abstracts the event handling process for Stone.js developers.

    The type of the raw event received from Node Cli.

    The type of the response to send back to Node Cli.

    The Node Cli execution context type.

    The type of the processed incoming event.

    Options used to create an incoming event.

    The type of the outgoing response after processing.

    Context type specific to the adapter.

    import { NodeCliAdapter } from '@stone-js/node-cli-adapter';

    const adapter = NodeCliAdapter.create({...});

    const handler = await adapter.run();

    export { handler };

    Hierarchy

    Index
    • Create an Adapter.

      Parameters

      • blueprint: IBlueprint

        The blueprint to create the adapter.

      Returns NodeCliAdapter

    blueprint: IBlueprint
    hooks: AdapterHookType<NodeCliAdapterContext, number>
    middleware: AdapterMixedPipeType<NodeCliAdapterContext, number>[]
    resolvedErrorHandlers: Record<
        string,
        IAdapterErrorHandler<RawEventType, RawResponseType, ExecutionContextType>,
    >
    • Apply the resolved response as the process exit code (POSIX-normalized).

      Parameters

      • response: number

        The raw response (an HTTP-ish status/exit code).

      Returns void

    • Build the raw response.

      Parameters

      • context: NodeCliAdapterContext

        The event context.

      • OptionaleventHandler: AdapterEventHandlerType<IncomingEvent, OutgoingResponse>

        The event handler to be run.

      Returns Promise<number>

      The raw response wrapper.

    • Processes an incoming Node Cli event.

      This method transforms the raw Node Cli event into a Stone.js IncomingEvent, processes it through the pipeline, and generates a RawResponse to send back.

      Parameters

      • rawEvent: NodeCliEvent

        The raw Node Cli event to be processed.

      • executionContext: CommandBuilder

        The Node Cli execution context for the event.

      Returns Promise<number>

      A promise resolving to the processed RawResponse.

    • Execute the event handler lifecycle hooks.

      Parameters

      • hook: KernelHookName

        The hook to execute.

      • eventHandler: AdapterEventHandlerType<IncomingEvent, OutgoingResponse>

        The event handler to be run.

      Returns Promise<void>

    • Execute adapter lifecycle hooks.

      Parameters

      • name: AdapterHookName

        The hook's name.

      • Optionalcontext: NodeCliAdapterContext

        The event context.

      • Optionalerror: any

        The error to handle.

      Returns Promise<void>

    • Handle error.

      Parameters

      Returns Promise<AdapterEventBuilderType<number>>

      The raw response.

    • Handle the event.

      Parameters

      • context: NodeCliAdapterContext

        The event context.

      • eventHandler: AdapterEventHandlerType<IncomingEvent, OutgoingResponse>

        The event handler to be run.

      Returns Promise<IAdapterEventBuilder<RawResponseOptions, IRawResponseWrapper<number>>>

      The raw response wrapper.

    • Create pipeline options for the Adapter.

      Returns PipelineOptions<NodeCliAdapterContext, AdapterEventBuilderType<number>>

      The pipeline options for transforming the event.

    • Initializes the adapter and validates its execution context.

      Ensures the adapter is running in an Node Cli environment. If not, it throws an error to prevent misuse.

      Returns Promise<void>

      If executed outside an Node Cli context (e.g., browser).

    • Get the error handler for the given error.

      Parameters

      • error: Error

        The error to get the handler for.

      Returns IAdapterErrorHandler<NodeCliEvent, number, CommandBuilder>

      The error handler.

      IntegrationError

    • Get the event handler for the adapter.

      Returns AdapterEventHandlerType<IncomingEvent, OutgoingResponse>

      The event handler for the adapter.

      If the event handler is missing.

    • Executes the adapter and provides an Node Cli-compatible handler function.

      The run method processes events, manages context, and returns the appropriate response.

      Type Parameters

      • ExecutionResultType = number

        The type representing the Node Cli event handler function.

      Returns Promise<ExecutionResultType>

      A promise resolving to the Node Cli handler function.

      If used outside the Node Cli environment.

    • Send the raw event through the destination.

      Parameters

      • context: NodeCliAdapterContext

        The event context.

      • eventHandler: AdapterEventHandlerType<IncomingEvent, OutgoingResponse>

        The event handler to be run.

      Returns Promise<number>

      Platform-specific response.

      IntegrationError

    • Normalize an internal response code to a POSIX exit code (0-255).

      Success (0 or a 2xx status) → 0; a "command not found" marker → 127; anything else that is not a finite in-range code → 1 (general failure). Codes already in the 0-255 range pass through so a command can return a precise POSIX code.

      Parameters

      • code: number

        The raw response code.

      Returns number

      The POSIX exit code.

    • Validate the context and event handler.

      Parameters

      • context: NodeCliAdapterContext

        The context to validate.

      • eventHandler: AdapterEventHandlerType<IncomingEvent, OutgoingResponse>

        The event handler to validate.

      Returns void

      IntegrationError

    • Creates an instance of the NodeCliAdapter.

      Parameters

      • blueprint: IBlueprint

        The application blueprint.

      Returns NodeCliAdapter

      A new instance of NodeCliAdapter.

      const adapter = NodeCliAdapter.create(blueprint);
      await adapter.run();