/** * AtomVM Node.js Runtime class * * **Poka-Yoke Design**: * - State machine prevents invalid operations (cannot execute before load) * - Validation prevents invalid inputs (non-empty avmPath) * - Type guards ensure state consistency */ export class AtomVMNodeRuntime { /** * @param {Object} [options] - Runtime options * @param {Function} [options.log] - Logging function * @param {Function} [options.errorLog] - Error logging function */ constructor(options?: { log?: Function; errorLog?: Function; }); log: Function; errorLog: Function; atomvmPath: string; /** @type {NodeRuntimeState} */ state: NodeRuntimeState; /** * Type guard: Check if runtime is ready for operations * * **Poka-Yoke**: Prevents operations in invalid states * * @returns {boolean} True if runtime is ready */ isReady(): boolean; /** * Type guard: Check if runtime is loaded * * **Poka-yoke**: Ensures state consistency * * @returns {boolean} True if runtime is loaded */ isLoaded(): boolean; /** * Load AtomVM Node.js module * * **Poka-Yoke**: State machine prevents multiple loads and loads after destroy * * @returns {Promise} * @throws {Error} If state is invalid or file not found */ load(): Promise; /** * Execute .avm file * * **Poka-Yoke**: State machine and validation prevent invalid operations * * @param {string} avmPath - Path to .avm file to execute (required, non-empty) * @returns {Promise} Execution result * @throws {Error} If runtime is not ready or avmPath is invalid */ execute(avmPath: string): Promise; /** * Execute .avm file (alias for execute) * @param {string} avmPath - Path to .avm file * @returns {Promise} */ executeBeam(avmPath: string): Promise; /** * Run a built-in example (simulated for Node) * @param {string} moduleName - Name of the example module * @returns {Promise} */ runExample(moduleName: string): Promise; /** * Clean up resources * * **Poka-Yoke**: Terminal state prevents further operations */ destroy(): void; } /** * Runtime state machine states * * **Poka-Yoke**: Enum prevents invalid states. Cannot be in multiple states simultaneously. * Valid transitions: * - Uninitialized => Loading => Ready * - Uninitialized => Loading => Error * - Ready => Executing => Ready * - Any => Destroyed (terminal state) */ export type NodeRuntimeState = "Uninitialized" | "Loading" | "Ready" | "Executing" | "Error" | "Destroyed";