normalizeFields

Source
import { normalizeFields } from "@prestojs/viewmodel";
normalizeFields(modelClass,fieldNames)

Takes an array of field paths for a model class and returns a normalized version in the form of ViewModelFieldPaths.

Note that ViewModelFieldPaths can be compared with normal equality operators - they are cached internally so a single instance exists for each unique fieldNames

Normalization means:

  • Id fields are always included
  • Expands a related field to include all it's subfields
  • If a related field is referenced ensures the related field sourceFieldName is included
  • Sorts field names consistently
ParameterTypeDescription
*modelClassViewModel Class

The ViewModel class the fields are from

*fieldNames'*'|[string|string[]][]

The array of field paths to normalize