Artifacts
Pipeline outputs and schemas
Artifacts
Artifacts represent the structured outputs generated by a pipeline route. They provide a contract (schema) for the data that a route produces.
This allows other routes in the same pipeline to consume these artifacts, building complex data dependencies and workflows.
Defining an Artifact
Artifacts are defined using definePipelineArtifact from @ucdjs/pipelines-artifacts.
import { definePipelineArtifact } from "@ucdjs/pipelines-artifacts";
import { z } from "zod";
const mySchema = z.object({
code: z.string(),
name: z.string()
});
const myArtifact = definePipelineArtifact({
id: "unicode-data-artifact",
schema: z.array(mySchema),
});The artifact is typed by the provided Zod schema. When a route resolves to this artifact, it must conform to the defined schema.
Consuming Artifacts
Routes can consume artifacts produced by other routes. This establishes a dependency graph where routes execute in an order determined by these artifact dependencies.
You can request an artifact using ctx.getArtifact in a route's resolver. The pipeline executor ensures the dependency is satisfied before executing the consuming route.
import { definePipelineRoute, byName } from "@ucdjs/pipelines-core";
import { myArtifact } from "./artifacts";
const downstreamRoute = definePipelineRoute({
id: "process-data",
filter: byName("SomeOtherFile.txt"),
parser: async function* (ctx) { /* ... */ },
resolver: async (ctx, rows) => {
// Consume the artifact from another route
const data = await ctx.getArtifact(myArtifact);
// Process using the data...
return { success: true };
}
});