@logarys/pipeline-validator
v0.2.0
Published
Validation helpers for Logarys pipeline runtime JSON configuration.
Downloads
316
Maintainers
Readme
@logarys/pipeline-validator
Validation helpers for Logarys pipeline runtime JSON configuration.
This package centralizes pipeline checks shared by Logarys applications:
- JSON syntax check
- required object checks
- required field checks
- parser type validation aligned with the ingestor (
raw,json,regex,loki) - regex syntax check
- ingestor pipeline field compatibility checks
- normalization of
parser.regextoparser.pattern
Install
npm install @logarys/pipeline-validatorUsage
import {
parsePipelineJson,
validatePipelineConfig,
normalizePipelineConfig,
} from "@logarys/pipeline-validator";
const result = parsePipelineJson(`{
"parser": {
"type": "loki"
},
"defaults": {
"source": "locafire-docker"
},
"publish": {
"subject": "logs.locafire-docker.normalized"
},
"security": {
"mode": "none"
}
}`);
if (!result.valid) {
console.error(result.errors);
} else {
console.log(result.value);
}Runtime config schema
A runtime config block must contain these required objects:
{
"parser": {},
"publish": {}
}Required fields:
parser.type
publish.subjectSupported parser types:
raw
json
regex
lokiFor regex pipelines:
parser.patternparser.regex is accepted for legacy configs and normalized to parser.pattern.
Optional objects:
mapping
mapping.timestamp
mapping.level
mapping.message
mapping.source
mapping.host
mapping.service
mapping.env
defaults
defaults.source
defaults.host
defaults.service
defaults.env
security
security.mode
security.tokenSupported security modes:
none
header
queryFull pipeline document validation
const result = validatePipelineConfig(pipeline, {
document: true,
requireDocumentFields: true,
});This also allows and checks:
id
source
enabledIngestor compatibility
The validator follows the ingestor pipeline conventions:
mappingis a top-level object, singular, notmappingsdefaultsis optional and contains onlysource,host,service,envsecurityis optional and containsmodeand optionaltokenparser.typemust be one ofraw,json,regex,loki- the legacy misspelling
lokkiis not accepted
The validator rejects fields that are not part of this schema, for example:
name
mappings
parser.mappings
mapping.environment
defaults.environment
defaults.job
defaults.levelAPI
parsePipelineJson(json, options?)
Parses JSON and validates the resulting object.
validatePipelineConfig(value, options?)
Validates an already parsed object.
normalizePipelineConfig(config)
Normalizes legacy accepted fields, currently:
parser.regex -> parser.patternisValidPipelineConfig(value, options?)
Boolean shortcut.
Validation result
type ValidationResult<T = unknown> = {
valid: boolean;
errors: ValidationIssue[];
warnings: ValidationIssue[];
value?: T;
};