Refactor flat entity maps to be universal oriented (#17665)

# Introduction
In preparation of the workspace agnostic builder, we're migrating
`FlatEntityMaps` to be universal identifier oriented and based
As in the builder context there're won't be any ids at all
Please also note that the FlatEntity is a UniversalFlatEntity superset

From
```ts
import { type SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-from.type';

export type FlatEntityMaps<T extends SyncableFlatEntity> = {
  byId: Partial<Record<string, T>>;
  idByUniversalIdentifier: Partial<Record<string, string>>;
  universalIdentifiersByApplicationId: Partial<Record<string, string[]>>;
};
```

To
```ts
export type FlatEntityMaps<
  T extends SyncableFlatEntity | UniversalSyncableFlatEntity,
> = {
  byUniversalIdentifier: Partial<Record<string, T>>;
  universalIdentifierById: Partial<Record<string, string>>;
  universalIdentifiersByApplicationId: Partial<Record<string, string[]>>; // this might make more sense to be migrated to universalIdentifiersByApplicationUniversalIdentifier but it's the main topic of this PR
};
```

## Low level maps tools
Had to refactor find | create | delete | replace | find-many | get-sub
tools ( through mutations and or throw equivalent )
This commit is contained in:
Paul Rastoin
2026-02-03 17:16:02 +01:00
committed by GitHub
parent 43042d55b2
commit 476bdf764c
202 changed files with 1853 additions and 909 deletions
@@ -45,7 +45,9 @@ export class RowLevelPermissionPredicateGroupService {
},
);
return Object.values(flatRowLevelPermissionPredicateGroupMaps.byId)
return Object.values(
flatRowLevelPermissionPredicateGroupMaps.byUniversalIdentifier,
)
.filter(isDefined)
.filter((group) => group.deletedAt === null)
.sort(
@@ -75,7 +77,9 @@ export class RowLevelPermissionPredicateGroupService {
},
);
return Object.values(flatRowLevelPermissionPredicateGroupMaps.byId)
return Object.values(
flatRowLevelPermissionPredicateGroupMaps.byUniversalIdentifier,
)
.filter(isDefined)
.filter((group) => group.deletedAt === null && group.roleId === roleId)
.sort(
@@ -60,7 +60,9 @@ export class RowLevelPermissionPredicateService {
},
);
return Object.values(flatRowLevelPermissionPredicateMaps.byId)
return Object.values(
flatRowLevelPermissionPredicateMaps.byUniversalIdentifier,
)
.filter(isDefined)
.filter((predicate) => predicate.deletedAt === null)
.sort(
@@ -91,7 +93,9 @@ export class RowLevelPermissionPredicateService {
},
);
return Object.values(flatRowLevelPermissionPredicateMaps.byId)
return Object.values(
flatRowLevelPermissionPredicateMaps.byUniversalIdentifier,
)
.filter(isDefined)
.filter(
(predicate) =>
@@ -173,7 +177,7 @@ export class RowLevelPermissionPredicateService {
);
const existingPredicates = Object.values(
flatRowLevelPermissionPredicateMaps.byId,
flatRowLevelPermissionPredicateMaps.byUniversalIdentifier,
)
.filter(isDefined)
.filter(
@@ -184,7 +188,7 @@ export class RowLevelPermissionPredicateService {
);
const existingGroups = Object.values(
flatRowLevelPermissionPredicateGroupMaps.byId,
flatRowLevelPermissionPredicateGroupMaps.byUniversalIdentifier,
)
.filter(isDefined)
.filter(
@@ -239,7 +243,9 @@ export class RowLevelPermissionPredicateService {
},
);
const resultPredicates = Object.values(updatedPredicateMaps.byId)
const resultPredicates = Object.values(
updatedPredicateMaps.byUniversalIdentifier,
)
.filter(isDefined)
.filter(
(predicate) =>
@@ -249,7 +255,7 @@ export class RowLevelPermissionPredicateService {
)
.map(fromFlatRowLevelPermissionPredicateToDto);
const resultGroups = Object.values(updatedGroupMaps.byId)
const resultGroups = Object.values(updatedGroupMaps.byUniversalIdentifier)
.filter(isDefined)
.filter(
(group) =>
@@ -295,8 +301,10 @@ export class RowLevelPermissionPredicateService {
inputGroupIds.add(groupId);
const existingGroup =
flatRowLevelPermissionPredicateGroupMaps.byId[groupId];
const existingGroup = findFlatEntityByIdInFlatEntityMaps({
flatEntityId: groupId,
flatEntityMaps: flatRowLevelPermissionPredicateGroupMaps,
});
if (isDefined(existingGroup) && existingGroup.deletedAt === null) {
groupsToUpdate.push({
@@ -377,8 +385,10 @@ export class RowLevelPermissionPredicateService {
inputPredicateIds.add(predicateId);
const existingPredicate =
flatRowLevelPermissionPredicateMaps.byId[predicateId];
const existingPredicate = findFlatEntityByIdInFlatEntityMaps({
flatEntityId: predicateId,
flatEntityMaps: flatRowLevelPermissionPredicateMaps,
});
if (
isDefined(existingPredicate) &&