purplekit 1.0.0

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.
Files changed (87) hide show
  1. package/README.md +103 -0
  2. package/bin/dataforge +2 -0
  3. package/build/src/app.d.ts +2 -0
  4. package/build/src/app.d.ts.map +1 -0
  5. package/build/src/app.js +63 -0
  6. package/build/src/app.js.map +1 -0
  7. package/build/src/config/constants.d.ts +8 -0
  8. package/build/src/config/constants.d.ts.map +1 -0
  9. package/build/src/config/constants.js +16 -0
  10. package/build/src/config/constants.js.map +1 -0
  11. package/build/src/config/index.d.ts +4 -0
  12. package/build/src/config/index.d.ts.map +1 -0
  13. package/build/src/config/index.js +79 -0
  14. package/build/src/config/index.js.map +1 -0
  15. package/build/src/features/createdb.d.ts +21 -0
  16. package/build/src/features/createdb.d.ts.map +1 -0
  17. package/build/src/features/createdb.js +80 -0
  18. package/build/src/features/createdb.js.map +1 -0
  19. package/build/src/features/dropdb.d.ts +18 -0
  20. package/build/src/features/dropdb.d.ts.map +1 -0
  21. package/build/src/features/dropdb.js +70 -0
  22. package/build/src/features/dropdb.js.map +1 -0
  23. package/build/src/features/gen.d.ts +84 -0
  24. package/build/src/features/gen.d.ts.map +1 -0
  25. package/build/src/features/gen.js +241 -0
  26. package/build/src/features/gen.js.map +1 -0
  27. package/build/src/features/index.d.ts +9 -0
  28. package/build/src/features/index.d.ts.map +1 -0
  29. package/build/src/features/index.js +20 -0
  30. package/build/src/features/index.js.map +1 -0
  31. package/build/src/features/init.d.ts +7 -0
  32. package/build/src/features/init.d.ts.map +1 -0
  33. package/build/src/features/init.js +118 -0
  34. package/build/src/features/init.js.map +1 -0
  35. package/build/src/features/migrate.d.ts +83 -0
  36. package/build/src/features/migrate.d.ts.map +1 -0
  37. package/build/src/features/migrate.js +331 -0
  38. package/build/src/features/migrate.js.map +1 -0
  39. package/build/src/features/migration.d.ts +28 -0
  40. package/build/src/features/migration.d.ts.map +1 -0
  41. package/build/src/features/migration.js +128 -0
  42. package/build/src/features/migration.js.map +1 -0
  43. package/build/src/features/seed.d.ts +9 -0
  44. package/build/src/features/seed.d.ts.map +1 -0
  45. package/build/src/features/seed.js +72 -0
  46. package/build/src/features/seed.js.map +1 -0
  47. package/build/src/features/status.d.ts +55 -0
  48. package/build/src/features/status.d.ts.map +1 -0
  49. package/build/src/features/status.js +229 -0
  50. package/build/src/features/status.js.map +1 -0
  51. package/build/src/index.d.ts +4 -0
  52. package/build/src/index.d.ts.map +1 -0
  53. package/build/src/index.js +15 -0
  54. package/build/src/index.js.map +1 -0
  55. package/build/src/libs/compare-mig.d.ts +27 -0
  56. package/build/src/libs/compare-mig.d.ts.map +1 -0
  57. package/build/src/libs/compare-mig.js +215 -0
  58. package/build/src/libs/compare-mig.js.map +1 -0
  59. package/build/src/libs/create-ds.d.ts +10 -0
  60. package/build/src/libs/create-ds.d.ts.map +1 -0
  61. package/build/src/libs/create-ds.js +56 -0
  62. package/build/src/libs/create-ds.js.map +1 -0
  63. package/build/src/libs/get-commands.d.ts +45 -0
  64. package/build/src/libs/get-commands.d.ts.map +1 -0
  65. package/build/src/libs/get-commands.js +128 -0
  66. package/build/src/libs/get-commands.js.map +1 -0
  67. package/build/src/libs/paths.d.ts +22 -0
  68. package/build/src/libs/paths.d.ts.map +1 -0
  69. package/build/src/libs/paths.js +37 -0
  70. package/build/src/libs/paths.js.map +1 -0
  71. package/build/src/libs/print.d.ts +5 -0
  72. package/build/src/libs/print.d.ts.map +1 -0
  73. package/build/src/libs/print.js +18 -0
  74. package/build/src/libs/print.js.map +1 -0
  75. package/build/src/libs/sanitize.d.ts +10 -0
  76. package/build/src/libs/sanitize.d.ts.map +1 -0
  77. package/build/src/libs/sanitize.js +19 -0
  78. package/build/src/libs/sanitize.js.map +1 -0
  79. package/build/src/libs/seed-entities.d.ts +13 -0
  80. package/build/src/libs/seed-entities.d.ts.map +1 -0
  81. package/build/src/libs/seed-entities.js +40 -0
  82. package/build/src/libs/seed-entities.js.map +1 -0
  83. package/build/src/types.d.ts +49 -0
  84. package/build/src/types.d.ts.map +1 -0
  85. package/build/src/types.js +3 -0
  86. package/build/src/types.js.map +1 -0
  87. package/package.json +63 -0
@@ -0,0 +1,331 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __rest = (this && this.__rest) || function (s, e) {
45
+ var t = {};
46
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
47
+ t[p] = s[p];
48
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
49
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
50
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
51
+ t[p[i]] = s[p[i]];
52
+ }
53
+ return t;
54
+ };
55
+ Object.defineProperty(exports, "__esModule", { value: true });
56
+ exports.migrate = migrate;
57
+ exports.runMigrationByConfig = runMigrationByConfig;
58
+ exports.runMigrationByName = runMigrationByName;
59
+ exports.getMigrationsToRun = getMigrationsToRun;
60
+ exports.hasMigration = hasMigration;
61
+ exports.getMigrationFiles = getMigrationFiles;
62
+ exports.getMigrationNameFromPath = getMigrationNameFromPath;
63
+ const get_commands_1 = require("../libs/get-commands");
64
+ const create_ds_1 = require("../libs/create-ds");
65
+ const print_1 = require("../libs/print");
66
+ const sanitize_1 = require("../libs/sanitize");
67
+ const config_1 = require("../config");
68
+ const fs = __importStar(require("fs"));
69
+ const path = __importStar(require("path"));
70
+ const paths_1 = require("../libs/paths");
71
+ /**
72
+ * Lists migration directories under the configured migrations directory and whether each
73
+ * contains a `migration.ts` file.
74
+ *
75
+ * @returns An array of {@link MigrationItem} entries, one per migration folder.
76
+ */
77
+ function getMigrationFiles() {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const root = (0, paths_1.getMigrationRoot)();
80
+ if (!fs.existsSync(root))
81
+ return [];
82
+ const entries = fs.readdirSync(root, { withFileTypes: true });
83
+ const dirs = entries.filter((d) => d.isDirectory());
84
+ return dirs
85
+ .map((i) => {
86
+ const loc = path.join(i.parentPath, i.name, 'migration.ts');
87
+ return {
88
+ name: i.name,
89
+ file: loc,
90
+ parentPath: i.parentPath,
91
+ exists: fs.existsSync(loc),
92
+ };
93
+ })
94
+ .filter((a) => a.exists);
95
+ });
96
+ }
97
+ /**
98
+ * Checks whether a migration has already been recorded in the database.
99
+ * Queries the `migrations` table via a dialect-specific command.
100
+ *
101
+ * @param ds - Initialized TypeORM data source.
102
+ * @param name - Migration folder name to look up.
103
+ * @returns Whether the migration name exists in the migrations table.
104
+ */
105
+ function hasMigration(ds, name) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ try {
108
+ const command = (0, get_commands_1.getCheckMigrationCommand)();
109
+ const rows = yield ds.query(command, [name]);
110
+ const v = rows.length > 0;
111
+ return v;
112
+ }
113
+ catch (e) {
114
+ const code = typeof e === 'object' && e && 'code' in e ? e.code : undefined;
115
+ const msg = e instanceof Error ? e.message : '';
116
+ if (code === '42P01' ||
117
+ msg.includes('relation "migrations" does not exist')) {
118
+ return false;
119
+ }
120
+ throw e;
121
+ }
122
+ });
123
+ }
124
+ /**
125
+ * Resolves which local migrations still need to run against the database.
126
+ * Opens a data source, discovers migration folders (optionally
127
+ * scoped to `name`), and filters out entries that are missing or already recorded.
128
+ *
129
+ * @param name - Optional migration folder name; when omitted, all folders are considered.
130
+ * @param db - Optional database override for the migration lookup.
131
+ * @returns Pending {@link MigrationItem} entries; empty when none apply.
132
+ * @throws When the data source cannot connect or migration lookup fails.
133
+ */
134
+ function getMigrationsToRun(name, db) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ const ds = (0, create_ds_1.createDataSource)(db ? { database: db } : {});
137
+ let initialized = false;
138
+ try {
139
+ yield ds.initialize();
140
+ initialized = true;
141
+ const items = new Set();
142
+ if (name) {
143
+ const p = (0, paths_1.getMigrationFile)(name);
144
+ if (fs.existsSync(p)) {
145
+ items.add({
146
+ exists: true,
147
+ file: p,
148
+ name,
149
+ parentPath: path.dirname((0, paths_1.getMigrationFile)(name)),
150
+ });
151
+ }
152
+ }
153
+ else {
154
+ const files = yield getMigrationFiles();
155
+ files.forEach((f) => items.add(f));
156
+ }
157
+ const a = yield Promise.all(Array.from(items).map((f) => __awaiter(this, void 0, void 0, function* () {
158
+ return Object.assign(Object.assign({}, f), { isMigrated: yield hasMigration(ds, f.name) });
159
+ })));
160
+ return a
161
+ .filter((f) => f.exists && !f.isMigrated)
162
+ .map((_a) => {
163
+ var { isMigrated } = _a, f = __rest(_a, ["isMigrated"]);
164
+ return f;
165
+ });
166
+ }
167
+ catch (e) {
168
+ const msg = e instanceof Error ? e.message : JSON.stringify(e);
169
+ throw new Error(msg);
170
+ }
171
+ finally {
172
+ if (initialized) {
173
+ yield ds.destroy();
174
+ }
175
+ }
176
+ });
177
+ }
178
+ /**
179
+ * Runs pending migrations discovered via {@link getMigrationsToRun}.
180
+ * When `name` is omitted, runs every unmigrated folder under the configured migrations directory.
181
+ *
182
+ * @param name - Optional migration folder name to run a single migration.
183
+ * @param db - Optional database override for migration discovery and execution.
184
+ * @returns Outcome with `migrated` flag and status (`migrated` or `no-migrations`).
185
+ * @throws When migration discovery or execution fails.
186
+ */
187
+ function runMigrationByName(name, db) {
188
+ return __awaiter(this, void 0, void 0, function* () {
189
+ let initialized = false;
190
+ let ds = null;
191
+ try {
192
+ const migratable = yield getMigrationsToRun(name, db);
193
+ if (migratable.length < 1) {
194
+ return {
195
+ migrated: false,
196
+ status: 'no-migrations',
197
+ };
198
+ }
199
+ ds = (0, create_ds_1.createDataSource)(Object.assign({ migrations: migratable.map((m) => m.file) }, (db ? { database: db } : {})));
200
+ yield ds.initialize();
201
+ initialized = true;
202
+ const executed = yield ds.runMigrations();
203
+ if (executed.length < 1) {
204
+ return {
205
+ migrated: false,
206
+ status: 'no-migrations',
207
+ };
208
+ }
209
+ return {
210
+ migrated: true,
211
+ status: 'migrated',
212
+ };
213
+ }
214
+ catch (e) {
215
+ const parsed = e instanceof Error ? e.message : JSON.stringify(e);
216
+ throw new Error(parsed);
217
+ }
218
+ finally {
219
+ if (initialized && ds) {
220
+ yield ds.destroy();
221
+ }
222
+ }
223
+ });
224
+ }
225
+ /**
226
+ * Runs all migrations registered on the configured TypeORM data source.
227
+ * Initializes the data source, executes pending migrations in a single
228
+ * transaction, then destroys the connection.
229
+ *
230
+ * @param db - Optional database override for the TypeORM data source.
231
+ * @returns Outcome with `migrated` flag and status (`migrated` or `no-migrations`).
232
+ * @throws When initialization or migration execution fails.
233
+ */
234
+ function runMigrationByConfig(db) {
235
+ return __awaiter(this, void 0, void 0, function* () {
236
+ const ds = (0, create_ds_1.createDataSource)(db ? { database: db } : {});
237
+ let initialized = false;
238
+ try {
239
+ yield ds.initialize();
240
+ initialized = true;
241
+ const response = yield ds.runMigrations({
242
+ fake: false,
243
+ transaction: 'all',
244
+ });
245
+ if (response.length < 1) {
246
+ return {
247
+ migrated: false,
248
+ status: 'no-migrations',
249
+ };
250
+ }
251
+ return {
252
+ migrated: true,
253
+ status: 'migrated',
254
+ };
255
+ }
256
+ catch (e) {
257
+ const msg = e instanceof Error ? e.message : JSON.stringify(e);
258
+ throw new Error(msg);
259
+ }
260
+ finally {
261
+ if (initialized) {
262
+ yield ds.destroy();
263
+ }
264
+ }
265
+ });
266
+ }
267
+ /**
268
+ * Resolves a migration folder name and `migration.ts` path from a CLI path input.
269
+ * Accepts either a migration directory or a direct path to `migration.ts`.
270
+ * Validates that the folder name is class-style and ends with a 13-digit timestamp.
271
+ *
272
+ * @param input - Migration folder or file path from `--file`.
273
+ * @returns The migration name and normalized path to `migration.ts`.
274
+ * @throws When the name is invalid or the migration file does not exist.
275
+ */
276
+ function getMigrationNameFromPath(input) {
277
+ const normalized = path.normalize(input);
278
+ const base = path.basename(normalized);
279
+ const file = base === 'migration.ts'
280
+ ? normalized
281
+ : path.join(normalized, 'migration.ts');
282
+ const migdir = path.dirname(file);
283
+ const name = path.basename(migdir);
284
+ const validMigName = new RegExp(/^[A-Za-z][A-Za-z0-9_]*\d{13}$/);
285
+ if (!validMigName.test(name)) {
286
+ throw new Error(`Invalid migration name. Expected a class-style name ending with a 13-digit timestamp`);
287
+ }
288
+ if (!fs.existsSync(file)) {
289
+ throw new Error(`Migration file doesn't exist: ${file}`);
290
+ }
291
+ return {
292
+ name,
293
+ path: file,
294
+ };
295
+ }
296
+ /**
297
+ * CLI handler for the `migrate` command.
298
+ * Runs pending migrations via {@link runMigrationByName}. When `--file` is
299
+ * provided, resolves the migration name from the path first.
300
+ * Prints the outcome to stdout and exits with code 0 or 1.
301
+ *
302
+ * @param args - CLI options; `--name` scopes to one migration folder, `--file` to a folder or `migration.ts` path.
303
+ */
304
+ function migrate(args) {
305
+ return __awaiter(this, void 0, void 0, function* () {
306
+ var _a;
307
+ const database = (0, sanitize_1.sanitize)((_a = args.db) !== null && _a !== void 0 ? _a : config_1.cfg.DATABASE_NAME);
308
+ try {
309
+ let response;
310
+ if (args.file) {
311
+ const result = getMigrationNameFromPath(args.file);
312
+ response = yield runMigrationByName(result.name, database);
313
+ }
314
+ else {
315
+ response = yield runMigrationByName(args.name, database);
316
+ }
317
+ if (response.migrated) {
318
+ (0, print_1.print)('Migrations run successfully');
319
+ process.exit(0);
320
+ }
321
+ (0, print_1.print)(`Migrations didn't run: ${response.status}`);
322
+ process.exit(0);
323
+ }
324
+ catch (e) {
325
+ const msg = e instanceof Error ? e.message : 'Unable to serialize error';
326
+ (0, print_1.printf)(msg);
327
+ process.exit(1);
328
+ }
329
+ });
330
+ }
331
+ //# sourceMappingURL=migrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../../src/features/migrate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8SE,0BAAO;AACP,oDAAoB;AACpB,gDAAkB;AAClB,gDAAkB;AAClB,oCAAY;AACZ,8CAAiB;AACjB,4DAAwB;AApT1B,sDAA+D;AAC/D,gDAAoD;AACpD,wCAA6C;AAG7C,8CAA2C;AAC3C,qCAA+B;AAC/B,uCAAyB;AAC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AAK,EAAC,0BAA0B,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,2BAA2B,CAAC;YACzE,IAAA,cAAM,EAAC,GAAG,CAAC,CAAC;YACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CAAA"}
@@ -0,0 +1,28 @@
1
+ import { MIGRATION } from '../types';
2
+ /**
3
+ * Removes a generated migration folder from a `migration.ts` file location.
4
+ *
5
+ * @param location - Generated migration file path.
6
+ */
7
+ declare function removeMig(location: string): Promise<void>;
8
+ type ApplyReturn = {
9
+ applied: boolean;
10
+ generated: boolean;
11
+ msg: string;
12
+ };
13
+ /**
14
+ * Generates a migration and immediately applies it to the configured database.
15
+ * The generated file is removed when execution fails or no migration runs.
16
+ *
17
+ * @param all - Whether to run all configured migrations instead of only the new one.
18
+ * @returns Result describing whether generation and application succeeded.
19
+ */
20
+ declare function apply(all?: boolean): Promise<ApplyReturn>;
21
+ /**
22
+ * CLI handler for the `migration` command.
23
+ *
24
+ * @param args - Command options, including whether to run all migrations.
25
+ */
26
+ declare function migration(args: MIGRATION): Promise<void>;
27
+ export { migration, apply, removeMig };
28
+ //# sourceMappingURL=migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/features/migration.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAMpC;;;;GAIG;AACH,iBAAe,SAAS,CAAC,QAAQ,EAAE,MAAM,iBAKxC;AAED,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;;GAMG;AACH,iBAAe,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAgCxD;AAED;;;;GAIG;AACH,iBAAe,SAAS,CAAC,IAAI,EAAE,SAAS,iBAWvC;AAED,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.migration = migration;
46
+ exports.apply = apply;
47
+ exports.removeMig = removeMig;
48
+ const gen_1 = require("./gen");
49
+ const config_1 = require("../config");
50
+ const migrate_1 = require("./migrate");
51
+ const sanitize_1 = require("../libs/sanitize");
52
+ const print_1 = require("../libs/print");
53
+ const fs = __importStar(require("fs/promises"));
54
+ const path = __importStar(require("path"));
55
+ /**
56
+ * Removes a generated migration folder from a `migration.ts` file location.
57
+ *
58
+ * @param location - Generated migration file path.
59
+ */
60
+ function removeMig(location) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ yield fs.rm(path.dirname(location), {
63
+ force: true,
64
+ recursive: true,
65
+ });
66
+ });
67
+ }
68
+ /**
69
+ * Generates a migration and immediately applies it to the configured database.
70
+ * The generated file is removed when execution fails or no migration runs.
71
+ *
72
+ * @param all - Whether to run all configured migrations instead of only the new one.
73
+ * @returns Result describing whether generation and application succeeded.
74
+ */
75
+ function apply(all) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ // generate migration files
78
+ const database = (0, sanitize_1.sanitize)(config_1.cfg.DATABASE_NAME);
79
+ const response = yield (0, gen_1.generate)({ db: database, save: false });
80
+ if (!response.generated) {
81
+ return {
82
+ applied: false,
83
+ generated: false,
84
+ msg: response.more.reason === 'duplicate-found'
85
+ ? `Duplicate migration found: ${response.more.duplicateOf}`
86
+ : 'No changes have been made to the schema files',
87
+ };
88
+ }
89
+ yield (0, gen_1.saveMig)(response.more.location, response.more.content);
90
+ try {
91
+ const ans = all
92
+ ? yield (0, migrate_1.runMigrationByConfig)(database)
93
+ : yield (0, migrate_1.runMigrationByName)(response.more.title, database);
94
+ if (!ans.migrated) {
95
+ yield removeMig(response.more.location);
96
+ return { generated: true, applied: false, msg: 'Nothing to migrate' };
97
+ }
98
+ return { generated: true, applied: true, msg: 'migrated' };
99
+ }
100
+ catch (e) {
101
+ yield removeMig(response.more.location);
102
+ throw e;
103
+ }
104
+ });
105
+ }
106
+ /**
107
+ * CLI handler for the `migration` command.
108
+ *
109
+ * @param args - Command options, including whether to run all migrations.
110
+ */
111
+ function migration(args) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ try {
114
+ const response = yield apply(args.all);
115
+ if (!response.applied)
116
+ (0, print_1.printf)(response.msg);
117
+ else
118
+ (0, print_1.print)(response.msg);
119
+ process.exit(0);
120
+ }
121
+ catch (e) {
122
+ const msg = e instanceof Error ? e.message : JSON.stringify(e);
123
+ (0, print_1.printf)(msg);
124
+ process.exit(1);
125
+ }
126
+ });
127
+ }
128
+ //# sourceMappingURL=migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.js","sourceRoot":"","sources":["../../../src/features/migration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFS,8BAAS;AAAE,sBAAK;AAAE,8BAAS;AAtFpC,+BAA0C;AAC1C,qCAA+B;AAC/B,uCAAqE;AAErE,8CAA2C;AAC3C,wCAA6C;AAC7C,gDAAkC;AAClC,2CAA6B;AAE7B;;;;GAIG;AACH,SAAe,SAAS,CAAC,QAAgB;;QACvC,MAAM,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAClC,KAAK,EAAE,IAAI;YACX,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;CAAA;AAQD;;;;;;GAMG;AACH,SAAe,KAAK,CAAC,GAAa;;QAChC,2BAA2B;QAC3B,MAAM,QAAQ,GAAG,IAAA,mBAAQ,EAAC,YAAG,CAAC,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CAAA;AAED;;;;GAIG;AACH,SAAe,SAAS,CAAC,IAAe;;QACtC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACvC,IAAI,CAAC,QAAQ,CAAC,OAAO;gBAAE,IAAA,cAAM,EAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;;gBACvC,IAAA,aAAK,EAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC/D,IAAA,cAAM,EAAC,GAAG,CAAC,CAAC;YACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CAAA"}
@@ -0,0 +1,9 @@
1
+ import { SEED } from '../types';
2
+ /**
3
+ * CLI handler for the `seed` command.
4
+ * Populates an existing, migrated database with configured seed classes.
5
+ *
6
+ * @param args - Command options including an optional database override.
7
+ */
8
+ export declare function seed(args: SEED): Promise<void>;
9
+ //# sourceMappingURL=seed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../../src/features/seed.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAiC/B;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,IAAI,EAAE,IAAI,iBAYpC"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.seed = seed;
13
+ const config_1 = require("../config");
14
+ const create_ds_1 = require("../libs/create-ds");
15
+ const print_1 = require("../libs/print");
16
+ const sanitize_1 = require("../libs/sanitize");
17
+ const typeorm_extension_1 = require("typeorm-extension");
18
+ /**
19
+ * Runs seed classes against a target database.
20
+ *
21
+ * @param seeds - Seeder classes to execute in order.
22
+ * @param db - Optional database override; defaults to configured database.
23
+ * @returns Whether all seeders completed successfully.
24
+ */
25
+ function seeder(seeds, db) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const database = (0, sanitize_1.sanitize)(db !== null && db !== void 0 ? db : config_1.cfg.DATABASE_NAME);
28
+ const ds = (0, create_ds_1.createDataSource)({ database });
29
+ let initialized = false;
30
+ try {
31
+ yield ds.initialize();
32
+ initialized = true;
33
+ for (const seed of seeds) {
34
+ yield (0, typeorm_extension_1.runSeeder)(ds, seed);
35
+ }
36
+ return true;
37
+ }
38
+ catch (e) {
39
+ const msg = e instanceof Error ? e.message : JSON.stringify(e);
40
+ throw new Error(msg);
41
+ }
42
+ finally {
43
+ if (initialized) {
44
+ yield ds.destroy();
45
+ }
46
+ }
47
+ });
48
+ }
49
+ /**
50
+ * CLI handler for the `seed` command.
51
+ * Populates an existing, migrated database with configured seed classes.
52
+ *
53
+ * @param args - Command options including an optional database override.
54
+ */
55
+ function seed(args) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ try {
58
+ const seeds = config_1.cfg.SEEDS;
59
+ const response = yield seeder(seeds, args.db);
60
+ if (!response)
61
+ throw new Error('unable to complete seeding');
62
+ (0, print_1.print)('Seeding complete');
63
+ process.exit(0);
64
+ }
65
+ catch (e) {
66
+ const msg = e instanceof Error ? e.message : JSON.stringify(e);
67
+ (0, print_1.printf)(msg);
68
+ process.exit(1);
69
+ }
70
+ });
71
+ }
72
+ //# sourceMappingURL=seed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.js","sourceRoot":"","sources":["../../../src/features/seed.ts"],"names":[],"mappings":";;;;;;;;;;;AA2CA,oBAYC;AAvDD,qCAA+B;AAC/B,gDAAoD;AACpD,wCAA6C;AAC7C,8CAA2C;AAE3C,yDAAsD;AAEtD;;;;;;GAMG;AACH,SAAe,MAAM,CAAC,KAA2B,EAAE,EAAW;;QAC5D,MAAM,QAAQ,GAAG,IAAA,mBAAQ,EAAC,EAAE,aAAF,EAAE,cAAF,EAAE,GAAI,YAAG,CAAC,aAAa,CAAC,CAAC;QACnD,MAAM,EAAE,GAAG,IAAA,4BAAgB,EAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC1C,IAAI,WAAW,GAAG,KAAK,CAAC;QAExB,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,UAAU,EAAE,CAAC;YACtB,WAAW,GAAG,IAAI,CAAC;YAEnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,IAAA,6BAAS,EAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YAC5B,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC/D,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;gBAAS,CAAC;YACT,IAAI,WAAW,EAAE,CAAC;gBAChB,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;CAAA;AAED;;;;;GAKG;AACH,SAAsB,IAAI,CAAC,IAAU;;QACnC,IAAI,CAAC;YACH,MAAM,KAAK,GAAyB,YAAG,CAAC,KAAK,CAAC;YAC9C,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;YAC9C,IAAI,CAAC,QAAQ;gBAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;YAC7D,IAAA,aAAK,EAAC,kBAAkB,CAAC,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC/D,IAAA,cAAM,EAAC,GAAG,CAAC,CAAC;YACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CAAA"}
@@ -0,0 +1,55 @@
1
+ import { DB_STATUS } from '../types';
2
+ import { MigrationItem } from './migrate';
3
+ import { MigrationDuplicate } from '../libs/compare-mig';
4
+ /**
5
+ * Splits local migration files into applied and pending groups for a database.
6
+ *
7
+ * @param name - Optional target database name.
8
+ * @returns Applied and pending local migration file metadata.
9
+ */
10
+ declare const migrationStatus: (name?: string) => Promise<{
11
+ applied: MigrationItem[];
12
+ pending: MigrationItem[];
13
+ }>;
14
+ /**
15
+ * Detects local migration files with equivalent normalized `up` SQL.
16
+ *
17
+ * @returns Total migration file count and duplicate matches.
18
+ */
19
+ declare const checkForDuplicateMig: () => Promise<{
20
+ total: number;
21
+ checks: (MigrationItem & {
22
+ duplicateOf: MigrationDuplicate;
23
+ })[];
24
+ }>;
25
+ /**
26
+ * Checks whether a database with the given name exists.
27
+ * Connects via the default data source and runs a dialect-specific query.
28
+ *
29
+ * @param name - Database name to check (expected to be sanitized).
30
+ * @returns Whether the database exists; includes `error` when the check fails.
31
+ */
32
+ declare const doesDbExists: (name: string) => Promise<{
33
+ databaseOk: boolean;
34
+ dbName: string;
35
+ } & Record<string, any>>;
36
+ /**
37
+ * Inspects a target database and returns its public/base table count.
38
+ * Opens a dedicated TypeORM data source pointed at `name`.
39
+ *
40
+ * @param db - Database to inspect.
41
+ * @returns Table count on success; `tables: 0` and `err` on failure.
42
+ */
43
+ declare const dbStatus: (db: string) => Promise<{
44
+ tables: number;
45
+ } & Record<string, any>>;
46
+ /**
47
+ * CLI handler for the `status` command.
48
+ * Checks database existence and, if it exists, reports the table count.
49
+ * Prints a JSON object to stdout.
50
+ *
51
+ * @param args - CLI options; `name` defaults to `cfg.DATABASE_NAME`.
52
+ */
53
+ declare const status: (args: DB_STATUS) => Promise<never>;
54
+ export { status, dbStatus, doesDbExists, migrationStatus, checkForDuplicateMig, };
55
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/features/status.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIpC,OAAO,EAAmC,aAAa,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAGL,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAG5B;;;;;GAKG;AACH,QAAA,MAAM,eAAe,GAAU,OAAO,MAAM;;;EAmC3C,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,oBAAoB,QAAa,OAAO,CAAC;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,CAAC,aAAa,GAAG;QAAE,WAAW,EAAE,kBAAkB,CAAA;KAAE,CAAC,EAAE,CAAC;CACjE,CAoBA,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,YAAY,GAChB,MAAM,MAAM,KACX,OAAO,CAAC;IAAE,UAAU,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAyBvE,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,QAAQ,GACZ,IAAI,MAAM,KACT,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAqBlD,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,MAAM,GAAU,MAAM,SAAS,mBA0CpC,CAAC;AAEF,OAAO,EACL,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,oBAAoB,GACrB,CAAC"}