@meticulous-home/espresso-profile-converter
v0.1.0
Published
Validate simplified espresso profiles and convert them to Meticulous node JSON.
Readme
@meticulous-home/espresso-profile-converter
A TypeScript/JavaScript library for:
- validating simplified JSON against the schema maintained in
../espresso-profile-schema - expanding
$...variables the same way the current backend does - converting simplified JSON into the node JSON currently produced by
profile_converter/
Installation
npm install @meticulous-home/espresso-profile-converterUsage
import {
convertSimplifiedToNodeProfile,
processVariables,
validateSimplifiedProfile,
} from "@meticulous-home/espresso-profile-converter";
const validation = validateSimplifiedProfile(profile);
if (!validation.valid) {
throw new Error(validation.errors.join("\n"));
}
const expanded = processVariables(profile);
const nodeProfile = convertSimplifiedToNodeProfile(expanded, {
clickToPurge: true,
endNodeHead: 1000,
initNodeTail: 7000,
allowStageSkipping: false,
partialRetraction: 45,
maxPistonPosition: 75,
validate: false,
processVariables: false,
});CLI
After building the package, you can convert a simplified profile from the command line:
npm run build
npm run convert -- ./test/fixtures/simplified-json-example.jsonTo write the result to a file instead of stdout:
npm run convert -- ./test/fixtures/simplified-json-example.json \
--output ./node-profile.jsonIf the package is installed globally or exposed through npx, the binary name is:
espresso-profile-convert ./profile.json --output ./node-profile.jsonAPI
validateSimplifiedProfile(profile): returns{ valid, errors }assertValidSimplifiedProfile(profile): throwsSchemaValidationErrorprocessVariables(profile): mirrorsProfilePreprocessor.processVariables(...)convertSimplifiedStagesToNodeStages(profile, options?): converts only the dynamic stagesconvertSimplifiedToNodeProfile(profile, options?): builds the full{ name, stages }node profile
Conversion Options
clickToPurge: defaulttrueendNodeHead: default1000initNodeTail: default7000allowStageSkipping: defaultfalsepartialRetraction: default45maxPistonPosition: default75validate: defaulttrueprocessVariables: defaulttrue
clickToStart is accepted by the interface for compatibility with the current Python signature, but it does not affect the output today because it is not used in profile_converter.py either.
Schema Sync
The package includes a copy of the schema so it can be published to npm independently. To sync it again from the sibling repository:
npm run sync:schemaThis copies ../../espresso-profile-schema/schema.json into src/schema/simplified-profile.schema.json.
