Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016VBGFXB9AbJBwXP19z75Qq
68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
/* =============================================================================
|
|
* Z01_MasterData_Api_Fetch.ts
|
|
* 마스터 데이터 읽기 — 서버 `Z01_MasterData_Router.py`(랩탑 메인) · 시스템 관리자만
|
|
*
|
|
* 응답 모양은 2026-09-15 브레인이 못박은 약속 그대로. 읽기 전용 — 고치기는 다음 차례.
|
|
* ========================================================================== */
|
|
|
|
import { API_BASE_URL } from "@config/config_frontend";
|
|
import type { MasterColumn } from "./Z01_MasterData_UI_Cells";
|
|
|
|
export interface MasterTable {
|
|
id: string;
|
|
label: string;
|
|
key: string;
|
|
row_count: number;
|
|
}
|
|
|
|
export interface MasterFile {
|
|
id: string;
|
|
label: string;
|
|
key: string;
|
|
tables: MasterTable[];
|
|
}
|
|
|
|
/** 표가 아닌 낱값(한 값짜리 요율 따위)을 모은 마디 — 여느 표처럼 이름·값 두 칸으로 옴. */
|
|
export const VALUES_TABLE_ID = "@values";
|
|
|
|
export interface MasterGroup {
|
|
/** fingerprint = 폴더 지문(_manifest) — 어느 판으로 셈했는지 못박는 자리(부산물 아님). */
|
|
key: "logic" | "base_value" | "byproduct" | "seed" | "fingerprint";
|
|
label: string;
|
|
files: MasterFile[];
|
|
}
|
|
|
|
export interface MasterRows {
|
|
columns: MasterColumn[];
|
|
rows: Record<string, unknown>[];
|
|
total: number;
|
|
}
|
|
|
|
async function request<T>(path: string): Promise<T> {
|
|
const response = await fetch(`${API_BASE_URL}${path}`, { credentials: "include" });
|
|
const data = (await response.json()) as { detail?: string } & T;
|
|
if (!response.ok) throw new Error(data.detail ?? "Request failed");
|
|
return data;
|
|
}
|
|
|
|
export async function fetchMasterTree(): Promise<MasterGroup[]> {
|
|
return (await request<{ groups: MasterGroup[] }>("/master-data/tree")).groups;
|
|
}
|
|
|
|
export function fetchMasterRows(query: {
|
|
file: string;
|
|
table: string;
|
|
page: number;
|
|
size: number;
|
|
q: string;
|
|
}): Promise<MasterRows> {
|
|
const params = new URLSearchParams({
|
|
file: query.file,
|
|
table: query.table,
|
|
page: String(query.page),
|
|
size: String(query.size),
|
|
q: query.q,
|
|
});
|
|
return request<MasterRows>(`/master-data/rows?${params}`);
|
|
}
|