mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-21 06:12:17 +03:00
* fix(models): apply compatible provider context overrides * refactor(models): remove synced model tombstones * fix(models): prefer custom model metadata * docs(changelog): describe custom model fixes
31 lines
961 B
TypeScript
31 lines
961 B
TypeScript
export type ModelMetadataRow = {
|
|
id: string;
|
|
[key: string]: unknown;
|
|
};
|
|
|
|
/**
|
|
* Overlay fields explicitly stored on a custom model without erasing richer
|
|
* discovered metadata for fields the custom row does not define.
|
|
*/
|
|
export function mergeCustomModelMetadata<T extends Record<string, unknown>>(
|
|
base: T,
|
|
custom: Record<string, unknown>
|
|
): T {
|
|
const definedCustom = Object.fromEntries(
|
|
Object.entries(custom).filter(([, value]) => value !== undefined)
|
|
);
|
|
return { ...base, ...definedCustom } as T;
|
|
}
|
|
|
|
export function mergeModelsWithCustomPrecedence<T extends ModelMetadataRow>(
|
|
baseModels: T[],
|
|
customModels: ModelMetadataRow[]
|
|
): T[] {
|
|
const merged = new Map(baseModels.map((model) => [model.id, model]));
|
|
for (const custom of customModels) {
|
|
const existing = merged.get(custom.id);
|
|
merged.set(custom.id, existing ? mergeCustomModelMetadata(existing, custom) : (custom as T));
|
|
}
|
|
return Array.from(merged.values());
|
|
}
|