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
@@ -5,6 +5,7 @@ import {
} from 'twenty-shared/utils';
import { type FlatPageLayoutTabMaps } from 'src/engine/metadata-modules/flat-page-layout-tab/types/flat-page-layout-tab-maps.type';
import { findFlatEntityByIdInFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps.util';
import { type FlatPageLayoutTab } from 'src/engine/metadata-modules/flat-page-layout-tab/types/flat-page-layout-tab.type';
import {
PageLayoutTabException,
@@ -27,8 +28,12 @@ export const fromDestroyPageLayoutTabInputToFlatPageLayoutTabOrThrow = ({
['id'],
);
const existingFlatPageLayoutTabToDestroy =
flatPageLayoutTabMaps.byId[pageLayoutTabId];
const existingFlatPageLayoutTabToDestroy = findFlatEntityByIdInFlatEntityMaps(
{
flatEntityId: pageLayoutTabId,
flatEntityMaps: flatPageLayoutTabMaps,
},
);
if (!isDefined(existingFlatPageLayoutTabToDestroy)) {
throw new PageLayoutTabException(
@@ -5,6 +5,7 @@ import {
} from 'twenty-shared/utils';
import { FLAT_PAGE_LAYOUT_TAB_EDITABLE_PROPERTIES } from 'src/engine/metadata-modules/flat-page-layout-tab/constants/flat-page-layout-tab-editable-properties.constant';
import { findFlatEntityByIdInFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps.util';
import { type FlatPageLayoutTabMaps } from 'src/engine/metadata-modules/flat-page-layout-tab/types/flat-page-layout-tab-maps.type';
import { type FlatPageLayoutTab } from 'src/engine/metadata-modules/flat-page-layout-tab/types/flat-page-layout-tab.type';
import { type UpdatePageLayoutTabInput } from 'src/engine/metadata-modules/page-layout-tab/dtos/inputs/update-page-layout-tab.input';
@@ -31,8 +32,10 @@ export const fromUpdatePageLayoutTabInputToFlatPageLayoutTabToUpdateOrThrow = ({
['id'],
);
const existingFlatPageLayoutTabToUpdate =
flatPageLayoutTabMaps.byId[pageLayoutTabToUpdateId];
const existingFlatPageLayoutTabToUpdate = findFlatEntityByIdInFlatEntityMaps({
flatEntityId: pageLayoutTabToUpdateId,
flatEntityMaps: flatPageLayoutTabMaps,
});
if (!isDefined(existingFlatPageLayoutTabToUpdate)) {
throw new PageLayoutTabException(
@@ -15,7 +15,9 @@ export const reconstructFlatPageLayoutTabWithWidgets = ({
tab: FlatPageLayoutTab;
flatPageLayoutWidgetMaps: FlatPageLayoutWidgetMaps;
}): FlatPageLayoutTabWithWidgets => {
const widgets = Object.values(flatPageLayoutWidgetMaps.byId).filter(
const widgets = Object.values(
flatPageLayoutWidgetMaps.byUniversalIdentifier,
).filter(
(widget): widget is FlatPageLayoutWidget =>
isDefined(widget) &&
widget.pageLayoutTabId === tab.id &&