npm.io
11.8.1 • Published 5d agoCLI

@codaco/protocol-validation

Licence
GPL-3.0-or-later
Version
11.8.1
Deps
3
Size
1.8 MB
Vulns
0
Weekly
0
Stars
2

@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:

  1. validateSchema - validates a schema against the JSON schema
const { hasErrors, errors } = validateSchema(schemaJson);
  1. 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);
  1. 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.

  1. migrateProtocol - migrates protocols from one version to another
const migratedProtocol = migrateProtocol(8, protocolJson);
  1. canUpgrade - checks if protocol can be upgraded from one schema version to another
const canProtocolUpgrade = canUpgrade(7, 8);
  1. getMigrationNotes - returns migration notes on the changes between a source schema version and a target schema version.
const migrationNotes = getMigrationNotes(7, 8);
  1. getVariableNamesFromNetwork - returns variable names from an external network data source
const variableNames = getVariableNamesFromNetwork(network);
  1. validateNames - validates variable names to ensure they only contain letters, numbers, and the symbols ._-:
const validationResult = validateNames(variableNamesArray);