LogoCyanPrint
ProcessorsReferenceSDK Reference

Processor Input/Output

Type definitions for processor interfaces

Processor Input/Output

Type definitions for the data structures passed to and returned from processors.

CyanProcessorInput

The input object passed to the processor handler.

Definition

interface CyanProcessorInput {
readDir: string;
writeDir: string;
globs: CyanGlob[];
config: unknown;
}

Properties

Prop

Type

Typical Values

PropertyTypical Value
readDir/workspace/cyanprint/
writeDir/workspace/output/

Usage

StartProcessorWithLambda(async (input, fileHelper) => {
console.log('Reading from:', input.readDir);
console.log('Writing to:', input.writeDir);
console.log('Globs:', input.globs);
console.log('Config:', input.config);
// Always return writeDir
return { directory: input.writeDir };
});
async def handler(input, file_helper):
print(f"Reading from: {input.read_dir}")
print(f"Writing to: {input.write_dir}")
print(f"Globs: {input.globs}")
print(f"Config: {input.config}")
# Always return write_dir
return {"directory": input.write_dir}
await Processor.StartAsync(async (input, fileHelper) =>
{
Console.WriteLine($"Reading from: {input.ReadDir}");
Console.WriteLine($"Writing to: {input.WriteDir}");
Console.WriteLine($"Globs: {input.Globs}");
Console.WriteLine($"Config: {input.Config}");
// Always return WriteDir
return new ProcessorOutput { Directory = input.WriteDir };
});

ProcessorOutput

The return value from the processor handler.

Definition

interface ProcessorOutput {
directory: string;
}

Properties

Prop

Type

Usage

StartProcessorWithLambda(async (input, fileHelper) => {
// ... processing ...
// Must return the write directory
return { directory: input.writeDir };
});
async def handler(input, file_helper):
# ... processing ...
# Must return the write directory
return {"directory": input.write_dir}
await Processor.StartAsync(async (input, fileHelper) =>
{
// ... processing ...
// Must return the write directory
return new ProcessorOutput { Directory = input.WriteDir };
});

CyanGlob

Defines which files to process.

Definition

interface CyanGlob {
root?: string | null;
glob: string;
exclude: string[];
type: GlobType;
}

Properties

Prop

Type

Examples

// All files in templates directory
{ root: 'templates', glob: '**/*', exclude: [], type: GlobType.Template }
// Only markdown files
{ root: 'docs', glob: '**/*.md', exclude: [], type: GlobType.Template }
// TypeScript files excluding tests
{
root: 'src',
glob: '**/*.ts',
exclude: ['**/*.test.ts', '**/*.spec.ts'],
type: GlobType.Template
}
// Multiple patterns (as array element)
[
{ root: 'src', glob: '**/*.ts', exclude: [], type: GlobType.Template },
{ root: 'styles', glob: '**/*.css', exclude: [], type: GlobType.Template }
]

GlobType

Enum defining the type of glob operation.

Definition

enum GlobType {
Template = 0,
Copy = 1
}

Values

Prop

Type

Glob Syntax

Prop

Type


Config Type

The config property is typed as unknown. Cast to your expected type:

Definitions

// In your processor
interface MyProcessorConfig {
// Define expected config shape
transformType: 'uppercase' | 'lowercase';
includeHeader: boolean;
customPrefix?: string;
}
StartProcessorWithLambda(async (input, fileHelper) => {
// Cast to your type
const config = input.config as MyProcessorConfig;
// Or provide defaults
const config: MyProcessorConfig = {
transformType: 'uppercase',
includeHeader: false,
...(input.config as Partial<MyProcessorConfig>)
};
});
from dataclasses import dataclass
from typing import Optional, Literal
# In your processor
@dataclass
class MyProcessorConfig:
# Define expected config shape
transform_type: Literal['uppercase', 'lowercase']
include_header: bool
custom_prefix: Optional[str] = None
async def handler(input, file_helper):
# Cast to your type with defaults
config_data = input.config or {}
config = MyProcessorConfig(
transform_type=config_data.get('transform_type', 'uppercase'),
include_header=config_data.get('include_header', False),
custom_prefix=config_data.get('custom_prefix')
)
// In your processor
public class MyProcessorConfig
{
// Define expected config shape
public string TransformType { get; set; } = "uppercase";
public bool IncludeHeader { get; set; } = false;
public string? CustomPrefix { get; set; }
}
await Processor.StartAsync(async (input, fileHelper) =>
{
// Deserialize JSON config into your type
var config = input.Config.Deserialize<MyProcessorConfig>() ?? new MyProcessorConfig();
});

Complex Config

interface ProcessorConfig {
// Simple types
enabled: boolean;
maxSize: number;
outputPath: string;
// Arrays
includePatterns: string[];
// Nested objects
formatting: {
indent: number;
newline: 'lf' | 'crlf';
};
// Optional properties
customHandler?: string;
}
from dataclasses import dataclass
from typing import Optional, List
@dataclass
class FormattingConfig:
indent: int
newline: str # 'lf' or 'crlf'
@dataclass
class ProcessorConfig:
# Simple types
enabled: bool
max_size: int
output_path: str
# Arrays
include_patterns: List[str]
# Nested objects
formatting: FormattingConfig
# Optional properties
custom_handler: Optional[str] = None
public class FormattingConfig
{
public int Indent { get; set; }
public string Newline { get; set; } // "lf" or "crlf"
}
public class ProcessorConfig
{
// Simple types
public bool Enabled { get; set; }
public int MaxSize { get; set; }
public string OutputPath { get; set; }
// Arrays
public List<string> IncludePatterns { get; set; }
// Nested objects
public FormattingConfig Formatting { get; set; }
// Optional properties
public string? CustomHandler { get; set; }
}

Full Example

import { StartProcessorWithLambda } from '@atomicloud/cyan-sdk';
// Define your config type
interface MarkdownConfig {
generateToc: boolean;
headingAnchors: boolean;
maxDepth?: number;
}
StartProcessorWithLambda(async (input, fileHelper) => {
// Parse config with defaults
const config: MarkdownConfig = {
generateToc: false,
headingAnchors: true,
...(input.config as Partial<MarkdownConfig>)
};
// Log input information
console.log('Processor Input:');
console.log(' Read directory:', input.readDir);
console.log(' Write directory:', input.writeDir);
console.log(' Globs:', JSON.stringify(input.globs, null, 2));
console.log(' Config:', JSON.stringify(config, null, 2));
// Load files based on globs
const files = fileHelper.resolveAll();
// Process files
files.forEach(file => {
if (config.generateToc) {
file.content = addTableOfContents(file.content, config.maxDepth);
}
if (config.headingAnchors) {
file.content = addHeadingAnchors(file.content);
}
file.writeFile();
});
// Return output
return { directory: input.writeDir };
});
import json
from dataclasses import dataclass
from typing import Optional
from atomicloud_cyan_sdk import start_processor_with_lambda
# Define your config type
@dataclass
class MarkdownConfig:
generate_toc: bool = False
heading_anchors: bool = True
max_depth: Optional[int] = None
async def handler(input, file_helper):
# Parse config with defaults
config_data = input.config or {}
config = MarkdownConfig(
generate_toc=config_data.get('generate_toc', False),
heading_anchors=config_data.get('heading_anchors', True),
max_depth=config_data.get('max_depth')
)
# Log input information
print("Processor Input:")
print(f" Read directory: {input.read_dir}")
print(f" Write directory: {input.write_dir}")
print(f" Globs: {json.dumps(input.globs, indent=2)}")
print(f" Config: {json.dumps(config.__dict__, indent=2)}")
# Load files based on globs
files = file_helper.resolve_all()
# Process files
for file in files:
if config.generate_toc:
file.content = add_table_of_contents(file.content, config.max_depth)
if config.heading_anchors:
file.content = add_heading_anchors(file.content)
file.write_file()
# Return output
return {"directory": input.write_dir}
start_processor_with_lambda(handler)
using AtomiLoud.CyanSdk;
using System.Text.Json;
// Define your config type
public class MarkdownConfig
{
public bool GenerateToc { get; set; } = false;
public bool HeadingAnchors { get; set; } = true;
public int? MaxDepth { get; set; }
}
await Processor.StartAsync(async (input, fileHelper) =>
{
// Deserialize config with defaults
var config = input.Config.Deserialize<MarkdownConfig>() ?? new MarkdownConfig();
// Log input information
Console.WriteLine("Processor Input:");
Console.WriteLine($" Read directory: {input.ReadDir}");
Console.WriteLine($" Write directory: {input.WriteDir}");
Console.WriteLine($" Globs: {JsonSerializer.Serialize(input.Globs, new JsonSerializerOptions { WriteIndented = true })}");
Console.WriteLine($" Config: {JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true })}");
// Load files based on globs
var files = fileHelper.ResolveAll();
// Process files
foreach (var file in files)
{
if (config.GenerateToc)
{
file.Content = AddTableOfContents(file.Content, config.MaxDepth);
}
if (config.HeadingAnchors)
{
file.Content = AddHeadingAnchors(file.Content);
}
file.WriteFile();
}
// Return output
return new ProcessorOutput { Directory = input.WriteDir };
});