import { getDataClient, getPropertyId, formatPropertyPath } from "../../client.js";
import type { PropertyId, GetMetadataOutput, MetadataItem } from "../../types.js";
/**
* 利用可能なディメンションとメトリクスの一覧を取得
*/
export async function getMetadata(input: PropertyId): Promise<GetMetadataOutput> {
const propertyId = getPropertyId(input.propertyId);
const property = formatPropertyPath(propertyId);
const client = getDataClient();
const [response] = await client.getMetadata({
name: `${property}/metadata`,
});
const dimensions: MetadataItem[] = [];
const metrics: MetadataItem[] = [];
// ディメンション情報を整形
for (const dim of response.dimensions || []) {
dimensions.push({
apiName: dim.apiName || "",
uiName: dim.uiName || "",
description: dim.description || "",
category: dim.category || "",
});
}
// メトリクス情報を整形
for (const metric of response.metrics || []) {
metrics.push({
apiName: metric.apiName || "",
uiName: metric.uiName || "",
description: metric.description || "",
category: metric.category || "",
});
}
return { dimensions, metrics };
}