Extract field metadata build out of object metadata build (#14763)
# Introduction Extracting the legacy fields build and dispatch out of the object one to follow the generic flat entity build, also update caches entries for object ## Main tasks - flat field map cache - flat field builder - refactored the dispatch matrix to return flat entity maps instead of flat entity arrays - orchestrator aggregator - removing legacy code - making universal identifier aka standardId of standard field for custom object deterministically dynamic - perfs debug logs for v2 ## TODO - [x] Refactor the generic entity builder to be dependency flat maps in order to main foreign keys list in flat parent - [x] Refactor the flat object metadata to contain the array of related fields and avoid costy find object fields - [ ] Improve the create field handler to handle multiple field at once - [ ] Refactor the dispatch to embbed the comparison - [ ] Improve perf by extracting from elements out of existing - [ ] Fix the labelIdentifierId validators on object before field creation ( integ tests are in failing mode ) ## Debug logs snippet ```ts [EntityBuilder fieldMetadata] matrix computation: 0.027ms [EntityBuilder fieldMetadata] creation validation: 0.001ms [EntityBuilder fieldMetadata] deletion validation: 0.293ms [EntityBuilder fieldMetadata] update validation: 0.006ms [EntityBuilder fieldMetadata] entity processing: 0.363ms [EntityBuilder fieldMetadata] validateAndBuild: 0.455ms [EntityBuilder index] matrix computation: 0.005ms [EntityBuilder index] creation validation: 0.001ms [EntityBuilder index] deletion validation: 0.146ms [EntityBuilder index] update validation: 0.004ms [EntityBuilder index] entity processing: 0.199ms [EntityBuilder index] validateAndBuild: 0.228ms [Runner] Initial cache retrieval: 0.549ms [BaseWorkspaceMigrationRunnerActionHandlerService] delete_index executeForWorkspaceSchema: 11.665ms [BaseWorkspaceMigrationRunnerActionHandlerService] delete_index executeForMetadata: 12.864ms [BaseWorkspaceMigrationRunnerActionHandlerService] delete_field executeForWorkspaceSchema: 1.476ms [BaseWorkspaceMigrationRunnerActionHandlerService] delete_field executeForMetadata: 6.816ms [BaseWorkspaceMigrationRunnerActionHandlerService] delete_field executeForWorkspaceSchema: 0.062ms [BaseWorkspaceMigrationRunnerActionHandlerService] delete_field executeForMetadata: 0.889ms [Runner] Transaction execution: 23.434ms [Runner] Cache invalidation: 316.662ms [Runner] Total execution: 340.767ms ``` As you can see cache invalidation is way to long, we could replace the cache by the optimistic in the end
This commit is contained in:
-488
@@ -89,159 +89,6 @@ exports[`fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test su
|
||||
"createdAt": Any<ClockDate>,
|
||||
"defaultValue": null,
|
||||
"description": "new field description",
|
||||
"flatRelationTargetFieldMetadata": {
|
||||
"createdAt": Any<ClockDate>,
|
||||
"defaultValue": null,
|
||||
"description": null,
|
||||
"flatRelationTargetFieldMetadata": {
|
||||
"createdAt": Any<ClockDate>,
|
||||
"defaultValue": null,
|
||||
"description": "new field description",
|
||||
"flatRelationTargetFieldMetadata": null,
|
||||
"flatRelationTargetObjectMetadata": {
|
||||
"applicationId": null,
|
||||
"createdAt": Any<String>,
|
||||
"description": null,
|
||||
"duplicateCriteria": null,
|
||||
"flatFieldMetadatas": [],
|
||||
"icon": "IconCat",
|
||||
"id": Any<String>,
|
||||
"imageIdentifierFieldMetadataId": null,
|
||||
"isActive": true,
|
||||
"isAuditLogged": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isRemote": false,
|
||||
"isSearchable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"labelIdentifierFieldMetadataId": Any<String>,
|
||||
"labelPlural": "Pets",
|
||||
"labelSingular": "Pet",
|
||||
"namePlural": "pets",
|
||||
"nameSingular": "pet",
|
||||
"shortcut": null,
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"targetTableName": "DEPRECATED",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<String>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"icon": "IconRelationOneToMany",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isNullable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"isUnique": null,
|
||||
"label": "newFieldLabel",
|
||||
"morphId": Any<String>,
|
||||
"name": "newFieldPets",
|
||||
"objectMetadataId": Any<String>,
|
||||
"options": null,
|
||||
"relationTargetFieldMetadataId": Any<String>,
|
||||
"relationTargetObjectMetadataId": Any<String>,
|
||||
"settings": {
|
||||
"relationType": "ONE_TO_MANY",
|
||||
},
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"type": "MORPH_RELATION",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<ClockDate>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"flatRelationTargetObjectMetadata": {
|
||||
"applicationId": null,
|
||||
"createdAt": Any<String>,
|
||||
"description": "A rocket",
|
||||
"duplicateCriteria": null,
|
||||
"flatFieldMetadatas": [],
|
||||
"icon": "IconRocket",
|
||||
"id": Any<String>,
|
||||
"imageIdentifierFieldMetadataId": null,
|
||||
"isActive": true,
|
||||
"isAuditLogged": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isRemote": false,
|
||||
"isSearchable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"labelIdentifierFieldMetadataId": Any<String>,
|
||||
"labelPlural": "Rockets",
|
||||
"labelSingular": "Rocket",
|
||||
"namePlural": "rockets",
|
||||
"nameSingular": "rocket",
|
||||
"shortcut": null,
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"targetTableName": "DEPRECATED",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<String>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"icon": "IconPet",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isNullable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"isUnique": null,
|
||||
"label": "Pet",
|
||||
"morphId": null,
|
||||
"name": "pet",
|
||||
"objectMetadataId": Any<String>,
|
||||
"options": null,
|
||||
"relationTargetFieldMetadataId": Any<String>,
|
||||
"relationTargetObjectMetadataId": Any<String>,
|
||||
"settings": {
|
||||
"joinColumnName": "petId",
|
||||
"onDelete": "SET_NULL",
|
||||
"relationType": "MANY_TO_ONE",
|
||||
},
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"type": "RELATION",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<ClockDate>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"flatRelationTargetObjectMetadata": {
|
||||
"applicationId": null,
|
||||
"createdAt": Any<String>,
|
||||
"description": null,
|
||||
"duplicateCriteria": null,
|
||||
"flatFieldMetadatas": [],
|
||||
"icon": "IconCat",
|
||||
"id": Any<String>,
|
||||
"imageIdentifierFieldMetadataId": null,
|
||||
"isActive": true,
|
||||
"isAuditLogged": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isRemote": false,
|
||||
"isSearchable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"labelIdentifierFieldMetadataId": Any<String>,
|
||||
"labelPlural": "Pets",
|
||||
"labelSingular": "Pet",
|
||||
"namePlural": "pets",
|
||||
"nameSingular": "pet",
|
||||
"shortcut": null,
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"targetTableName": "DEPRECATED",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<String>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"icon": "IconRelationOneToMany",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
@@ -272,97 +119,6 @@ exports[`fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test su
|
||||
"createdAt": Any<ClockDate>,
|
||||
"defaultValue": null,
|
||||
"description": null,
|
||||
"flatRelationTargetFieldMetadata": {
|
||||
"createdAt": Any<ClockDate>,
|
||||
"defaultValue": null,
|
||||
"description": "new field description",
|
||||
"flatRelationTargetFieldMetadata": null,
|
||||
"flatRelationTargetObjectMetadata": {
|
||||
"applicationId": null,
|
||||
"createdAt": Any<String>,
|
||||
"description": null,
|
||||
"duplicateCriteria": null,
|
||||
"flatFieldMetadatas": [],
|
||||
"icon": "IconCat",
|
||||
"id": Any<String>,
|
||||
"imageIdentifierFieldMetadataId": null,
|
||||
"isActive": true,
|
||||
"isAuditLogged": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isRemote": false,
|
||||
"isSearchable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"labelIdentifierFieldMetadataId": Any<String>,
|
||||
"labelPlural": "Pets",
|
||||
"labelSingular": "Pet",
|
||||
"namePlural": "pets",
|
||||
"nameSingular": "pet",
|
||||
"shortcut": null,
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"targetTableName": "DEPRECATED",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<String>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"icon": "IconRelationOneToMany",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isNullable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"isUnique": null,
|
||||
"label": "newFieldLabel",
|
||||
"morphId": Any<String>,
|
||||
"name": "newFieldPets",
|
||||
"objectMetadataId": Any<String>,
|
||||
"options": null,
|
||||
"relationTargetFieldMetadataId": Any<String>,
|
||||
"relationTargetObjectMetadataId": Any<String>,
|
||||
"settings": {
|
||||
"relationType": "ONE_TO_MANY",
|
||||
},
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"type": "MORPH_RELATION",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<ClockDate>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"flatRelationTargetObjectMetadata": {
|
||||
"applicationId": null,
|
||||
"createdAt": Any<String>,
|
||||
"description": "A rocket",
|
||||
"duplicateCriteria": null,
|
||||
"flatFieldMetadatas": [],
|
||||
"icon": "IconRocket",
|
||||
"id": Any<String>,
|
||||
"imageIdentifierFieldMetadataId": null,
|
||||
"isActive": true,
|
||||
"isAuditLogged": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isRemote": false,
|
||||
"isSearchable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"labelIdentifierFieldMetadataId": Any<String>,
|
||||
"labelPlural": "Rockets",
|
||||
"labelSingular": "Rocket",
|
||||
"namePlural": "rockets",
|
||||
"nameSingular": "rocket",
|
||||
"shortcut": null,
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"targetTableName": "DEPRECATED",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<String>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"icon": "IconPet",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
@@ -395,159 +151,6 @@ exports[`fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test su
|
||||
"createdAt": Any<ClockDate>,
|
||||
"defaultValue": null,
|
||||
"description": "new field description",
|
||||
"flatRelationTargetFieldMetadata": {
|
||||
"createdAt": Any<ClockDate>,
|
||||
"defaultValue": null,
|
||||
"description": null,
|
||||
"flatRelationTargetFieldMetadata": {
|
||||
"createdAt": Any<ClockDate>,
|
||||
"defaultValue": null,
|
||||
"description": "new field description",
|
||||
"flatRelationTargetFieldMetadata": null,
|
||||
"flatRelationTargetObjectMetadata": {
|
||||
"applicationId": null,
|
||||
"createdAt": Any<String>,
|
||||
"description": "A company",
|
||||
"duplicateCriteria": null,
|
||||
"flatFieldMetadatas": [],
|
||||
"icon": "IconBuildingSkyscraper",
|
||||
"id": Any<String>,
|
||||
"imageIdentifierFieldMetadataId": null,
|
||||
"isActive": true,
|
||||
"isAuditLogged": true,
|
||||
"isCustom": false,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isRemote": false,
|
||||
"isSearchable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"labelIdentifierFieldMetadataId": Any<String>,
|
||||
"labelPlural": "Companies",
|
||||
"labelSingular": "Company",
|
||||
"namePlural": "companies",
|
||||
"nameSingular": "company",
|
||||
"shortcut": "C",
|
||||
"standardId": Any<String>,
|
||||
"standardOverrides": null,
|
||||
"targetTableName": "DEPRECATED",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<String>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"icon": "IconRelationOneToMany",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isNullable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"isUnique": null,
|
||||
"label": "newFieldLabel",
|
||||
"morphId": Any<String>,
|
||||
"name": "newFieldCompanies",
|
||||
"objectMetadataId": Any<String>,
|
||||
"options": null,
|
||||
"relationTargetFieldMetadataId": Any<String>,
|
||||
"relationTargetObjectMetadataId": Any<String>,
|
||||
"settings": {
|
||||
"relationType": "ONE_TO_MANY",
|
||||
},
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"type": "MORPH_RELATION",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<ClockDate>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"flatRelationTargetObjectMetadata": {
|
||||
"applicationId": null,
|
||||
"createdAt": Any<String>,
|
||||
"description": "A rocket",
|
||||
"duplicateCriteria": null,
|
||||
"flatFieldMetadatas": [],
|
||||
"icon": "IconRocket",
|
||||
"id": Any<String>,
|
||||
"imageIdentifierFieldMetadataId": null,
|
||||
"isActive": true,
|
||||
"isAuditLogged": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isRemote": false,
|
||||
"isSearchable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"labelIdentifierFieldMetadataId": Any<String>,
|
||||
"labelPlural": "Rockets",
|
||||
"labelSingular": "Rocket",
|
||||
"namePlural": "rockets",
|
||||
"nameSingular": "rocket",
|
||||
"shortcut": null,
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"targetTableName": "DEPRECATED",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<String>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"icon": "IconBuilding",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isNullable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"isUnique": null,
|
||||
"label": "Company",
|
||||
"morphId": null,
|
||||
"name": "company",
|
||||
"objectMetadataId": Any<String>,
|
||||
"options": null,
|
||||
"relationTargetFieldMetadataId": Any<String>,
|
||||
"relationTargetObjectMetadataId": Any<String>,
|
||||
"settings": {
|
||||
"joinColumnName": "companyId",
|
||||
"onDelete": "SET_NULL",
|
||||
"relationType": "MANY_TO_ONE",
|
||||
},
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"type": "RELATION",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<ClockDate>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"flatRelationTargetObjectMetadata": {
|
||||
"applicationId": null,
|
||||
"createdAt": Any<String>,
|
||||
"description": "A company",
|
||||
"duplicateCriteria": null,
|
||||
"flatFieldMetadatas": [],
|
||||
"icon": "IconBuildingSkyscraper",
|
||||
"id": Any<String>,
|
||||
"imageIdentifierFieldMetadataId": null,
|
||||
"isActive": true,
|
||||
"isAuditLogged": true,
|
||||
"isCustom": false,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isRemote": false,
|
||||
"isSearchable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"labelIdentifierFieldMetadataId": Any<String>,
|
||||
"labelPlural": "Companies",
|
||||
"labelSingular": "Company",
|
||||
"namePlural": "companies",
|
||||
"nameSingular": "company",
|
||||
"shortcut": "C",
|
||||
"standardId": Any<String>,
|
||||
"standardOverrides": null,
|
||||
"targetTableName": "DEPRECATED",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<String>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"icon": "IconRelationOneToMany",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
@@ -578,97 +181,6 @@ exports[`fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test su
|
||||
"createdAt": Any<ClockDate>,
|
||||
"defaultValue": null,
|
||||
"description": null,
|
||||
"flatRelationTargetFieldMetadata": {
|
||||
"createdAt": Any<ClockDate>,
|
||||
"defaultValue": null,
|
||||
"description": "new field description",
|
||||
"flatRelationTargetFieldMetadata": null,
|
||||
"flatRelationTargetObjectMetadata": {
|
||||
"applicationId": null,
|
||||
"createdAt": Any<String>,
|
||||
"description": "A company",
|
||||
"duplicateCriteria": null,
|
||||
"flatFieldMetadatas": [],
|
||||
"icon": "IconBuildingSkyscraper",
|
||||
"id": Any<String>,
|
||||
"imageIdentifierFieldMetadataId": null,
|
||||
"isActive": true,
|
||||
"isAuditLogged": true,
|
||||
"isCustom": false,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isRemote": false,
|
||||
"isSearchable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"labelIdentifierFieldMetadataId": Any<String>,
|
||||
"labelPlural": "Companies",
|
||||
"labelSingular": "Company",
|
||||
"namePlural": "companies",
|
||||
"nameSingular": "company",
|
||||
"shortcut": "C",
|
||||
"standardId": Any<String>,
|
||||
"standardOverrides": null,
|
||||
"targetTableName": "DEPRECATED",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<String>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"icon": "IconRelationOneToMany",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isNullable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"isUnique": null,
|
||||
"label": "newFieldLabel",
|
||||
"morphId": Any<String>,
|
||||
"name": "newFieldCompanies",
|
||||
"objectMetadataId": Any<String>,
|
||||
"options": null,
|
||||
"relationTargetFieldMetadataId": Any<String>,
|
||||
"relationTargetObjectMetadataId": Any<String>,
|
||||
"settings": {
|
||||
"relationType": "ONE_TO_MANY",
|
||||
},
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"type": "MORPH_RELATION",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<ClockDate>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"flatRelationTargetObjectMetadata": {
|
||||
"applicationId": null,
|
||||
"createdAt": Any<String>,
|
||||
"description": "A rocket",
|
||||
"duplicateCriteria": null,
|
||||
"flatFieldMetadatas": [],
|
||||
"icon": "IconRocket",
|
||||
"id": Any<String>,
|
||||
"imageIdentifierFieldMetadataId": null,
|
||||
"isActive": true,
|
||||
"isAuditLogged": true,
|
||||
"isCustom": true,
|
||||
"isLabelSyncedWithName": false,
|
||||
"isRemote": false,
|
||||
"isSearchable": true,
|
||||
"isSystem": false,
|
||||
"isUIReadOnly": false,
|
||||
"labelIdentifierFieldMetadataId": Any<String>,
|
||||
"labelPlural": "Rockets",
|
||||
"labelSingular": "Rocket",
|
||||
"namePlural": "rockets",
|
||||
"nameSingular": "rocket",
|
||||
"shortcut": null,
|
||||
"standardId": null,
|
||||
"standardOverrides": null,
|
||||
"targetTableName": "DEPRECATED",
|
||||
"universalIdentifier": Any<String>,
|
||||
"updatedAt": Any<String>,
|
||||
"workspaceId": Any<String>,
|
||||
},
|
||||
"icon": "IconBuilding",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
|
||||
+32
-41
@@ -1,39 +1,34 @@
|
||||
import { extractRecordIdsAndDatesAsExpectAny } from 'test/utils/extract-record-ids-and-dates-as-expect-any';
|
||||
import { type EachTestingContext } from 'twenty-shared/testing';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { jestExpectToBeDefined } from 'test/utils/expect-to-be-defined.util.test';
|
||||
|
||||
import { RelationType } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-type.interface';
|
||||
|
||||
import { type CreateFieldInput } from 'src/engine/metadata-modules/field-metadata/dtos/create-field.input';
|
||||
import { fromCreateFieldInputToFlatFieldMetadatasToCreate } from 'src/engine/metadata-modules/flat-field-metadata/utils/from-create-field-input-to-flat-field-metadatas-to-create.util';
|
||||
import { FLAT_OBJECT_METADATA_MAPS_MOCKS } from 'src/engine/metadata-modules/flat-object-metadata-maps/mocks/flat-object-metadata-maps.mock';
|
||||
import { type FlatObjectMetadataMaps } from 'src/engine/metadata-modules/flat-object-metadata-maps/types/flat-object-metadata-maps.type';
|
||||
import { replaceFlatObjectMetadataInFlatObjectMetadataMapsOrThrow } from 'src/engine/metadata-modules/flat-object-metadata-maps/utils/replace-flat-object-metadata-in-flat-object-metadata-maps-or-throw.util';
|
||||
import { EMPTY_FLAT_ENTITY_MAPS } from 'src/engine/core-modules/common/constant/empty-flat-entity-maps.constant';
|
||||
import { addFlatEntityToFlatEntityMapsOrThrow } from 'src/engine/core-modules/common/utils/add-flat-entity-to-flat-entity-maps-or-throw.util';
|
||||
import {
|
||||
fromCreateFieldInputToFlatFieldMetadatasToCreate,
|
||||
type FromCreateFieldInputToFlatObjectMetadataArgs,
|
||||
} from 'src/engine/metadata-modules/flat-field-metadata/utils/from-create-field-input-to-flat-field-metadatas-to-create.util';
|
||||
import { COMPANY_FLAT_OBJECT_MOCK } from 'src/engine/metadata-modules/flat-object-metadata/__mocks__/company-flat-object.mock';
|
||||
import { FLAT_OBJECT_METADATA_MAPS_MOCKS } from 'src/engine/metadata-modules/flat-object-metadata/__mocks__/flat-object-metadata-maps.mock';
|
||||
import { PET_FLAT_OBJECT_MOCK } from 'src/engine/metadata-modules/flat-object-metadata/__mocks__/pet-flat-object.mock';
|
||||
import { ROCKET_FLAT_OBJECT_MOCK } from 'src/engine/metadata-modules/flat-object-metadata/__mocks__/rocket-flat-object.mock';
|
||||
|
||||
const existingFlatObjectMetadataMaps = [
|
||||
const flatObjectMetadataMaps = [
|
||||
COMPANY_FLAT_OBJECT_MOCK,
|
||||
ROCKET_FLAT_OBJECT_MOCK,
|
||||
PET_FLAT_OBJECT_MOCK,
|
||||
].reduce((flatObjectMetadataMaps, flatObjectMetadata) => {
|
||||
return replaceFlatObjectMetadataInFlatObjectMetadataMapsOrThrow({
|
||||
flatObjectMetadata: {
|
||||
...flatObjectMetadata,
|
||||
flatFieldMetadatas: [],
|
||||
},
|
||||
flatObjectMetadataMaps,
|
||||
return addFlatEntityToFlatEntityMapsOrThrow({
|
||||
flatEntity: flatObjectMetadata,
|
||||
flatEntityMaps: flatObjectMetadataMaps,
|
||||
});
|
||||
}, FLAT_OBJECT_METADATA_MAPS_MOCKS);
|
||||
}, EMPTY_FLAT_ENTITY_MAPS);
|
||||
|
||||
type TestCase = EachTestingContext<{
|
||||
input: {
|
||||
rawCreateFieldInput: CreateFieldInput &
|
||||
Required<Pick<CreateFieldInput, 'morphRelationsCreationPayload'>>;
|
||||
workspaceId: string;
|
||||
existingFlatObjectMetadataMaps: FlatObjectMetadataMaps;
|
||||
};
|
||||
input: FromCreateFieldInputToFlatObjectMetadataArgs;
|
||||
expected: 'success' | 'fail';
|
||||
}>;
|
||||
|
||||
@@ -47,13 +42,12 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
'should create morph relation field metadata with valid input on rocket object to pet object',
|
||||
context: {
|
||||
input: {
|
||||
rawCreateFieldInput: {
|
||||
createFieldInput: {
|
||||
name: 'newField',
|
||||
label: 'newFieldLabel',
|
||||
description: 'new field description',
|
||||
type: FieldMetadataType.MORPH_RELATION,
|
||||
objectMetadataId: ROCKET_FLAT_OBJECT_MOCK.id,
|
||||
workspaceId: mockWorkspaceId,
|
||||
morphRelationsCreationPayload: [
|
||||
{
|
||||
type: RelationType.ONE_TO_MANY,
|
||||
@@ -70,7 +64,7 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
],
|
||||
},
|
||||
workspaceId: mockWorkspaceId,
|
||||
existingFlatObjectMetadataMaps,
|
||||
flatObjectMetadataMaps,
|
||||
},
|
||||
expected: 'success',
|
||||
},
|
||||
@@ -87,8 +81,11 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
if (result.status !== 'success') {
|
||||
throw new Error('Should never occur, typecheck');
|
||||
}
|
||||
jestExpectToBeDefined(
|
||||
input.createFieldInput.morphRelationsCreationPayload,
|
||||
);
|
||||
expect(result.result.flatFieldMetadatas.length).toBe(
|
||||
input.rawCreateFieldInput.morphRelationsCreationPayload.length * 2,
|
||||
input.createFieldInput.morphRelationsCreationPayload.length * 2,
|
||||
);
|
||||
expect(result).toMatchSnapshot(
|
||||
extractRecordIdsAndDatesAsExpectAny(result),
|
||||
@@ -103,17 +100,16 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
title: 'should fail when morphRelationsCreationPayload is missing',
|
||||
context: {
|
||||
input: {
|
||||
rawCreateFieldInput: {
|
||||
createFieldInput: {
|
||||
name: 'newField',
|
||||
label: 'newFieldLabel',
|
||||
description: 'new field description',
|
||||
type: FieldMetadataType.MORPH_RELATION,
|
||||
objectMetadataId: ROCKET_FLAT_OBJECT_MOCK.id,
|
||||
workspaceId: mockWorkspaceId,
|
||||
morphRelationsCreationPayload: undefined as any,
|
||||
},
|
||||
workspaceId: mockWorkspaceId,
|
||||
existingFlatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
flatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
},
|
||||
expected: 'fail',
|
||||
},
|
||||
@@ -122,17 +118,16 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
title: 'should fail when morphRelationsCreationPayload is empty array',
|
||||
context: {
|
||||
input: {
|
||||
rawCreateFieldInput: {
|
||||
createFieldInput: {
|
||||
name: 'newField',
|
||||
label: 'newFieldLabel',
|
||||
description: 'new field description',
|
||||
type: FieldMetadataType.MORPH_RELATION,
|
||||
objectMetadataId: ROCKET_FLAT_OBJECT_MOCK.id,
|
||||
workspaceId: mockWorkspaceId,
|
||||
morphRelationsCreationPayload: [],
|
||||
},
|
||||
workspaceId: mockWorkspaceId,
|
||||
existingFlatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
flatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
},
|
||||
expected: 'fail',
|
||||
},
|
||||
@@ -142,13 +137,12 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
'should fail when morphRelationsCreationPayload has different relation types',
|
||||
context: {
|
||||
input: {
|
||||
rawCreateFieldInput: {
|
||||
createFieldInput: {
|
||||
name: 'newField',
|
||||
label: 'newFieldLabel',
|
||||
description: 'new field description',
|
||||
type: FieldMetadataType.MORPH_RELATION,
|
||||
objectMetadataId: ROCKET_FLAT_OBJECT_MOCK.id,
|
||||
workspaceId: mockWorkspaceId,
|
||||
morphRelationsCreationPayload: [
|
||||
{
|
||||
type: RelationType.ONE_TO_MANY,
|
||||
@@ -165,7 +159,7 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
],
|
||||
},
|
||||
workspaceId: mockWorkspaceId,
|
||||
existingFlatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
flatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
},
|
||||
expected: 'fail',
|
||||
},
|
||||
@@ -175,13 +169,12 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
'should fail when morphRelationsCreationPayload has several references to same object metadata',
|
||||
context: {
|
||||
input: {
|
||||
rawCreateFieldInput: {
|
||||
createFieldInput: {
|
||||
name: 'newField',
|
||||
label: 'newFieldLabel',
|
||||
description: 'new field description',
|
||||
type: FieldMetadataType.MORPH_RELATION,
|
||||
objectMetadataId: ROCKET_FLAT_OBJECT_MOCK.id,
|
||||
workspaceId: mockWorkspaceId,
|
||||
morphRelationsCreationPayload: [
|
||||
{
|
||||
type: RelationType.MANY_TO_ONE,
|
||||
@@ -198,7 +191,7 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
],
|
||||
},
|
||||
workspaceId: mockWorkspaceId,
|
||||
existingFlatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
flatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
},
|
||||
expected: 'fail',
|
||||
},
|
||||
@@ -208,13 +201,12 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
'should fail when morphRelationsCreationPayload has invalid relation payload',
|
||||
context: {
|
||||
input: {
|
||||
rawCreateFieldInput: {
|
||||
createFieldInput: {
|
||||
name: 'newField',
|
||||
label: 'newFieldLabel',
|
||||
description: 'new field description',
|
||||
type: FieldMetadataType.MORPH_RELATION,
|
||||
objectMetadataId: ROCKET_FLAT_OBJECT_MOCK.id,
|
||||
workspaceId: mockWorkspaceId,
|
||||
morphRelationsCreationPayload: [
|
||||
{
|
||||
type: RelationType.ONE_TO_MANY,
|
||||
@@ -224,7 +216,7 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
],
|
||||
},
|
||||
workspaceId: mockWorkspaceId,
|
||||
existingFlatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
flatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
},
|
||||
expected: 'fail',
|
||||
},
|
||||
@@ -233,13 +225,12 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
title: 'should fail when target object metadata is not found',
|
||||
context: {
|
||||
input: {
|
||||
rawCreateFieldInput: {
|
||||
createFieldInput: {
|
||||
name: 'newField',
|
||||
label: 'newFieldLabel',
|
||||
description: 'new field description',
|
||||
type: FieldMetadataType.MORPH_RELATION,
|
||||
objectMetadataId: ROCKET_FLAT_OBJECT_MOCK.id,
|
||||
workspaceId: mockWorkspaceId,
|
||||
morphRelationsCreationPayload: [
|
||||
{
|
||||
type: RelationType.ONE_TO_MANY,
|
||||
@@ -250,7 +241,7 @@ describe('fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test s
|
||||
],
|
||||
},
|
||||
workspaceId: mockWorkspaceId,
|
||||
existingFlatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
flatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
},
|
||||
expected: 'fail',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user