nartc / mapper

🔥 An Object-Object AutoMapper for TypeScript 🔥
https://automapperts.netlify.app/
MIT License
985 stars 87 forks source link

feat(core) Add beforeMapArray and afterMapArray configs #618

Open koenigstag opened 7 months ago

koenigstag commented 7 months ago

Description

For cases when we need to map an array of values - existing afterMap is not called for optimization purposes.

So I've decided to add new map configurations such as beforeMapArray and afterMapArray.

They are intended to work like beforeMap/afterMap configurations, but are executed only in mapArray and mutateArray methods. These callbacks would receive an array of sources and array of destination objects, respectively.

Types

export type Mapping<
    TSource extends Dictionary<TSource> = any,
    TDestination extends Dictionary<TDestination> = any
> = [
  // ...
  callbacks?: [
      beforeMap?: MapCallback<TSource, TDestination>,
      afterMap?: MapCallback<TSource, TDestination>,
      beforeMapArray?: MapCallback<TSource[], TDestination[]>,
      afterMapArray?: MapCallback<TSource[], TDestination[]>,
  ],
  // ...
];

Checklist

sonarcloud[bot] commented 6 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.9% Duplication on New Code

See analysis details on SonarCloud