[OBJECT_MANIFEST_BREAKING_CHANGE] Sync returns workspace migration (#17918)
# Introduction In this PR we start returning a workspace migration post sync so it can committed and provided within the tarball ## Universal aggregators utils Created two utils ### deleteUniversalFlatEntityForeignKeyAggregators Used when building a universal create action, a newly created actions should not contain any aggregated foreign key so they won't be codegen in the workspace migration but also they are overriden at uninversal to flat transpilation anw ### resetUniversalFlatEntityForeignKeyAggregators Used before validating a new flat entity creation, some validator will consume the fk aggregator in order to validate integrity, but of optimstically provided it can result to errors. To avoid caller responsability we override them here ## create-field-action refactor Refactored the universal and flat field create action to be following the base actions in order to ease typing Also it was tailored to handle unlimited amount of flat field metadata in the same actions whereas in the reality we were always only sending at max 2 ( for relation fields ) Note: relation field has to be provided at the same as if not optimistic would fail to retrieve circular universal identifiers ## ObjectManifest Now always expect a `labelIdentifierFieldMetadataUniversalIdentifier` ## Integration test Created an integration test that creates an app, sync a first manifest and a second implying update workspace migration action generation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { defineObject } from '@/sdk';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { type ObjectManifest } from 'twenty-shared/application';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
describe('defineObject', () => {
|
||||
const validConfig: ObjectManifest = {
|
||||
@@ -10,6 +10,8 @@ describe('defineObject', () => {
|
||||
labelSingular: 'Post Card',
|
||||
labelPlural: 'Post Cards',
|
||||
icon: 'IconMail',
|
||||
labelIdentifierFieldMetadataUniversalIdentifier:
|
||||
'58a0a314-d7ea-4865-9850-7fb84e72f30b',
|
||||
fields: [
|
||||
{
|
||||
universalIdentifier: '58a0a314-d7ea-4865-9850-7fb84e72f30b',
|
||||
@@ -111,17 +113,6 @@ describe('defineObject', () => {
|
||||
expect(result.config.fields).toEqual([]);
|
||||
});
|
||||
|
||||
it('should accept missing fields', () => {
|
||||
const config = {
|
||||
...validConfig,
|
||||
fields: undefined,
|
||||
};
|
||||
|
||||
const result = defineObject(config as any);
|
||||
|
||||
expect(result.config.fields).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return error when field is missing label', () => {
|
||||
const config = {
|
||||
...validConfig,
|
||||
@@ -239,4 +230,19 @@ describe('defineObject', () => {
|
||||
|
||||
expect(result.config.fields[0].options).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should return error when labelIdentifierFieldMetadataUniversalIdentifier references non-existent field', () => {
|
||||
const config: ObjectManifest = {
|
||||
...validConfig,
|
||||
labelIdentifierFieldMetadataUniversalIdentifier:
|
||||
'non-existent-field-uuid',
|
||||
};
|
||||
|
||||
const result = defineObject(config);
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.errors).toContain(
|
||||
'labelIdentifierFieldMetadataUniversalIdentifier must reference a field defined in the fields array',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { type ObjectManifest } from 'twenty-shared/application';
|
||||
|
||||
import { createValidationResult } from '@/sdk/common/utils/create-validation-result';
|
||||
import { type DefineEntity } from '@/sdk/common/types/define-entity.type';
|
||||
import { createValidationResult } from '@/sdk/common/utils/create-validation-result';
|
||||
import { validateFields } from '@/sdk/fields/validate-fields';
|
||||
import { type ObjectConfig } from '@/sdk/objects/object-config';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export const defineObject: DefineEntity<ObjectManifest> = (config) => {
|
||||
export const defineObject: DefineEntity<ObjectConfig> = (config) => {
|
||||
const errors = [];
|
||||
|
||||
if (!config.universalIdentifier) {
|
||||
@@ -31,6 +31,19 @@ export const defineObject: DefineEntity<ObjectManifest> = (config) => {
|
||||
|
||||
errors.push(...fieldErrors);
|
||||
|
||||
if (
|
||||
isDefined(config.labelIdentifierFieldMetadataUniversalIdentifier) &&
|
||||
!config.fields.some(
|
||||
(field) =>
|
||||
field.universalIdentifier ===
|
||||
config.labelIdentifierFieldMetadataUniversalIdentifier,
|
||||
)
|
||||
) {
|
||||
errors.push(
|
||||
'labelIdentifierFieldMetadataUniversalIdentifier must reference a field defined in the fields array',
|
||||
);
|
||||
}
|
||||
|
||||
return createValidationResult({
|
||||
config,
|
||||
errors,
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { type ObjectManifest } from 'twenty-shared/application';
|
||||
|
||||
export type ObjectConfig = Omit<
|
||||
ObjectManifest,
|
||||
'labelIdentifierFieldMetadataUniversalIdentifier'
|
||||
> & {
|
||||
labelIdentifierFieldMetadataUniversalIdentifier?: string;
|
||||
};
|
||||
Reference in New Issue
Block a user