@datalayer/core
Version:
[](https://datalayer.io)
125 lines (124 loc) • 3.48 kB
TypeScript
/**
* Credit information for a user.
*/
export interface CreditsInfo {
/** Available credits */
credits: number;
/** Credit quota (null if unlimited) */
quota: number | null;
/** Last update timestamp */
last_update: string;
}
/**
* Credit reservation information.
*/
export interface CreditReservation {
/** Reservation ID */
id: string;
/** Reserved credits */
credits: number;
/** Resource ID (e.g., runtime ID) */
resource: string;
/** Last update timestamp */
last_update: string;
/** Burning rate (credits per hour) for this reservation */
burning_rate: number;
/** Start date of the reservation */
start_date: string;
}
/**
* Response from the credits endpoint.
*/
export interface CreditsResponse {
/** Operation success status */
success: boolean;
/** Credit information */
credits: CreditsInfo;
/** Active credit reservations */
reservations: CreditReservation[];
}
/**
* Credits model representing user's available credits and usage.
*
* @example
* ```typescript
* const credits = await sdk.getCredits();
* console.log(`Available: ${credits.available}`);
* console.log(`Quota: ${credits.quota || 'unlimited'}`);
*
* // Calculate maximum runtime for an environment
* const maxMinutes = credits.calculateMaxRuntimeMinutes(environment.burningRate);
* ```
*/
export declare class CreditsDTO {
/** @internal */
_data: CreditsInfo;
private _reservations;
constructor(data: CreditsInfo, reservations?: CreditReservation[]);
/**
* Available credits for the user.
*/
get available(): number;
/**
* Credit quota for the user.
* Returns null if unlimited.
*/
get quota(): number | null;
/**
* Last update timestamp.
*/
get lastUpdate(): string;
/**
* Active credit reservations.
*/
get reservations(): CreditReservation[];
/**
* Total reserved credits across all reservations.
*/
get totalReserved(): number;
/**
* Net available credits (available minus reserved).
*/
get netAvailable(): number;
/**
* Get runtime reservations (reservations that start with 'runtime-').
*/
get runtimeReservations(): CreditReservation[];
/**
* Check if there are any active runtime reservations.
*/
get hasActiveRuntimes(): boolean;
/**
* Calculate maximum runtime in minutes based on environment burning rate.
*
* @param burningRate - Credits consumed per hour
* @returns Maximum runtime in minutes
*/
calculateMaxRuntimeMinutes(burningRate: number): number;
/**
* Calculate credits needed for runtime duration.
*
* @param minutes - Runtime duration in minutes
* @param burningRate - Credits consumed per hour
* @returns Credits needed
*/
calculateCreditsFromMinutes(minutes: number, burningRate: number): number;
/**
* Check if user has enough credits for runtime.
*
* @param minutes - Runtime duration in minutes
* @param burningRate - Credits consumed per hour
* @returns True if user has enough credits
*/
hasEnoughCreditsForRuntime(minutes: number, burningRate: number): boolean;
/**
* Convert to JSON representation.
*/
toJSON(): CreditsInfo & {
reservations: CreditReservation[];
};
/**
* String representation of credits.
*/
toString(): string;
}