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
@@ -2,6 +2,7 @@ import { isString } from 'class-validator';
import { FieldMetadataType } from 'twenty-shared/types';
import { isDefined, resolveRichTextVariables } from 'twenty-shared/utils';
import { findManyFlatEntityByIdInFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/utils/find-many-flat-entity-by-id-in-flat-entity-maps.util';
import { type ObjectMetadataInfo } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';
export const resolveRichTextFieldsInRecord = (
@@ -11,8 +12,10 @@ export const resolveRichTextFieldsInRecord = (
): Record<string, unknown> => {
const { flatObjectMetadata, flatFieldMetadataMaps } = objectMetadataInfo;
const richTextFieldNames = flatObjectMetadata.fieldIds
.map((fieldId) => flatFieldMetadataMaps.byId[fieldId])
const richTextFieldNames = findManyFlatEntityByIdInFlatEntityMaps({
flatEntityIds: flatObjectMetadata.fieldIds,
flatEntityMaps: flatFieldMetadataMaps,
})
.filter((field) => field?.type === FieldMetadataType.RICH_TEXT_V2)
.map((field) => field?.name)
.filter(isDefined);
@@ -5,6 +5,7 @@ import { resolveInput } from 'twenty-shared/utils';
import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/interfaces/workflow-action.interface';
import { LogicFunctionExecutorService } from 'src/engine/core-modules/logic-function/logic-function-executor/services/logic-function-executor.service';
import { findFlatEntityByIdInFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps.util';
import { WorkspaceManyOrAllFlatEntityMapsCacheService } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.service';
import {
WorkflowStepExecutorException,
@@ -57,8 +58,10 @@ export class LogicFunctionWorkflowAction implements WorkflowAction {
},
);
const logicFunction =
flatLogicFunctionMaps.byId[workflowActionInput.logicFunctionId];
const logicFunction = findFlatEntityByIdInFlatEntityMaps({
flatEntityId: workflowActionInput.logicFunctionId,
flatEntityMaps: flatLogicFunctionMaps,
});
if (!logicFunction) {
throw new WorkflowStepExecutorException(
@@ -17,6 +17,7 @@ import {
RecordCrudExceptionCode,
} from 'src/engine/core-modules/record-crud/exceptions/record-crud.exception';
import { FindRecordsService } from 'src/engine/core-modules/record-crud/services/find-records.service';
import { findFlatEntityByIdInFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps.util';
import { WorkflowCommonWorkspaceService } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';
import {
WorkflowStepExecutorException,
@@ -73,7 +74,10 @@ export class FindRecordsWorkflowAction implements WorkflowAction {
const fields = flatObjectMetadata.fieldIds
.map((fieldId) => {
const field = flatFieldMetadataMaps.byId[fieldId];
const field = findFlatEntityByIdInFlatEntityMaps({
flatEntityId: fieldId,
flatEntityMaps: flatFieldMetadataMaps,
});
if (!field) {
return null;