Feat workspace migration maintains flat object metadata maps (#13620)

# Introduction
The workspace migration runner v2 now computes the next
flatObjectMetadataMaps post current ws migration action has been run
So the following one have an up to date informations

## Still TODO
~~Remove any contextual information from workspace migration v2 and
consume the optimistic cache to retrieve them~~

## Next steps
- Create flat-object-metadata-maps testing toolbox and flat-object/field
testing toolbox
- Implement strong coverage on every created utils/transpiler and
applyWorkspaceMigrationAction method
This commit is contained in:
Paul Rastoin
2025-08-06 15:10:14 +02:00
committed by GitHub
parent e1d169e51e
commit ca3383cd86
38 changed files with 897 additions and 592 deletions
@@ -1,4 +1,3 @@
export type FromTo<T> = {
from: T;
to: T;
export type FromTo<T, K extends string = ''> = {
[P in 'from' | 'to' as `${P}${Capitalize<K>}`]: T;
};
@@ -0,0 +1,90 @@
import { EachTestingContext } from '@/testing/types/EachTestingContext.type';
import { fromArrayToUniqueKeyRecord } from '@/utils/from-array-to-unique-key-record.util';
type FromArrayToUniqueKeyRecordTestCase = EachTestingContext<{
input: {
array: any[];
uniqueKey: string;
};
expected: Record<string, any> | Error;
}>;
describe('fromArrayToUniqueKeyRecord', () => {
const testCases: FromArrayToUniqueKeyRecordTestCase[] = [
{
title: 'should convert array to record using id as unique key',
context: {
input: {
array: [
{ id: '1', name: 'John' },
{ id: '2', name: 'Jane' },
],
uniqueKey: 'id',
},
expected: {
'1': { id: '1', name: 'John' },
'2': { id: '2', name: 'Jane' },
},
},
},
{
title: 'should convert array to record using email as unique key',
context: {
input: {
array: [
{ email: 'john@test.com', name: 'John' },
{ email: 'jane@test.com', name: 'Jane' },
],
uniqueKey: 'email',
},
expected: {
'john@test.com': { email: 'john@test.com', name: 'John' },
'jane@test.com': { email: 'jane@test.com', name: 'Jane' },
},
},
},
{
title: 'should handle empty array',
context: {
input: {
array: [],
uniqueKey: 'id',
},
expected: {},
},
},
{
title: 'should throw error when array contains duplicate unique keys',
context: {
input: {
array: [
{ id: '1', name: 'John' },
{ id: '1', name: 'Jane' },
],
uniqueKey: 'id',
},
expected: new Error(
'Should never occur, flat array contains twice the same unique key 1',
),
},
},
];
test.each(testCases)('$title', ({ context: { input, expected } }) => {
if (expected instanceof Error) {
expect(() =>
fromArrayToUniqueKeyRecord({
array: input.array,
uniqueKey: input.uniqueKey,
}),
).toThrow(expected.message);
} else {
const result = fromArrayToUniqueKeyRecord({
array: input.array,
uniqueKey: input.uniqueKey,
});
expect(result).toEqual(expected);
}
});
});