UNPKG

axiodb

Version:

A blazing-fast, lightweight, and scalable nodejs package based DBMS for modern application. Supports schemas, encryption, and advanced query capabilities.

86 lines 3.37 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const child_process_1 = require("child_process"); const util_1 = require("util"); const execAsync = (0, util_1.promisify)(child_process_1.exec); /** * Provides methods to execute and spawn worker processes. */ class WorkerProcess { /** * Executes a shell command and returns its standard output as a string. * * @param command - The command to execute. * @returns A promise that resolves with the command's standard output. * @throws If the command fails to execute. */ execCommand(command) { return __awaiter(this, void 0, void 0, function* () { try { const { stdout } = yield execAsync(command); return stdout; } catch (error) { throw new Error(`Failed to execute command: ${error}`); } }); } /** * Spawns a new process using the given command and arguments, inheriting stdio. * * @param command - The command to run. * @param args - Optional array of arguments for the command. * @returns A promise that resolves when the process exits with code 0, or rejects on error. * @throws If the process fails to spawn. */ spawnCommand(command_1) { return __awaiter(this, arguments, void 0, function* (command, args = []) { try { const child = (0, child_process_1.spawn)(command, args, { stdio: "inherit" }); return new Promise((resolve, reject) => { child.on("close", (code) => { if (code !== 0) { reject(new Error(`Command failed with exit code ${code}`)); } else { resolve(); } }); }); } catch (error) { throw new Error(`Failed to spawn command: ${error}`); } }); } /** * Returns the operating system type. * * @returns A string representing the OS type: "windows", "macos", or "linux". * @throws If the platform is unsupported. */ static getOS() { const platform = process.platform; if (platform === "win32") { return "windows"; } if (platform === "darwin") { return "macos"; } if (platform === "linux") { return "linux"; } throw new Error(`Unsupported platform: ${platform}`); } } exports.default = WorkerProcess; //# sourceMappingURL=worker_process.js.map