fbbd8fe967
# Introduction
In this PR we're migrating both the `field` and `object` metadata to be
using the new `FlatEntityFromV2` that requires all the
`UniversalFlatEntityExtraProperties` to be spread at the flat entity
root.
This means that we have to update all of their flat declaration
This type swap allows to isole a specific entity migration into his own
type scope and avoid to have everything handled at once
```ts
/**
* Currently under migration but aims to replace FlatEntity afterwards
*/
export type FlatEntityFromV2<
TEntity,
TMetadataName extends AllMetadataName | undefined = undefined,
TInnerFlatEntity extends { __universal?: unknown } = FlatEntityFrom<
TEntity,
TMetadataName
>,
> = Omit<TInnerFlatEntity, '__universal'> & TInnerFlatEntity['__universal'];
```
## Impact
Both object and field:
- Create input transpilation utils
- from entity to flat tools
- mocks
## Note
Removed from the universal extra properties the jsonb properties that do
not contain a serialized
## Next
Next step is to incrementally make the builder and runner expect
`UniversalFlatEntity` for both of these metadata
This way we will be able to fully migrate an entity e2e typesafely
33 lines
948 B
TypeScript
33 lines
948 B
TypeScript
import { type AllFieldMetadataSettings } from 'twenty-shared/types';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
type JunctionTargetSettings = {
|
|
junctionTargetFieldId?: string;
|
|
};
|
|
|
|
// TODO refactor using either type predicate or FieldMetadataType discriminating union
|
|
// Extracts junction target settings from untyped settings input
|
|
// This function handles the boundary where settings come from external API input
|
|
export const extractJunctionTargetSettingsFromSettings = (
|
|
settings: AllFieldMetadataSettings | null | undefined,
|
|
): JunctionTargetSettings => {
|
|
if (!isDefined(settings)) {
|
|
return {};
|
|
}
|
|
|
|
if (typeof settings !== 'object' || settings === null) {
|
|
return {};
|
|
}
|
|
|
|
const result: JunctionTargetSettings = {};
|
|
|
|
if (
|
|
'junctionTargetFieldId' in settings &&
|
|
typeof settings.junctionTargetFieldId === 'string'
|
|
) {
|
|
result.junctionTargetFieldId = settings.junctionTargetFieldId;
|
|
}
|
|
|
|
return result;
|
|
};
|