Refactor workspace migration and validation error types and centralize runner optimistic rendering (#16920)
# Introduction In this PR we're: - Refactoring the workspace migration action type introducing grain over metadata and operation type ( for example operation `create` and metadata `field` ) - Thanks to above point we can now factorize the runner optimistic rendering out of each runner actions-handler file using the existing into the generic one ( -3200 lines of code here ) - Still thanks to action type refactor we're able to dynamically compose the response error type only send data when there's here. No more static counter and static summary error message. This way we won't have to re run snapshot every time we add a new entity to the engine ( huge snapshot diff here ) ## Noticeable points: - We introduce an index update action to avoid any complex typing for not having one or a tuple of actions instead. Now the drop and insert logic is directly inferred from the update action handler instead of being two action ( delete index and create index ) ## TODO - [x] Define base actions types - [x] Migrate all actions to action type and metadata name pattern ( base actions ) - [x] Refactor flat entity validation type to embed metadata name - [x] Refactor optimistic rendering within runner - [x] Refactor legacy cache invalidation switch - [x] Refactor response error format ( dynamic counter again + no empty entries ) - [x] Try factorizing and removing redundant nor unused type declaration in metadata actions type intermediary files - [x] Adapt front to new response error format ## Remarks - ~~Should create an issue for generic replace flat entity in related flat entity maps~~ overkill - Should create an issue for oneToMany foreignKey being nullable not always cascade delete optimistic rendering edge case to either docs or fix it in delete flat entity and related entity ( re-code the pg cascading behavior ) - We could also factorize the builder to only implement validators and not the intermediary file
This commit is contained in:
+4
-3
@@ -3,13 +3,14 @@ import { type Expect } from 'twenty-shared/testing';
|
||||
|
||||
import { type AllFlatEntityTypesByMetadataName } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-types-by-metadata-name';
|
||||
import { type SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity.type';
|
||||
import { type WorkspaceMigrationActionType } from 'src/engine/metadata-modules/flat-entity/types/metadata-workspace-migration-action.type';
|
||||
import { type WorkspaceMigrationActionV2 } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/workspace-migration-action-common-v2';
|
||||
|
||||
type ExpectedGenericFlatEntityInformation = {
|
||||
actions: {
|
||||
created: WorkspaceMigrationActionV2 | WorkspaceMigrationActionV2[];
|
||||
deleted: WorkspaceMigrationActionV2 | WorkspaceMigrationActionV2[];
|
||||
updated: WorkspaceMigrationActionV2 | WorkspaceMigrationActionV2[];
|
||||
[P in WorkspaceMigrationActionType]:
|
||||
| WorkspaceMigrationActionV2
|
||||
| WorkspaceMigrationActionV2[];
|
||||
};
|
||||
flatEntity: SyncableFlatEntity;
|
||||
};
|
||||
|
||||
+64
-66
@@ -63,6 +63,7 @@ import {
|
||||
import {
|
||||
type CreateIndexAction,
|
||||
type DeleteIndexAction,
|
||||
type UpdateIndexAction,
|
||||
} from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/builders/index/types/workspace-migration-index-action-v2';
|
||||
import {
|
||||
type CreateObjectAction,
|
||||
@@ -107,7 +108,6 @@ import {
|
||||
import {
|
||||
type CreateRowLevelPermissionPredicateAction,
|
||||
type DeleteRowLevelPermissionPredicateAction,
|
||||
type DestroyRowLevelPermissionPredicateAction,
|
||||
type UpdateRowLevelPermissionPredicateAction,
|
||||
} from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/builders/row-level-permission-predicate/types/workspace-migration-row-level-permission-predicate-action-v2.type';
|
||||
import {
|
||||
@@ -149,191 +149,189 @@ import {
|
||||
export type AllFlatEntityTypesByMetadataName = {
|
||||
fieldMetadata: {
|
||||
actions: {
|
||||
created: CreateFieldAction;
|
||||
updated: UpdateFieldAction;
|
||||
deleted: DeleteFieldAction;
|
||||
create: CreateFieldAction;
|
||||
update: UpdateFieldAction;
|
||||
delete: DeleteFieldAction;
|
||||
};
|
||||
flatEntity: FlatFieldMetadata;
|
||||
entity: FieldMetadataEntity;
|
||||
};
|
||||
objectMetadata: {
|
||||
actions: {
|
||||
created: CreateObjectAction;
|
||||
updated: UpdateObjectAction;
|
||||
deleted: DeleteObjectAction;
|
||||
create: CreateObjectAction;
|
||||
update: UpdateObjectAction;
|
||||
delete: DeleteObjectAction;
|
||||
};
|
||||
flatEntity: FlatObjectMetadata;
|
||||
entity: ObjectMetadataEntity;
|
||||
};
|
||||
view: {
|
||||
actions: {
|
||||
created: CreateViewAction;
|
||||
updated: UpdateViewAction;
|
||||
deleted: DeleteViewAction;
|
||||
create: CreateViewAction;
|
||||
update: UpdateViewAction;
|
||||
delete: DeleteViewAction;
|
||||
};
|
||||
flatEntity: FlatView;
|
||||
entity: ViewEntity;
|
||||
};
|
||||
viewField: {
|
||||
actions: {
|
||||
created: CreateViewFieldAction;
|
||||
updated: UpdateViewFieldAction;
|
||||
deleted: DeleteViewFieldAction;
|
||||
create: CreateViewFieldAction;
|
||||
update: UpdateViewFieldAction;
|
||||
delete: DeleteViewFieldAction;
|
||||
};
|
||||
flatEntity: FlatViewField;
|
||||
entity: ViewFieldEntity;
|
||||
};
|
||||
viewGroup: {
|
||||
actions: {
|
||||
created: CreateViewGroupAction;
|
||||
updated: UpdateViewGroupAction;
|
||||
deleted: DeleteViewGroupAction;
|
||||
create: CreateViewGroupAction;
|
||||
update: UpdateViewGroupAction;
|
||||
delete: DeleteViewGroupAction;
|
||||
};
|
||||
flatEntity: FlatViewGroup;
|
||||
entity: ViewGroupEntity;
|
||||
};
|
||||
rowLevelPermissionPredicate: {
|
||||
actions: {
|
||||
created: CreateRowLevelPermissionPredicateAction;
|
||||
updated: UpdateRowLevelPermissionPredicateAction;
|
||||
deleted:
|
||||
| DeleteRowLevelPermissionPredicateAction
|
||||
| DestroyRowLevelPermissionPredicateAction;
|
||||
create: CreateRowLevelPermissionPredicateAction;
|
||||
update: UpdateRowLevelPermissionPredicateAction;
|
||||
delete: DeleteRowLevelPermissionPredicateAction;
|
||||
};
|
||||
flatEntity: FlatRowLevelPermissionPredicate;
|
||||
entity: RowLevelPermissionPredicateEntity;
|
||||
};
|
||||
rowLevelPermissionPredicateGroup: {
|
||||
actions: {
|
||||
created: CreateRowLevelPermissionPredicateGroupAction;
|
||||
updated: UpdateRowLevelPermissionPredicateGroupAction;
|
||||
deleted: DeleteRowLevelPermissionPredicateGroupAction;
|
||||
create: CreateRowLevelPermissionPredicateGroupAction;
|
||||
update: UpdateRowLevelPermissionPredicateGroupAction;
|
||||
delete: DeleteRowLevelPermissionPredicateGroupAction;
|
||||
};
|
||||
flatEntity: FlatRowLevelPermissionPredicateGroup;
|
||||
entity: RowLevelPermissionPredicateGroupEntity;
|
||||
};
|
||||
viewFilterGroup: {
|
||||
actions: {
|
||||
created: CreateViewFilterGroupAction;
|
||||
updated: UpdateViewFilterGroupAction;
|
||||
deleted: DeleteViewFilterGroupAction;
|
||||
create: CreateViewFilterGroupAction;
|
||||
update: UpdateViewFilterGroupAction;
|
||||
delete: DeleteViewFilterGroupAction;
|
||||
};
|
||||
flatEntity: FlatViewFilterGroup;
|
||||
entity: ViewFilterGroupEntity;
|
||||
};
|
||||
index: {
|
||||
actions: {
|
||||
created: CreateIndexAction;
|
||||
updated: [DeleteIndexAction, CreateIndexAction];
|
||||
deleted: DeleteIndexAction;
|
||||
create: CreateIndexAction;
|
||||
update: UpdateIndexAction;
|
||||
delete: DeleteIndexAction;
|
||||
};
|
||||
flatEntity: FlatIndexMetadata;
|
||||
entity: IndexMetadataEntity;
|
||||
};
|
||||
serverlessFunction: {
|
||||
actions: {
|
||||
created: CreateServerlessFunctionAction;
|
||||
updated: UpdateServerlessFunctionAction;
|
||||
deleted: DeleteServerlessFunctionAction;
|
||||
create: CreateServerlessFunctionAction;
|
||||
update: UpdateServerlessFunctionAction;
|
||||
delete: DeleteServerlessFunctionAction;
|
||||
};
|
||||
flatEntity: FlatServerlessFunction;
|
||||
entity: ServerlessFunctionEntity;
|
||||
};
|
||||
cronTrigger: {
|
||||
actions: {
|
||||
created: CreateCronTriggerAction;
|
||||
updated: UpdateCronTriggerAction;
|
||||
deleted: DeleteCronTriggerAction;
|
||||
create: CreateCronTriggerAction;
|
||||
update: UpdateCronTriggerAction;
|
||||
delete: DeleteCronTriggerAction;
|
||||
};
|
||||
flatEntity: FlatCronTrigger;
|
||||
entity: CronTriggerEntity;
|
||||
};
|
||||
databaseEventTrigger: {
|
||||
actions: {
|
||||
created: CreateDatabaseEventTriggerAction;
|
||||
updated: UpdateDatabaseEventTriggerAction;
|
||||
deleted: DeleteDatabaseEventTriggerAction;
|
||||
create: CreateDatabaseEventTriggerAction;
|
||||
update: UpdateDatabaseEventTriggerAction;
|
||||
delete: DeleteDatabaseEventTriggerAction;
|
||||
};
|
||||
flatEntity: FlatDatabaseEventTrigger;
|
||||
entity: DatabaseEventTriggerEntity;
|
||||
};
|
||||
routeTrigger: {
|
||||
actions: {
|
||||
created: CreateRouteTriggerAction;
|
||||
updated: UpdateRouteTriggerAction;
|
||||
deleted: DeleteRouteTriggerAction;
|
||||
create: CreateRouteTriggerAction;
|
||||
update: UpdateRouteTriggerAction;
|
||||
delete: DeleteRouteTriggerAction;
|
||||
};
|
||||
flatEntity: FlatRouteTrigger;
|
||||
entity: RouteTriggerEntity;
|
||||
};
|
||||
viewFilter: {
|
||||
actions: {
|
||||
created: CreateViewFilterAction;
|
||||
updated: UpdateViewFilterAction;
|
||||
deleted: DeleteViewFilterAction;
|
||||
create: CreateViewFilterAction;
|
||||
update: UpdateViewFilterAction;
|
||||
delete: DeleteViewFilterAction;
|
||||
};
|
||||
flatEntity: FlatViewFilter;
|
||||
entity: ViewFilterEntity;
|
||||
};
|
||||
role: {
|
||||
actions: {
|
||||
created: CreateRoleAction;
|
||||
updated: UpdateRoleAction;
|
||||
deleted: DeleteRoleAction;
|
||||
create: CreateRoleAction;
|
||||
update: UpdateRoleAction;
|
||||
delete: DeleteRoleAction;
|
||||
};
|
||||
flatEntity: FlatRole;
|
||||
entity: RoleEntity;
|
||||
};
|
||||
roleTarget: {
|
||||
actions: {
|
||||
created: CreateRoleTargetAction;
|
||||
updated: UpdateRoleTargetAction;
|
||||
deleted: DeleteRoleTargetAction;
|
||||
create: CreateRoleTargetAction;
|
||||
update: UpdateRoleTargetAction;
|
||||
delete: DeleteRoleTargetAction;
|
||||
};
|
||||
flatEntity: FlatRoleTarget;
|
||||
entity: RoleTargetEntity;
|
||||
};
|
||||
agent: {
|
||||
actions: {
|
||||
created: CreateAgentAction;
|
||||
updated: UpdateAgentAction;
|
||||
deleted: DeleteAgentAction;
|
||||
create: CreateAgentAction;
|
||||
update: UpdateAgentAction;
|
||||
delete: DeleteAgentAction;
|
||||
};
|
||||
flatEntity: FlatAgent;
|
||||
entity: AgentEntity;
|
||||
};
|
||||
skill: {
|
||||
actions: {
|
||||
created: CreateSkillAction;
|
||||
updated: UpdateSkillAction;
|
||||
deleted: DeleteSkillAction;
|
||||
create: CreateSkillAction;
|
||||
update: UpdateSkillAction;
|
||||
delete: DeleteSkillAction;
|
||||
};
|
||||
flatEntity: FlatSkill;
|
||||
entity: SkillEntity;
|
||||
};
|
||||
pageLayout: {
|
||||
actions: {
|
||||
created: CreatePageLayoutAction;
|
||||
updated: UpdatePageLayoutAction;
|
||||
deleted: DeletePageLayoutAction;
|
||||
create: CreatePageLayoutAction;
|
||||
update: UpdatePageLayoutAction;
|
||||
delete: DeletePageLayoutAction;
|
||||
};
|
||||
flatEntity: FlatPageLayout;
|
||||
entity: PageLayoutEntity;
|
||||
};
|
||||
pageLayoutWidget: {
|
||||
actions: {
|
||||
created: CreatePageLayoutWidgetAction;
|
||||
updated: UpdatePageLayoutWidgetAction;
|
||||
deleted: DeletePageLayoutWidgetAction;
|
||||
create: CreatePageLayoutWidgetAction;
|
||||
update: UpdatePageLayoutWidgetAction;
|
||||
delete: DeletePageLayoutWidgetAction;
|
||||
};
|
||||
flatEntity: FlatPageLayoutWidget;
|
||||
entity: PageLayoutWidgetEntity;
|
||||
};
|
||||
pageLayoutTab: {
|
||||
actions: {
|
||||
created: CreatePageLayoutTabAction;
|
||||
updated: UpdatePageLayoutTabAction;
|
||||
deleted: DeletePageLayoutTabAction;
|
||||
create: CreatePageLayoutTabAction;
|
||||
update: UpdatePageLayoutTabAction;
|
||||
delete: DeletePageLayoutTabAction;
|
||||
};
|
||||
flatEntity: FlatPageLayoutTab;
|
||||
entity: PageLayoutTabEntity;
|
||||
|
||||
+12
-16
@@ -1,32 +1,28 @@
|
||||
import { type AllMetadataName } from 'twenty-shared/metadata';
|
||||
|
||||
import { type AllFlatEntityTypesByMetadataName } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-types-by-metadata-name';
|
||||
import { type BaseCreateWorkspaceMigrationAction } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/base-create-workspace-migration-action.type';
|
||||
import { type BaseDeleteWorkspaceMigrationAction } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/base-delete-workspace-migration-action.type';
|
||||
import { type BaseUpdateWorkspaceMigrationAction } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/base-update-workspace-migration-action.type';
|
||||
|
||||
export type WorkspaceMigrationActionType =
|
||||
| BaseCreateWorkspaceMigrationAction<AllMetadataName>['type']
|
||||
| BaseUpdateWorkspaceMigrationAction<AllMetadataName>['type']
|
||||
| BaseDeleteWorkspaceMigrationAction<AllMetadataName>['type'];
|
||||
|
||||
export type MetadataWorkspaceMigrationActionsRecord<T extends AllMetadataName> =
|
||||
{
|
||||
[K in 'created' | 'updated' | 'deleted']: MetadataWorkspaceMigrationAction<
|
||||
[K in WorkspaceMigrationActionType]: MetadataWorkspaceMigrationAction<
|
||||
T,
|
||||
K
|
||||
>[];
|
||||
};
|
||||
|
||||
export type MetadataWorkspaceMigrationAction<
|
||||
T extends AllMetadataName,
|
||||
TOperation extends 'created' | 'deleted' | 'updated' =
|
||||
| 'created'
|
||||
| 'deleted'
|
||||
| 'updated',
|
||||
> = AllFlatEntityTypesByMetadataName[T]['actions'][TOperation] extends infer Action
|
||||
TMetadataName extends AllMetadataName,
|
||||
TActionType extends WorkspaceMigrationActionType,
|
||||
> = AllFlatEntityTypesByMetadataName[TMetadataName]['actions'][TActionType] extends infer Action
|
||||
? Action extends Array<unknown>
|
||||
? Action[number]
|
||||
: Action
|
||||
: never;
|
||||
|
||||
export type FromWorkspaceMigrationActionToMetadataName<TAction> = {
|
||||
[K in AllMetadataName]: TAction extends AllFlatEntityTypesByMetadataName[K]['actions'][
|
||||
| 'created'
|
||||
| 'deleted'
|
||||
| 'updated']
|
||||
? K
|
||||
: never;
|
||||
}[AllMetadataName];
|
||||
|
||||
Reference in New Issue
Block a user