feat: APIPathGen 도우미
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
import { APIPathGen } from "./util/APIPathGen";
|
||||||
|
|
||||||
|
const apiRealPath = {
|
||||||
|
Command: {
|
||||||
|
GetReservedCommand: '',
|
||||||
|
PushCommand: '',
|
||||||
|
RepeatCommand: '',
|
||||||
|
ReserveCommand: '',
|
||||||
|
},
|
||||||
|
General: {
|
||||||
|
Join: '',
|
||||||
|
},
|
||||||
|
InheritAction: {
|
||||||
|
BuyHiddenBuff: '',
|
||||||
|
BuyRandomUnique: '',
|
||||||
|
BuySpecificUnique: '',
|
||||||
|
ResetSpecialWar: '',
|
||||||
|
ResetTurnTime: '',
|
||||||
|
SetNextSpecialWar: '',
|
||||||
|
},
|
||||||
|
Misc: { UploadImage: '' },
|
||||||
|
NationCommand: {
|
||||||
|
GetReservedCommand: '',
|
||||||
|
PushCommand: '',
|
||||||
|
RepeatCommand: '',
|
||||||
|
ReserveCommand: '',
|
||||||
|
},
|
||||||
|
Nation: {
|
||||||
|
SetNotice: '',
|
||||||
|
SetScoutMsg: '',
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export const APIPath = APIPathGen(apiRealPath);
|
||||||
+16
-3
@@ -163,11 +163,11 @@ export const NoneValue = 'None' as const;
|
|||||||
|
|
||||||
export type Optional<Type> = {
|
export type Optional<Type> = {
|
||||||
[Property in keyof Type]+?: Type[Property];
|
[Property in keyof Type]+?: Type[Property];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type OptionalFull<Type> = {
|
export type OptionalFull<Type> = {
|
||||||
[Property in keyof Type]: Type[Property]|undefined;
|
[Property in keyof Type]: Type[Property] | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type commandItem = {
|
export type commandItem = {
|
||||||
value: string;
|
value: string;
|
||||||
@@ -210,3 +210,16 @@ export type ChiefResponse = {
|
|||||||
values: commandItem[];
|
values: commandItem[];
|
||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
type diplomacyInfo = {
|
||||||
|
name: string,
|
||||||
|
color?: string,
|
||||||
|
}
|
||||||
|
export type diplomacyState = 0 | 1 | 2 | 7;
|
||||||
|
export const diplomacyStateInfo: Record<diplomacyState, diplomacyInfo> = {
|
||||||
|
0: { name: '교전', color: 'red' },
|
||||||
|
1: { name: '선포중', color: 'magenta' },
|
||||||
|
2: { name: '통상' },
|
||||||
|
7: { name: '불가침', color: 'green' },
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
type SubValue = string | { [property: string]: SubValue };
|
||||||
|
|
||||||
|
const hasKey = <T extends Record<string | symbol, unknown>>(obj: T, k: string | symbol | number): k is keyof T =>
|
||||||
|
k in obj;
|
||||||
|
|
||||||
|
export function APIPathGen<K extends string, V extends SubValue>(obj: Record<K, V>, path?: string[]): Record<K, V> {
|
||||||
|
return new Proxy(obj, {
|
||||||
|
get(target, key: K) {
|
||||||
|
if (path === undefined) {
|
||||||
|
path = [key];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
path.push(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (hasKey(target, key)) {
|
||||||
|
const next: V = target[key];
|
||||||
|
if (typeof (next) === 'string') {
|
||||||
|
return path.join('/');
|
||||||
|
}
|
||||||
|
if (typeof (next) === 'object') {
|
||||||
|
return APIPathGen(next, path);
|
||||||
|
}
|
||||||
|
throw 'unknown';
|
||||||
|
}
|
||||||
|
throw `${path.join('/')} is not exists`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user