Using TypeScript
App-Compose comes with built-in TypeScript support, so you can start writing type-safe code right away.
TypeScript with Tags
Section titled “TypeScript with Tags”When creating a Tag, you can specify the data type it holds.
import { createTag } from "@grlt-hub/app-compose"
const tag = createTag<string>({ name: "title" })This provides full type safety for both Tag inputs and outputs.
Useful Types
Section titled “Useful Types”TaskResult<T>
Section titled “TaskResult<T>”Extracts the return type of a given Task.
import { type TaskResult, createTask } from "@grlt-hub/app-compose"
const alpha = createTask({ name: "alpha", run: { fn: () => ({ value: "hello" }) },})
type AlphaResult = TaskResult<typeof alpha> // => { value: string }TaskStatus
Section titled “TaskStatus”Represents the possible execution outcomes of a Task.
type TaskStatus = "done" | "fail" | "skip"Task<T>
Section titled “Task<T>”Represents a Task created by createTask. Use it to type function parameters or variables that hold a Task reference.
import { type Task, createTask } from "@grlt-hub/app-compose"
const alpha = createTask({ name: "alpha", run: { fn: () => ({ value: "hello" }) },})
// Use Task<T> to type a variable or function parameter that holds a Task referenceconst ref: Task<{ value: string }> = alphaComposeLogger
Section titled “ComposeLogger”Defines lifecycle hooks for observing stage and task execution.
import { type ComposeLogger } from "@grlt-hub/app-compose"
const myLogger: ComposeLogger = { onTaskFail: (event) => console.log(event), onStageStart: (event) => console.log(event), onStageComplete: (event) => console.log(event),}StageConfig
Section titled “StageConfig”Represents the configuration for a single stage passed to compose.
import { type StageConfig, createTask } from "@grlt-hub/app-compose"
const task = createTask({ name: "task", run: { fn: () => true } })
const stages: StageConfig = { steps: [task],}