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:
+4
-4
@@ -12,15 +12,15 @@ export const buildObjectIdByNameMaps = (
|
||||
const idByNameSingular: Record<string, string> = {};
|
||||
const idByNamePlural: Record<string, string> = {};
|
||||
|
||||
for (const [objectId, objectMetadata] of Object.entries(
|
||||
flatObjectMetadataMaps.byId,
|
||||
for (const objectMetadata of Object.values(
|
||||
flatObjectMetadataMaps.byUniversalIdentifier,
|
||||
)) {
|
||||
if (!isDefined(objectMetadata)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
idByNameSingular[objectMetadata.nameSingular] = objectId;
|
||||
idByNamePlural[objectMetadata.namePlural] = objectId;
|
||||
idByNameSingular[objectMetadata.nameSingular] = objectMetadata.id;
|
||||
idByNamePlural[objectMetadata.namePlural] = objectMetadata.id;
|
||||
}
|
||||
|
||||
return { idByNameSingular, idByNamePlural };
|
||||
|
||||
+3
-1
@@ -78,7 +78,9 @@ export const fromDeleteObjectInputToFlatFieldMetadatasToDelete = ({
|
||||
);
|
||||
|
||||
// TODO We should maintain a idsByObjectMetadataId in the flatIndexMaps
|
||||
const flatIndexMetadataToDelete = Object.values(flatIndexMaps.byId).filter(
|
||||
const flatIndexMetadataToDelete = Object.values(
|
||||
flatIndexMaps.byUniversalIdentifier,
|
||||
).filter(
|
||||
(flatIndex): flatIndex is FlatIndexMetadata =>
|
||||
isDefined(flatIndex) &&
|
||||
flatIndex.objectMetadataId === flatObjectMetadataToDelete.id,
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ export const doesOtherObjectWithSameNameExists = ({
|
||||
objectMetadataNameSingular,
|
||||
existingObjectMetadataId,
|
||||
}: ValidateNoOtherObjectWithSameNameExistsOrThrowsParams) =>
|
||||
Object.values(objectMetadataMaps.byId)
|
||||
Object.values(objectMetadataMaps.byUniversalIdentifier)
|
||||
.filter(isDefined)
|
||||
.some(
|
||||
(objectMetadata) =>
|
||||
|
||||
Reference in New Issue
Block a user