feat(registry): validate unique addresses and routes

This commit was merged in pull request #66.
This commit is contained in:
2026-08-25 22:29:56 -04:00
parent f45aa44ead
commit 48d9d3280f
5 changed files with 117 additions and 69 deletions

View File

@@ -16,26 +16,37 @@ let
nameValuePair
removeSuffix
types
unique
;
assertionType = types.submodule {
checkType = types.submodule {
options = {
assertion = mkOption {
type = types.bool;
type = types.functionTo types.bool;
description = ''
Whether this registry validation assertion passed.
Predicate run against this registry's flattened collected entries.
'';
};
message = mkOption {
type = types.str;
description = ''
Error message shown when this registry validation assertion fails.
Error message shown when this registry validation check fails.
'';
};
};
};
predicates = {
uniqueValue = value: entries: builtins.length (unique (map value entries)) == builtins.length entries;
};
registryLib = lib // {
registry = (lib.registry or { }) // {
inherit predicates;
};
};
registryDefinitionModule = {
options = {
type = mkOption {
@@ -53,11 +64,11 @@ let
'';
};
validate = mkOption {
type = types.functionTo (types.listOf assertionType);
default = _entries: [ ];
checks = mkOption {
type = types.listOf checkType;
default = [ ];
description = ''
Validate this registry's flattened collected entries.
Validation checks for this registry's flattened collected entries.
'';
};
};
@@ -76,7 +87,7 @@ let
mkRegistry = path:
let
evaluated = lib.evalModules {
specialArgs = { inherit lib; };
specialArgs.lib = registryLib;
modules = [
registryDefinitionModule
path
@@ -84,7 +95,7 @@ let
};
in
{
inherit (evaluated.config) type replicate validate;
inherit (evaluated.config) type replicate checks;
};
definitions = mapAttrs' (
@@ -149,7 +160,13 @@ let
concatLists (
mapAttrsToList (
registryName: registry:
registry.validate (flattenRegistryEntries registryName data.${registryName})
let
entries = flattenRegistryEntries registryName data.${registryName};
in
map (check: {
assertion = check.assertion entries;
inherit (check) message;
}) registry.checks
) definitions
);
@@ -189,7 +206,7 @@ let
};
in
{
inherit definitions;
inherit definitions predicates;
module = {
options.registry = mapAttrs (_name: registry: registryOption registry) definitions;