Files
twenty/packages/twenty-server/src/engine/metadata-modules/flat-object-metadata/utils/build-object-id-by-name-maps.util.ts
T
Weiko 04562b11fb Migrate metadata cache (#16030)
## Context
Deprecating legacy ObjectMetadata from cache in favor of flat entities.
Introducing utils to build byName/byNameSingular/byNamePlural in
isolated cases

## Next
- I had to introduce a util to build from flat to legacy
objectMetadataMaps, we should instead use flat maps directly when needed
(datasource, schema generation, etc)
- Deprecate metadata version in the cache
- Use the new cache strategy for flat entities with permissions and
feature flags and inject in the global datasource context
2025-11-24 19:50:47 +01:00

28 lines
927 B
TypeScript

import { isDefined } from 'twenty-shared/utils';
import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
import { type FlatObjectMetadata } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata.type';
export const buildObjectIdByNameMaps = (
flatObjectMetadataMaps: FlatEntityMaps<FlatObjectMetadata>,
): {
idByNameSingular: Record<string, string>;
idByNamePlural: Record<string, string>;
} => {
const idByNameSingular: Record<string, string> = {};
const idByNamePlural: Record<string, string> = {};
for (const [objectId, objectMetadata] of Object.entries(
flatObjectMetadataMaps.byId,
)) {
if (!isDefined(objectMetadata)) {
continue;
}
idByNameSingular[objectMetadata.nameSingular] = objectId;
idByNamePlural[objectMetadata.namePlural] = objectId;
}
return { idByNameSingular, idByNamePlural };
};