Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wocker/pgsql-plugin

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wocker/pgsql-plugin - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

4

lib/controllers/PgSqlController.d.ts

@@ -9,4 +9,8 @@ import { AppConfigService, DockerService } from "@wocker/core";

protected init(email?: string, password?: string, skipPassword?: boolean): Promise<void>;
pgsql(name?: string): Promise<void>;
dump(name?: string): Promise<void>;
protected create(service: string, user: string, password: string, host: string, port: string): Promise<void>;
protected upgrade(name?: string, image?: string, imageVersion?: string): Promise<void>;
protected destroy(service: string): Promise<void>;
list(): Promise<string>;
protected start(service?: string, restart?: boolean): Promise<void>;

@@ -13,0 +17,0 @@ protected stop(service?: string): Promise<void>;

@@ -39,2 +39,12 @@ "use strict";

}
pgsql(name) {
return __awaiter(this, void 0, void 0, function* () {
yield this.pgSqlService.pgsql(name);
});
}
dump(name) {
return __awaiter(this, void 0, void 0, function* () {
yield this.pgSqlService.dump(name);
});
}
create(service, user, password, host, port) {

@@ -48,2 +58,7 @@ return __awaiter(this, void 0, void 0, function* () {

}
upgrade(name, image, imageVersion) {
return __awaiter(this, void 0, void 0, function* () {
yield this.pgSqlService.upgrade(name, image, imageVersion);
});
}
destroy(service) {

@@ -54,2 +69,7 @@ return __awaiter(this, void 0, void 0, function* () {

}
list() {
return __awaiter(this, void 0, void 0, function* () {
return this.pgSqlService.listTable();
});
}
start(service, restart) {

@@ -98,3 +118,20 @@ return __awaiter(this, void 0, void 0, function* () {

__decorate([
(0, core_1.Command)("pgsql [service]"),
(0, core_1.Description)("Interacts with a specified PostgreSQL service."),
__param(0, (0, core_1.Param)("service")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], PgSqlController.prototype, "pgsql", null);
__decorate([
(0, core_1.Command)("pgsql:dump [service]"),
(0, core_1.Description)("Creates a dump of the specified PostgreSQL service."),
__param(0, (0, core_1.Param)("service")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], PgSqlController.prototype, "dump", null);
__decorate([
(0, core_1.Command)("pgsql:create <service>"),
(0, core_1.Description)("Creates a PostgreSQL service with configurable user, password, host, and port options."),
__param(0, (0, core_1.Param)("service")),

@@ -104,3 +141,3 @@ __param(1, (0, core_1.Option)("user", {

alias: "u",
description: "User"
description: "User name"
})),

@@ -127,3 +164,22 @@ __param(2, (0, core_1.Option)("password", {

__decorate([
(0, core_1.Command)("pgsql:upgrade [service]"),
(0, core_1.Description)("Upgrades a PostgreSQL service with options to specify image and version."),
__param(0, (0, core_1.Param)("service")),
__param(1, (0, core_1.Option)("image", {
type: "string",
alias: "i",
description: "Image name"
})),
__param(2, (0, core_1.Option)("image-version", {
type: "string",
alias: "I",
description: "Image version"
})),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String, String]),
__metadata("design:returntype", Promise)
], PgSqlController.prototype, "upgrade", null);
__decorate([
(0, core_1.Command)("pgsql:destroy <service>"),
(0, core_1.Description)("Destroys a specified PostgreSQL service."),
__param(0, (0, core_1.Param)("service")),

@@ -135,3 +191,11 @@ __metadata("design:type", Function),

__decorate([
(0, core_1.Command)("pgsql:ls"),
(0, core_1.Description)("Lists all available PostgreSQL tables in the service."),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], PgSqlController.prototype, "list", null);
__decorate([
(0, core_1.Command)("pgsql:start [service]"),
(0, core_1.Description)("Starts the specified PostgreSQL service and opens the admin interface."),
__param(0, (0, core_1.Param)("service")),

@@ -141,3 +205,3 @@ __param(1, (0, core_1.Option)("restart", {

alias: "r",
description: "Restart service"
description: "Restart the service if it's already running"
})),

@@ -150,2 +214,3 @@ __metadata("design:type", Function),

(0, core_1.Command)("pgsql:stop [service]"),
(0, core_1.Description)("Stops a PostgreSQL service and opens the administration interface."),
__param(0, (0, core_1.Param)("service")),

@@ -158,2 +223,3 @@ __metadata("design:type", Function),

(0, core_1.Command)("pgsql:use <service>"),
(0, core_1.Description)("Sets the specified PostgreSQL service as the default."),
__param(0, (0, core_1.Param)("service")),

@@ -160,0 +226,0 @@ __metadata("design:type", Function),

2

lib/makes/Config.d.ts

@@ -19,4 +19,4 @@ import { PickProperties } from "@wocker/core";

unsetService(name: string): void;
abstract save(): Promise<void>;
abstract save(): void;
toJSON(): ConfigProps;
}

@@ -9,2 +9,4 @@ import { PickProperties } from "@wocker/core";

port?: string | number;
image?: string;
imageVersion?: string;
constructor(data: ServiceProps);

@@ -11,0 +13,0 @@ get containerName(): string;

@@ -6,3 +6,3 @@ "use strict";

constructor(data) {
const { name, host, port, user, password } = data;
const { name, host, port, user, password, image = "postgres", imageVersion = "latest" } = data;
this.name = name;

@@ -13,2 +13,4 @@ this.host = host;

this.password = password;
this.image = image;
this.imageVersion = imageVersion;
}

@@ -24,3 +26,5 @@ get containerName() {

user: this.user,
password: this.password
password: this.password,
image: this.image,
imageVersion: this.imageVersion
};

@@ -27,0 +31,0 @@ }

@@ -1,2 +0,2 @@

import { AppConfigService, PluginConfigService, DockerService, ProxyService } from "@wocker/core";
import { AppConfigService, PluginConfigService, DockerService, FileSystem, ProxyService } from "@wocker/core";
import { Config } from "../makes/Config";

@@ -9,4 +9,6 @@ export declare class PgSqlService {

protected adminContainerName: string;
protected _config?: Config;
constructor(appConfigService: AppConfigService, pluginConfigService: PluginConfigService, dockerService: DockerService, proxyService: ProxyService);
get dbDir(): string;
get config(): Config;
get fs(): FileSystem;
get configPath(): string;

@@ -16,9 +18,12 @@ dbPath(service: string): string;

create(name: string, user?: string, password?: string, host?: string, port?: string): Promise<void>;
upgrade(name?: string, image?: string, imageVersion?: string): Promise<void>;
destroy(service: string): Promise<void>;
listTable(): Promise<string>;
start(name?: string, restart?: boolean): Promise<void>;
stop(name?: string): Promise<void>;
pgsql(name?: string): Promise<void>;
dump(name?: string): Promise<void>;
admin(): Promise<void>;
setDefault(name: string): Promise<void>;
getServices(): Promise<string[]>;
protected getConfig(): Promise<Config>;
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

@@ -24,19 +8,2 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

};
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __metadata = (this && this.__metadata) || function (k, v) {

@@ -54,2 +21,5 @@ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -59,3 +29,3 @@ exports.PgSqlService = void 0;

const utils_1 = require("@wocker/utils");
const Path = __importStar(require("path"));
const cli_table3_1 = __importDefault(require("cli-table3"));
const Config_1 = require("../makes/Config");

@@ -71,5 +41,20 @@ const Service_1 = require("../makes/Service");

}
get dbDir() {
return this.appConfigService.dataPath("db/pgsql");
get config() {
if (!this._config) {
const _this = this, fs = this.fs, data = fs.exists("config.json") ? fs.readJSON("config.json") : {};
this._config = new class extends Config_1.Config {
save() {
fs.writeJSON(_this.configPath, this.toJSON());
}
}(data);
}
return this._config;
}
get fs() {
let fs = this.pluginConfigService.fs;
if (!fs) {
fs = new core_1.FileSystem(this.pluginConfigService.dataPath());
}
return fs;
}
get configPath() {

@@ -79,7 +64,7 @@ return "config.json";

dbPath(service) {
return Path.join(this.dbDir, service);
return this.appConfigService.dataPath("db/pgsql", service);
}
init(email, password, skipPassword) {
return __awaiter(this, void 0, void 0, function* () {
const config = yield this.getConfig();
const config = this.config;
if (!email) {

@@ -113,4 +98,3 @@ email = yield (0, utils_1.promptText)({

return __awaiter(this, void 0, void 0, function* () {
const config = yield this.getConfig();
let service = config.getService(name);
let service = this.config.getService(name);
if (!service) {

@@ -139,17 +123,42 @@ service = new Service_1.Service({

}
config.setService(service);
yield config.save();
this.config.setService(service);
this.config.save();
});
}
upgrade(name, image, imageVersion) {
return __awaiter(this, void 0, void 0, function* () {
const service = this.config.getServiceOrDefault(name);
if (image) {
service.image = image;
}
if (imageVersion) {
service.imageVersion = imageVersion;
}
this.config.setService(service);
this.config.save();
});
}
destroy(service) {
return __awaiter(this, void 0, void 0, function* () {
const config = yield this.getConfig();
config.unsetService(service);
yield config.save();
this.config.unsetService(service);
this.config.save();
});
}
listTable() {
return __awaiter(this, void 0, void 0, function* () {
const table = new cli_table3_1.default({
head: ["Name", "Host"]
});
for (const service of this.config.services) {
table.push([
service.name + (this.config.default === service.name ? " (default)" : ""),
service.host || service.containerName
]);
}
return table.toString();
});
}
start(name, restart) {
return __awaiter(this, void 0, void 0, function* () {
const config = yield this.getConfig();
const service = config.getServiceOrDefault(name);
const service = this.config.getServiceOrDefault(name);
if (restart) {

@@ -163,3 +172,3 @@ yield this.dockerService.removeContainer(service.containerName);

name: service.containerName,
image: "postgres:latest",
image: `${service.image}:${service.imageVersion}`,
restart: "always",

@@ -184,10 +193,35 @@ volumes: [

return __awaiter(this, void 0, void 0, function* () {
const config = yield this.getConfig();
const service = config.getServiceOrDefault(name);
const service = this.config.getServiceOrDefault(name);
yield this.dockerService.removeContainer(service.containerName);
});
}
pgsql(name) {
return __awaiter(this, void 0, void 0, function* () {
const service = this.config.getServiceOrDefault(name);
const container = yield this.dockerService.getContainer(service.containerName);
if (!container) {
throw new Error(`Service "${service.name}" isn't started`);
}
yield this.dockerService.exec(service.containerName, {
tty: true,
cmd: ["psql"]
});
});
}
dump(name) {
return __awaiter(this, void 0, void 0, function* () {
const service = this.config.getServiceOrDefault(name);
const container = yield this.dockerService.getContainer(service.containerName);
if (!container) {
throw new Error(`Service "${service.name}" isn't started`);
}
yield this.dockerService.exec(service.containerName, {
tty: true,
cmd: ["pg_dump"]
});
});
}
admin() {
return __awaiter(this, void 0, void 0, function* () {
const config = yield this.getConfig();
const config = this.config;
if (!config.adminEmail || !config.adminPassword) {

@@ -235,3 +269,3 @@ console.info("Can't start admin credentials missed");

}
yield core_1.FS.writeJSON(this.pluginConfigService.dataPath("servers.json"), {
this.fs.writeJSON("servers.json", {
Servers: servers.reduce((res, server, index) => {

@@ -291,3 +325,3 @@ return Object.assign(Object.assign({}, res), { [`${index}`]: server });

return __awaiter(this, void 0, void 0, function* () {
const config = yield this.getConfig();
const config = this.config;
if (!config.getService(name)) {

@@ -302,4 +336,3 @@ throw new Error(`Service "${name}" not found`);

return __awaiter(this, void 0, void 0, function* () {
const config = yield this.getConfig();
return (config.services || []).map((service) => {
return (this.config.services || []).map((service) => {
return service.name;

@@ -309,26 +342,2 @@ });

}
getConfig() {
return __awaiter(this, void 0, void 0, function* () {
let data = !this.pluginConfigService.exists(this.configPath)
? {
default: "default",
services: [
{
name: "default",
user: "root",
password: "root"
}
]
}
: yield this.pluginConfigService.readJSON(this.configPath);
const _this = this;
return new class extends Config_1.Config {
save() {
return __awaiter(this, void 0, void 0, function* () {
yield _this.pluginConfigService.writeJSON(_this.configPath, this.toJSON());
});
}
}(data);
});
}
};

@@ -335,0 +344,0 @@ exports.PgSqlService = PgSqlService;

{
"name": "@wocker/pgsql-plugin",
"version": "1.0.8",
"version": "1.0.9",
"author": "Kris Papercut <krispcut@gmail.com>",
"description": "PostgresSQL plugin for wocker",
"license": "MIT",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"keywords": [

@@ -17,3 +17,3 @@ "docker",

],
"homepage": "https://kearisp.github.io/wocker/plugins/pgsql",
"homepage": "https://kearisp.github.io/wocker/docs/plugins/pgsql",
"repository": {

@@ -33,9 +33,9 @@ "type": "git",

"dependencies": {
"@wocker/core": "^1.0.20",
"@wocker/utils": "^1.0.7"
"@wocker/core": "^1.0.21",
"@wocker/utils": "^1.0.7",
"cli-table3": "^0.6.5"
},
"devDependencies": {
"@types/node": "^20.11.20",
"typescript": "^5.5.4"
"typescript": "^5.7.2"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc