Files
Alex Khomenko f9fb9d268f Restore dashboards: Add API client endpoints (#106435)
* Dashboards: Add restore endpoints to the API

* Fix unified api

* Fix resource version

* Add tests

* Update api

* Update type guards

* Update comments

* Add missing type

* Cleanup

* Move spec checking logic to v1 client

* Handle mixed versions in deleted dbs list

* Update tests

* comment

* type
2025-06-12 15:49:55 +03:00

48 lines
1.3 KiB
TypeScript

import { Resource, ResourceList } from './types';
/**
* Helper function to safely check if a value is a non-null object
*/
function isObject(value: unknown): value is Record<string, unknown> {
return value !== null && typeof value === 'object';
}
/**
* Type guard to check if an unknown value has all required fields to be a Resource
*/
export function isResource<T = object, S = object, K = string>(value: unknown): value is Resource<T, S, K> {
if (!isObject(value)) {
return false;
}
const metadata = value.metadata;
if (!isObject(metadata)) {
return false;
}
return (
typeof value.apiVersion === 'string' &&
typeof value.kind === 'string' &&
typeof metadata.name === 'string' &&
typeof metadata.resourceVersion === 'string' &&
typeof metadata.creationTimestamp === 'string' &&
isObject(value.spec)
);
}
/**
* Type guard to check if an unknown value has all required fields to be a ResourceList
*/
export function isResourceList<T = object, S = object, K = string>(value: unknown): value is ResourceList<T, S, K> {
if (!isObject(value)) {
return false;
}
const metadata = value.metadata;
if (!isObject(metadata)) {
return false;
}
return typeof metadata.resourceVersion === 'string' && Array.isArray(value.items);
}