purplekit 1.0.4 → 1.0.6
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/README.md +46 -6
- package/build/src/app.js +48 -12
- package/build/src/app.js.map +1 -1
- package/build/src/config/constants.d.ts +2 -1
- package/build/src/config/constants.d.ts.map +1 -1
- package/build/src/config/constants.js +3 -1
- package/build/src/config/constants.js.map +1 -1
- package/build/src/config/index.d.ts +7 -1
- package/build/src/config/index.d.ts.map +1 -1
- package/build/src/config/index.js +30 -1
- package/build/src/config/index.js.map +1 -1
- package/build/src/features/createdb.d.ts +1 -1
- package/build/src/features/createdb.d.ts.map +1 -1
- package/build/src/features/createdb.js +6 -7
- package/build/src/features/createdb.js.map +1 -1
- package/build/src/features/dropdb.d.ts +1 -1
- package/build/src/features/dropdb.d.ts.map +1 -1
- package/build/src/features/dropdb.js +6 -7
- package/build/src/features/dropdb.js.map +1 -1
- package/build/src/features/gen.d.ts +5 -5
- package/build/src/features/gen.d.ts.map +1 -1
- package/build/src/features/gen.js +17 -15
- package/build/src/features/gen.js.map +1 -1
- package/build/src/features/init.d.ts +1 -1
- package/build/src/features/init.d.ts.map +1 -1
- package/build/src/features/init.js +18 -9
- package/build/src/features/init.js.map +1 -1
- package/build/src/features/migrate.d.ts +3 -2
- package/build/src/features/migrate.d.ts.map +1 -1
- package/build/src/features/migrate.js +28 -39
- package/build/src/features/migrate.js.map +1 -1
- package/build/src/features/migration.d.ts +3 -1
- package/build/src/features/migration.d.ts.map +1 -1
- package/build/src/features/migration.js +13 -8
- package/build/src/features/migration.js.map +1 -1
- package/build/src/features/seed.d.ts +1 -1
- package/build/src/features/seed.d.ts.map +1 -1
- package/build/src/features/seed.js +5 -8
- package/build/src/features/seed.js.map +1 -1
- package/build/src/features/status.d.ts +1 -1
- package/build/src/features/status.d.ts.map +1 -1
- package/build/src/features/status.js +11 -19
- package/build/src/features/status.js.map +1 -1
- package/build/src/index.d.ts +1 -1
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js.map +1 -1
- package/build/src/libs/compare-mig.d.ts +2 -2
- package/build/src/libs/compare-mig.d.ts.map +1 -1
- package/build/src/libs/compare-mig.js +12 -11
- package/build/src/libs/compare-mig.js.map +1 -1
- package/build/src/libs/create-ds.d.ts +19 -1
- package/build/src/libs/create-ds.d.ts.map +1 -1
- package/build/src/libs/create-ds.js +35 -8
- package/build/src/libs/create-ds.js.map +1 -1
- package/build/src/libs/format-error.d.ts +12 -0
- package/build/src/libs/format-error.d.ts.map +1 -0
- package/build/src/libs/format-error.js +56 -0
- package/build/src/libs/format-error.js.map +1 -0
- package/build/src/libs/get-commands.d.ts +9 -9
- package/build/src/libs/get-commands.d.ts.map +1 -1
- package/build/src/libs/get-commands.js +10 -35
- package/build/src/libs/get-commands.js.map +1 -1
- package/build/src/libs/print.d.ts +1 -1
- package/build/src/libs/print.js +2 -2
- package/build/src/libs/print.js.map +1 -1
- package/build/src/libs/sanitize.d.ts +8 -4
- package/build/src/libs/sanitize.d.ts.map +1 -1
- package/build/src/libs/sanitize.js +19 -9
- package/build/src/libs/sanitize.js.map +1 -1
- package/build/src/libs/version.d.ts +10 -0
- package/build/src/libs/version.d.ts.map +1 -0
- package/build/src/libs/version.js +64 -0
- package/build/src/libs/version.js.map +1 -0
- package/build/src/types.d.ts +12 -2
- package/build/src/types.d.ts.map +1 -1
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -13,12 +13,17 @@ away from application code.
|
|
|
13
13
|
npm install purplekit typeorm reflect-metadata
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Purplekit supports **PostgreSQL**, **MySQL** and **MariaDB**, and requires
|
|
17
|
+
Node.js 22.13 or newer.
|
|
18
|
+
|
|
19
|
+
For PostgreSQL, install the driver:
|
|
17
20
|
|
|
18
21
|
```bash
|
|
19
22
|
npm install pg
|
|
20
23
|
```
|
|
21
24
|
|
|
25
|
+
The MySQL/MariaDB driver (`mysql2`) ships with Purplekit.
|
|
26
|
+
|
|
22
27
|
## Quick Start
|
|
23
28
|
|
|
24
29
|
```bash
|
|
@@ -35,7 +40,7 @@ purplekit/
|
|
|
35
40
|
```
|
|
36
41
|
|
|
37
42
|
Edit `purplekit/purplekit.config.ts` with your TypeORM connection options, entities, and
|
|
38
|
-
seed classes.
|
|
43
|
+
seed classes. A `purplekit/purplekit.config.js` file works too.
|
|
39
44
|
|
|
40
45
|
## Commands
|
|
41
46
|
|
|
@@ -55,12 +60,21 @@ Useful options:
|
|
|
55
60
|
npx purplekit createdb --name app_dev
|
|
56
61
|
npx purplekit dropdb --name app_dev
|
|
57
62
|
npx purplekit status --name app_dev
|
|
58
|
-
npx purplekit
|
|
63
|
+
npx purplekit migrate --db app_dev
|
|
59
64
|
npx purplekit migrate --name CreateUsers1780000000000
|
|
60
65
|
npx purplekit migrate --file purplekit/migrations/CreateUsers1780000000000/migration.ts
|
|
66
|
+
npx purplekit migration --all
|
|
61
67
|
npx purplekit seed --db app_dev
|
|
62
68
|
```
|
|
63
69
|
|
|
70
|
+
- `gen` skips when there are no schema changes, and refuses to save a migration
|
|
71
|
+
that duplicates an existing one.
|
|
72
|
+
- `migration` generates a migration and applies it right away; `--all` also runs
|
|
73
|
+
every other pending migration.
|
|
74
|
+
- Database and migration names must start with a letter and contain only letters,
|
|
75
|
+
numbers and underscores.
|
|
76
|
+
- Errors are printed to stderr and exit with code `1`.
|
|
77
|
+
|
|
64
78
|
## Config
|
|
65
79
|
|
|
66
80
|
```ts
|
|
@@ -79,7 +93,8 @@ const config: PURPLEKIT_CONFIGURATIONS = {
|
|
|
79
93
|
INITIAL_DATABASE: 'postgres',
|
|
80
94
|
|
|
81
95
|
SSL_MODE: false,
|
|
82
|
-
SSL_TYPE: 'light',
|
|
96
|
+
SSL_TYPE: 'light', // 'heavy' also supplies DATABASE_CA_CERT as the trusted CA
|
|
97
|
+
SSL_REJECT_UNAUTHORIZED: false, // true rejects servers whose certificate does not verify
|
|
83
98
|
DATABASE_CA_CERT: './',
|
|
84
99
|
SYNCHRONIZE: false,
|
|
85
100
|
LOGGING: false,
|
|
@@ -88,14 +103,39 @@ const config: PURPLEKIT_CONFIGURATIONS = {
|
|
|
88
103
|
export default config;
|
|
89
104
|
```
|
|
90
105
|
|
|
106
|
+
`INITIAL_DATABASE` is the database Purplekit connects to for `createdb`, `dropdb`
|
|
107
|
+
and `status`, so it must already exist. For MySQL or MariaDB, use:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
TYPE: 'mysql', // or 'mariadb'
|
|
111
|
+
DATABASE_PORT: 3306,
|
|
112
|
+
INITIAL_DATABASE: 'mysql',
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
With `SSL_MODE: true`, `SSL_TYPE: 'heavy'` passes `DATABASE_CA_CERT` to the driver.
|
|
116
|
+
Certificates are only enforced when `SSL_REJECT_UNAUTHORIZED` is `true` (default
|
|
117
|
+
`false`).
|
|
118
|
+
|
|
91
119
|
## Public API
|
|
92
120
|
|
|
93
121
|
```ts
|
|
94
122
|
import type { PURPLEKIT_CONFIGURATIONS } from 'purplekit';
|
|
95
|
-
import {
|
|
123
|
+
import {
|
|
124
|
+
seedEntities,
|
|
125
|
+
createdb,
|
|
126
|
+
dropdb,
|
|
127
|
+
gen,
|
|
128
|
+
init,
|
|
129
|
+
migrate,
|
|
130
|
+
migration,
|
|
131
|
+
seed,
|
|
132
|
+
status,
|
|
133
|
+
} from 'purplekit';
|
|
96
134
|
```
|
|
97
135
|
|
|
98
|
-
`seedEntities` is provided for building reusable seed classes.
|
|
136
|
+
`seedEntities` is provided for building reusable seed classes. The command
|
|
137
|
+
handlers print their output and resolve to an exit code (`0` or `1`); they never
|
|
138
|
+
exit your process.
|
|
99
139
|
|
|
100
140
|
## Documentation
|
|
101
141
|
|
package/build/src/app.js
CHANGED
|
@@ -1,64 +1,100 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
3
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
13
|
require("reflect-metadata");
|
|
5
14
|
const commander_1 = require("commander");
|
|
6
15
|
const features_1 = require("./features");
|
|
16
|
+
const config_1 = require("./config");
|
|
17
|
+
const format_error_1 = require("./libs/format-error");
|
|
18
|
+
const print_1 = require("./libs/print");
|
|
19
|
+
const version_1 = require("./libs/version");
|
|
20
|
+
/** Prints any error as a readable message and exits with code 1. */
|
|
21
|
+
const fail = (e) => {
|
|
22
|
+
(0, print_1.printf)(`Error: ${(0, format_error_1.formatError)(e)}`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
};
|
|
25
|
+
// last-resort net so nothing ever surfaces as a raw stack trace
|
|
26
|
+
process.on('unhandledRejection', fail);
|
|
27
|
+
process.on('uncaughtException', fail);
|
|
28
|
+
/**
|
|
29
|
+
* Wraps a command action so config problems and anything thrown outside a
|
|
30
|
+
* handler's own try/catch still reach the user as a message. Handlers return
|
|
31
|
+
* an exit code instead of exiting, so they stay safe to call as a library;
|
|
32
|
+
* only the CLI exits the process.
|
|
33
|
+
*/
|
|
34
|
+
const run = (action) => (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
try {
|
|
36
|
+
(0, config_1.assertConfigLoaded)();
|
|
37
|
+
const code = yield action(args);
|
|
38
|
+
process.exit(typeof code === 'number' ? code : 0);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
7
44
|
// initialize the desc and info of the app
|
|
8
45
|
commander_1.program
|
|
9
46
|
.name('purplekit')
|
|
10
47
|
.description('typeorm database actions wrapper')
|
|
11
|
-
.version(
|
|
48
|
+
.version((0, version_1.getVersion)(), '-v, --cli-version', 'Output the purplekit CLI version.');
|
|
12
49
|
// create core parts
|
|
13
50
|
commander_1.program
|
|
14
51
|
.command('init')
|
|
15
52
|
.description('Setup required configurations, files and folders')
|
|
16
|
-
.action(() => (0, features_1.init)());
|
|
53
|
+
.action(run(() => (0, features_1.init)()));
|
|
17
54
|
// generate a new migration
|
|
18
55
|
commander_1.program
|
|
19
56
|
.command('gen')
|
|
20
57
|
.description('Generate a new migrations file')
|
|
21
58
|
.option('--name <name>', 'Title/Name of the migration')
|
|
22
|
-
.
|
|
23
|
-
.action((args) => (0, features_1.gen)(args));
|
|
59
|
+
.action(run((args) => (0, features_1.gen)(args)));
|
|
24
60
|
// create database
|
|
25
61
|
commander_1.program
|
|
26
62
|
.command('createdb')
|
|
27
63
|
.description('Create a new database')
|
|
28
64
|
.option('--name <name>', 'Database name')
|
|
29
|
-
.action((args) => (0, features_1.createdb)(args));
|
|
65
|
+
.action(run((args) => (0, features_1.createdb)(args)));
|
|
30
66
|
// drop database
|
|
31
67
|
commander_1.program
|
|
32
68
|
.command('dropdb')
|
|
33
69
|
.description('Drop an existing database')
|
|
34
70
|
.option('--name <name>', 'Database name')
|
|
35
|
-
.action((args) => (0, features_1.dropdb)(args));
|
|
71
|
+
.action(run((args) => (0, features_1.dropdb)(args)));
|
|
36
72
|
// seed database
|
|
37
73
|
commander_1.program
|
|
38
74
|
.command('seed')
|
|
39
75
|
.description('Populate an existing database with seed data')
|
|
40
76
|
.option('--db <db>', 'The name of the db to be seeded')
|
|
41
|
-
.action((args) => (0, features_1.seed)(args));
|
|
77
|
+
.action(run((args) => (0, features_1.seed)(args)));
|
|
42
78
|
// get the status of a database
|
|
43
79
|
commander_1.program
|
|
44
80
|
.command('status')
|
|
45
81
|
.description('Get the status of an existing database')
|
|
46
82
|
.option('--name <name>', 'Database name')
|
|
47
|
-
.action((args) => (0, features_1.status)(args));
|
|
83
|
+
.action(run((args) => (0, features_1.status)(args)));
|
|
48
84
|
// execute existing migrations
|
|
49
85
|
commander_1.program
|
|
50
86
|
.command('migrate')
|
|
51
87
|
.description('Execute already existing migration files')
|
|
52
88
|
.option('--name <name>', 'Migration basename/class name without .ts')
|
|
53
89
|
.option('--db <database>', 'Database which migration should be applied to')
|
|
54
|
-
.option('--file <file>', '
|
|
55
|
-
.action((args) => (0, features_1.migrate)(args));
|
|
90
|
+
.option('--file <file>', 'Path to a migration folder or migration.ts, e.g. purplekit/migrations/CreateUsers1780000000000')
|
|
91
|
+
.action(run((args) => (0, features_1.migrate)(args)));
|
|
56
92
|
// run the whole migration process
|
|
57
93
|
commander_1.program
|
|
58
94
|
.command('migration')
|
|
59
95
|
.description('Generate a new migration file and execute it immediately')
|
|
60
96
|
.option('-a, --all', 'Run all migration files along with the newly generated migration')
|
|
61
|
-
.action((args) => (0, features_1.migration)(args));
|
|
97
|
+
.action(run((args) => (0, features_1.migration)(args)));
|
|
62
98
|
// start the app
|
|
63
|
-
commander_1.program.parseAsync();
|
|
99
|
+
commander_1.program.parseAsync().catch(fail);
|
|
64
100
|
//# sourceMappingURL=app.js.map
|
package/build/src/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,4BAA0B;AAU1B,yCAAoC;AACpC,yCASoB;AACpB,qCAA8C;AAC9C,sDAAkD;AAClD,wCAAsC;AACtC,4CAA4C;AAE5C,oEAAoE;AACpE,MAAM,IAAI,GAAG,CAAC,CAAU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AAE,+CAA+C,CAAC;KAC1E,MAAM,CACL,eAAe,EACf,gGAAgG,CACjG;KACA,MAAM,CAAC,GAAG,CAAC,CAAC,IAAa,EAAE,EAAE,CAAC,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAEjD,kCAAkC;AAClC,mBAAO;KACJ,OAAO,CAAC,WAAW,CAAC;KACpB,WAAW,CAAC,0DAA0D,CAAC;KACvE,MAAM,CACL,WAAW,EACX,kEAAkE,CACnE;KACA,MAAM,CAAC,GAAG,CAAC,CAAC,IAAe,EAAE,EAAE,CAAC,IAAA,oBAAS,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAErD,gBAAgB;AAChB,mBAAO,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -4,5 +4,6 @@ declare const PURPLEKIT_CONFIG_JS = "purplekit/purplekit.config.js";
|
|
|
4
4
|
declare const PURPLEKIT_MIGRATIONS_DIR = "purplekit/migrations";
|
|
5
5
|
declare const PURPLEKIT_SEEDS_DIR = "purplekit/seeds";
|
|
6
6
|
declare const PURPLEKIT_MIGRATIONS_GLOB = "purplekit/migrations/**/*.{ts,js}";
|
|
7
|
-
|
|
7
|
+
declare const SUPPORTED_TYPES: readonly ["postgres", "mysql", "mariadb"];
|
|
8
|
+
export { SUPPORTED_TYPES, PURPLEKIT_CONFIG_JS, PURPLEKIT_CONFIG_TS, PURPLEKIT_MIGRATIONS_DIR, PURPLEKIT_MIGRATIONS_GLOB, PURPLEKIT_ROOT, PURPLEKIT_SEEDS_DIR, };
|
|
8
9
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/config/constants.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,cAAc,cAAc,CAAC;AACnC,QAAA,MAAM,mBAAmB,kCAAkC,CAAC;AAC5D,QAAA,MAAM,mBAAmB,kCAAkC,CAAC;AAC5D,QAAA,MAAM,wBAAwB,yBAAyB,CAAC;AACxD,QAAA,MAAM,mBAAmB,oBAAoB,CAAC;AAC9C,QAAA,MAAM,yBAAyB,sCAAsC,CAAC;AAEtE,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,cAAc,EACd,mBAAmB,GACpB,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/config/constants.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,cAAc,cAAc,CAAC;AACnC,QAAA,MAAM,mBAAmB,kCAAkC,CAAC;AAC5D,QAAA,MAAM,mBAAmB,kCAAkC,CAAC;AAC5D,QAAA,MAAM,wBAAwB,yBAAyB,CAAC;AACxD,QAAA,MAAM,mBAAmB,oBAAoB,CAAC;AAC9C,QAAA,MAAM,yBAAyB,sCAAsC,CAAC;AAEtE,QAAA,MAAM,eAAe,2CAA4C,CAAC;AAElE,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,cAAc,EACd,mBAAmB,GACpB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PURPLEKIT_SEEDS_DIR = exports.PURPLEKIT_ROOT = exports.PURPLEKIT_MIGRATIONS_GLOB = exports.PURPLEKIT_MIGRATIONS_DIR = exports.PURPLEKIT_CONFIG_TS = exports.PURPLEKIT_CONFIG_JS = void 0;
|
|
3
|
+
exports.PURPLEKIT_SEEDS_DIR = exports.PURPLEKIT_ROOT = exports.PURPLEKIT_MIGRATIONS_GLOB = exports.PURPLEKIT_MIGRATIONS_DIR = exports.PURPLEKIT_CONFIG_TS = exports.PURPLEKIT_CONFIG_JS = exports.SUPPORTED_TYPES = void 0;
|
|
4
4
|
const PURPLEKIT_ROOT = 'purplekit';
|
|
5
5
|
exports.PURPLEKIT_ROOT = PURPLEKIT_ROOT;
|
|
6
6
|
const PURPLEKIT_CONFIG_TS = 'purplekit/purplekit.config.ts';
|
|
@@ -13,4 +13,6 @@ const PURPLEKIT_SEEDS_DIR = 'purplekit/seeds';
|
|
|
13
13
|
exports.PURPLEKIT_SEEDS_DIR = PURPLEKIT_SEEDS_DIR;
|
|
14
14
|
const PURPLEKIT_MIGRATIONS_GLOB = 'purplekit/migrations/**/*.{ts,js}';
|
|
15
15
|
exports.PURPLEKIT_MIGRATIONS_GLOB = PURPLEKIT_MIGRATIONS_GLOB;
|
|
16
|
+
const SUPPORTED_TYPES = ['postgres', 'mysql', 'mariadb'];
|
|
17
|
+
exports.SUPPORTED_TYPES = SUPPORTED_TYPES;
|
|
16
18
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/config/constants.ts"],"names":[],"mappings":";;;AAAA,MAAM,cAAc,GAAG,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/config/constants.ts"],"names":[],"mappings":";;;AAAA,MAAM,cAAc,GAAG,WAAW,CAAC;AAejC,wCAAc;AAdhB,MAAM,mBAAmB,GAAG,+BAA+B,CAAC;AAW1D,kDAAmB;AAVrB,MAAM,mBAAmB,GAAG,+BAA+B,CAAC;AAS1D,kDAAmB;AARrB,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAUtD,4DAAwB;AAT1B,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAY5C,kDAAmB;AAXrB,MAAM,yBAAyB,GAAG,mCAAmC,CAAC;AASpE,8DAAyB;AAP3B,MAAM,eAAe,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,SAAS,CAAU,CAAC;AAGhE,0CAAe"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { PURPLEKIT_INTERNAL_CONFIGURATIONS } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Throws the config load error, if any, so commands never run against
|
|
4
|
+
* silently-defaulted settings when the user's config is broken. Also rejects
|
|
5
|
+
* database types purplekit does not support.
|
|
6
|
+
*/
|
|
7
|
+
declare function assertConfigLoaded(): void;
|
|
2
8
|
declare const cfg: PURPLEKIT_INTERNAL_CONFIGURATIONS;
|
|
3
|
-
export { cfg };
|
|
9
|
+
export { cfg, assertConfigLoaded };
|
|
4
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iCAAiC,EAClC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iCAAiC,EAClC,MAAM,SAAS,CAAC;AAiFjB;;;;GAIG;AACH,iBAAS,kBAAkB,SAO1B;AAID,QAAA,MAAM,GAAG,EAAE,iCAOV,CAAC;AAEF,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.cfg = void 0;
|
|
37
|
+
exports.assertConfigLoaded = assertConfigLoaded;
|
|
37
38
|
const constants_1 = require("./constants");
|
|
38
39
|
const node_module_1 = require("node:module");
|
|
39
40
|
const node_fs_1 = require("node:fs");
|
|
@@ -45,6 +46,7 @@ const defaults = {
|
|
|
45
46
|
TYPE: 'postgres',
|
|
46
47
|
SSL_MODE: false,
|
|
47
48
|
SSL_TYPE: 'light',
|
|
49
|
+
SSL_REJECT_UNAUTHORIZED: false,
|
|
48
50
|
DATABASE_CA_CERT: './',
|
|
49
51
|
DATABASE_HOST: 'localhost',
|
|
50
52
|
DATABASE_PORT: 5432,
|
|
@@ -76,7 +78,34 @@ function loadUserConfig() {
|
|
|
76
78
|
}
|
|
77
79
|
return {};
|
|
78
80
|
}
|
|
79
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Error raised while loading the user config, kept so the CLI can report it
|
|
83
|
+
* as a normal message instead of crashing during module import.
|
|
84
|
+
*/
|
|
85
|
+
let configError = null;
|
|
86
|
+
function safeLoadUserConfig() {
|
|
87
|
+
try {
|
|
88
|
+
return loadUserConfig();
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
const detail = e instanceof Error ? e.message : String(e);
|
|
92
|
+
configError = new Error(`Unable to load the purplekit config (${constants_1.PURPLEKIT_CONFIG_TS} or ${constants_1.PURPLEKIT_CONFIG_JS}): ${detail}`);
|
|
93
|
+
return {};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Throws the config load error, if any, so commands never run against
|
|
98
|
+
* silently-defaulted settings when the user's config is broken. Also rejects
|
|
99
|
+
* database types purplekit does not support.
|
|
100
|
+
*/
|
|
101
|
+
function assertConfigLoaded() {
|
|
102
|
+
if (configError)
|
|
103
|
+
throw configError;
|
|
104
|
+
if (!constants_1.SUPPORTED_TYPES.includes(cfg.TYPE)) {
|
|
105
|
+
throw new Error(`Unsupported database TYPE '${String(cfg.TYPE)}' in the purplekit config. Supported types: ${constants_1.SUPPORTED_TYPES.join(', ')}.`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const userConfig = safeLoadUserConfig();
|
|
80
109
|
const cfg = Object.assign(Object.assign(Object.assign({}, defaults), userConfig), { ROOT: constants_1.PURPLEKIT_ROOT, MIGRATIONS_DIR: constants_1.PURPLEKIT_MIGRATIONS_DIR, SEEDS_DIR: constants_1.PURPLEKIT_SEEDS_DIR, MIGRATIONS: [constants_1.PURPLEKIT_MIGRATIONS_GLOB] });
|
|
81
110
|
exports.cfg = cfg;
|
|
82
111
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6Gc,gDAAkB;AAzGhC,2CAQqB;AACrB,6CAA4C;AAC5C,qCAAqC;AACrC,gDAAkC;AAElC,MAAM,aAAa,GAAG,IAAA,2BAAa,EACjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,sBAAsB,CAAC,CACjD,CAAC;AAEF,MAAM,QAAQ,GAA6B;IACzC,QAAQ,EAAE,CAAC,oBAAoB,CAAC;IAChC,KAAK,EAAE,EAAE;IAET,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,OAAO;IACjB,uBAAuB,EAAE,KAAK;IAC9B,gBAAgB,EAAE,IAAI;IACtB,aAAa,EAAE,WAAW;IAC1B,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,UAAU;IAC7B,iBAAiB,EAAE,EAAE;IACrB,aAAa,EAAE,KAAK;IACpB,WAAW,EAAE,KAAK;IAClB,OAAO,EAAE,KAAK;IACd,gBAAgB,EAAE,UAAU;CAC7B,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,cAAc;;IACrB,KAAK,MAAM,IAAI,IAAI,CAAC,+BAAmB,EAAE,+BAAmB,CAAC,EAAE,CAAC;QAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,IAAA,oBAAU,EAAC,QAAQ,CAAC;YAAE,SAAS;QAEpC,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,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*
|
|
17
17
|
* @param args - CLI options; `name` defaults to `cfg.DATABASE_NAME`.
|
|
18
18
|
*/
|
|
19
|
-
declare function createdb(args: CREATE_DB): Promise<
|
|
19
|
+
declare function createdb(args: CREATE_DB): Promise<0 | 1>;
|
|
20
20
|
export { createdb, create };
|
|
21
21
|
//# sourceMappingURL=createdb.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createdb.d.ts","sourceRoot":"","sources":["../../../src/features/createdb.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"createdb.d.ts","sourceRoot":"","sources":["../../../src/features/createdb.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAOpC;;;;;;GAMG;AACH,iBAAe,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3C,MAAM,EAAE,SAAS,GAAG,gBAAgB,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAwBD;AAED;;;;GAIG;AACH,iBAAe,QAAQ,CAAC,IAAI,EAAE,SAAS,kBAetC;AAED,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -14,6 +14,7 @@ exports.create = create;
|
|
|
14
14
|
const get_commands_1 = require("../libs/get-commands");
|
|
15
15
|
const config_1 = require("../config");
|
|
16
16
|
const print_1 = require("../libs/print");
|
|
17
|
+
const format_error_1 = require("../libs/format-error");
|
|
17
18
|
const sanitize_1 = require("../libs/sanitize");
|
|
18
19
|
const create_ds_1 = require("../libs/create-ds");
|
|
19
20
|
/**
|
|
@@ -42,10 +43,6 @@ function create(name) {
|
|
|
42
43
|
return { status: 'already-exists', created: false };
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
const err = e instanceof Error ? e.message : 'Unable to serialize error';
|
|
47
|
-
throw new Error(err);
|
|
48
|
-
}
|
|
49
46
|
finally {
|
|
50
47
|
if (initialized) {
|
|
51
48
|
yield ds.destroy();
|
|
@@ -61,19 +58,21 @@ function create(name) {
|
|
|
61
58
|
function createdb(args) {
|
|
62
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
60
|
var _a;
|
|
64
|
-
const name = (
|
|
61
|
+
const name = (_a = args.name) !== null && _a !== void 0 ? _a : config_1.cfg.DATABASE_NAME;
|
|
65
62
|
try {
|
|
63
|
+
(0, sanitize_1.sanitize)(name, 'database name');
|
|
66
64
|
const response = yield create(name);
|
|
67
65
|
if (response.status === 'created') {
|
|
68
66
|
(0, print_1.print)(`Database '${name}' created successfully.`);
|
|
69
67
|
}
|
|
70
68
|
else
|
|
71
69
|
(0, print_1.print)(`Database '${name}' already exists.`);
|
|
70
|
+
return 0;
|
|
72
71
|
}
|
|
73
72
|
catch (e) {
|
|
74
|
-
const err =
|
|
73
|
+
const err = (0, format_error_1.formatError)(e);
|
|
75
74
|
(0, print_1.printf)(`Failed to create database '${name}': ${err}`);
|
|
76
|
-
|
|
75
|
+
return 1;
|
|
77
76
|
}
|
|
78
77
|
});
|
|
79
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createdb.js","sourceRoot":"","sources":["../../../src/features/createdb.ts"],"names":[],"mappings":";;;;;;;;;;;AAmES,4BAAQ;AAAE,wBAAM;AAnEzB,sDAA4E;AAE5E,qCAA+B;AAC/B,wCAA6C;AAC7C,8CAA2C;AAC3C,gDAAoD;AAEpD;;;;;;GAMG;AACH,SAAe,MAAM,CAAC,IAAY;;QAKhC,MAAM,EAAE,GAAG,IAAA,4BAAgB,GAAE,CAAC;QAC9B,IAAI,WAAW,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,IAAA,iCAAkB,EAAC,IAAI,CAAC,CAAC;YAC/C,MAAM,aAAa,GAAG,IAAA,gCAAi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DATABASE_NAME`.
|
|
15
15
|
*/
|
|
16
|
-
declare function dropdb(args: DROP_DB): Promise<
|
|
16
|
+
declare function dropdb(args: DROP_DB): Promise<0 | 1>;
|
|
17
17
|
export { dropdb, drop };
|
|
18
18
|
//# sourceMappingURL=dropdb.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdb.d.ts","sourceRoot":"","sources":["../../../src/features/dropdb.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dropdb.d.ts","sourceRoot":"","sources":["../../../src/features/dropdb.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAMlC;;;;;GAKG;AACH,iBAAe,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAe/D;AAED;;;;GAIG;AACH,iBAAe,MAAM,CAAC,IAAI,EAAE,OAAO,kBAelC;AAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC"}
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.dropdb = dropdb;
|
|
13
13
|
exports.drop = drop;
|
|
14
14
|
const print_1 = require("../libs/print");
|
|
15
|
+
const format_error_1 = require("../libs/format-error");
|
|
15
16
|
const config_1 = require("../config");
|
|
16
17
|
const sanitize_1 = require("../libs/sanitize");
|
|
17
18
|
const get_commands_1 = require("../libs/get-commands");
|
|
@@ -33,10 +34,6 @@ function drop(name) {
|
|
|
33
34
|
yield ds.query(command);
|
|
34
35
|
return { dropped: true };
|
|
35
36
|
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
const err = e instanceof Error ? e.message : 'Unable to serialize err';
|
|
38
|
-
throw new Error(err);
|
|
39
|
-
}
|
|
40
37
|
finally {
|
|
41
38
|
if (initialized) {
|
|
42
39
|
yield ds.destroy();
|
|
@@ -52,18 +49,20 @@ function drop(name) {
|
|
|
52
49
|
function dropdb(args) {
|
|
53
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
51
|
var _a;
|
|
55
|
-
const name = (
|
|
52
|
+
const name = (_a = args.name) !== null && _a !== void 0 ? _a : config_1.cfg.DATABASE_NAME;
|
|
56
53
|
try {
|
|
54
|
+
(0, sanitize_1.sanitize)(name, 'database name');
|
|
57
55
|
const response = yield drop(name);
|
|
58
56
|
const msg = response.dropped
|
|
59
57
|
? `Database '${name}' dropped successfully.`
|
|
60
58
|
: `Database '${name}' was not dropped.`;
|
|
61
59
|
(0, print_1.print)(msg);
|
|
60
|
+
return 0;
|
|
62
61
|
}
|
|
63
62
|
catch (e) {
|
|
64
|
-
const err =
|
|
63
|
+
const err = (0, format_error_1.formatError)(e);
|
|
65
64
|
(0, print_1.printf)(`Failed to drop database '${name}': ${err}`);
|
|
66
|
-
|
|
65
|
+
return 1;
|
|
67
66
|
}
|
|
68
67
|
});
|
|
69
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdb.js","sourceRoot":"","sources":["../../../src/features/dropdb.ts"],"names":[],"mappings":";;;;;;;;;;;AAqDS,wBAAM;AAAE,oBAAI;AArDrB,wCAA6C;
|
|
1
|
+
{"version":3,"file":"dropdb.js","sourceRoot":"","sources":["../../../src/features/dropdb.ts"],"names":[],"mappings":";;;;;;;;;;;AAqDS,wBAAM;AAAE,oBAAI;AArDrB,wCAA6C;AAC7C,sDAAkD;AAElD,qCAA+B;AAC/B,8CAA2C;AAC3C,sDAAuD;AACvD,gDAAoD;AAEpD;;;;;GAKG;AACH,SAAe,IAAI,CAAC,IAAY;;QAC9B,MAAM,EAAE,GAAG,IAAA,4BAAgB,GAAE,CAAC;QAC9B,IAAI,WAAW,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,IAAA,+BAAgB,EAAC,IAAI,CAAC,CAAC;YACvC,MAAM,EAAE,CAAC,UAAU,EAAE,CAAC;YACtB,WAAW,GAAG,IAAI,CAAC;YAEnB,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACxB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3B,CAAC;gBAAS,CAAC;YACT,IAAI,WAAW,EAAE,CAAC;gBAChB,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;CAAA;AAED;;;;GAIG;AACH,SAAe,MAAM,CAAC,IAAa;;;QACjC,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,IAAI,mCAAI,YAAG,CAAC,aAAa,CAAC;QAC5C,IAAI,CAAC;YACH,IAAA,mBAAQ,EAAC,IAAI,EAAE,eAAe,CAAC,CAAC;YAChC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;YAClC,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO;gBAC1B,CAAC,CAAC,aAAa,IAAI,yBAAyB;gBAC5C,CAAC,CAAC,aAAa,IAAI,oBAAoB,CAAC;YAC1C,IAAA,aAAK,EAAC,GAAG,CAAC,CAAC;YACX,OAAO,CAAC,CAAC;QACX,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,GAAG,GAAG,IAAA,0BAAW,EAAC,CAAC,CAAC,CAAC;YAC3B,IAAA,cAAM,EAAC,4BAA4B,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC;YACpD,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;CAAA"}
|
|
@@ -35,6 +35,7 @@ declare const hasSchemaChanges: (ds: DataSource) => Promise<boolean>;
|
|
|
35
35
|
* @param name - Migration class/name prefix.
|
|
36
36
|
* @param timestamp - Timestamp suffix TypeORM uses in the migration class.
|
|
37
37
|
* @returns Generated source, formatted source, and whether schema changes exist.
|
|
38
|
+
* Both sources are empty when there is nothing to generate.
|
|
38
39
|
*/
|
|
39
40
|
declare const genMig: (ds: DataSource, name: string, timestamp: number) => Promise<{
|
|
40
41
|
content: string;
|
|
@@ -62,23 +63,22 @@ declare const getMetadata: (name?: string) => {
|
|
|
62
63
|
};
|
|
63
64
|
type GenerateParams = {
|
|
64
65
|
db: string;
|
|
65
|
-
force: boolean | undefined;
|
|
66
66
|
name: string | undefined;
|
|
67
67
|
save: boolean | undefined;
|
|
68
68
|
};
|
|
69
69
|
/**
|
|
70
70
|
* Generates a migration file from current entity schemas.
|
|
71
71
|
*
|
|
72
|
-
* @param params - Generation options including target database,
|
|
73
|
-
*
|
|
72
|
+
* @param params - Generation options including target database, migration
|
|
73
|
+
* name prefix, and whether to save the file.
|
|
74
74
|
* @returns Generation outcome including title and whether changes were found.
|
|
75
75
|
*/
|
|
76
76
|
declare const generate: (params?: Partial<GenerateParams>) => Promise<GeneratReturn>;
|
|
77
77
|
/**
|
|
78
78
|
* CLI handler for the `gen` command.
|
|
79
79
|
*
|
|
80
|
-
* @param args - CLI options for migration name
|
|
80
|
+
* @param args - CLI options for the migration name.
|
|
81
81
|
*/
|
|
82
|
-
declare const gen: (args: GENERATE_MIGRATIONS) => Promise<
|
|
82
|
+
declare const gen: (args: GENERATE_MIGRATIONS) => Promise<0 | 1>;
|
|
83
83
|
export { gen, generate, genMig, compareMig, getMetadata, saveMig, hasSchemaChanges, };
|
|
84
84
|
//# sourceMappingURL=gen.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gen.d.ts","sourceRoot":"","sources":["../../../src/features/gen.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"gen.d.ts","sourceRoot":"","sources":["../../../src/features/gen.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAG9C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,OAAO,EAAE,UAAU,EAAoB,MAAM,oBAAoB,CAAC;AAOlE,KA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ACL,GAAG,EACH,QAAQ,EACR,MAAM,EACN,UAAU,EACV,WAAW,EACX,OAAO,EACP,gBAAgB,GACjB,CAAC"}
|
|
@@ -49,6 +49,7 @@ exports.hasSchemaChanges = exports.saveMig = exports.getMetadata = exports.compa
|
|
|
49
49
|
const typeorm_extension_1 = require("typeorm-extension");
|
|
50
50
|
const create_ds_1 = require("../libs/create-ds");
|
|
51
51
|
const print_1 = require("../libs/print");
|
|
52
|
+
const format_error_1 = require("../libs/format-error");
|
|
52
53
|
const config_1 = require("../config");
|
|
53
54
|
const sanitize_1 = require("../libs/sanitize");
|
|
54
55
|
const compare_mig_1 = require("../libs/compare-mig");
|
|
@@ -78,6 +79,7 @@ exports.hasSchemaChanges = hasSchemaChanges;
|
|
|
78
79
|
* @param name - Migration class/name prefix.
|
|
79
80
|
* @param timestamp - Timestamp suffix TypeORM uses in the migration class.
|
|
80
81
|
* @returns Generated source, formatted source, and whether schema changes exist.
|
|
82
|
+
* Both sources are empty when there is nothing to generate.
|
|
81
83
|
*/
|
|
82
84
|
const genMig = (ds, name, timestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
85
|
const hasChanges = yield hasSchemaChanges(ds);
|
|
@@ -87,6 +89,10 @@ const genMig = (ds, name, timestamp) => __awaiter(void 0, void 0, void 0, functi
|
|
|
87
89
|
dataSource: ds,
|
|
88
90
|
preview: true,
|
|
89
91
|
});
|
|
92
|
+
// typeorm-extension returns no `content` when the schema is already in sync
|
|
93
|
+
if (!result.content) {
|
|
94
|
+
return { content: '', formatted: '', hasChanges };
|
|
95
|
+
}
|
|
90
96
|
const formatted = yield prettier_1.default.format(result.content, {
|
|
91
97
|
parser: 'typescript',
|
|
92
98
|
singleQuote: true,
|
|
@@ -134,8 +140,8 @@ exports.getMetadata = getMetadata;
|
|
|
134
140
|
/**
|
|
135
141
|
* Generates a migration file from current entity schemas.
|
|
136
142
|
*
|
|
137
|
-
* @param params - Generation options including target database,
|
|
138
|
-
*
|
|
143
|
+
* @param params - Generation options including target database, migration
|
|
144
|
+
* name prefix, and whether to save the file.
|
|
139
145
|
* @returns Generation outcome including title and whether changes were found.
|
|
140
146
|
*/
|
|
141
147
|
const generate = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (params = {}) {
|
|
@@ -147,7 +153,7 @@ const generate = (...args_1) => __awaiter(void 0, [...args_1], void 0, function*
|
|
|
147
153
|
yield ds.initialize();
|
|
148
154
|
initialized = true;
|
|
149
155
|
const generated = yield genMig(ds, metadata.migrationName, metadata.timestamp);
|
|
150
|
-
if (!generated.
|
|
156
|
+
if (!generated.content || !generated.hasChanges) {
|
|
151
157
|
return {
|
|
152
158
|
generated: false,
|
|
153
159
|
more: {
|
|
@@ -189,10 +195,6 @@ const generate = (...args_1) => __awaiter(void 0, [...args_1], void 0, function*
|
|
|
189
195
|
},
|
|
190
196
|
};
|
|
191
197
|
}
|
|
192
|
-
catch (e) {
|
|
193
|
-
const err = e instanceof Error ? e.message : JSON.stringify(e);
|
|
194
|
-
throw new Error(err);
|
|
195
|
-
}
|
|
196
198
|
finally {
|
|
197
199
|
if (initialized) {
|
|
198
200
|
yield ds.destroy();
|
|
@@ -203,15 +205,14 @@ exports.generate = generate;
|
|
|
203
205
|
/**
|
|
204
206
|
* CLI handler for the `gen` command.
|
|
205
207
|
*
|
|
206
|
-
* @param args - CLI options for migration name
|
|
208
|
+
* @param args - CLI options for the migration name.
|
|
207
209
|
*/
|
|
208
210
|
const gen = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
209
|
-
const database = (0, sanitize_1.sanitize)(config_1.cfg.DATABASE_NAME);
|
|
210
|
-
const name = args.name ? (0, sanitize_1.sanitize)(args.name) : undefined;
|
|
211
211
|
try {
|
|
212
|
+
const database = (0, sanitize_1.sanitize)(config_1.cfg.DATABASE_NAME, 'DATABASE_NAME');
|
|
213
|
+
const name = args.name ? (0, sanitize_1.sanitize)(args.name, 'migration name') : undefined;
|
|
212
214
|
(0, print_1.print)(`Generating migration for '${database}'...`);
|
|
213
215
|
const response = yield generate({
|
|
214
|
-
force: args.force,
|
|
215
216
|
db: database,
|
|
216
217
|
name: name,
|
|
217
218
|
save: true,
|
|
@@ -221,7 +222,8 @@ const gen = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
221
222
|
(0, print_1.print)('No schema changes detected. Migration generation skipped.');
|
|
222
223
|
}
|
|
223
224
|
else if (response.more.reason === 'duplicate-found') {
|
|
224
|
-
(0, print_1.printf)(`
|
|
225
|
+
(0, print_1.printf)(`Migration not saved: it duplicates existing migration '${response.more.duplicateOf}'.`);
|
|
226
|
+
return 1;
|
|
225
227
|
}
|
|
226
228
|
else
|
|
227
229
|
throw new Error('Unknown generated response');
|
|
@@ -229,12 +231,12 @@ const gen = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
229
231
|
else {
|
|
230
232
|
(0, print_1.print)(`Migration for '${database}' created successfully: ${response.more.title}.`);
|
|
231
233
|
}
|
|
232
|
-
|
|
234
|
+
return 0;
|
|
233
235
|
}
|
|
234
236
|
catch (e) {
|
|
235
|
-
const err =
|
|
237
|
+
const err = (0, format_error_1.formatError)(e);
|
|
236
238
|
(0, print_1.printf)(`Failed to generate migration: ${err}`);
|
|
237
|
-
|
|
239
|
+
return 1;
|
|
238
240
|
}
|
|
239
241
|
});
|
|
240
242
|
exports.gen = gen;
|