upmind / provision-validation-conformance
Validation conformance cases for Upmind provision data sets
Package info
github.com/upmind/provision-validation-conformance
Language:JavaScript
pkg:composer/upmind/provision-validation-conformance
Requires
None
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-27 13:17:57 UTC
README
This package defines the expected behaviour of every validation rule that
upmind/provision-provider-base
data sets can use. Every validator implementation must pass every case.
The expected results are the results of the Laravel validator, which
upmind/provision-provider-base uses. A case that looks wrong can be Laravel
behaviour: e.g. before passes for a value which is not a date.
The package contains data, a schema and checks. It contains no validator code. Each consumer keeps its own runner.
rules.json lists the supported rules. Each supported rule has one case file,
validation/<rule>.json.
Install
composer require --dev upmind/provision-validation-conformance npm install --save-dev @upmind/provision-validation-conformance
Both packages have the same content and the same version.
Case file format
schema.json is the JSON Schema of a case file.
{
"rule": "max",
"cases": [
{
"name": "string at the maximum length",
"rules": { "value": ["string", "max:3"] },
"data": { "value": "abc" },
"valid": true
},
{
"name": "string over the maximum length",
"rules": { "value": ["string", "max:3"] },
"data": { "value": "abcd" },
"valid": false,
"failed": { "value": ["max"] }
}
]
}
rule: the canonical rule name. It is the same as the file name.name: the case name. It is unique in the file.ruleandnametogether identify the case.rules: the rules of each field. Each value is a list of rule strings. Field names can use dot notation and*wildcards.data: the input data. A field that is not indatais missing.valid: whether the data passes all rules.failed: for invalid cases only. The rules that fail, per field. The order is not significant.
Supported rules
rules.json is the list of rules that data sets can use:
rules: the canonical names of the supported rules. Each rule needs only the input data. No rule reads a database, the authenticated user or uploaded files.aliases: other names of supported rules.
Validators must reject every rule which is not in the list.
Rule names
A rule string is name or name:parameters. The canonical name is snake case.
Validators must accept - in place of _, e.g. alpha-dash, and the aliases
in rules.json.
Determinism
- Cases do not depend on the current date, the network, a database or files.
- Date cases use fixed dates. Date rules also accept relative dates such as
today. Cases do not use them. regexpatterns use PCRE syntax.emailwith thednsparameter does a DNS lookup. Cases do not use it.country_codeandinternational_phonedepend on ISO 3166 and phone number metadata.timezonedepends on the time zone database. Cases use stable values.
Write a runner
Read every validation/*.json file from the installed package:
- Composer:
vendor/upmind/provision-validation-conformance/validation - npm:
node_modules/@upmind/provision-validation-conformance/validation
For each case:
- Validate
dataagainstrules. - Get the canonical names of the failed rules, per field.
- The case conforms if the result equals
validand the failed rules equalfailed. Ignore the order. A valid case has no failed rules. An error, e.g. an exception, does not conform.
Also check that your validator supports every rule in rules.json and rejects
every other rule.
Add or change cases
-
Edit
validation/<rule>.json. Keep the keysname,rules,data,validfirst, in that order. For a new rule, also add it torules.json. -
Run the checks:
npm ci npm test -
Add a line to
CHANGELOG.md.
Do not rename a case without a reason. Runners refer to cases by rule and
name.
License
GPL-3.0-only. See LICENSE.