election-game/backend/packages/protocol/src/common.ts

39 lines
1.6 KiB
TypeScript
Raw Normal View History

import { z } from "zod";
/** 協定版本:破壞性變更時升版(docs/16) */
export const PROTOCOL_VERSION = "1.0.0";
/** 村里代碼(= 國土測繪中心 VILLCODE = 戶政 district_code),11 碼 */
export const VillageCode = z.string().regex(/^\d{11}$/, "村里代碼應為 11 碼數字");
/** 鄉鎮市區代碼(TOWNCODE),8 碼 */
export const TownCode = z.string().regex(/^\d{8}$/, "鄉鎮市區代碼應為 8 碼數字");
/** 縣市代碼(COUNTYCODE),5 碼 */
export const CountyCode = z.string().regex(/^\d{5}$/, "縣市代碼應為 5 碼數字");
export const IsoDate = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "日期格式應為 YYYY-MM-DD");
export const Share = z.number().min(0).max(1);
export const NonNegative = z.number().min(0);
/** 資料來源:每個欄位都要能追到這裡(docs/10、docs/15) */
export const SourceRef = z.object({
id: z.string().min(1),
title: z.string().min(1),
agency: z.string().min(1),
url: z.string().url(),
license: z.string().min(1),
retrievedAt: IsoDate,
version: z.string().optional(),
note: z.string().optional(),
});
export type SourceRef = z.infer<typeof SourceRef>;
export const SourceList = z.object({
protocolVersion: z.string(),
sources: z.array(SourceRef),
});
export type SourceList = z.infer<typeof SourceList>;
/** 候選人類型(docs/25):真實候選人依中選會選舉紀錄、自創角色依出身;決定選戰卡牌的技能與弱點 */
export const RogueArchetype = z.enum(["media", "organization", "eloquence", "finance", "integrity", "newcomer"]);
export type RogueArchetype = z.infer<typeof RogueArchetype>;