UNPKG

@wocker/pgsql-plugin

Version:
90 lines (89 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Service = exports.STORAGE_FILESYSTEM = exports.STORAGE_VOLUME = void 0; exports.STORAGE_VOLUME = "volume"; exports.STORAGE_FILESYSTEM = "filesystem"; class Service { constructor(data) { const { name, host, port, user, password, image, imageName, imageVersion, containerPort, storage = exports.STORAGE_FILESYSTEM, volume } = data; this.name = name; this.host = host; this.port = port; this.user = user; this.password = password; this._image = image; this._imageName = imageName; this._imageVersion = imageVersion; this.containerPort = containerPort; this.storage = storage; this._volume = volume; } get isExternal() { return !!this.host; } get auth() { const cmd = []; if (this.user) { cmd.push("-U", this.user); } if (this.isExternal) { if (this.host) { cmd.push("--host", this.host); } if (this.port) { cmd.push("--port", `${this.port}`); } } return cmd; } get containerName() { return `pgsql-${this.name}.ws`; } get image() { if (!this._image) { let imageName = this._imageName, imageVersion = this._imageVersion; if (!imageName) { imageName = "postgres"; } if (!imageVersion) { return imageName; } return `${imageName}:${imageVersion}`; } return this._image; } set image(image) { this._image = image; } set imageName(imageName) { const [, imageVersion] = this.image.split(":"); this._image = !imageVersion ? imageName : `${imageName}:${imageVersion}`; } set imageVersion(imageVersion) { const [imageName] = this.image.split(":"); this._image = `${imageName}:${imageVersion}`; } get volume() { if (!this._volume) { this._volume = this.defaultVolume; } return this._volume; } get defaultVolume() { return `wocker-pgsql-${this.name}`; } toObject() { return { name: this.name, host: this.host, port: this.port, user: this.user, password: this.password, image: this.image, containerPort: this.containerPort, storage: this.storage, volume: this._volume }; } } exports.Service = Service;