Skip to main content

@diby/openset-validator

A comprehensive validator for OpenSet documents, available as both a CLI tool and a programmatic API.

Installation

npm install @diby/openset-validator

CLI Usage

npx openset validate <file> [options]

Options

FlagDescription
--summaryShow document summary (counts of blocks, series, exercises, sets)
--verboseShow all details including passing checks
--jsonOutput results as JSON

Example Output

openset_version: 1.0
type: workout
2 blocks, 4 series, 12 exercises, 31 sets

ERRORS (1):
E003 blocks[0].series[1].exercises[0].sets[2]
dimensions declares "reps" but field is missing from set

WARNINGS (2):
W003 blocks[1].series[0].exercises[2]
exercise_id "chest_press" not found in the provided library

Result: INVALID

Programmatic API

import { validate } from '@diby/openset-validator';

const document = {
openset_version: '1.0',
type: 'workout',
blocks: [/* ... */]
};

const result = validate(document);

console.log(result.valid); // true or false
console.log(result.errors); // ValidationMessage[]
console.log(result.warnings); // ValidationMessage[]

By default, the validator checks structure and semantics only. If you also want exercise_id membership checks, pass a library explicitly.

Options

const result = validate(document, {
library: customExerciseLibrary // Enable exercise_id membership checks for this library
});

Validation Rules

Errors

CodeDescription
E001Unknown dimension name in dimensions array
E002Removed
E003Dimension declared in dimensions array but missing from set
E004Removed
E005Invalid value type for dimension
E006Range min must be less than max
E007Invalid value type used on dimension
E008sides value must be 1 or 2
E009heart_rate_zone must be 1-5
E010rpe must be 1-10
E011group only valid in CLUSTER execution mode
E012Conflicting dimensions on same set (e.g. pace + speed)
E013Unknown dimension without a valid namespace prefix
E014Unsupported major version
E015Extension field has invalid value (must be a ValueObject)

Warnings

CodeDescription
W001Set rest_after overrides series rest
W002rest_after on non-last exercise in a CLUSTER group
W003exercise_id not found in provided library
W004Exercise has no exercise_id and no name
W005CLUSTER mode but no group fields
W006Workout has no date field
W007Load is a range but rpe is absent
W008Uneven set counts in non-SEQUENTIAL series
W009Extension field detected
W010Document minor version newer than validator minor version

Version Handling

The validator checks openset_version on every document:

  • Same major, same or older minor (e.g. 1.0) — validates normally
  • Same major, newer minor (e.g. 1.1) — validates with W010 warning, continues checking all rules
  • Different major (e.g. 2.0) — E014 error, stops validation immediately

This ensures forward compatibility: a v1.0 validator can still validate v1.1 documents (with a warning about potentially unvalidated features), while rejecting incompatible major versions.

Supported Document Types

The validator supports all four OpenSet document types:

  • workout — Standalone workout documents
  • program — Multi-phase training programs
  • exercise_library — Exercise definition collections
  • workout_library — Reusable workout template collections

For workout library documents, inner workouts are validated using the same rules as standalone workouts. W006 ("Workout has no date") is suppressed for library workouts since they are templates without a scheduled date.