@yandjin-mikro-orm/cli 6.1.4-rc-sti-changes-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli.js ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
5
+ require('@jercle/yargonaut')
6
+ .style('blue')
7
+ .style('yellow', 'required')
8
+ .helpStyle('green')
9
+ .errorsStyle('red');
10
+ const CLIHelper_1 = require("./CLIHelper");
11
+ const CLIConfigurator_1 = require("./CLIConfigurator");
12
+ (async () => {
13
+ const argv = await CLIConfigurator_1.CLIConfigurator.configure();
14
+ const args = await argv.parse(process.argv.slice(2));
15
+ if (args._.length === 0) {
16
+ CLIHelper_1.CLIHelper.showHelp();
17
+ }
18
+ })();
@@ -0,0 +1,9 @@
1
+ import type { ArgumentsCamelCase, CommandModule } from "yargs";
2
+ export declare class ClearCacheCommand implements CommandModule {
3
+ command: string;
4
+ describe: string;
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ handler(args: ArgumentsCamelCase): Promise<void>;
9
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClearCacheCommand = void 0;
4
+ const core_1 = require("@yandjin-mikro-orm/core");
5
+ const CLIHelper_1 = require("../CLIHelper");
6
+ class ClearCacheCommand {
7
+ command = "cache:clear";
8
+ describe = "Clear metadata cache";
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ async handler(args) {
13
+ const config = await CLIHelper_1.CLIHelper.getConfiguration();
14
+ if (!config.get("metadataCache").enabled) {
15
+ CLIHelper_1.CLIHelper.dump(core_1.colors.red("Metadata cache is disabled in your configuration. Set cache.enabled to true to use this command."));
16
+ return;
17
+ }
18
+ const cache = config.getMetadataCacheAdapter();
19
+ await cache.clear();
20
+ CLIHelper_1.CLIHelper.dump(core_1.colors.green("Metadata cache was successfully cleared"));
21
+ }
22
+ }
23
+ exports.ClearCacheCommand = ClearCacheCommand;
@@ -0,0 +1,9 @@
1
+ import type { ArgumentsCamelCase, CommandModule } from "yargs";
2
+ export declare class CreateDatabaseCommand implements CommandModule {
3
+ command: string;
4
+ describe: string;
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ handler(args: ArgumentsCamelCase): Promise<void>;
9
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateDatabaseCommand = void 0;
4
+ const CLIHelper_1 = require("../CLIHelper");
5
+ class CreateDatabaseCommand {
6
+ command = "database:create";
7
+ describe = "Create your database if it does not exist";
8
+ /**
9
+ * @inheritDoc
10
+ */
11
+ async handler(args) {
12
+ const orm = (await CLIHelper_1.CLIHelper.getORM());
13
+ const schemaGenerator = orm.getSchemaGenerator();
14
+ await schemaGenerator.ensureDatabase();
15
+ await orm.close(true);
16
+ }
17
+ }
18
+ exports.CreateDatabaseCommand = CreateDatabaseCommand;
@@ -0,0 +1,20 @@
1
+ import type { ArgumentsCamelCase, Argv, CommandModule } from "yargs";
2
+ export declare class CreateSeederCommand<T> implements CommandModule<T, {
3
+ seeder: string;
4
+ }> {
5
+ command: string;
6
+ describe: string;
7
+ builder: (args: Argv<T>) => Argv<{
8
+ seeder: string;
9
+ }>;
10
+ /**
11
+ * @inheritDoc
12
+ */
13
+ handler(args: ArgumentsCamelCase<{
14
+ seeder?: string;
15
+ }>): Promise<void>;
16
+ /**
17
+ * Will return a seeder name that is formatted like this EntitySeeder
18
+ */
19
+ private static getSeederClassName;
20
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateSeederCommand = void 0;
4
+ const core_1 = require("@yandjin-mikro-orm/core");
5
+ const CLIHelper_1 = require("../CLIHelper");
6
+ class CreateSeederCommand {
7
+ command = "seeder:create <seeder>";
8
+ describe = "Create a new seeder class";
9
+ builder = (args) => {
10
+ args.positional("seeder", {
11
+ describe: 'Name for the seeder class. (e.g. "test" will generate "TestSeeder" or "TestSeeder" will generate "TestSeeder")',
12
+ });
13
+ args.demandOption("seeder");
14
+ return args;
15
+ };
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ async handler(args) {
20
+ const className = CreateSeederCommand.getSeederClassName(args.seeder);
21
+ const orm = await CLIHelper_1.CLIHelper.getORM();
22
+ const seeder = orm.getSeeder();
23
+ const path = await seeder.createSeeder(className);
24
+ CLIHelper_1.CLIHelper.dump(core_1.colors.green(`Seeder ${args.seeder} successfully created at ${path}`));
25
+ await orm.close(true);
26
+ }
27
+ /**
28
+ * Will return a seeder name that is formatted like this EntitySeeder
29
+ */
30
+ static getSeederClassName(name) {
31
+ name = name.match(/(.+)seeder/i)?.[1] ?? name;
32
+ const parts = name.split("-");
33
+ return (parts
34
+ .map((name) => name.charAt(0).toUpperCase() + name.slice(1))
35
+ .join("") + "Seeder");
36
+ }
37
+ }
38
+ exports.CreateSeederCommand = CreateSeederCommand;
@@ -0,0 +1,16 @@
1
+ import type { ArgumentsCamelCase, Argv, CommandModule } from "yargs";
2
+ export declare class DatabaseSeedCommand<T> implements CommandModule<T, {
3
+ class: string;
4
+ }> {
5
+ command: string;
6
+ describe: string;
7
+ builder: (args: Argv<T>) => Argv<{
8
+ class: string;
9
+ }>;
10
+ /**
11
+ * @inheritDoc
12
+ */
13
+ handler(args: ArgumentsCamelCase<{
14
+ class?: string;
15
+ }>): Promise<void>;
16
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseSeedCommand = void 0;
4
+ const core_1 = require("@yandjin-mikro-orm/core");
5
+ const CLIHelper_1 = require("../CLIHelper");
6
+ class DatabaseSeedCommand {
7
+ command = "seeder:run";
8
+ describe = "Seed the database using the seeder class";
9
+ builder = (args) => {
10
+ args.option("c", {
11
+ alias: "class",
12
+ type: "string",
13
+ desc: "Seeder class to run",
14
+ });
15
+ return args;
16
+ };
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ async handler(args) {
21
+ const orm = await CLIHelper_1.CLIHelper.getORM();
22
+ const className = args.class ?? orm.config.get("seeder").defaultSeeder;
23
+ await orm.getSeeder().seedString(className);
24
+ CLIHelper_1.CLIHelper.dump(core_1.colors.green(`Seeder ${className} successfully executed`));
25
+ await orm.close(true);
26
+ }
27
+ }
28
+ exports.DatabaseSeedCommand = DatabaseSeedCommand;
@@ -0,0 +1,10 @@
1
+ import type { CommandModule } from "yargs";
2
+ export declare class DebugCommand implements CommandModule {
3
+ command: string;
4
+ describe: string;
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ handler(): Promise<void>;
9
+ private static checkPaths;
10
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DebugCommand = void 0;
4
+ const core_1 = require("@yandjin-mikro-orm/core");
5
+ const CLIHelper_1 = require("../CLIHelper");
6
+ class DebugCommand {
7
+ command = "debug";
8
+ describe = "Debug CLI configuration";
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ async handler() {
13
+ CLIHelper_1.CLIHelper.dump(`Current ${core_1.colors.cyan("MikroORM")} CLI configuration`);
14
+ await CLIHelper_1.CLIHelper.dumpDependencies();
15
+ const settings = await core_1.ConfigurationLoader.getSettings();
16
+ if (settings.useTsNode) {
17
+ CLIHelper_1.CLIHelper.dump(" - ts-node " + core_1.colors.green("enabled"));
18
+ }
19
+ const configPaths = await CLIHelper_1.CLIHelper.getConfigPaths();
20
+ CLIHelper_1.CLIHelper.dump(" - searched config paths:");
21
+ await DebugCommand.checkPaths(configPaths, "yellow");
22
+ try {
23
+ const config = await CLIHelper_1.CLIHelper.getConfiguration();
24
+ CLIHelper_1.CLIHelper.dump(` - configuration ${core_1.colors.green("found")}`);
25
+ const isConnected = await CLIHelper_1.CLIHelper.isDBConnected();
26
+ if (isConnected) {
27
+ CLIHelper_1.CLIHelper.dump(` - ${core_1.colors.green("database connection succesful")}`);
28
+ }
29
+ else {
30
+ CLIHelper_1.CLIHelper.dump(` - ${core_1.colors.yellow("database connection failed")}`);
31
+ }
32
+ const tsNode = config.get("tsNode");
33
+ if ([true, false].includes(tsNode)) {
34
+ const warning = tsNode
35
+ ? " (this value should be set to `false` when running compiled code!)"
36
+ : "";
37
+ CLIHelper_1.CLIHelper.dump(` - \`tsNode\` flag explicitly set to ${tsNode}, will use \`entities${tsNode ? "Ts" : ""}\` array${warning}`);
38
+ }
39
+ const entities = config.get("entities", []);
40
+ if (entities.length > 0) {
41
+ const refs = entities.filter((p) => !core_1.Utils.isString(p));
42
+ const paths = entities.filter((p) => core_1.Utils.isString(p));
43
+ const will = !config.get("tsNode") ? "will" : "could";
44
+ CLIHelper_1.CLIHelper.dump(` - ${will} use \`entities\` array (contains ${refs.length} references and ${paths.length} paths)`);
45
+ if (paths.length > 0) {
46
+ await DebugCommand.checkPaths(paths, "red", config.get("baseDir"));
47
+ }
48
+ }
49
+ const entitiesTs = config.get("entitiesTs", []);
50
+ if (entitiesTs.length > 0) {
51
+ const refs = entitiesTs.filter((p) => !core_1.Utils.isString(p));
52
+ const paths = entitiesTs.filter((p) => core_1.Utils.isString(p));
53
+ /* istanbul ignore next */
54
+ const will = config.get("tsNode") ? "will" : "could";
55
+ CLIHelper_1.CLIHelper.dump(` - ${will} use \`entitiesTs\` array (contains ${refs.length} references and ${paths.length} paths)`);
56
+ /* istanbul ignore else */
57
+ if (paths.length > 0) {
58
+ await DebugCommand.checkPaths(paths, "red", config.get("baseDir"));
59
+ }
60
+ }
61
+ }
62
+ catch (e) {
63
+ CLIHelper_1.CLIHelper.dump(`- configuration ${core_1.colors.red("not found")} ${core_1.colors.red(`(${e.message})`)}`);
64
+ }
65
+ }
66
+ static async checkPaths(paths, failedColor, baseDir) {
67
+ for (let path of paths) {
68
+ path = core_1.Utils.absolutePath(path, baseDir);
69
+ path = core_1.Utils.normalizePath(path);
70
+ const found = await core_1.Utils.pathExists(path);
71
+ if (found) {
72
+ CLIHelper_1.CLIHelper.dump(` - ${path} (${core_1.colors.green("found")})`);
73
+ }
74
+ else {
75
+ CLIHelper_1.CLIHelper.dump(` - ${path} (${core_1.colors[failedColor]("not found")})`);
76
+ }
77
+ }
78
+ }
79
+ }
80
+ exports.DebugCommand = DebugCommand;
@@ -0,0 +1,15 @@
1
+ import type { ArgumentsCamelCase, Argv, CommandModule } from "yargs";
2
+ type CacheArgs = {
3
+ ts?: boolean;
4
+ combined?: string;
5
+ };
6
+ export declare class GenerateCacheCommand<T> implements CommandModule<T, CacheArgs> {
7
+ command: string;
8
+ describe: string;
9
+ builder: (args: Argv<T>) => Argv<CacheArgs>;
10
+ /**
11
+ * @inheritDoc
12
+ */
13
+ handler(args: ArgumentsCamelCase<CacheArgs>): Promise<void>;
14
+ }
15
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GenerateCacheCommand = void 0;
4
+ const core_1 = require("@yandjin-mikro-orm/core");
5
+ const CLIHelper_1 = require("../CLIHelper");
6
+ class GenerateCacheCommand {
7
+ command = "cache:generate";
8
+ describe = "Generate metadata cache";
9
+ builder = (args) => {
10
+ args.option("ts-node", {
11
+ alias: "ts",
12
+ type: "boolean",
13
+ desc: `Use ts-node to generate '.ts' cache`,
14
+ });
15
+ args.option("combined", {
16
+ alias: "c",
17
+ desc: `Generate production cache into a single JSON file that can be used with the GeneratedCacheAdapter.`,
18
+ });
19
+ return args;
20
+ };
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ async handler(args) {
25
+ const options = args.combined ? { combined: "./metadata.json" } : {};
26
+ const config = await CLIHelper_1.CLIHelper.getConfiguration(true, {
27
+ metadataCache: { enabled: true, adapter: core_1.FileCacheAdapter, options },
28
+ });
29
+ config.getMetadataCacheAdapter().clear();
30
+ config.set("logger", CLIHelper_1.CLIHelper.dump.bind(null));
31
+ config.set("debug", true);
32
+ const discovery = new core_1.MetadataDiscovery(core_1.MetadataStorage.init(), config.getDriver().getPlatform(), config);
33
+ await discovery.discover(args.ts ?? false);
34
+ const combined = args.combined && config.get("metadataCache").combined;
35
+ CLIHelper_1.CLIHelper.dump(core_1.colors.green(`${combined ? "Combined " : ""}${args.ts ? "TS" : "JS"} metadata cache was successfully generated${combined ? " to " + combined : ""}`));
36
+ }
37
+ }
38
+ exports.GenerateCacheCommand = GenerateCacheCommand;
@@ -0,0 +1,19 @@
1
+ import type { ArgumentsCamelCase, Argv, CommandModule } from 'yargs';
2
+ export type Options = {
3
+ dump: boolean;
4
+ save: boolean;
5
+ path: string;
6
+ schema: string;
7
+ };
8
+ export declare class GenerateEntitiesCommand<U extends Options = Options> implements CommandModule<unknown, U> {
9
+ command: string;
10
+ describe: string;
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ builder(args: Argv): Argv<U>;
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ handler(args: ArgumentsCamelCase<U>): Promise<void>;
19
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GenerateEntitiesCommand = void 0;
4
+ const CLIHelper_1 = require("../CLIHelper");
5
+ class GenerateEntitiesCommand {
6
+ command = 'generate-entities';
7
+ describe = 'Generate entities based on current database schema';
8
+ /**
9
+ * @inheritDoc
10
+ */
11
+ builder(args) {
12
+ args.option('s', {
13
+ alias: 'save',
14
+ type: 'boolean',
15
+ desc: 'Saves entities to directory defined by --path',
16
+ });
17
+ args.option('d', {
18
+ alias: 'dump',
19
+ type: 'boolean',
20
+ desc: 'Dumps all entities to console',
21
+ });
22
+ args.option('p', {
23
+ alias: 'path',
24
+ type: 'string',
25
+ desc: 'Sets path to directory where to save entities',
26
+ });
27
+ args.option('schema', {
28
+ type: 'string',
29
+ desc: 'Generates entities only for given schema',
30
+ });
31
+ return args;
32
+ }
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ async handler(args) {
37
+ if (!args.save && !args.dump) {
38
+ return CLIHelper_1.CLIHelper.showHelp();
39
+ }
40
+ const orm = await CLIHelper_1.CLIHelper.getORM(false);
41
+ const dump = await orm.entityGenerator.generate({
42
+ save: args.save,
43
+ path: args.path,
44
+ schema: args.schema,
45
+ });
46
+ if (args.dump) {
47
+ CLIHelper_1.CLIHelper.dump(dump.join('\n\n'));
48
+ }
49
+ await orm.close(true);
50
+ }
51
+ }
52
+ exports.GenerateEntitiesCommand = GenerateEntitiesCommand;
@@ -0,0 +1,9 @@
1
+ import type { ArgumentsCamelCase, CommandModule } from "yargs";
2
+ export declare class ImportCommand implements CommandModule {
3
+ command: string;
4
+ describe: string;
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ handler(args: ArgumentsCamelCase): Promise<void>;
9
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportCommand = void 0;
4
+ const core_1 = require("@yandjin-mikro-orm/core");
5
+ const CLIHelper_1 = require("../CLIHelper");
6
+ class ImportCommand {
7
+ command = "database:import <file>";
8
+ describe = "Imports the SQL file to the database";
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ async handler(args) {
13
+ const orm = (await CLIHelper_1.CLIHelper.getORM());
14
+ await orm.em.getConnection().loadFile(args.file);
15
+ CLIHelper_1.CLIHelper.dump(core_1.colors.green(`File ${args.file} successfully imported`));
16
+ await orm.close(true);
17
+ }
18
+ }
19
+ exports.ImportCommand = ImportCommand;
@@ -0,0 +1,48 @@
1
+ import type { ArgumentsCamelCase, Argv, CommandModule } from "yargs";
2
+ export declare class MigrationCommandFactory {
3
+ static readonly DESCRIPTIONS: {
4
+ create: string;
5
+ up: string;
6
+ down: string;
7
+ list: string;
8
+ check: string;
9
+ pending: string;
10
+ fresh: string;
11
+ };
12
+ static create<U extends Opts = Opts>(command: MigratorMethod): CommandModule<unknown, U> & {
13
+ builder: (args: Argv) => Argv<U>;
14
+ handler: (args: ArgumentsCamelCase<U>) => Promise<void>;
15
+ };
16
+ static configureMigrationCommand(args: Argv, method: MigratorMethod): Argv<{}>;
17
+ private static configureUpDownCommand;
18
+ private static configureCreateCommand;
19
+ static handleMigrationCommand(args: ArgumentsCamelCase<Opts>, method: MigratorMethod): Promise<void>;
20
+ private static configureFreshCommand;
21
+ private static handleUpDownCommand;
22
+ private static handlePendingCommand;
23
+ private static handleListCommand;
24
+ private static handleCreateCommand;
25
+ private static handleCheckCommand;
26
+ private static handleFreshCommand;
27
+ private static getUpDownOptions;
28
+ private static getUpDownSuccessMessage;
29
+ }
30
+ type MigratorMethod = "create" | "check" | "up" | "down" | "list" | "pending" | "fresh";
31
+ type CliUpDownOptions = {
32
+ to?: string | number;
33
+ from?: string | number;
34
+ only?: string;
35
+ };
36
+ type GenerateOptions = {
37
+ dump?: boolean;
38
+ blank?: boolean;
39
+ initial?: boolean;
40
+ path?: string;
41
+ disableFkChecks?: boolean;
42
+ seed: string;
43
+ name?: string;
44
+ };
45
+ type Opts = GenerateOptions & CliUpDownOptions & {
46
+ dropDb?: boolean;
47
+ };
48
+ export {};