UNPKG

@nasriya/orchestriq

Version:

A package to generate Docker files

48 lines (47 loc) 1.68 kB
import StackVolume from "../containers/templates/assets/volumes/StackVolume.js"; 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 ? data : new StackVolume(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; } } } export default VolumesManager;