export type RequestLogItem = { failed: boolean; url: string; name: string; error?: string; }; export const gridSortOrderKeys = [ 'name', 'category', 'aliases', 'type', 'license', 'host', 'uri', 'publicUrl', 'isSensitive', 'localOnly', 'updatedAt', ]; export type GridSortOrderKey = typeof gridSortOrderKeys[number]; export type GridSortOrder = { key: GridSortOrderKey; direction: 'ASC' | 'DESC'; } export function emptyStrToUndefined(value: string | null) { return value ? value : undefined; } export function emptyStrToNull(value: string) { return value === '' ? null : value; } export function emptyStrToEmptyArray(value: string) { return value === '' ? [] : value.split(',').map(it => it.trim()); } export function roleIdsParser(text: string): { id: string, name: string }[] { // idとnameのペア配列をJSONで受け取る。それ以外の形式は許容しない try { const obj = JSON.parse(text); if (!Array.isArray(obj)) { return []; } if (!obj.every(it => typeof it === 'object' && 'id' in it && 'name' in it)) { return []; } return obj.map(it => ({ id: it.id, name: it.name })); } catch (ex) { console.warn(ex); return []; } }