refactor: rename getSubModules to submodules for types

BREAKING: The previous implementation was created with the assumption
that this submodules property would be a function in some cases. As it
turns out this was not necessary and the name became confusing as
"getSubModules" does not read as "this is a list" to the user. It has
been renamed to "submodules" instead.
This commit is contained in:
Jake Hamilton 2025-03-11 22:49:24 -07:00
parent 397419d8ab
commit 5fc4fd1b5c
Signed by: jakehamilton
GPG key ID: 9762169A1B35EA68
3 changed files with 20 additions and 20 deletions
lib/src

View file

@ -100,7 +100,7 @@ lib: {
## @type List String -> Option -> Option
fixup =
location: option:
if option.type.getSubModules or null == null then
if option.type.submodules or null == null then
option // { type = option.type or lib.types.unspecified; }
else
option

View file

@ -106,13 +106,13 @@ lib: {
typeSet = lib.attrs.when ((shared "type") && isTypeMergeable) { type = mergedType; };
files = result.declarations;
serializedFiles = builtins.concatStringsSep " and " files;
getSubModules = option.options.type.getSubModules or null;
typeSubmodules = option.options.type.submodules or null;
submodules =
if getSubModules != null then
if typeSubmodules != null then
builtins.map (module: {
__file__ = option.__file__;
includes = [ module ];
}) getSubModules
}) typeSubmodules
++ result.options
else
result.options;

View file

@ -58,7 +58,7 @@ lib: {
functor ? lib.types.functor name,
mergeType ? lib.types.merge functor,
getSubOptions ? lib.fp.const { },
getSubModules ? null,
submodules ? null,
withSubModules ? lib.fp.const null,
children ? { },
}:
@ -73,7 +73,7 @@ lib: {
functor
mergeType
getSubOptions
getSubModules
submodules
withSubModules
children
;
@ -490,7 +490,7 @@ lib: {
in
builtins.mapAttrs (name: value: value.value) filtered;
getSubOptions = prefix: type.getSubOptions (prefix ++ [ "<name>" ]);
getSubModules = type.getSubModules;
submodules = type.submodules;
withSubModules = modules: lib.types.attrs.of (type.withSubModules modules);
functor = lib.types.functor "attrs.of" // {
wrapped = type;
@ -533,7 +533,7 @@ lib: {
in
builtins.zipAttrsWith zipper normalized;
getSubOptions = prefix: type.getSubOptions (prefix ++ [ "<name>" ]);
getSubModules = type.getSubModules;
submodules = type.submodules;
withSubModules = modules: lib.types.attrs.lazy (type.withSubModules modules);
functor = lib.types.functor "attrs.lazy" // {
wrapped = type;
@ -631,7 +631,7 @@ lib: {
in
values;
getSubOptions = prefix: type.getSubOptions (prefix ++ [ "*" ]);
getSubModules = type.getSubModules;
submodules = type.submodules;
withSubModules = modules: lib.types.list.of (type.withSubModules modules);
functor = lib.types.functor "list.of" // {
wrapped = type;
@ -665,7 +665,7 @@ lib: {
check = type.check;
merge = lib.options.merge.unique message;
getSubOptions = type.getSubOptions;
getSubModules = type.getSubModules;
submodules = type.submodules;
withSubModules = modules: lib.types.unique message (type.withSubModules modules);
functor = lib.types.functor "unique" // {
wrapped = type;
@ -688,7 +688,7 @@ lib: {
check = type.check;
merge = lib.options.merge.one;
getSubOptions = type.getSubOptions;
getSubModules = type.getSubModules;
submodules = type.submodules;
withSubModules = modules: lib.types.single (type.withSubModules modules);
functor = lib.types.functor "unique" // {
wrapped = type;
@ -725,7 +725,7 @@ lib: {
else
type.merge location definitions;
getSubOptions = type.getSubOptions;
getSubModules = type.getSubModules;
submodules = type.submodules;
withSubModules = modules: lib.types.nullish (type.withSubModules modules);
functor = lib.types.functor "nullish" // {
wrapped = type;
@ -756,7 +756,7 @@ lib: {
in
merged.merged;
getSubOptions = prefix: type.getSubOptions (prefix ++ [ "<function body>" ]);
getSubModules = type.getSubModules;
submodules = type.submodules;
withSubModules = modules: lib.types.function (type.withSubModules modules);
functor = lib.types.functor "function" // {
wrapped = type;
@ -853,7 +853,7 @@ lib: {
in
result.options
// lib.attrs.when (freeform != null) { __freeformOptions__ = freeform.getSubOptions prefix; };
getSubModules = modules;
submodules = modules;
withSubModules =
modules:
lib.types.submodules.of {
@ -1046,7 +1046,7 @@ lib: {
}) definitions;
};
getSubOptions = submodule.getSubOptions;
getSubModules = submodule.getSubModules;
submodules = submodule.submodules;
withSubModules = modules: lib.types.deferred.of { modules = modules; };
functor = lib.types.functor "deferred.of" // {
type = lib.types.deferred.of;
@ -1190,7 +1190,7 @@ lib: {
initial: transform: final:
let
in
if initial.getSubModules != null then
if initial.submodules != null then
builtins.throw "lib.types.coerce's first argument may not have submodules, but got ${initial.description}"
else
lib.types.create {
@ -1207,7 +1207,7 @@ lib: {
in
final.merge location normalized;
getSubOptions = final.getSubOptions;
getSubModules = final.getSubModules;
submodules = final.submodules;
withSubModules = modules: lib.types.coerce initial transform (final.withSubModules modules);
mergeType = x: y: null;
functor = lib.types.functor "coerce" // {
@ -1226,7 +1226,7 @@ lib: {
initial: transform: final:
let
in
if initial.getSubModules != null then
if initial.submodules != null then
builtins.throw "lib.types.coerceWithLocation's first argument may not have submodules, but got ${initial.description}"
else
lib.types.create {
@ -1243,7 +1243,7 @@ lib: {
in
final.merge location normalized;
getSubOptions = final.getSubOptions;
getSubModules = final.getSubModules;
submodules = final.submodules;
withSubModules =
modules: lib.types.coerceWithLocation initial transform (final.withSubModules modules);
mergeType = x: y: null;
@ -1271,7 +1271,7 @@ lib: {
merge = resolved.merge;
fallback = resolved.fallback;
getSubOptions = prefix: type.getSubOptions (prefix ++ [ "<name>" ]);
getSubModules = type.getSubModules;
submodules = type.submodules;
withSubModules = modules: lib.types.dag.of (type.withSubModules modules);
functor = lib.types.functor "dag.of" // {
wrapped = type;