resolve static method

RiverpodCraftOptions resolve({
  1. String? errorMapperPath,
  2. String? errorMapperContent,
  3. String? pagedMapperPath,
  4. String? pagedMapperContent,
})

Parses both mapper sources. Pure — no filesystem, no globals — so the caller can cache the result by source content.

Implementation

static RiverpodCraftOptions resolve({
  String? errorMapperPath,
  String? errorMapperContent,
  String? pagedMapperPath,
  String? pagedMapperContent,
}) {
  final error = errorMapperContent == null
      ? null
      : _findFunction(errorMapperContent, 'errorMapper');
  final paged = pagedMapperContent == null
      ? null
      : _findFunction(pagedMapperContent, 'pagedMapper');

  // The paths are only carried when the function was actually found.
  // `hasErrorMapper`/`hasPagedMapper` key off them, and a path without a
  // resolved function would make the generator emit calls to a mapper whose
  // definition never gets inlined.
  return RiverpodCraftOptions(
    errorMapperPath: error == null ? null : errorMapperPath,
    errorMapperSource: error?.toSource().replaceFirst(
      'errorMapper',
      RiverpodCraftOptions.errorMapperInlineName,
    ),
    errorMapperOutputType: error?.returnType?.toSource(),
    pagedMapperPath: paged == null ? null : pagedMapperPath,
    pagedMapperSource: paged?.toSource(),
    pagedMapperInputType: _firstParamType(paged),
  );
}