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

@cedx/cli

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cedx/cli - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

src/cli/db_backup.coffee.bak

6

lib/cli.js

@@ -30,2 +30,6 @@ var command, error, index, path, positionals, run, tokens, usage, values, version;

Commands:
db-charset [options] <collation> Alter the character set of MariaDB tables.
db-engine [options] <engine> Alter the storage engine of MariaDB tables.
db-optimize [options] Optimize a set of MariaDB tables.
iconv [options] <fileOrDirectory> Convert the encoding of input files.
jdk [options] Download and install the latest OpenJDK release.

@@ -76,3 +80,3 @@ node [options] Download and install the latest Node.js release.

[command] = positionals;
path = `../lib/cli/${command}.js`;
path = `../lib/cli/${command.replaceAll("-", "_")}.js`;
await access(join(import.meta.dirname, path));

@@ -79,0 +83,0 @@ } catch (error1) {

@@ -1,4 +0,136 @@

(function() {
var usage;
import console from "node:console";
}).call(this);
import {
parseArgs
} from "node:util";
import {
Schema
} from "../data/schema.js";
import {
Table
} from "../data/table.js";
import {
createConnection
} from "../sql/connection.js";
// The usage information.
usage = `Alter the character set of MariaDB tables.
Usage:
npx @cedx/cli db-charset [options] <collation>
Arguments:
collation The name of the new character set.
Options:
-d, --dsn <uri> The connection string.
-s, --schema <name> The schema name.
-t, --table <name> The table names (requires a schema).
-h, --help Display this help.`;
// Alters the character set of MariaDB tables.
export var DbCharsetCommand = class DbCharsetCommand {
// Creates a new command.
constructor(options = {}) {
var dsn, ref, ref1, ref2;
dsn = (ref = options.dsn) != null ? ref : "root@localhost";
// The connection string.
this.dsn = new URL(dsn.startsWith("mariadb:") ? dsn : `mariadb://${dsn}`);
// The schema name.
this.schema = (ref1 = options.schema) != null ? ref1 : "";
// The table names (requires a schema).
this.table = (ref2 = options.table) != null ? ref2 : [];
if (this.table.length && !this.schema) {
throw Error(`The table \"${this.table[0]}\" requires that a schema be specified.`);
}
// The database connection.
this._db = null;
}
// Runs this command.
async run(collation) {
var normalizedCollation, ref, schemas, table, tables;
this._db = (await createConnection(new URL("/information_schema", this.dsn)));
schemas = this.schema ? [
new Schema({
name: this.schema
})
] : (await this._db.getSchemas());
tables = (await Promise.all(schemas.map((schema) => {
if (this.table.length) {
return Promise.resolve(this.table.map(function(item) {
return new Table({
name: item,
schema: schema.name
});
}));
} else {
return this._db.getTables(schema);
}
})));
normalizedCollation = collation.toLowerCase();
await this._db.query("SET foreign_key_checks = 0");
ref = tables.flat();
for (table of ref) {
if (table.collation.toLowerCase() !== normalizedCollation) {
await this._alterTable(table, collation);
}
}
await this._db.query("SET foreign_key_checks = 1");
return (await this._db.end());
}
// Alters the specified database table.
async _alterTable(table, collation) {
var qualifiedName;
qualifiedName = `${this._db.escapeId(table.schema)}.${this._db.escapeId(table.name)}`;
console.log(`Processing: ${qualifiedName}`);
return (await this._db.query(`ALTER TABLE ${qualifiedName} CONVERT TO CHARACTER SET ${collation.split("_").at(0)} COLLATE ${collation}`));
}
};
// Alters the character set of MariaDB tables.
export default function(args) {
var positionals, values;
({positionals, values} = parseArgs({
allowPositionals: true,
args: args,
options: {
dsn: {
short: "d",
type: "string"
},
help: {
short: "h",
type: "boolean",
default: false
},
schema: {
short: "s",
type: "string",
default: ""
},
table: {
short: "t",
type: "string",
default: [],
multiple: true
}
}
}));
switch (false) {
case !values.help:
return Promise.resolve(console.log(usage.replaceAll("\t", " ")));
case !!positionals.length:
throw Error('The required argument "collation" is missing.');
case !!values.dsn:
throw Error('The required option "--dsn" is missing.');
}
return new DbCharsetCommand(values).run(positionals[0]);
};

@@ -1,4 +0,136 @@

(function() {
var usage;
import console from "node:console";
}).call(this);
import {
parseArgs
} from "node:util";
import {
Schema
} from "../data/schema.js";
import {
Table
} from "../data/table.js";
import {
createConnection
} from "../sql/connection.js";
// The usage information.
usage = `Alter the storage engine of MariaDB tables.
Usage:
npx @cedx/cli db-engine [options] <engine>
Arguments:
engine The name of the new storage engine.
Options:
-d, --dsn <uri> The connection string.
-s, --schema <name> The schema name.
-t, --table <name> The table names (requires a schema).
-h, --help Display this help.`;
// Alters the storage engine of MariaDB tables.
export var DbEngineCommand = class DbEngineCommand {
// Creates a new command.
constructor(options = {}) {
var dsn, ref, ref1, ref2;
dsn = (ref = options.dsn) != null ? ref : "root@localhost";
// The connection string.
this.dsn = new URL(dsn.startsWith("mariadb:") ? dsn : `mariadb://${dsn}`);
// The schema name.
this.schema = (ref1 = options.schema) != null ? ref1 : "";
// The table names (requires a schema).
this.table = (ref2 = options.table) != null ? ref2 : [];
if (this.table.length && !this.schema) {
throw Error(`The table \"${this.table[0]}\" requires that a schema be specified.`);
}
// The database connection.
this._db = null;
}
// Runs this command.
async run(engine) {
var normalizedEngine, ref, schemas, table, tables;
this._db = (await createConnection(new URL("/information_schema", this.dsn)));
schemas = this.schema ? [
new Schema({
name: this.schema
})
] : (await this._db.getSchemas());
tables = (await Promise.all(schemas.map((schema) => {
if (this.table.length) {
return Promise.resolve(this.table.map(function(item) {
return new Table({
name: item,
schema: schema.name
});
}));
} else {
return this._db.getTables(schema);
}
})));
normalizedEngine = engine.toLowerCase();
await this._db.query("SET foreign_key_checks = 0");
ref = tables.flat();
for (table of ref) {
if (table.engine.toLowerCase() !== normalizedEngine) {
await this._alterTable(table, engine);
}
}
await this._db.query("SET foreign_key_checks = 1");
return (await this._db.end());
}
// Alters the specified database table.
async _alterTable(table, engine) {
var qualifiedName;
qualifiedName = `${this._db.escapeId(table.schema)}.${this._db.escapeId(table.name)}`;
console.log(`Processing: ${qualifiedName}`);
return (await this._db.query(`ALTER TABLE ${qualifiedName} ENGINE = ${engine}`));
}
};
// Alters the storage engine of MariaDB tables.
export default function(args) {
var positionals, values;
({positionals, values} = parseArgs({
allowPositionals: true,
args: args,
options: {
dsn: {
short: "d",
type: "string"
},
help: {
short: "h",
type: "boolean",
default: false
},
schema: {
short: "s",
type: "string",
default: ""
},
table: {
short: "t",
type: "string",
default: [],
multiple: true
}
}
}));
switch (false) {
case !values.help:
return Promise.resolve(console.log(usage.replaceAll("\t", " ")));
case !!positionals.length:
throw Error('The required argument "engine" is missing.');
case !!values.dsn:
throw Error('The required option "--dsn" is missing.');
}
return new DbEngineCommand(values).run(positionals[0]);
};

@@ -1,4 +0,125 @@

(function() {
var usage;
import console from "node:console";
}).call(this);
import {
parseArgs
} from "node:util";
import {
Schema
} from "../data/schema.js";
import {
Table
} from "../data/table.js";
import {
createConnection
} from "../sql/connection.js";
// The usage information.
usage = `Optimize a set of MariaDB tables.
Usage:
npx @cedx/cli db-optimize [options]
Options:
-d, --dsn <uri> The connection string.
-s, --schema <name> The schema name.
-t, --table <name> The table names (requires a schema).
-h, --help Display this help.`;
// Optimizes a set of MariaDB tables.
export var DbOptimizeCommand = class DbOptimizeCommand {
// Creates a new command.
constructor(options = {}) {
var dsn, ref, ref1, ref2;
dsn = (ref = options.dsn) != null ? ref : "root@localhost";
// The connection string.
this.dsn = new URL(dsn.startsWith("mariadb:") ? dsn : `mariadb://${dsn}`);
// The schema name.
this.schema = (ref1 = options.schema) != null ? ref1 : "";
// The table names (requires a schema).
this.table = (ref2 = options.table) != null ? ref2 : [];
if (this.table.length && !this.schema) {
throw Error(`The table \"${this.table[0]}\" requires that a schema be specified.`);
}
// The database connection.
this._db = null;
}
// Runs this command.
async run() {
var ref, schemas, table, tables;
this._db = (await createConnection(new URL("/information_schema", this.dsn)));
schemas = this.schema ? [
new Schema({
name: this.schema
})
] : (await this._db.getSchemas());
tables = (await Promise.all(schemas.map((schema) => {
if (this.table.length) {
return Promise.resolve(this.table.map(function(item) {
return new Table({
name: item,
schema: schema.name
});
}));
} else {
return this._db.getTables(schema);
}
})));
ref = tables.flat();
for (table of ref) {
await this._optimizeTable(table);
}
return (await this._db.end());
}
// Optimizes the specified database table.
async _optimizeTable(table) {
var qualifiedName;
qualifiedName = `${this._db.escapeId(table.schema)}.${this._db.escapeId(table.name)}`;
console.log(`Optimizing: ${qualifiedName}`);
return (await this._db.query(`OPTIMIZE TABLE ${qualifiedName}`));
}
};
// Optimizes a set of MariaDB tables.
export default function(args) {
var values;
({values} = parseArgs({
args: args,
options: {
dsn: {
short: "d",
type: "string"
},
help: {
short: "h",
type: "boolean",
default: false
},
schema: {
short: "s",
type: "string",
default: ""
},
table: {
short: "t",
type: "string",
default: [],
multiple: true
}
}
}));
switch (false) {
case !values.help:
return Promise.resolve(console.log(usage.replaceAll("\t", " ")));
case !!values.dsn:
throw Error('The required option "--dsn" is missing.');
}
return new DbOptimizeCommand(values).run();
};

@@ -1,4 +0,125 @@

(function() {
var usage;
import {
transcode
} from "node:buffer";
}).call(this);
import console from "node:console";
import {
readdir,
readFile,
stat,
writeFile
} from "node:fs/promises";
import {
extname,
join,
resolve
} from "node:path";
import {
parseArgs
} from "node:util";
import textExtensions from "text-extensions";
// The usage information.
usage = `Convert the encoding of input files.
Usage:
npx @cedx/cli iconv [options] <fileOrDirectory>
Arguments:
fileOrDirectory The path to the file or directory to process.
Options:
-f, --from <encoding> The input charset. Defaults to "latin1".
-t, --to <encoding> The output charset. Defaults to "utf8".
-r, --recursive Whether to process the directory recursively.
-h, --help Display this help.`;
// Converts the encoding of input files.
export var IconvCommand = class IconvCommand {
// Creates a new command.
constructor(options = {}) {
var ref, ref1, ref2;
// The input charset.
this.from = (ref = options.from) != null ? ref : "latin1";
// Value indicating whether to process the directory recursively.
this.recursive = (ref1 = options.recursive) != null ? ref1 : false;
// The output charset.
this.to = (ref2 = options.to) != null ? ref2 : "utf8";
// The text file extensions.
this._textExtensions = new Set(textExtensions);
}
// Runs this command.
async run(input) {
var file, files, results;
if (!((await stat(input))).isDirectory()) {
return (await this._transcodeFile(resolve(input)));
} else {
files = (await readdir(input, {
recursive: this.recursive,
withFileTypes: true
}));
results = [];
for await (file of files) {
if (file.isFile()) {
results.push((await this._transcodeFile(join(file.parentPath, file.name))));
}
}
return results;
}
}
// Converts the encoding of the specified file.
async _transcodeFile(file) {
if (!this._textExtensions.has(extname(file).slice(1).toLowerCase())) {
return;
}
console.log(`Converting: ${file}`);
return (await writeFile(file, transcode((await readFile(file)), this.from, this.to)));
}
};
// Converts the encoding of input files.
export default function(args) {
var positionals, values;
({positionals, values} = parseArgs({
allowPositionals: true,
args: args,
options: {
from: {
short: "f",
type: "string",
default: "latin1"
},
help: {
short: "h",
type: "boolean",
default: false
},
recursive: {
short: "r",
type: "boolean",
default: false
},
to: {
short: "t",
type: "string",
default: "utf8"
}
}
}));
switch (false) {
case !values.help:
return Promise.resolve(console.log(usage.replaceAll("\t", " ")));
case !!positionals.length:
throw Error('The required argument "fileOrDirectory" is missing.');
}
return new IconvCommand(values).run(positionals[0]);
};

6

lib/cli/node.js

@@ -99,7 +99,9 @@ var defaultDirectory, run, usage;

async _detachProcess() {
var handle, output;
var handle, logFile, output;
console.log("This command will run in detached mode.");
output = join(tmpdir(), basename(execPath));
logFile = `${output}.log`;
console.log(`Logging to file \"${logFile}\"...`);
await cp(execPath, output);
handle = (await open(join(import.meta.dirname, "../../var/node.log"), "w"));
handle = (await open(logFile, "w"));
return spawn(output, argv.slice(1), {

@@ -106,0 +108,0 @@ detached: true,

@@ -14,6 +14,2 @@ var run, usage;

import {
access
} from "node:fs/promises";
import {
join,

@@ -20,0 +16,0 @@ resolve

@@ -9,3 +9,3 @@ {

"type": "module",
"version": "1.0.1",
"version": "1.1.0",
"author": {

@@ -12,0 +12,0 @@ "email": "cedric@belin.io",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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