UNPKG

@nasriya/orchestriq

Version:

A package to generate Docker files

53 lines (52 loc) 1.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const StackVolume_1 = __importDefault(require("../containers/templates/assets/volumes/StackVolume")); class VolumesManager { #_socket; constructor(socket) { this.#_socket = socket; } /** * Retrieves a list of volumes from the Docker daemon. * * @returns A promise that resolves to an array of Volume objects. * @throws {Error} If unable to fetch the list of volumes. */ async list() { try { const res = await this.#_socket.fetch('/volumes'); const volumes = res.Volumes; return volumes; } catch (error) { if (error instanceof Error) { error.message = `Unable to list volumes: ${error.message}`; } throw error; } } /** * Creates a new volume and returns its name. * @param data The volume to create, which can be either a {@link CreateVolumeOptions} object or a {@link StackVolume} instance. * @returns A promise that resolves to the name of the created volume. * @throws {Error} If the volume could not be created. */ async create(data) { try { const stackVolume = data instanceof StackVolume_1.default ? data : new StackVolume_1.default(data); const json = stackVolume.toJSON('api'); const volume = await this.#_socket.fetch('/volumes/create', { method: 'POST', body: JSON.stringify(json) }); return volume.Name; } catch (error) { if (error instanceof Error) { error.message = `Unable to create volume: ${error.message}`; } throw error; } } } exports.default = VolumesManager;