Files
pterodactyl-panel/resources/scripts/api/queryKeyGuards.ts
T

22 lines
759 B
TypeScript
Raw Normal View History

2026-10-05 18:10:18 -04:00
import type { QueryKey } from '@tanstack/react-query';
import { isObject, isString } from '@/lib/objects';
interface GeneratedQueryKeyRoot {
_id?: string;
}
const isGeneratedQueryKeyRoot = (value: QueryKey[number]): value is GeneratedQueryKeyRoot =>
isObject(value) && (!('_id' in value) || value._id === undefined || isString(value._id));
export const hasGeneratedOperationId = (queryKey: QueryKey, id: string): boolean => {
const [key] = queryKey;
return isGeneratedQueryKeyRoot(key) && key._id === id;
};
export const hasPathParam = (queryKey: QueryKey, name: string, value: string): boolean => {
const [key] = queryKey;
return isObject(key) && 'path' in key && isObject(key.path) && Reflect.get(key.path, name) === value;
};