Improve builder return type (#14592)
We need grain in orchestrator over actions ordering for upcoming index integration to v2
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
import { type OrchestratorActionsReport } from 'src/engine/workspace-manager/workspace-migration-v2/types/workspace-migration-orchestrator.type';
|
||||
import { type CreatedDeletedUpdatedActions } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/services/workspace-entity-migration-builder-v2.service';
|
||||
import { type WorkspaceMigrationActionV2 } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/workspace-migration-action-common-v2';
|
||||
|
||||
const emptyCreatedDeletedUpdated: CreatedDeletedUpdatedActions<WorkspaceMigrationActionV2> =
|
||||
{
|
||||
created: [],
|
||||
deleted: [],
|
||||
updated: [],
|
||||
};
|
||||
|
||||
export const EMPTY_ORCHESTRATOR_ACTIONS_REPORT = {
|
||||
index: emptyCreatedDeletedUpdated,
|
||||
objectMetadata: emptyCreatedDeletedUpdated,
|
||||
view: emptyCreatedDeletedUpdated,
|
||||
viewField: emptyCreatedDeletedUpdated,
|
||||
fieldMetadata: emptyCreatedDeletedUpdated,
|
||||
} as const satisfies OrchestratorActionsReport;
|
||||
+31
-8
@@ -4,6 +4,7 @@ import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { EMPTY_ALL_FLAT_ENTITY_MAPS } from 'src/engine/core-modules/common/constant/empty-all-flat-entity-maps.constant';
|
||||
import { AllFlatEntityMaps } from 'src/engine/core-modules/common/types/all-flat-entity-maps.type';
|
||||
import { EMPTY_ORCHESTRATOR_ACTIONS_REPORT } from 'src/engine/workspace-manager/workspace-migration-v2/constant/empty-orchestrator-actions-report.constant';
|
||||
import {
|
||||
OrchestratorFailureReport,
|
||||
WorkspaceMigrationOrchestratorBuildArgs,
|
||||
@@ -14,7 +15,6 @@ import { WorkspaceMigrationV2IndexActionsBuilderService } from 'src/engine/works
|
||||
import { WorkspaceMigrationV2ViewFieldActionsBuilderService } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/builders/view-field/workspace-migration-v2-view-field-actions-builder.service';
|
||||
import { WorkspaceMigrationV2ViewActionsBuilderService } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/builders/view/workspace-migration-v2-view-actions-builder.service';
|
||||
import { WorkspaceMigrationBuilderV2Service } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/services/workspace-migration-builder-v2.service';
|
||||
import { WorkspaceMigrationActionV2 } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/workspace-migration-action-common-v2';
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceMigrationBuildOrchestratorService {
|
||||
@@ -69,7 +69,9 @@ export class WorkspaceMigrationBuildOrchestratorService {
|
||||
| WorkspaceMigrationOrchestratorFailedResult
|
||||
| WorkspaceMigrationOrchestratorSuccessfulResult
|
||||
> {
|
||||
const allActions: WorkspaceMigrationActionV2[] = [];
|
||||
const orchestratorActionsReport = structuredClone({
|
||||
...EMPTY_ORCHESTRATOR_ACTIONS_REPORT,
|
||||
});
|
||||
const orchestratorFailureReport: OrchestratorFailureReport = {
|
||||
objectMetadata: [],
|
||||
view: [],
|
||||
@@ -96,7 +98,6 @@ export class WorkspaceMigrationBuildOrchestratorService {
|
||||
await this.workspaceMigrationBuilderV2Service.validateAndBuild({
|
||||
fromFlatObjectMetadataMaps,
|
||||
toFlatObjectMetadataMaps,
|
||||
workspaceId,
|
||||
buildOptions,
|
||||
});
|
||||
|
||||
@@ -106,7 +107,8 @@ export class WorkspaceMigrationBuildOrchestratorService {
|
||||
if (objectResult.status === 'fail') {
|
||||
orchestratorFailureReport.objectMetadata.push(...objectResult.errors);
|
||||
} else {
|
||||
allActions.push(...objectResult.workspaceMigration.actions);
|
||||
orchestratorActionsReport.fieldMetadata = objectResult.fieldsActions;
|
||||
orchestratorActionsReport.objectMetadata = objectResult.objectActions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +133,7 @@ export class WorkspaceMigrationBuildOrchestratorService {
|
||||
if (indexResult.status === 'fail') {
|
||||
orchestratorFailureReport.index.push(...indexResult.errors);
|
||||
} else {
|
||||
allActions.push(...indexResult.actions);
|
||||
orchestratorActionsReport.index = indexResult.actions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +158,7 @@ export class WorkspaceMigrationBuildOrchestratorService {
|
||||
if (viewResult.status === 'fail') {
|
||||
orchestratorFailureReport.view.push(...viewResult.errors);
|
||||
} else {
|
||||
allActions.push(...viewResult.actions);
|
||||
orchestratorActionsReport.view = viewResult.actions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +185,7 @@ export class WorkspaceMigrationBuildOrchestratorService {
|
||||
if (viewFieldResult.status === 'fail') {
|
||||
orchestratorFailureReport.viewField.push(...viewFieldResult.errors);
|
||||
} else {
|
||||
allActions.push(...viewFieldResult.actions);
|
||||
orchestratorActionsReport.viewField = viewFieldResult.actions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +206,28 @@ export class WorkspaceMigrationBuildOrchestratorService {
|
||||
status: 'success',
|
||||
workspaceMigration: {
|
||||
relatedFlatEntityMapsKeys,
|
||||
actions: allActions,
|
||||
actions: [
|
||||
// Object and fields
|
||||
...orchestratorActionsReport.fieldMetadata.deleted,
|
||||
...orchestratorActionsReport.index.deleted,
|
||||
...orchestratorActionsReport.objectMetadata.deleted,
|
||||
...orchestratorActionsReport.objectMetadata.created,
|
||||
...orchestratorActionsReport.index.created,
|
||||
...orchestratorActionsReport.objectMetadata.updated,
|
||||
...orchestratorActionsReport.fieldMetadata.created,
|
||||
...orchestratorActionsReport.fieldMetadata.updated,
|
||||
...orchestratorActionsReport.index.updated,
|
||||
///
|
||||
|
||||
// Views
|
||||
...orchestratorActionsReport.view.deleted,
|
||||
...orchestratorActionsReport.view.created,
|
||||
...orchestratorActionsReport.view.updated,
|
||||
...orchestratorActionsReport.viewField.deleted,
|
||||
...orchestratorActionsReport.viewField.created,
|
||||
...orchestratorActionsReport.viewField.updated,
|
||||
///
|
||||
],
|
||||
workspaceId,
|
||||
},
|
||||
};
|
||||
|
||||
+8
@@ -3,7 +3,9 @@ import { type FromTo } from 'twenty-shared/types';
|
||||
import { type AllFlatEntitiesByMetadataEngineName } from 'src/engine/core-modules/common/types/all-flat-entities-by-metadata-engine-name.type';
|
||||
import { type AllFlatEntityMaps } from 'src/engine/core-modules/common/types/all-flat-entity-maps.type';
|
||||
import { type FailedFlatEntityValidation } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/builders/types/failed-flat-entity-validation.type';
|
||||
import { type CreatedDeletedUpdatedActions } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/services/workspace-entity-migration-builder-v2.service';
|
||||
import { type WorkspaceMigrationV2BuilderOptions } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/services/workspace-migration-builder-v2.service';
|
||||
import { type WorkspaceMigrationActionV2 } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/workspace-migration-action-common-v2';
|
||||
import { type WorkspaceMigrationV2 } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/workspace-migration-v2';
|
||||
|
||||
export type WorkspaceMigrationOrchestratorBuildArgs = {
|
||||
@@ -21,6 +23,12 @@ export type OrchestratorFailureReport = {
|
||||
>[];
|
||||
};
|
||||
|
||||
export type OrchestratorActionsReport = {
|
||||
[P in keyof AllFlatEntitiesByMetadataEngineName]: CreatedDeletedUpdatedActions<WorkspaceMigrationActionV2>;
|
||||
} & {
|
||||
fieldMetadata: CreatedDeletedUpdatedActions<WorkspaceMigrationActionV2>;
|
||||
};
|
||||
|
||||
export type WorkspaceMigrationOrchestratorFailedResult = {
|
||||
status: 'fail';
|
||||
report: OrchestratorFailureReport;
|
||||
|
||||
+2911
-2730
File diff suppressed because it is too large
Load Diff
-21
@@ -19,9 +19,6 @@ import { ROCKET_FLAT_OBJECT_MOCK } from 'src/engine/metadata-modules/flat-object
|
||||
import { type WorkspaceMigrationBuilderTestCase } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/__tests__/types/workspace-migration-builder-test-case.type';
|
||||
import { fromFlatObjectMetadataToFlatObjectMetadataWithoutFields } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/utils/from-flat-object-metadata-to-flat-object-metadata-without-fields.util';
|
||||
|
||||
// TODO prastoin test defaultValue and settings updates
|
||||
// TODO prastoin test standard abstraction in TDD style
|
||||
|
||||
const relationTestCases: WorkspaceMigrationBuilderTestCase[] = [
|
||||
{
|
||||
title: 'It should build an create_field action for a RELATION field',
|
||||
@@ -92,9 +89,6 @@ const relationTestCases: WorkspaceMigrationBuilderTestCase[] = [
|
||||
toFlatObjectMetadataMaps,
|
||||
};
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
createField: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -112,9 +106,6 @@ const relationTestCases: WorkspaceMigrationBuilderTestCase[] = [
|
||||
flatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
}),
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
updateField: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -159,9 +150,6 @@ const basicCrudTestCases: WorkspaceMigrationBuilderTestCase[] = [
|
||||
flatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
}),
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
createField: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -181,9 +169,6 @@ const basicCrudTestCases: WorkspaceMigrationBuilderTestCase[] = [
|
||||
}),
|
||||
}),
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
updateField: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -201,9 +186,6 @@ const basicCrudTestCases: WorkspaceMigrationBuilderTestCase[] = [
|
||||
}),
|
||||
}),
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
updateField: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -224,9 +206,6 @@ const basicCrudTestCases: WorkspaceMigrationBuilderTestCase[] = [
|
||||
flatObjectMetadataMaps: FLAT_OBJECT_METADATA_MAPS_MOCKS,
|
||||
}),
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
deleteField: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
-22
@@ -33,9 +33,6 @@ const DELETE_OBJECT_TEST_CASES: WorkspaceMigrationBuilderTestCase[] = [
|
||||
},
|
||||
),
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
deleteObject: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -55,9 +52,6 @@ const DELETE_OBJECT_TEST_CASES: WorkspaceMigrationBuilderTestCase[] = [
|
||||
},
|
||||
),
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
deleteObject: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -79,9 +73,6 @@ const CREATE_OBJECT_TEST_CASES: WorkspaceMigrationBuilderTestCase[] = [
|
||||
...STANDARD_RELATION_TARGET_FLAT_OBJECT_METADATA_MOCKS,
|
||||
]),
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
createObject: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -100,19 +91,12 @@ const CREATE_OBJECT_TEST_CASES: WorkspaceMigrationBuilderTestCase[] = [
|
||||
...STANDARD_RELATION_TARGET_FLAT_OBJECT_METADATA_MOCKS,
|
||||
]),
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
createObject: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title:
|
||||
'It should build a create_object and create_index actions for each of this fieldMetadata',
|
||||
context: {
|
||||
expectedActionsTypeCounter: {
|
||||
createIndex: 1,
|
||||
createObject: 1,
|
||||
},
|
||||
input: {
|
||||
fromFlatObjectMetadataMaps:
|
||||
fromFlatObjectMetadatasToFlatObjectMetadataMaps([
|
||||
@@ -153,9 +137,6 @@ const UPDATE_OBJECT_TEST_CASES: WorkspaceMigrationBuilderTestCase[] = [
|
||||
}),
|
||||
}),
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
updateObject: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -174,9 +155,6 @@ const UPDATE_OBJECT_TEST_CASES: WorkspaceMigrationBuilderTestCase[] = [
|
||||
}),
|
||||
}),
|
||||
},
|
||||
expectedActionsTypeCounter: {
|
||||
updateObject: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
-1
@@ -21,5 +21,4 @@ export type WorkspaceMigrationBuilderTestCase = EachTestingContext<{
|
||||
input:
|
||||
| TestWorkspaceMigrationBuildArgs
|
||||
| (() => TestWorkspaceMigrationBuildArgs);
|
||||
expectedActionsTypeCounter?: ExpectedActionCounters;
|
||||
}>;
|
||||
|
||||
+12
-57
@@ -1,6 +1,5 @@
|
||||
import { extractRecordIdsAndDatesAsExpectAny } from 'test/utils/extract-record-ids-and-dates-as-expect-any';
|
||||
import { eachTestingContextFilter } from 'twenty-shared/testing';
|
||||
import { capitalize } from 'twenty-shared/utils';
|
||||
|
||||
import { type FeatureFlagService } from 'src/engine/core-modules/feature-flag/services/feature-flag.service';
|
||||
import { FlatFieldMetadataTypeValidatorService } from 'src/engine/metadata-modules/flat-field-metadata/services/flat-field-metadata-type-validator.service';
|
||||
@@ -8,15 +7,11 @@ import { FlatFieldMetadataValidatorService } from 'src/engine/metadata-modules/f
|
||||
import { FlatObjectMetadataValidatorService } from 'src/engine/metadata-modules/flat-object-metadata/services/flat-object-metadata-validator.service';
|
||||
import { WORKSPACE_MIGRATION_FIELD_BUILDER_TEST_CASES } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/__tests__/common/workspace-migration-builder-field-test-case';
|
||||
import { WORKSPACE_MIGRATION_OBJECT_BUILDER_TEST_CASES } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/__tests__/common/workspace-migration-builder-object-test-case';
|
||||
import {
|
||||
type CamelCasedWorkspaceMigrationActionsType,
|
||||
type ExpectedActionCounters,
|
||||
type WorkspaceMigrationBuilderTestCase,
|
||||
} from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/__tests__/types/workspace-migration-builder-test-case.type';
|
||||
import { type WorkspaceMigrationBuilderTestCase } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/__tests__/types/workspace-migration-builder-test-case.type';
|
||||
import { WorkspaceMigrationV2FieldActionsBuilderService } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/builders/field/services/workspace-migration-v2-field-actions-builder.service';
|
||||
import { WorkspaceMigrationV2ObjectActionsBuilderService } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/builders/object/services/workspace-migration-v2-object-actions-builder.service';
|
||||
import { WorkspaceMigrationBuilderV2Service } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/services/workspace-migration-builder-v2.service';
|
||||
import { type WorkspaceMigrationV2 } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/workspace-migration-v2';
|
||||
``;
|
||||
|
||||
const allWorkspaceBuilderTestCases: {
|
||||
label: string;
|
||||
@@ -32,45 +27,6 @@ const allWorkspaceBuilderTestCases: {
|
||||
},
|
||||
];
|
||||
|
||||
// TODO prastoin add coverage to infer deletion from missing entities
|
||||
const expectedActionsTypeCounterChecker = ({
|
||||
expectedActionsTypeCounter,
|
||||
workspaceMigration,
|
||||
}: {
|
||||
workspaceMigration: WorkspaceMigrationV2;
|
||||
expectedActionsTypeCounter?: ExpectedActionCounters;
|
||||
}) => {
|
||||
const initialAcc: ExpectedActionCounters = {
|
||||
createField: 0,
|
||||
createIndex: 0,
|
||||
createObject: 0,
|
||||
deleteField: 0,
|
||||
deleteIndex: 0,
|
||||
deleteObject: 0,
|
||||
updateField: 0,
|
||||
updateObject: 0,
|
||||
};
|
||||
const actualActionsTypeCounter = workspaceMigration.actions.reduce(
|
||||
(acc, action) => {
|
||||
const { type } = action;
|
||||
const [operation, target] = type.split('_');
|
||||
const formattedActionKey =
|
||||
`${operation}${capitalize(target)}` as CamelCasedWorkspaceMigrationActionsType;
|
||||
|
||||
return {
|
||||
...acc,
|
||||
[formattedActionKey]: (acc[formattedActionKey] ?? 0) + 1,
|
||||
};
|
||||
},
|
||||
initialAcc,
|
||||
);
|
||||
|
||||
expect(actualActionsTypeCounter).toEqual({
|
||||
...initialAcc,
|
||||
...expectedActionsTypeCounter,
|
||||
});
|
||||
};
|
||||
|
||||
describe.each(allWorkspaceBuilderTestCases)(
|
||||
'Workspace migration builder $label actions test suite',
|
||||
({ testCases }) => {
|
||||
@@ -114,7 +70,7 @@ describe.each(allWorkspaceBuilderTestCases)(
|
||||
|
||||
it.each(eachTestingContextFilter(testCases))(
|
||||
'$title',
|
||||
async ({ context: { input, expectedActionsTypeCounter } }) => {
|
||||
async ({ context: { input } }) => {
|
||||
const {
|
||||
fromFlatObjectMetadataMaps,
|
||||
toFlatObjectMetadataMaps,
|
||||
@@ -127,22 +83,21 @@ describe.each(allWorkspaceBuilderTestCases)(
|
||||
buildOptions,
|
||||
fromFlatObjectMetadataMaps,
|
||||
toFlatObjectMetadataMaps,
|
||||
workspaceId: '20202020-52cc-4c64-ad63-76c26fc3a1e1',
|
||||
});
|
||||
|
||||
expect(validateAndBuildResult.status).toBe('success');
|
||||
if (validateAndBuildResult.status !== 'success') {
|
||||
throw new Error('Should never occur');
|
||||
}
|
||||
|
||||
expectedActionsTypeCounterChecker({
|
||||
expectedActionsTypeCounter,
|
||||
workspaceMigration: validateAndBuildResult.workspaceMigration,
|
||||
});
|
||||
const { actions } = validateAndBuildResult.workspaceMigration;
|
||||
|
||||
expect(actions).toMatchSnapshot(
|
||||
actions.map(extractRecordIdsAndDatesAsExpectAny),
|
||||
expect(validateAndBuildResult.fieldsActions).toMatchSnapshot(
|
||||
extractRecordIdsAndDatesAsExpectAny(
|
||||
validateAndBuildResult.fieldsActions,
|
||||
),
|
||||
);
|
||||
expect(validateAndBuildResult.objectActions).toMatchSnapshot(
|
||||
extractRecordIdsAndDatesAsExpectAny(
|
||||
validateAndBuildResult.objectActions,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
+15
-10
@@ -16,12 +16,20 @@ import { type FailedFlatEntityValidation } from 'src/engine/workspace-manager/wo
|
||||
import { type WorkspaceMigrationV2BuilderOptions } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/services/workspace-migration-builder-v2.service';
|
||||
import { type WorkspaceMigrationActionV2 } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/workspace-migration-action-common-v2';
|
||||
|
||||
export type CreatedDeletedUpdatedActions<
|
||||
TActions extends WorkspaceMigrationActionV2,
|
||||
> = {
|
||||
created: TActions[];
|
||||
deleted: TActions[];
|
||||
updated: TActions[];
|
||||
};
|
||||
|
||||
export type SuccessfulEntityMigrationBuildResult<
|
||||
TActions extends WorkspaceMigrationActionV2,
|
||||
TFlatEntity extends FlatEntity,
|
||||
> = {
|
||||
status: 'success';
|
||||
actions: TActions[];
|
||||
actions: CreatedDeletedUpdatedActions<TActions>;
|
||||
optimisticFlatEntityMaps: FlatEntityMaps<TFlatEntity>;
|
||||
};
|
||||
|
||||
@@ -57,10 +65,7 @@ export type ValidateAndBuilActionsReturnType<
|
||||
TActions extends WorkspaceMigrationActionV2,
|
||||
> = {
|
||||
failed: FailedFlatEntityValidation<TFlatEntity>[];
|
||||
created: TActions[];
|
||||
deleted: TActions[];
|
||||
updated: TActions[];
|
||||
};
|
||||
} & CreatedDeletedUpdatedActions<TActions>;
|
||||
|
||||
export type FlatEntityValidationArgs<
|
||||
TFlatEntity extends FlatEntity,
|
||||
@@ -219,11 +224,11 @@ export abstract class WorkspaceEntityMigrationBuilderV2Service<
|
||||
|
||||
return {
|
||||
status: 'success',
|
||||
actions: [
|
||||
...validateAndBuildResult.deleted,
|
||||
...validateAndBuildResult.created,
|
||||
...validateAndBuildResult.updated,
|
||||
],
|
||||
actions: {
|
||||
created: validateAndBuildResult.created,
|
||||
deleted: validateAndBuildResult.deleted,
|
||||
updated: validateAndBuildResult.updated,
|
||||
},
|
||||
optimisticFlatEntityMaps,
|
||||
};
|
||||
}
|
||||
|
||||
+15
-24
@@ -9,9 +9,10 @@ import { deletedCreatedUpdatedMatrixDispatcher } from 'src/engine/workspace-mana
|
||||
import { WorkspaceMigrationV2FieldActionsBuilderService } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/builders/field/services/workspace-migration-v2-field-actions-builder.service';
|
||||
import { WorkspaceMigrationV2ObjectActionsBuilderService } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/builders/object/services/workspace-migration-v2-object-actions-builder.service';
|
||||
import { FailedFlatEntityValidation } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/builders/types/failed-flat-entity-validation.type';
|
||||
import { WorkspaceMigrationV2 } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/workspace-migration-v2';
|
||||
import { CreatedDeletedUpdatedActions } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/services/workspace-entity-migration-builder-v2.service';
|
||||
import { WorkspaceMigrationFieldActionV2 } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/workspace-migration-field-action-v2';
|
||||
import { WorkspaceMigrationObjectActionV2 } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/types/workspace-migration-object-action-v2';
|
||||
import { computeUpdatedObjectMetadataDeletedCreatedUpdatedFieldMatrix } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/utils/compute-updated-object-metadata-deleted-created-updated-field-matrix.util';
|
||||
import { getWorkspaceMigrationV2CreateIndexAction } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-builder-v2/utils/get-workspace-migration-v2-index-actions';
|
||||
|
||||
export type WorkspaceMigrationV2BuilderOptions = {
|
||||
inferDeletionFromMissingEntities: boolean;
|
||||
@@ -20,7 +21,8 @@ export type WorkspaceMigrationV2BuilderOptions = {
|
||||
|
||||
export type SuccessfulWorkspaceMigrationBuildResult = {
|
||||
status: 'success';
|
||||
workspaceMigration: WorkspaceMigrationV2;
|
||||
objectActions: CreatedDeletedUpdatedActions<WorkspaceMigrationObjectActionV2>;
|
||||
fieldsActions: CreatedDeletedUpdatedActions<WorkspaceMigrationFieldActionV2>;
|
||||
optimisticFlatObjectMetadataMaps: FlatObjectMetadataMaps;
|
||||
};
|
||||
|
||||
@@ -31,7 +33,6 @@ export type FailedWorkspaceMigrationBuildResult = {
|
||||
};
|
||||
|
||||
export type WorkspaceMigrationBuildArgs = {
|
||||
workspaceId: string;
|
||||
buildOptions: WorkspaceMigrationV2BuilderOptions;
|
||||
} & FromTo<FlatObjectMetadataMaps, 'FlatObjectMetadataMaps'>;
|
||||
// TODO deprecate this file
|
||||
@@ -45,11 +46,10 @@ export class WorkspaceMigrationBuilderV2Service {
|
||||
public async validateAndBuild({
|
||||
fromFlatObjectMetadataMaps,
|
||||
toFlatObjectMetadataMaps,
|
||||
workspaceId,
|
||||
buildOptions,
|
||||
}: WorkspaceMigrationBuildArgs): Promise<
|
||||
| SuccessfulWorkspaceMigrationBuildResult
|
||||
| FailedWorkspaceMigrationBuildResult
|
||||
| SuccessfulWorkspaceMigrationBuildResult
|
||||
> {
|
||||
const fromFlatObjectMetadatas =
|
||||
fromFlatObjectMetadataMapsToFlatObjectMetadatas(
|
||||
@@ -99,13 +99,6 @@ export class WorkspaceMigrationBuilderV2Service {
|
||||
},
|
||||
);
|
||||
|
||||
const createdObjectMetadataCreateIndexActions =
|
||||
createdFlatObjectMetadatas.flatMap((objectMetadata) =>
|
||||
objectMetadata.flatIndexMetadatas.map(
|
||||
getWorkspaceMigrationV2CreateIndexAction,
|
||||
),
|
||||
);
|
||||
|
||||
const allValidateAndBuildResultFailures = [
|
||||
...objectActionsValidateAndBuildResult.failed,
|
||||
...fieldActionsValidateAndBuildResult.failed,
|
||||
@@ -122,17 +115,15 @@ export class WorkspaceMigrationBuilderV2Service {
|
||||
|
||||
return {
|
||||
status: 'success',
|
||||
workspaceMigration: {
|
||||
workspaceId,
|
||||
actions: [
|
||||
...fieldActionsValidateAndBuildResult.deleted, // Should be handled separately from objects
|
||||
...objectActionsValidateAndBuildResult.deleted,
|
||||
...objectActionsValidateAndBuildResult.created,
|
||||
...objectActionsValidateAndBuildResult.updated,
|
||||
...fieldActionsValidateAndBuildResult.created, // Should be handled separately from objects
|
||||
...fieldActionsValidateAndBuildResult.updated, // Should be handled separately from objects
|
||||
...createdObjectMetadataCreateIndexActions,
|
||||
],
|
||||
fieldsActions: {
|
||||
created: fieldActionsValidateAndBuildResult.created,
|
||||
deleted: fieldActionsValidateAndBuildResult.deleted,
|
||||
updated: fieldActionsValidateAndBuildResult.updated,
|
||||
},
|
||||
objectActions: {
|
||||
created: objectActionsValidateAndBuildResult.created,
|
||||
deleted: objectActionsValidateAndBuildResult.deleted,
|
||||
updated: objectActionsValidateAndBuildResult.updated,
|
||||
},
|
||||
optimisticFlatObjectMetadataMaps:
|
||||
fieldActionsValidateAndBuildResult.optimisticFlatObjectMetadataMaps,
|
||||
|
||||
Reference in New Issue
Block a user