Skip to content

Commit

Permalink
Support setting record type(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed Jan 14, 2024
1 parent d36155b commit 5dcd616
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## 0.6.1 - 2024-01-14

- Support setting record type(s)
- Extend error messages
- Fix Avram version number

## 0.6.0 - 2024-01-13

- Update metaschema and validation rules to Avram 0.9.5
Expand Down
1 change: 1 addition & 0 deletions bin/avram.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cli.usage("avram [options] [validation options] <schema> [<files...>]")
.description("Validate file(s) with an Avram schema")
.option(`-f, --format [name] input format (${Object.keys(formats).join("|")})`)
.option("-s, --schema validate schema instead of record files")
.option("-t, --type [types] specify comma-separated record type(s)")
.option("-p, --print print all input records (in JSON)")
.option("-v, --verbose verbose error messages")
.option("-l, --list list supported validation options")
Expand Down
8 changes: 6 additions & 2 deletions lib/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export default async (args, opt) => {
throw new Error(`Unknown or unsupported format '${opt.format}'`)
}

const schemaFile = opt.schema && !files.length ? "/dev/stdin" : files.shift()
const types = typeof opt.type == "string" ? opt.type.split(",") : []

const schemaFile = (opt.schema && !files.length) ? "/dev/stdin" : files.shift()
if (schemaFile === undefined) throw new Error("Missing schema argument")
const schema = loadSchema(schemaFile, opt)

const validator = new Validator(schema, options)
Expand All @@ -83,7 +86,8 @@ export default async (args, opt) => {
const input = file === "-" ? process.stdin : fs.createReadStream(file)
const stream = format.stream(input) // TODO: marcxml parser should emit error on parsing error

stream.on("data", record => {
stream.on("data", fields => {
const record = { fields, types }
const errors = validator.validate(record)
errors.forEach(e => {
if (file !== "-") {
Expand Down

0 comments on commit 5dcd616

Please sign in to comment.