UNPKG

endfield-mcp

Version:

MCP Server for Arknights: Endfield (TypeScript / stdio + Streamable HTTP)

70 lines (69 loc) • 2.56 kB
/** * JSON store abstraction for local dataset access. * * Mirrors PRTS-MCP's `ts/src/data/stores.ts` shape-for-shape so the data * layer stays portable across the two projects. Business code only ever * touches the {@link JsonStore} interface; whether a file lives in a real * directory, inside a zip, or in a bundled fallback is invisible to callers. * * The same path-safety guarantees are preserved: * - backslashes normalized to forward slashes * - no leading "/" * - no ".." segments * - resolved target must remain inside the store root (DirectoryStore) */ export interface JsonStore { exists(path: string): boolean; readText(path: string): string; readJson<T = unknown>(path: string): T; /** * Parse JSON with int64-safe number handling. * * Endfield tables store localization ids as raw int64 numbers (e.g. * `-7078064683023630592`), which exceed JS Number.MAX_SAFE_INTEGER * (2^53-1). A plain `JSON.parse` silently truncates them, breaking i18n * lookups. This variant pre-processes the text to wrap any integer * whose absolute value exceeds MAX_SAFE_INTEGER in quotes, so the id * survives as a string. Use it for any table containing `{id, text}` * localization objects. */ readJsonInt64Safe<T = unknown>(path: string): T; describe(): string; close(): void; } export declare class DirectoryStore implements JsonStore { readonly root: string; constructor(root: string); private resolvePath; resolveForDiagnostics(path: string): string; exists(path: string): boolean; readText(path: string): string; readJson<T = unknown>(path: string): T; readJsonInt64Safe<T = unknown>(path: string): T; describe(): string; close(): void; } export declare class ZipStore implements JsonStore { readonly zipPath: string; private _zip; constructor(zipPath: string); private zip; close(): void; exists(path: string): boolean; readText(path: string): string; readJson<T = unknown>(path: string): T; readJsonInt64Safe<T = unknown>(path: string): T; describe(): string; } export declare class FallbackStore implements JsonStore { readonly primary: JsonStore; readonly fallback: JsonStore; constructor(primary: JsonStore, fallback: JsonStore); private storeFor; exists(path: string): boolean; readText(path: string): string; readJson<T = unknown>(path: string): T; readJsonInt64Safe<T = unknown>(path: string): T; describe(): string; close(): void; }