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:
@@ -37,7 +37,7 @@ export class AgentService {
|
||||
'flatRoleTargetByAgentIdMaps',
|
||||
]);
|
||||
|
||||
return Object.values(flatAgentMaps.byId)
|
||||
return Object.values(flatAgentMaps.byUniversalIdentifier)
|
||||
.filter(isDefined)
|
||||
.map((flatAgent) => {
|
||||
const roleId = flatRoleTargetByAgentIdMaps[flatAgent.id]?.roleId;
|
||||
|
||||
+5
-1
@@ -13,6 +13,7 @@ import {
|
||||
import { type UpdateAgentInput } from 'src/engine/metadata-modules/ai/ai-agent/dtos/update-agent.input';
|
||||
import { FLAT_AGENT_EDITABLE_PROPERTIES } from 'src/engine/metadata-modules/flat-agent/constants/flat-agent-editable-properties.constant';
|
||||
import { type FlatAgentMaps } from 'src/engine/metadata-modules/flat-agent/types/flat-agent-maps.type';
|
||||
import { findFlatEntityByIdInFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps.util';
|
||||
import { type FlatAgent } from 'src/engine/metadata-modules/flat-agent/types/flat-agent.type';
|
||||
import { type FlatRoleTargetByAgentIdMaps } from 'src/engine/metadata-modules/flat-agent/types/flat-role-target-by-agent-id-maps.type';
|
||||
import { type FlatRoleTarget } from 'src/engine/metadata-modules/flat-role-target/types/flat-role-target.type';
|
||||
@@ -95,7 +96,10 @@ export const fromUpdateAgentInputToFlatAgentToUpdate = ({
|
||||
['id'],
|
||||
);
|
||||
|
||||
const existingFlatAgent = flatAgentMaps.byId[agentIdToUpdate];
|
||||
const existingFlatAgent = findFlatEntityByIdInFlatEntityMaps({
|
||||
flatEntityId: agentIdToUpdate,
|
||||
flatEntityMaps: flatAgentMaps,
|
||||
});
|
||||
|
||||
if (!isDefined(existingFlatAgent)) {
|
||||
throw new AgentException(
|
||||
|
||||
Reference in New Issue
Block a user