Skip to content

The open alternative to Salesforce, designed for AI.

Snapshot the exported manifest and guard the compared properties in the export spec (#25593)

Weikoe9db61dabe1f
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/export-covers-compared-properties.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/export-covers-compared-properties.spec.ts
new file mode 100644
index 00000000000..e81ad077f0e
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/export-covers-compared-properties.spec.ts
@@ -0,0 +1,130 @@
+import { FieldMetadataType } from 'twenty-shared/types';
+
+import { fromFlatFieldMetadataToFieldManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-field-metadata-to-field-manifest.util';
+import { fromFlatIndexMetadataToIndexManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-index-metadata-to-index-manifest.util';
+import { fromFlatObjectMetadataToObjectManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-object-metadata-to-object-manifest.util';
+import { ALL_UNIVERSAL_FLAT_ENTITY_PROPERTIES_TO_COMPARE_AND_STRINGIFY } from 'src/engine/metadata-modules/flat-entity/constant/all-universal-flat-entity-properties-to-compare-and-stringify.constant';
+import { getFlatFieldMetadataMock } from 'src/engine/metadata-modules/flat-field-metadata/__mocks__/get-flat-field-metadata.mock';
+import { getFlatIndexMetadataMock } from 'src/engine/metadata-modules/flat-index-metadata/__mocks__/get-flat-index-metadata.mock';
+import { getFlatObjectMetadataMock } from 'src/engine/metadata-modules/flat-object-metadata/__mocks__/get-flat-object-metadata.mock';
+
+const APP_UID = '11111111-1111-4111-8111-111111111111';
+const OBJECT_UID = '22222222-2222-4222-8222-222222222222';
+const FIELD_UID = '33333333-3333-4333-8333-333333333333';
+const INDEX_UID = '44444444-4444-4444-8444-444444444444';
+
+type ExportedKind = {
+ metadataName: 'objectMetadata' | 'fieldMetadata' | 'index';
+ emittedProperties: string[];
+ renamedProperties: Record<string, string>;
+ workspaceLocalProperties: string[];
+ knownGaps: Record<string, string>;
+};
+
+const WORKSPACE_LOCAL_PROPERTIES = ['isActive', 'overrides'];
+
+const EXPORTED_KINDS: ExportedKind[] = [
+ {
+ metadataName: 'objectMetadata',
+ emittedProperties: Object.keys(
+ fromFlatObjectMetadataToObjectManifest({
+ flatObjectMetadata: getFlatObjectMetadataMock({
+ universalIdentifier: OBJECT_UID,
+ applicationUniversalIdentifier: APP_UID,
+ description: 'An object',
+ icon: 'IconBox',
+ color: 'blue',
+ imageIdentifierFieldMetadataUniversalIdentifier: FIELD_UID,
+ labelIdentifierFieldMetadataUniversalIdentifier: FIELD_UID,
+ }),
+ fields: [],
+ labelIdentifierFieldMetadataUniversalIdentifier: FIELD_UID,
+ }),
+ ),
+ renamedProperties: {},
+ workspaceLocalProperties: WORKSPACE_LOCAL_PROPERTIES,
+ knownGaps: {},
+ },
+ {
+ metadataName: 'fieldMetadata',
+ emittedProperties: Object.keys(
+ fromFlatFieldMetadataToFieldManifest({
+ flatFieldMetadata: getFlatFieldMetadataMock({
+ universalIdentifier: FIELD_UID,
+ objectMetadataId: 'object-id',
+ objectMetadataUniversalIdentifier: OBJECT_UID,
+ applicationUniversalIdentifier: APP_UID,
+ type: FieldMetadataType.TEXT,
+ description: 'A field',
+ icon: 'IconAbc',
+ defaultValue: "'x'",
+ options: null,
+ universalSettings: null,
+ }),
+ }),
+ ),
+ renamedProperties: {},
+ workspaceLocalProperties: WORKSPACE_LOCAL_PROPERTIES,
+ knownGaps: {},
+ },
+ {
+ metadataName: 'index',
+ emittedProperties: Object.keys(
+ fromFlatIndexMetadataToIndexManifest({
+ flatIndexMetadata: getFlatIndexMetadataMock({
+ universalIdentifier: INDEX_UID,
+ objectMetadataId: 'object-id',
+ objectMetadataUniversalIdentifier: OBJECT_UID,
+ applicationUniversalIdentifier: APP_UID,
+ }),
+ }),
+ ),
+ renamedProperties: { universalFlatIndexFieldMetadatas: 'fields' },
+ workspaceLocalProperties: [],
+ knownGaps: {
+ name: 'the forward converter derives the index name from the object and field names, so a renamed index is a known asymmetry',
+ indexWhereClause:
+ 'partial indexes are reported as unsupported instead of exported',
+ },
+ },
+];
+
+describe('export coverage of the compared properties', () => {
+ it.each(EXPORTED_KINDS)(
+ 'should emit every compared property of $metadataName or account for it explicitly',
+ ({
+ metadataName,
+ emittedProperties,
+ renamedProperties,
+ workspaceLocalProperties,
+ knownGaps,
+ }) => {
+ const comparedProperties: readonly string[] =
+ ALL_UNIVERSAL_FLAT_ENTITY_PROPERTIES_TO_COMPARE_AND_STRINGIFY[
+ metadataName
+ ].propertiesToCompare;
+ const unaccounted = comparedProperties.filter(
+ (property) =>
+ !emittedProperties.includes(
+ renamedProperties[property] ?? property,
+ ) &&
+ !workspaceLocalProperties.includes(property) &&
+ !(property in knownGaps),
+ );
+
+ expect(unaccounted).toEqual([]);
+ },
+ );
+
+ it.each(EXPORTED_KINDS)(
+ 'should not keep accounting for a property of $metadataName that is now emitted',
+ ({ emittedProperties, workspaceLocalProperties, knownGaps }) => {
+ const staleEntries = [
+ ...workspaceLocalProperties,
+ ...Object.keys(knownGaps),
+ ].filter((property) => emittedProperties.includes(property));
+
+ expect(staleEntries).toEqual([]);
+ },
+ );
+});
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/successful-export-application-data-model.integration-spec.ts.snap b/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/successful-export-application-data-model.integration-spec.ts.snap
new file mode 100644
index 00000000000..2b9e70b9915
--- /dev/null
+++ b/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/successful-export-application-data-model.integration-spec.ts.snap
@@ -0,0 +1,782 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Application export - data model exports the whole application as a stable manifest and classifies every row: coverage 1`] = `
+{
+ "deterministicUnnamed": [],
+ "named": [
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "EXPORTED",
+ "universalIdentifier": "<COMPANY_TAGLINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_attachment_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_createdAt_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_createdBy_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_deletedAt_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_id_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_noteTarget_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_position_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_searchVector_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_taskTarget_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "EXPORTED",
+ "universalIdentifier": "<PROJECT_TICKETS_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_timelineActivity_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_updatedAt_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_updatedBy_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<STANDARD_attachment_targetPROJECT_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<STANDARD_attachment_targetTICKET_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<STANDARD_noteTarget_targetPROJECT_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<STANDARD_noteTarget_targetTICKET_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<STANDARD_taskTarget_targetPROJECT_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<STANDARD_taskTarget_targetTICKET_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<STANDARD_timelineActivity_targetPROJECT_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<STANDARD_timelineActivity_targetTICKET_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_attachment_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_createdAt_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_createdBy_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_deletedAt_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_id_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_noteTarget_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_position_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "EXPORTED",
+ "universalIdentifier": "<TICKET_PROJECT_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_searchVector_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_taskTarget_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_timelineActivity_SYSTEM_RELATION_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "EXPORTED",
+ "universalIdentifier": "<TICKET_TITLE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_updatedAt_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "fieldMetadata",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_updatedBy_ENGINE_FIELD>",
+ },
+ {
+ "metadataName": "index",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_SEARCH_VECTOR_ENGINE_INDEX>",
+ },
+ {
+ "metadataName": "index",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_SEARCH_VECTOR_ENGINE_INDEX>",
+ },
+ {
+ "metadataName": "index",
+ "reason": null,
+ "status": "EXPORTED",
+ "universalIdentifier": "<TICKET_TITLE_INDEX>",
+ },
+ {
+ "metadataName": "objectMetadata",
+ "reason": null,
+ "status": "EXPORTED",
+ "universalIdentifier": "<PROJECT_OBJECT>",
+ },
+ {
+ "metadataName": "objectMetadata",
+ "reason": null,
+ "status": "EXPORTED",
+ "universalIdentifier": "<TICKET_OBJECT>",
+ },
+ {
+ "metadataName": "pageLayout",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_FORM_LAYOUT>",
+ },
+ {
+ "metadataName": "pageLayout",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_PAGE_LAYOUT>",
+ },
+ {
+ "metadataName": "pageLayout",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_FORM_LAYOUT>",
+ },
+ {
+ "metadataName": "pageLayout",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_PAGE_LAYOUT>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_FORM_TAB>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_PAGE_TAB_Files>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_PAGE_TAB_Home>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_PAGE_TAB_Notes>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_PAGE_TAB_Tasks>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_PAGE_TAB_Timeline>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_FORM_TAB>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_PAGE_TAB_Files>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_PAGE_TAB_Home>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_PAGE_TAB_Notes>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_PAGE_TAB_Tasks>",
+ },
+ {
+ "metadataName": "pageLayoutTab",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_PAGE_TAB_Timeline>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_PAGE_WIDGET_Fields>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_PAGE_WIDGET_Files>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_PAGE_WIDGET_Notes>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_PAGE_WIDGET_Tasks>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_RECORD_PAGE_WIDGET_Timeline>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<STANDARD_COMPANY_RECORD_FORM_WIDGET_tagline>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_FORM_WIDGET_project>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_FORM_WIDGET_title>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_PAGE_WIDGET_Fields>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_PAGE_WIDGET_Files>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_PAGE_WIDGET_Notes>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_PAGE_WIDGET_Tasks>",
+ },
+ {
+ "metadataName": "pageLayoutWidget",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_RECORD_PAGE_WIDGET_Timeline>",
+ },
+ {
+ "metadataName": "role",
+ "reason": null,
+ "status": "UNSUPPORTED",
+ "universalIdentifier": "<TEST_ROLE>",
+ },
+ {
+ "metadataName": "view",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_FIELDS_WIDGET_ENGINE_VIEW>",
+ },
+ {
+ "metadataName": "view",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_INDEX_ENGINE_VIEW>",
+ },
+ {
+ "metadataName": "view",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_FIELDS_WIDGET_ENGINE_VIEW>",
+ },
+ {
+ "metadataName": "view",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_INDEX_ENGINE_VIEW>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_FIELDS_WIDGET_ENGINE_VIEW_FIELD_createdAt>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_FIELDS_WIDGET_ENGINE_VIEW_FIELD_createdBy>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_FIELDS_WIDGET_ENGINE_VIEW_FIELD_tickets>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_FIELDS_WIDGET_ENGINE_VIEW_FIELD_updatedAt>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_FIELDS_WIDGET_ENGINE_VIEW_FIELD_updatedBy>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_INDEX_ENGINE_VIEW_FIELD_createdAt>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_INDEX_ENGINE_VIEW_FIELD_createdBy>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_INDEX_ENGINE_VIEW_FIELD_id>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_INDEX_ENGINE_VIEW_FIELD_tickets>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_INDEX_ENGINE_VIEW_FIELD_updatedAt>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<PROJECT_INDEX_ENGINE_VIEW_FIELD_updatedBy>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<STANDARD_COMPANY_FIELDS_WIDGET_ENGINE_VIEW_FIELD_tagline>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<STANDARD_COMPANY_INDEX_ENGINE_VIEW_FIELD_tagline>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_FIELDS_WIDGET_ENGINE_VIEW_FIELD_createdAt>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_FIELDS_WIDGET_ENGINE_VIEW_FIELD_createdBy>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_FIELDS_WIDGET_ENGINE_VIEW_FIELD_project>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_FIELDS_WIDGET_ENGINE_VIEW_FIELD_title>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_FIELDS_WIDGET_ENGINE_VIEW_FIELD_updatedAt>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_FIELDS_WIDGET_ENGINE_VIEW_FIELD_updatedBy>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_INDEX_ENGINE_VIEW_FIELD_createdAt>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_INDEX_ENGINE_VIEW_FIELD_createdBy>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_INDEX_ENGINE_VIEW_FIELD_id>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_INDEX_ENGINE_VIEW_FIELD_project>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_INDEX_ENGINE_VIEW_FIELD_title>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_INDEX_ENGINE_VIEW_FIELD_updatedAt>",
+ },
+ {
+ "metadataName": "viewField",
+ "reason": null,
+ "status": "ENGINE_DERIVED",
+ "universalIdentifier": "<TICKET_INDEX_ENGINE_VIEW_FIELD_updatedBy>",
+ },
+ ],
+ "randomlyIdentifiedByKindAndStatus": {
+ "index ENGINE_DERIVED": 8,
+ },
+}
+`;
+
+exports[`Application export - data model exports the whole application as a stable manifest and classifies every row: manifest 1`] = `
+{
+ "agents": [],
+ "application": {
+ "defaultRoleUniversalIdentifier": "<TEST_ROLE>",
+ "description": "Test application",
+ "displayName": "Test Application",
+ "packageJsonChecksum": null,
+ "universalIdentifier": "<TEST_APP>",
+ "yarnLockChecksum": null,
+ },
+ "commandMenuItems": [],
+ "fields": [
+ {
+ "defaultValue": null,
+ "isLabelSyncedWithName": false,
+ "isNullable": true,
+ "isSearchable": false,
+ "isUIEditable": true,
+ "isUnique": false,
+ "label": "Export Tagline",
+ "name": "exportTagline",
+ "objectUniversalIdentifier": "<STANDARD_COMPANY_OBJECT>",
+ "options": null,
+ "type": "TEXT",
+ "universalIdentifier": "<COMPANY_TAGLINE_FIELD>",
+ "universalSettings": null,
+ "writability": "OPEN",
+ },
+ ],
+ "frontComponents": [],
+ "indexes": [
+ {
+ "fields": [
+ {
+ "fieldUniversalIdentifier": "<TICKET_TITLE_FIELD>",
+ "universalIdentifier": "<TICKET_TITLE_INDEX_FIELD_ENGINE_DERIVED>",
+ },
+ ],
+ "indexType": "BTREE",
+ "isUnique": false,
+ "objectUniversalIdentifier": "<TICKET_OBJECT>",
+ "universalIdentifier": "<TICKET_TITLE_INDEX>",
+ },
+ ],
+ "logicFunctions": [],
+ "navigationMenuItems": [],
+ "objects": [
+ {
+ "color": null,
+ "description": "A project",
+ "fields": [
+ {
+ "defaultValue": null,
+ "isLabelSyncedWithName": false,
+ "isNullable": true,
+ "isSearchable": false,
+ "isUIEditable": true,
+ "isUnique": false,
+ "label": "Tickets",
+ "name": "tickets",
+ "options": null,
+ "relationTargetFieldMetadataUniversalIdentifier": "<TICKET_PROJECT_FIELD>",
+ "relationTargetObjectMetadataUniversalIdentifier": "<TICKET_OBJECT>",
+ "type": "RELATION",
+ "universalIdentifier": "<PROJECT_TICKETS_FIELD>",
+ "universalSettings": {
+ "relationType": "ONE_TO_MANY",
+ },
+ "writability": "OPEN",
+ },
+ ],
+ "icon": "IconTicket",
+ "imageIdentifierFieldMetadataUniversalIdentifier": null,
+ "isLabelSyncedWithName": false,
+ "isSearchable": true,
+ "isUICreatable": true,
+ "isUIEditable": true,
+ "labelIdentifierFieldMetadataUniversalIdentifier": "<PROJECT_id_ENGINE_FIELD>",
+ "labelPlural": "Export Projects",
+ "labelSingular": "Export Project",
+ "namePlural": "exportProjects",
+ "nameSingular": "exportProject",
+ "openRecordIn": "USER_CHOICE",
+ "readability": "OPEN",
+ "universalIdentifier": "<PROJECT_OBJECT>",
+ "writability": "OPEN",
+ },
+ {
+ "color": "blue",
+ "description": "A ticket",
+ "fields": [
+ {
+ "defaultValue": null,
+ "isLabelSyncedWithName": false,
+ "isNullable": true,
+ "isSearchable": false,
+ "isUIEditable": true,
+ "isUnique": false,
+ "label": "Project",
+ "name": "project",
+ "options": null,
+ "relationTargetFieldMetadataUniversalIdentifier": "<PROJECT_TICKETS_FIELD>",
+ "relationTargetObjectMetadataUniversalIdentifier": "<PROJECT_OBJECT>",
+ "type": "RELATION",
+ "universalIdentifier": "<TICKET_PROJECT_FIELD>",
+ "universalSettings": {
+ "joinColumnName": "projectId",
+ "onDelete": "SET_NULL",
+ "relationType": "MANY_TO_ONE",
+ },
+ "writability": "OPEN",
+ },
+ {
+ "defaultValue": null,
+ "isLabelSyncedWithName": true,
+ "isNullable": true,
+ "isSearchable": false,
+ "isUIEditable": true,
+ "isUnique": false,
+ "label": "Title",
+ "name": "title",
+ "options": null,
+ "type": "TEXT",
+ "universalIdentifier": "<TICKET_TITLE_FIELD>",
+ "universalSettings": null,
+ "writability": "OPEN",
+ },
+ ],
+ "icon": "IconTicket",
+ "imageIdentifierFieldMetadataUniversalIdentifier": null,
+ "isLabelSyncedWithName": true,
+ "isSearchable": true,
+ "isUICreatable": true,
+ "isUIEditable": true,
+ "labelIdentifierFieldMetadataUniversalIdentifier": "<TICKET_id_ENGINE_FIELD>",
+ "labelPlural": "Export Tickets",
+ "labelSingular": "Export Ticket",
+ "namePlural": "exportTickets",
+ "nameSingular": "exportTicket",
+ "openRecordIn": "USER_CHOICE",
+ "readability": "OPEN",
+ "universalIdentifier": "<TICKET_OBJECT>",
+ "writability": "OPEN",
+ },
+ ],
+ "pageLayoutTabs": [],
+ "pageLayouts": [],
+ "permissionFlags": [],
+ "publicAssets": [],
+ "roles": [],
+ "skills": [],
+ "timelineActivityTypes": [],
+ "translations": {
+ "fr-FR": {
+ "export.ticket.project": "Projet",
+ "export.ticket.title": "Titre du ticket",
+ },
+ },
+ "viewFields": [],
+ "views": [],
+}
+`;
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/successful-export-application-data-model.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/successful-export-application-data-model.integration-spec.ts
index 090d0947cc8..6e75f793956 100644
--- a/packages/twenty-server/test/integration/metadata/suites/application/successful-export-application-data-model.integration-spec.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/application/successful-export-application-data-model.integration-spec.ts
@@ -7,7 +7,18 @@ import { setupApplicationForSync } from 'test/integration/metadata/suites/applic
import { syncApplication } from 'test/integration/metadata/suites/application/utils/sync-application.util';
import {
type FieldManifest,
+ getFieldUniversalIdentifier,
+ getIndexFieldUniversalIdentifier,
+ getSystemFormFieldPageLayoutWidgetUniversalIdentifier,
+ getSystemPageLayoutTabUniversalIdentifier,
+ getSystemPageLayoutWidgetUniversalIdentifier,
+ getSystemRecordFormPageLayoutUniversalIdentifier,
+ getSystemRecordPageLayoutUniversalIdentifier,
+ getSystemRelationFieldUniversalIdentifier,
+ getSystemViewFieldUniversalIdentifier,
+ getSystemViewUniversalIdentifier,
type ObjectManifest,
+ SYSTEM_VIEW_KEYS,
type TranslationsManifest,
TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,
} from 'twenty-shared/application';
@@ -18,20 +29,317 @@ import {
RelationType,
} from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
-import { v4 as uuidv4 } from 'uuid';
+import { version as getUuidVersion } from 'uuid';
import { WORKSPACE_CUSTOM_APPLICATION_NAME } from 'src/engine/core-modules/application/constants/workspace-custom-application.constant';
import { ApplicationExportCoverageStatus } from 'src/engine/core-modules/application/enums/application-export-coverage-status.enum';
+import { fromObjectManifestToUniversalFlatObjectMetadata } from 'src/engine/core-modules/application/application-manifest/converters/from-object-manifest-to-universal-flat-object-metadata.util';
+import { buildSearchVectorFlatFieldMetadataForCustomObject } from 'src/engine/metadata-modules/object-metadata/utils/build-search-vector-flat-field-metadata-for-custom-object.util';
+import { buildSearchVectorGinIndexForCustomObject } from 'src/engine/metadata-modules/object-metadata/utils/build-search-vector-gin-index-for-custom-object.util';
+
+const TEST_APP_ID = '7e3d1c2b-0000-4a7b-8c9d-0e1f2a3b4c5d';
+const TEST_ROLE_ID = '7e3d1c2b-0001-4a7b-8c9d-0e1f2a3b4c5d';
+const TICKET_OBJECT_ID = '7e3d1c2b-0002-4a7b-8c9d-0e1f2a3b4c5d';
+const PROJECT_OBJECT_ID = '7e3d1c2b-0003-4a7b-8c9d-0e1f2a3b4c5d';
+const TICKET_TITLE_FIELD_ID = '7e3d1c2b-0004-4a7b-8c9d-0e1f2a3b4c5d';
+const TICKET_PROJECT_FIELD_ID = '7e3d1c2b-0005-4a7b-8c9d-0e1f2a3b4c5d';
+const PROJECT_TICKETS_FIELD_ID = '7e3d1c2b-0006-4a7b-8c9d-0e1f2a3b4c5d';
+const COMPANY_TAGLINE_FIELD_ID = '7e3d1c2b-0007-4a7b-8c9d-0e1f2a3b4c5d';
+const INDEX_ID = '7e3d1c2b-0008-4a7b-8c9d-0e1f2a3b4c5d';
+const INDEX_FIELD_ID = '7e3d1c2b-0009-4a7b-8c9d-0e1f2a3b4c5d';
+
+const ENGINE_DERIVED_FIELD_NAMES = [
+ 'id',
+ 'createdAt',
+ 'updatedAt',
+ 'deletedAt',
+ 'createdBy',
+ 'updatedBy',
+ 'position',
+ 'searchVector',
+];
+
+const SYSTEM_RELATION_TARGET_OBJECT_NAMES = [
+ 'timelineActivity',
+ 'attachment',
+ 'noteTarget',
+ 'taskTarget',
+] as const;
+
+const RECORD_PAGE_TABS = [
+ { tabTitle: 'Home', widgetTitle: 'Fields' },
+ { tabTitle: 'Timeline', widgetTitle: 'Timeline' },
+ { tabTitle: 'Tasks', widgetTitle: 'Tasks' },
+ { tabTitle: 'Notes', widgetTitle: 'Notes' },
+ { tabTitle: 'Files', widgetTitle: 'Files' },
+];
+
+const RECORD_FORM_TAB_TITLE = 'Fields';
+
+type SystemRowsOwner = {
+ objectName: string;
+ objectUniversalIdentifier: string;
+ objectMetadataApplicationUniversalIdentifier: string;
+ applicationFieldUniversalIdentifierByName: Record<string, string>;
+};
+
+const buildIdentifierNames = (): Map<string, string> => {
+ const names = new Map<string, string>([
+ [TEST_APP_ID, 'TEST_APP'],
+ [TEST_ROLE_ID, 'TEST_ROLE'],
+ [TICKET_OBJECT_ID, 'TICKET_OBJECT'],
+ [PROJECT_OBJECT_ID, 'PROJECT_OBJECT'],
+ [TICKET_TITLE_FIELD_ID, 'TICKET_TITLE_FIELD'],
+ [TICKET_PROJECT_FIELD_ID, 'TICKET_PROJECT_FIELD'],
+ [PROJECT_TICKETS_FIELD_ID, 'PROJECT_TICKETS_FIELD'],
+ [COMPANY_TAGLINE_FIELD_ID, 'COMPANY_TAGLINE_FIELD'],
+ [INDEX_ID, 'TICKET_TITLE_INDEX'],
+ [
+ getIndexFieldUniversalIdentifier({
+ applicationUniversalIdentifier: TEST_APP_ID,
+ indexUniversalIdentifier: INDEX_ID,
+ fieldUniversalIdentifier: TICKET_TITLE_FIELD_ID,
+ }),
+ 'TICKET_TITLE_INDEX_FIELD_ENGINE_DERIVED',
+ ],
+ [STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.company, 'STANDARD_COMPANY_OBJECT'],
+ ]);
+
+ const nameSystemRowsOfObject = ({
+ objectName,
+ objectUniversalIdentifier,
+ objectMetadataApplicationUniversalIdentifier,
+ applicationFieldUniversalIdentifierByName,
+ }: SystemRowsOwner) => {
+ const applicationFields = Object.entries(
+ applicationFieldUniversalIdentifierByName,
+ );
+
+ for (const viewKey of Object.values(SYSTEM_VIEW_KEYS)) {
+ const viewUniversalIdentifier = getSystemViewUniversalIdentifier({
+ objectMetadataApplicationUniversalIdentifier,
+ objectUniversalIdentifier,
+ viewKey,
+ });
+
+ names.set(
+ viewUniversalIdentifier,
+ `${objectName}_${viewKey}_ENGINE_VIEW`,
+ );
+
+ for (const [
+ fieldName,
+ fieldMetadataUniversalIdentifier,
+ ] of applicationFields) {
+ names.set(
+ getSystemViewFieldUniversalIdentifier({
+ fieldMetadataApplicationUniversalIdentifier: TEST_APP_ID,
+ viewUniversalIdentifier,
+ fieldMetadataUniversalIdentifier,
+ }),
+ `${objectName}_${viewKey}_ENGINE_VIEW_FIELD_${fieldName}`,
+ );
+ }
+ }
+
+ const recordPageLayoutUniversalIdentifier =
+ getSystemRecordPageLayoutUniversalIdentifier({
+ objectMetadataApplicationUniversalIdentifier,
+ objectUniversalIdentifier,
+ });
+
+ names.set(
+ recordPageLayoutUniversalIdentifier,
+ `${objectName}_RECORD_PAGE_LAYOUT`,
+ );
+
+ for (const { tabTitle, widgetTitle } of RECORD_PAGE_TABS) {
+ const pageLayoutTabUniversalIdentifier =
+ getSystemPageLayoutTabUniversalIdentifier({
+ objectMetadataApplicationUniversalIdentifier,
+ pageLayoutUniversalIdentifier: recordPageLayoutUniversalIdentifier,
+ title: tabTitle,
+ });
+
+ names.set(
+ pageLayoutTabUniversalIdentifier,
+ `${objectName}_RECORD_PAGE_TAB_${tabTitle}`,
+ );
+ names.set(
+ getSystemPageLayoutWidgetUniversalIdentifier({
+ objectMetadataApplicationUniversalIdentifier,
+ pageLayoutTabUniversalIdentifier,
+ title: widgetTitle,
+ }),
+ `${objectName}_RECORD_PAGE_WIDGET_${widgetTitle}`,
+ );
+ }
+
+ const recordFormLayoutUniversalIdentifier =
+ getSystemRecordFormPageLayoutUniversalIdentifier({
+ objectMetadataApplicationUniversalIdentifier,
+ objectUniversalIdentifier,
+ });
+ const recordFormTabUniversalIdentifier =
+ getSystemPageLayoutTabUniversalIdentifier({
+ objectMetadataApplicationUniversalIdentifier,
+ pageLayoutUniversalIdentifier: recordFormLayoutUniversalIdentifier,
+ title: RECORD_FORM_TAB_TITLE,
+ });
+
+ names.set(
+ recordFormLayoutUniversalIdentifier,
+ `${objectName}_RECORD_FORM_LAYOUT`,
+ );
+ names.set(
+ recordFormTabUniversalIdentifier,
+ `${objectName}_RECORD_FORM_TAB`,
+ );
+
+ for (const [
+ fieldName,
+ fieldMetadataUniversalIdentifier,
+ ] of applicationFields) {
+ names.set(
+ getSystemFormFieldPageLayoutWidgetUniversalIdentifier({
+ fieldMetadataApplicationUniversalIdentifier: TEST_APP_ID,
+ pageLayoutTabUniversalIdentifier: recordFormTabUniversalIdentifier,
+ fieldMetadataUniversalIdentifier,
+ }),
+ `${objectName}_RECORD_FORM_WIDGET_${fieldName}`,
+ );
+ }
+ };
+
+ for (const {
+ objectName,
+ objectUniversalIdentifier,
+ objectManifest,
+ authoredFieldUniversalIdentifierByName,
+ } of [
+ {
+ objectName: 'TICKET',
+ objectUniversalIdentifier: TICKET_OBJECT_ID,
+ objectManifest: ticketObject,
+ authoredFieldUniversalIdentifierByName: {
+ title: TICKET_TITLE_FIELD_ID,
+ project: TICKET_PROJECT_FIELD_ID,
+ },
+ },
+ {
+ objectName: 'PROJECT',
+ objectUniversalIdentifier: PROJECT_OBJECT_ID,
+ objectManifest: projectObject,
+ authoredFieldUniversalIdentifierByName: {
+ tickets: PROJECT_TICKETS_FIELD_ID,
+ },
+ },
+ ]) {
+ const engineFieldUniversalIdentifierByName = Object.fromEntries(
+ ENGINE_DERIVED_FIELD_NAMES.map((fieldName) => [
+ fieldName,
+ getFieldUniversalIdentifier({
+ applicationUniversalIdentifier: TEST_APP_ID,
+ objectUniversalIdentifier,
+ name: fieldName,
+ }),
+ ]),
+ );
+
+ for (const [fieldName, fieldUniversalIdentifier] of Object.entries(
+ engineFieldUniversalIdentifierByName,
+ )) {
+ names.set(
+ fieldUniversalIdentifier,
+ `${objectName}_${fieldName}_ENGINE_FIELD`,
+ );
+ }
+
+ const flatObjectMetadata = fromObjectManifestToUniversalFlatObjectMetadata({
+ objectManifest,
+ applicationUniversalIdentifier: TEST_APP_ID,
+ now: new Date().toISOString(),
+ });
+
+ names.set(
+ buildSearchVectorGinIndexForCustomObject({
+ flatObjectMetadata,
+ searchVectorFlatFieldMetadata:
+ buildSearchVectorFlatFieldMetadataForCustomObject({
+ flatObjectMetadata,
+ }),
+ }).universalIdentifier,
+ `${objectName}_SEARCH_VECTOR_ENGINE_INDEX`,
+ );
+
+ const systemRelationFieldUniversalIdentifierByName: Record<string, string> =
+ {};
+
+ for (const targetObjectName of SYSTEM_RELATION_TARGET_OBJECT_NAMES) {
+ const targetObjectUniversalIdentifier =
+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS[targetObjectName];
+ const forwardFieldUniversalIdentifier =
+ getSystemRelationFieldUniversalIdentifier({
+ applicationUniversalIdentifier: TEST_APP_ID,
+ objectUniversalIdentifier,
+ relationTargetObjectUniversalIdentifier:
+ targetObjectUniversalIdentifier,
+ });
+ const reverseFieldUniversalIdentifier =
+ getSystemRelationFieldUniversalIdentifier({
+ applicationUniversalIdentifier: TEST_APP_ID,
+ objectUniversalIdentifier: targetObjectUniversalIdentifier,
+ relationTargetObjectUniversalIdentifier: objectUniversalIdentifier,
+ });
+
+ systemRelationFieldUniversalIdentifierByName[targetObjectName] =
+ forwardFieldUniversalIdentifier;
+ names.set(
+ forwardFieldUniversalIdentifier,
+ `${objectName}_${targetObjectName}_SYSTEM_RELATION_FIELD`,
+ );
+ names.set(
+ reverseFieldUniversalIdentifier,
+ `STANDARD_${targetObjectName}_target${objectName}_SYSTEM_RELATION_FIELD`,
+ );
+ nameSystemRowsOfObject({
+ objectName: `STANDARD_${targetObjectName}`,
+ objectUniversalIdentifier: targetObjectUniversalIdentifier,
+ objectMetadataApplicationUniversalIdentifier:
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,
+ applicationFieldUniversalIdentifierByName: {
+ [`target${objectName}`]: reverseFieldUniversalIdentifier,
+ },
+ });
+ }
+
+ nameSystemRowsOfObject({
+ objectName,
+ objectUniversalIdentifier,
+ objectMetadataApplicationUniversalIdentifier: TEST_APP_ID,
+ applicationFieldUniversalIdentifierByName: {
+ ...authoredFieldUniversalIdentifierByName,
+ ...engineFieldUniversalIdentifierByName,
+ ...systemRelationFieldUniversalIdentifierByName,
+ },
+ });
+ }
+
+ nameSystemRowsOfObject({
+ objectName: 'STANDARD_COMPANY',
+ objectUniversalIdentifier: STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.company,
+ objectMetadataApplicationUniversalIdentifier:
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,
+ applicationFieldUniversalIdentifierByName: {
+ tagline: COMPANY_TAGLINE_FIELD_ID,
+ },
+ });
-const TEST_APP_ID = uuidv4();
-const TEST_ROLE_ID = uuidv4();
-const TICKET_TITLE_FIELD_ID = uuidv4();
-const TICKET_PROJECT_FIELD_ID = uuidv4();
-const PROJECT_TICKETS_FIELD_ID = uuidv4();
-const COMPANY_TAGLINE_FIELD_ID = uuidv4();
-const INDEX_ID = uuidv4();
+ return names;
+};
const projectObject = buildDefaultObjectManifest({
+ universalIdentifier: PROJECT_OBJECT_ID,
applicationUniversalIdentifier: TEST_APP_ID,
nameSingular: 'exportProject',
namePlural: 'exportProjects',
@@ -42,6 +350,7 @@ const projectObject = buildDefaultObjectManifest({
const ticketObject: ObjectManifest = {
...buildDefaultObjectManifest({
+ universalIdentifier: TICKET_OBJECT_ID,
applicationUniversalIdentifier: TEST_APP_ID,
nameSingular: 'exportTicket',
namePlural: 'exportTickets',
@@ -120,7 +429,7 @@ const manifest = buildBaseManifest({
objectUniversalIdentifier: ticketObject.universalIdentifier,
fields: [
{
- universalIdentifier: uuidv4(),
+ universalIdentifier: INDEX_FIELD_ID,
fieldUniversalIdentifier: TICKET_TITLE_FIELD_ID,
},
],
@@ -129,8 +438,23 @@ const manifest = buildBaseManifest({
},
});
+const IDENTIFIER_NAMES = buildIdentifierNames();
+
+const nameIdentifiers = <TValue>(value: TValue): TValue => {
+ const named: TValue = JSON.parse(JSON.stringify(value), (_key, nodeValue) =>
+ typeof nodeValue === 'string' && IDENTIFIER_NAMES.has(nodeValue)
+ ? `<${IDENTIFIER_NAMES.get(nodeValue)}>`
+ : nodeValue,
+ );
+
+ return named;
+};
+
describe('Application export - data model', () => {
beforeAll(async () => {
+ await cleanupApplicationAndAppRegistration({
+ applicationUniversalIdentifier: TEST_APP_ID,
+ });
await setupApplicationForSync({
applicationUniversalIdentifier: TEST_APP_ID,
name: 'Export Data Model Test Application',
@@ -147,7 +471,7 @@ describe('Application export - data model', () => {
});
});
- it('exports the data model with its fidelity fields and classifies every row', async () => {
+ it('exports the whole application as a stable manifest and classifies every row', async () => {
const { data, errors } = await exportApplication({
universalIdentifier: TEST_APP_ID,
expectToFail: false,
@@ -162,77 +486,94 @@ describe('Application export - data model', () => {
displayName: 'Test Application',
sourceType: 'LOCAL',
});
- expect(exported.manifest.translations).toEqual(FIXTURE_TRANSLATIONS);
- expect(exported.manifest.application.defaultRoleUniversalIdentifier).toBe(
- TEST_ROLE_ID,
+ expect(exported.files).toEqual([]);
+ expect(nameIdentifiers(exported.manifest)).toMatchSnapshot('manifest');
+
+ const isNamedRow = ({
+ universalIdentifier,
+ }: {
+ universalIdentifier: string;
+ }) => IDENTIFIER_NAMES.has(universalIdentifier);
+ const hasRandomUniversalIdentifier = ({
+ universalIdentifier,
+ }: {
+ universalIdentifier: string;
+ }) => getUuidVersion(universalIdentifier) === 4;
+ const compareCoverageRows = (
+ left: { metadataName: string; universalIdentifier: string },
+ right: { metadataName: string; universalIdentifier: string },
+ ) =>
+ left.metadataName.localeCompare(right.metadataName) ||
+ left.universalIdentifier.localeCompare(right.universalIdentifier);
+
+ const unnamedCoverage = exported.coverage.filter((row) => !isNamedRow(row));
+ const randomlyIdentifiedCoverageCounts = Object.fromEntries(
+ Object.entries(
+ unnamedCoverage
+ .filter(hasRandomUniversalIdentifier)
+ .reduce<Record<string, number>>((counts, entry) => {
+ const key = `${entry.metadataName} ${entry.status}${isDefined(entry.reason) ? ` (${entry.reason})` : ''}`;
+
+ counts[key] = (counts[key] ?? 0) + 1;
+
+ return counts;
+ }, {}),
+ ).sort(([left], [right]) => left.localeCompare(right)),
);
- expect(
- exported.manifest.objects.map(({ nameSingular }) => nameSingular),
- ).toEqual(['exportProject', 'exportTicket']);
-
- const exportedTicket = exported.manifest.objects[1];
+ expect({
+ named: nameIdentifiers(exported.coverage.filter(isNamedRow)).sort(
+ compareCoverageRows,
+ ),
+ deterministicUnnamed: unnamedCoverage
+ .filter((row) => !hasRandomUniversalIdentifier(row))
+ .sort(compareCoverageRows),
+ randomlyIdentifiedByKindAndStatus: randomlyIdentifiedCoverageCounts,
+ }).toMatchSnapshot('coverage');
+ }, 60000);
- expect(exportedTicket).toMatchObject({
- color: 'blue',
- isLabelSyncedWithName: true,
- imageIdentifierFieldMetadataUniversalIdentifier: null,
- labelIdentifierFieldMetadataUniversalIdentifier:
- ticketObject.labelIdentifierFieldMetadataUniversalIdentifier,
- });
- expect(exportedTicket.fields.map(({ name }) => name)).toEqual([
- 'project',
- 'title',
- ]);
- expect(
- exportedTicket.fields.find(({ name }) => name === 'project'),
- ).toMatchObject({
- type: FieldMetadataType.RELATION,
- relationTargetFieldMetadataUniversalIdentifier: PROJECT_TICKETS_FIELD_ID,
- universalSettings: {
- relationType: RelationType.MANY_TO_ONE,
- joinColumnName: 'projectId',
- onDelete: RelationOnDeleteAction.SET_NULL,
- },
+ it('keeps the engine-derived label identifier pointer and classifies the rows it cannot export', async () => {
+ const { data } = await exportApplication({
+ universalIdentifier: TEST_APP_ID,
+ expectToFail: false,
});
-
- expect(exported.manifest.fields).toMatchObject([
- {
- universalIdentifier: COMPANY_TAGLINE_FIELD_ID,
- name: 'exportTagline',
- objectUniversalIdentifier:
- STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.company,
- },
- ]);
- expect(exported.manifest.indexes).toMatchObject([
- {
- universalIdentifier: INDEX_ID,
- fields: [{ fieldUniversalIdentifier: TICKET_TITLE_FIELD_ID }],
- },
- ]);
-
+ const exported = data.exportApplication;
+ const exportedTicket = exported.manifest.objects.find(
+ ({ universalIdentifier }) => universalIdentifier === TICKET_OBJECT_ID,
+ );
const statusOf = (universalIdentifier: string) =>
exported.coverage.find(
(entry) => entry.universalIdentifier === universalIdentifier,
)?.status;
- expect(statusOf(ticketObject.universalIdentifier)).toBe(
+ expect(
+ exportedTicket?.labelIdentifierFieldMetadataUniversalIdentifier,
+ ).toBe(
+ getFieldUniversalIdentifier({
+ applicationUniversalIdentifier: TEST_APP_ID,
+ objectUniversalIdentifier: TICKET_OBJECT_ID,
+ name: 'id',
+ }),
+ );
+ expect(exported.manifest.translations).toEqual(FIXTURE_TRANSLATIONS);
+ expect(statusOf(TICKET_OBJECT_ID)).toBe(
ApplicationExportCoverageStatus.EXPORTED,
);
- expect(statusOf(TICKET_TITLE_FIELD_ID)).toBe(
+ expect(statusOf(COMPANY_TAGLINE_FIELD_ID)).toBe(
ApplicationExportCoverageStatus.EXPORTED,
);
- expect(statusOf(INDEX_ID)).toBe(ApplicationExportCoverageStatus.EXPORTED);
expect(statusOf(TEST_ROLE_ID)).toBe(
ApplicationExportCoverageStatus.UNSUPPORTED,
);
expect(
- exported.coverage.filter(
- ({ metadataName, status }) =>
- metadataName === 'fieldMetadata' &&
- status === ApplicationExportCoverageStatus.ENGINE_DERIVED,
- ).length,
- ).toBeGreaterThan(0);
+ statusOf(
+ getSystemViewUniversalIdentifier({
+ objectMetadataApplicationUniversalIdentifier: TEST_APP_ID,
+ objectUniversalIdentifier: TICKET_OBJECT_ID,
+ viewKey: SYSTEM_VIEW_KEYS.INDEX,
+ }),
+ ),
+ ).toBe(ApplicationExportCoverageStatus.ENGINE_DERIVED);
}, 60000);
it('round-trips the raw export through an additive dry-run sync without any action', async () => {