import type { Component, ComponentSet } from "@figma/rest-api-spec";
export interface SimplifiedComponentDefinition {
id: string;
key: string;
name: string;
componentSetId?: string;
}
export interface SimplifiedComponentSetDefinition {
id: string;
key: string;
name: string;
description?: string;
}
export function sanitizeComponents(
aggregatedComponents: Record<string, Component>,
): Record<string, SimplifiedComponentDefinition> {
return Object.fromEntries(
Object.entries(aggregatedComponents).map(([id, comp]) => [
id,
{
id,
key: comp.key,
name: comp.name,
componentSetId: comp.componentSetId,
},
]),
);
}
export function sanitizeComponentSets(
aggregatedComponentSets: Record<string, ComponentSet>,
): Record<string, SimplifiedComponentSetDefinition> {
return Object.fromEntries(
Object.entries(aggregatedComponentSets).map(([id, set]) => [
id,
{
id,
key: set.key,
name: set.name,
description: set.description,
},
]),
);
}