Move "getAppMetadataFrom" to "MetadataMigrations"

This commit is contained in:
schroda
2025-01-04 21:27:51 +01:00
parent 3782091601
commit b7971f5183
2 changed files with 17 additions and 21 deletions

View File

@@ -7,12 +7,8 @@
*/
import { APP_METADATA_KEY_PREFIX, METADATA_MIGRATIONS } from '@/modules/metadata/Metadata.constants.ts';
import {
doesMetadataKeyExistIn,
getAppMetadataFrom,
getMetadataKey,
} from '@/modules/metadata/services/MetadataReader.ts';
import { IMetadataMigration, Metadata } from '@/modules/metadata/Metadata.types.ts';
import { doesMetadataKeyExistIn, getMetadataKey } from '@/modules/metadata/services/MetadataReader.ts';
export const getAppKeyPrefixForMigration = (migrationId: number): string => {
const appKeyPrefix = METADATA_MIGRATIONS.slice(0, migrationId)
@@ -22,6 +18,22 @@ export const getAppKeyPrefixForMigration = (migrationId: number): string => {
return appKeyPrefix?.appKeyPrefix?.newPrefix ?? APP_METADATA_KEY_PREFIX;
};
const getAppMetadataFrom = (
meta: Metadata,
prefixes: string[] = [],
appPrefix: string = APP_METADATA_KEY_PREFIX,
): Metadata => {
const appMetadata: Metadata = {};
Object.entries(meta).forEach(([key, value]) => {
if (key.startsWith([appPrefix, ...prefixes].join('_'))) {
appMetadata[key] = value;
}
});
return appMetadata;
};
export const applyAppKeyPrefixMigration = (meta: Metadata, migration: IMetadataMigration): Metadata => {
const migratedMetadata: Metadata = { ...meta };

View File

@@ -276,19 +276,3 @@ export function getMetadataFrom<METADATA extends Partial<Metadata<AppMetadataKey
return appMetadata;
}
export const getAppMetadataFrom = (
meta: Metadata,
prefixes: string[] = [],
appPrefix: string = APP_METADATA_KEY_PREFIX,
): Metadata => {
const appMetadata: Metadata = {};
Object.entries(meta).forEach(([key, value]) => {
if (key.startsWith([appPrefix, ...prefixes].join('_'))) {
appMetadata[key] = value;
}
});
return appMetadata;
};