UNPKG

@datalayer/core

Version:

[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.io)

174 lines (173 loc) 5.46 kB
/** * Snapshot domain model for the Datalayer SDK. * * @module models/RuntimeSnapshotDTO */ import type { DatalayerClient } from '../index'; import { RuntimeDTO } from './RuntimeDTO'; /** * Represents a runthime snapshot of a runtime's state and files. * @interface RuntimeSnapshotData */ export interface RuntimeSnapshotData { /** Unique identifier for the snapshot */ uid: string; /** Name of the snapshot */ name: string; /** Optional description of the snapshot */ description?: string; /** Name of the environment used by the runtime */ environment: string; /** Metadata associated with the snapshot */ metadata?: { version?: string; language_info?: any; [key: string]: any; }; /** Size of the snapshot in bytes */ size?: number; /** Format of the snapshot */ format?: string; /** Format version of the snapshot */ format_version?: string; /** Status of the snapshot */ status?: string; /** ISO 8601 timestamp when the snapshot was last updated */ updated_at: string; /** List of files included in the snapshot */ files?: any[]; } /** * Stable public interface for Snapshot data. * This is the contract that SDK consumers can rely on. * The raw API may change, but this interface remains stable. */ export interface RuntimeSnapshotJSON { /** Unique identifier for the snapshot */ uid: string; /** Name of the snapshot */ name: string; /** Optional description of the snapshot */ description?: string; /** Name of the environment used by the runtime */ environment: string; /** ISO 8601 timestamp when the snapshot was last updated */ updatedAt: string; } /** * Request payload for creating a runtime snapshot * @interface CreateRuntimeSnapshotRequest */ export interface CreateRuntimeSnapshotRequest { /** Pod name of the runtime to snapshot */ pod_name: string; /** Name for the snapshot */ name: string; /** Description of the snapshot */ description: string; /** Whether to stop the runtime after creating snapshot */ stop: boolean; } /** * Response for getting a specific runtime snapshot * @interface GetRuntimeSnapshotResponse */ export interface GetRuntimeSnapshotResponse { /** Indicates if the request was successful */ success: boolean; /** Response message */ message: string; /** The snapshot details */ snapshot: RuntimeSnapshotData; } /** * Response for creating a runtime snapshot * @interface CreateRuntimeSnapshotResponse */ export interface CreateRuntimeSnapshotResponse { /** Indicates if the request was successful */ success: boolean; /** Response message */ message: string; /** The created snapshot details */ snapshot: RuntimeSnapshotData; } /** * Response from listing runtime snapshots * @interface RuntimeSnapshotsListResponse */ export interface ListRuntimeSnapshotsResponse { /** Whether the request was successful */ success: boolean; /** Response message from the server */ message: string; /** Array of runtime snapshots */ snapshots: RuntimeSnapshotData[]; } /** * Snapshot domain model that wraps API responses with convenient methods. * Provides runtime snapshot management with data refresh and lifecycle operations. * * @example * ```typescript * const snapshot = await runtime.createSnapshot('my-checkpoint'); * const runtime = await snapshot.restore(); * ``` */ export declare class RuntimeSnapshotDTO { protected _data: RuntimeSnapshotData; private _sdk; private _deleted; /** * Create a Runtime Snapshot instance. * * @param data - Snapshot data from API * @param sdk - SDK instance */ constructor(data: RuntimeSnapshotData, sdk: DatalayerClient); /** * Check if this snapshot has been deleted and throw error if so. * @throws Error if deleted */ private _checkDeleted; /** Unique identifier for the snapshot. */ get uid(): string; /** Name of the snapshot. */ get name(): string; /** Description of the snapshot. */ get description(): string; /** Name of the environment used by the runtime. */ get environment(): string; /** When the snapshot was last updated. */ get updatedAt(): Date; /** * Delete this snapshot permanently. * After deletion, subsequent calls to dynamic methods will throw errors. */ delete(): Promise<void>; /** * Create a runtime from this snapshot (restore functionality). * * @param config - Optional runtime configuration to override defaults * @returns Created Runtime instance */ restore(minutesLimit: number): Promise<RuntimeDTO>; /** * Get snapshot data in camelCase format. * Returns only the core fields that consumers need. * This provides a stable interface regardless of API changes. * Note: Returns current cached state - call getStatus() first if you need fresh data. * * @returns Core snapshot data with camelCase properties */ toJSON(): RuntimeSnapshotJSON; /** * Get the raw snapshot data exactly as received from the API. * This preserves the original snake_case naming from the API response. * * @returns Raw snapshot data from API */ rawData(): RuntimeSnapshotData; /** String representation of the snapshot. */ toString(): string; }