@datalayer/core
Version:
[](https://datalayer.io)
192 lines (191 loc) • 6.45 kB
TypeScript
import type { DatalayerClient } from '../index';
import { RuntimeSnapshotDTO } from './RuntimeSnapshotDTO';
/**
* Represents a running instance of a computing environment.
* @interface RuntimeData
*/
export interface RuntimeData {
/** Kubernetes pod name for the runtime instance */
pod_name: string;
/** Unique identifier for the runtime */
uid: string;
/** Name of the environment this runtime is based on */
environment_name: string;
/** Title of the environment for display */
environment_title: string;
/** Type of runtime - notebook, terminal, or job */
type: string;
/** Credits consumed per second */
burning_rate: number;
/** User-friendly name for the runtime */
given_name: string;
/** Authentication token for accessing the runtime */
token: string;
/** Ingress URL for accessing the runtime */
ingress: string;
/** ISO 8601 timestamp of when the runtime started */
started_at: string;
/** ISO 8601 timestamp of when the runtime will expire */
expired_at: string;
}
/**
* Stable public interface for Runtime data.
* This is the contract that SDK consumers can rely on.
* The raw API may change, but this interface remains stable.
*/
export interface RuntimeJSON {
/** ulid for the runtime */
uid: string;
/** Kubernetes pod name for the runtime instance */
podName: string;
/** User-friendly name for the runtime */
givenName: string;
/** Name of the environment this runtime is based on */
environmentName: string;
/** Title of the environment for display */
environmentTitle: string;
/** Type of runtime - notebook, terminal, or job */
type: string;
/** Credits consumed per second */
burningRate: number;
/** Credits allocated/available to this runtime */
ingress: string;
/** Authentication token for accessing the runtime */
token: string;
/** When the runtime was started */
startedAt: string;
/** When the runtime will expire */
expiredAt: string;
}
/**
* Request payload for creating a new runtime
* @interface CreateRuntimeRequest
*/
export interface CreateRuntimeRequest {
/** Name of the environment to use */
environment_name: string;
/** Type of runtime (e.g., 'notebook', 'terminal', 'job') */
type?: 'notebook' | 'terminal' | 'job';
/** Optional given name for the runtime */
given_name?: string;
/** Maximum credits this runtime can consume */
credits_limit?: number;
/** Optional capabilities for the runtime */
capabilities?: string[];
/** Optional source to create runtime from (e.g., snapshot ID) */
from?: string;
}
/**
* Response from creating a new runtime
* @interface CreateRuntimeResponse
*/
export interface CreateRuntimeResponse {
/** Whether the request was successful */
success: boolean;
/** Response message from the server */
message: string;
/** The created runtime instance */
runtime: RuntimeData;
}
/**
* Response from listing runtimes
* @interface ListRuntimesResponse
*/
export interface ListRuntimesResponse {
/** Whether the request was successful */
success: boolean;
/** Response message from the server */
message: string;
/** Array of runtime instances */
runtimes: RuntimeData[];
}
/**
* Runtime domain model that wraps API responses with convenient methods.
* Provides state management and lifecycle operations for computational runtimes.
*
* @example
* ```typescript
* const runtime = await sdk.createRuntime({ environment_name: 'python-cpu' });
* await runtime.waitUntilReady();
* ```
*/
export declare class RuntimeDTO {
/** @internal */
_data: RuntimeData;
private _sdk;
private _deleted;
/**
* Create a Runtime instance.
*
* @param data - Runtime data from API
* @param sdk - SDK instance
*/
constructor(data: RuntimeData, sdk: DatalayerClient);
/**
* Check if this runtime has been deleted and throw error if so.
* @throws Error if deleted
*/
private _checkDeleted;
/** Kubernetes pod name for the runtime instance. */
get podName(): string;
/** Unique identifier for the runtime. */
get uid(): string;
/** Name of the environment this runtime is based on. */
get environmentName(): string;
/** Ingress URL for accessing the runtime. */
get ingress(): string;
/** Authentication token for accessing the runtime. */
get token(): string;
/** Credits consumed per second. */
get burningRate(): number;
/** User-friendly name for the runtime. */
get givenName(): string;
/** Type of runtime (notebook, terminal, or job). */
get type(): string;
/** When the runtime started. */
get startedAt(): Date;
/** When the runtime will expire. */
get expiredAt(): Date;
/** Environment title for display. */
get environmentTitle(): string;
/**
* Delete this runtime permanently.
* After deletion, subsequent calls to dynamic methods will throw errors.
*/
delete(): Promise<void>;
/**
* Update runtime from a snapshot.
*
* @param from - Snapshot identifier to restore from
* @returns Updated Runtime instance
*/
update(from: string): Promise<RuntimeDTO>;
/**
* Create a snapshot of this runtime.
*
* @param name - Name for the snapshot
* @param description - Optional description
* @param stop - Whether to stop runtime after snapshotting
* @returns Created Snapshot instance
*/
createSnapshot(name: string, description?: string, stop?: boolean): Promise<RuntimeSnapshotDTO>;
/**
* Get runtime data in camelCase format.
* Returns only the core fields that consumers need.
* This provides a stable interface regardless of API changes.
* Returns the current cached state - call getState() first if you need fresh data.
*
* @returns Core runtime data with camelCase properties
*/
toJSON(): RuntimeJSON;
/**
* Get the raw runtime data exactly as received from the API.
* This preserves the original snake_case naming from the API response.
* Returns the current cached state - call getState() first if you need fresh data.
*
* @returns Raw runtime data from API
*/
rawData(): RuntimeData;
/** String representation of the runtime. */
toString(): string;
}