casesOfModule method

List<ContractCase> casesOfModule(
  1. ModuleId id
)

The cases of the module id:

  • for each subset of the roles the module only uses, the largest first, one case for each combination of a provider of the role of its variants, of each role it requires and of each role of the subset, as <module> (<providers>) with <roles of the subset>, which names the providers of the roles that have several in the registry, such as home (bloc, firebase_analytics) with analytics. The providers of the role of its variants include those the module has no variant for, whose app the pipeline rejects. A combination is left out when two of its providers, or one of them and the module, with the modules they depend on, provide a role that takes one provider, as another router does for a module that depends on go_router: they cannot be in one app. When no combination of the subset can be in an app with the module, none is left out, so that its cases report why, such as when the module and the modules it depends on provide such a role twice by themselves, or when every provider of a role it requires brings another provider of a role that the module has through a module it depends on;
  • every provider of a role in the registry whose package the module contributes, itself or in a variant, and that can be in an app with the module, as <module> with <provider>, such as banner with bloc for a module without a role that contributes flutter_bloc. The case requests the provider, so its roles need no pick. With a provider of a role other than that of the variants of the module, there is a case for each variant that contributes the package, as <module> (<provider of the variant>) with <provider>, or for the first variant if only the module itself contributes it.

A package is a provider's when the provider contributes it itself, not in a variant, with a constraint of its own rather than any, and no module that the provider depends on, directly or not, contributes it so too. Another module takes such a package only in its variant for the provider, or for a provider that depends on it, or when it depends on the provider, and the pipeline checks that only in an app with the provider, which the last cases build. A provider can be in an app with the module when neither they nor the modules they depend on, directly or not, provide a role that takes one provider twice, and each of them that has variants has one for the provider of the role of its variants among them.

A role left out of a subset is still present when a module of the case brings it, such as a provider of several roles or a module that requires it. checkAll then leaves out the case, since the case of a larger subset built its app already and names the roles it has; so it does with a case with a provider whose app another case built.

Implementation

List<ContractCase> casesOfModule(ModuleId id) {
  final module = registry[id];
  if (module == null) throw ArgumentError.value(id, 'id', 'Not registered');
  final descriptor = module.descriptor;
  final used = [
    for (final role in descriptor.effectiveUses)
      if (registry.providersOf(role).isNotEmpty) role,
  ];
  final withDependencies = _withDependencies(module);
  return [
    for (final subset in _subsets(used))
      for (final picks in _fittingPicks(
        withDependencies,
        _picksOf([
          if (descriptor.variants case final variants?) variants.role,
          ...descriptor.effectiveRequires,
          ...subset,
        ]),
      ))
        _case(
          _caseName(id.value, picks, subset),
          [id],
          picks: picks,
          present: subset,
        ),
    ..._casesWithOwners(module),
  ];
}