@codaco/protocol-validation
v8.0.1
Published
Utilities for validating and migrating Network Canvas protocol files.
Readme
@codaco/protocol-validation
This npm package implements methods for validating Network Canvas protocol files against an appropriate JSON schema.
It exports three primary methods for protocol validation:
- validateSchema - validates a schema against the JSON schema
const { hasErrors, errors } = validateSchema(schemaJson);- validateLogic - validates the logic of the protocol to ensure there are no inconsistencies. This includes validations that cannot be implemented within the JSON schema.
const { hasErrors, errors } = validateLogic(protocolJson);- validateProtocol - validates the protocol against the schema and logic.
const result = await validateProtocol(protocolJson);
if (result.success) {
// protocol is valid, validated data available in result.data
} else {
// protocol is invalid
// result.error contains the Zod error
console.error(result.error);
}It also exports several utility methods for managing protocol validation.
- migrateProtocol - migrates protocols from one version to another
const migratedProtocol = migrateProtocol(8, protocolJson);- canUpgrade - checks if protocol can be upgraded from one schema version to another
const canProtocolUpgrade = canUpgrade(7, 8);- getMigrationNotes - returns migration notes on the changes between a source schema version and a target schema version.
const migrationNotes = getMigrationNotes(7, 8);- getVariableNamesFromNetwork - returns variable names from an external network data source
const variableNames = getVariableNamesFromNetwork(network);- validateNames - validates variable names to ensure they only contain letters, numbers, and the symbols ._-:
const validationResult = validateNames(variableNamesArray);