@steroidsjs/nest 1.3.7 → 1.3.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/nest",
3
- "version": "1.3.7",
3
+ "version": "1.3.8",
4
4
  "scripts": {
5
5
  "build": "tsc && copyfiles ./{package.json,LICENSE,README.md} dist/",
6
6
  "watch": "tsc -p tsconfig-debug.json",
@@ -18,6 +18,14 @@ const common_1 = require("@nestjs/common");
18
18
  const typeorm_1 = require("typeorm");
19
19
  const dbml2code_1 = require("./dbml/dbml2code");
20
20
  const generate_1 = require("./generate");
21
+ const ConnectionMetadataBuilder_1 = require("typeorm/connection/ConnectionMetadataBuilder");
22
+ const OrmUtils_1 = require("typeorm/util/OrmUtils");
23
+ const importClassesFromDirectories_1 = require("./importClassesFromDirectories");
24
+ ConnectionMetadataBuilder_1.ConnectionMetadataBuilder.prototype.buildMigrations = async function (migrations) {
25
+ const [migrationClasses, migrationDirectories] = OrmUtils_1.OrmUtils.splitClassesAndStrings(migrations);
26
+ const allMigrationClasses = [...migrationClasses, ...(await (0, importClassesFromDirectories_1.importClassesFromDirectories)(this.connection.logger, migrationDirectories))];
27
+ return allMigrationClasses.map(migrationClass => (0, typeorm_1.getFromContainer)(migrationClass));
28
+ };
21
29
  let MigrateCommand = class MigrateCommand {
22
30
  constructor(connection) {
23
31
  this.connection = connection;
@@ -1 +1 @@
1
- {"version":3,"file":"MigrateCommand.js","sourceRoot":"","sources":["../../../../src/infrastructure/commands/MigrateCommand.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mDAAmD;AACnD,2CAA0C;AAC1C,qCAAmC;AACnC,gDAA2C;AAC3C,yCAAoC;AAWpC,IAAa,cAAc,GAA3B,MAAa,cAAc;IACvB,YACY,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAElC,CAAC;IAMD,KAAK,CAAC,KAAK;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S,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAMD,KAAK,CAAC,QAAQ;QACV,MAAM,IAAA,mBAAQ,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;CAEJ,CAAA;AAhDG;IAJC,IAAA,wBAAO,EAAC;QACL,OAAO,EAAE,SAAS;QAClB,QAAQ,EAAE,gBAAgB;KAC7B,CAAC;;;;2CAKD;AAMD;IAJC,IAAA,wBAAO,EAAC;QACL,OAAO,EAAE,gBAAgB;QACzB,QAAQ,EAAE,uBAAuB;KACpC,CAAC;;;;0CAKD;AAMD;IAJC,IAAA,wBAAO,EAAC;QACL,OAAO,EAAE,cAAc;QACvB,QAAQ,EAAE,sBAAsB;KACnC,CAAC;;;;0CAGD;AAMD;IAJC,IAAA,wBAAO,EAAC;QACL,OAAO,EAAE,0BAA0B;QACnC,QAAQ,EAAE,iCAAiC;KAC9C,CAAC;IAEG,WAAA,IAAA,2BAAU,EAAC;QACR,IAAI,EAAE,MAAM;QAEZ,QAAQ,EAAE,qBAAqB;QAC/B,IAAI,EAAE,QAAQ;KACjB,CAAC,CAAA;;;;+CAIL;AAMD;IAJC,IAAA,wBAAO,EAAC;QACL,OAAO,EAAE,kBAAkB;QAC3B,QAAQ,EAAE,0CAA0C;KACvD,CAAC;;;;8CAGD;AAxDQ,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAGe,oBAAU;GAFzB,cAAc,CA0D1B;AA1DY,wCAAc"}
@@ -0,0 +1,2 @@
1
+ import { Logger } from "typeorm/logger/Logger";
2
+ export declare function importClassesFromDirectories(logger: Logger, directories: string[], formats?: string[]): Promise<Function[]>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.importClassesFromDirectories = void 0;
4
+ const glob = require("glob");
5
+ const PlatformTools_1 = require("typeorm/platform/PlatformTools");
6
+ const EntitySchema_1 = require("typeorm/entity-schema/EntitySchema");
7
+ const ImportUtils_1 = require("typeorm/util/ImportUtils");
8
+ class MockMigration {
9
+ async up(queryRunner) {
10
+ await this._load();
11
+ await this._lazyInstance.up(queryRunner);
12
+ }
13
+ async down(queryRunner) {
14
+ await this._load();
15
+ await this._lazyInstance.down(queryRunner);
16
+ }
17
+ async _load() {
18
+ var _a, _b;
19
+ if (!this._lazyInstance) {
20
+ const result = await (0, ImportUtils_1.importOrRequireFile)(PlatformTools_1.PlatformTools.pathResolve(this.file));
21
+ const MigrationClass = ((_a = result === null || result === void 0 ? void 0 : result[0]) === null || _a === void 0 ? void 0 : _a[this.name]) || ((_b = result === null || result === void 0 ? void 0 : result[0]) === null || _b === void 0 ? void 0 : _b.default) || (result === null || result === void 0 ? void 0 : result[0]);
22
+ this._lazyInstance = new MigrationClass();
23
+ }
24
+ }
25
+ }
26
+ const createMockMigration = file => {
27
+ const matches = /([0-9]+)-([a-zA-Z0-9]+)+.(ts|js)$/.exec(file);
28
+ const name = matches ? matches[2] + matches[1] : 'MockMigration';
29
+ const NewClass = new Function('return function ' + name + '(){ this.name = "' + name + '"; this.file = "' + file + '" }')();
30
+ NewClass.prototype = Object.create(MockMigration.prototype);
31
+ return NewClass;
32
+ };
33
+ async function importClassesFromDirectories(logger, directories, formats = [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"]) {
34
+ const logLevel = "info";
35
+ const classesNotFoundMessage = "No classes were found using the provided glob pattern: ";
36
+ const classesFoundMessage = "All classes found using provided glob pattern";
37
+ function loadFileClasses(exported, allLoaded) {
38
+ if (typeof exported === "function" || exported instanceof EntitySchema_1.EntitySchema) {
39
+ allLoaded.push(exported);
40
+ }
41
+ else if (Array.isArray(exported)) {
42
+ exported.forEach((i) => loadFileClasses(i, allLoaded));
43
+ }
44
+ else if (typeof exported === "object" && exported !== null) {
45
+ Object.keys(exported).forEach(key => loadFileClasses(exported[key], allLoaded));
46
+ }
47
+ return allLoaded;
48
+ }
49
+ let allFiles = [];
50
+ await Promise.all(directories.map(dir => {
51
+ return new Promise((resolve, reject) => {
52
+ glob(PlatformTools_1.PlatformTools.pathNormalize(dir), (err, matches) => {
53
+ if (err) {
54
+ reject(err);
55
+ }
56
+ else {
57
+ allFiles = allFiles.concat(matches);
58
+ resolve(null);
59
+ }
60
+ });
61
+ });
62
+ }));
63
+ if (directories.length > 0 && allFiles.length === 0) {
64
+ logger.log(logLevel, `${classesNotFoundMessage} "${directories}"`);
65
+ }
66
+ else if (allFiles.length > 0) {
67
+ logger.log(logLevel, `${classesFoundMessage} "${directories}" : "${allFiles}"`);
68
+ }
69
+ const dirs = allFiles
70
+ .filter(file => {
71
+ const dtsExtension = file.substring(file.length - 5, file.length);
72
+ return formats.indexOf(PlatformTools_1.PlatformTools.pathExtname(file)) !== -1 && dtsExtension !== ".d.ts";
73
+ })
74
+ .map(file => createMockMigration(file));
75
+ return loadFileClasses(dirs, []);
76
+ }
77
+ exports.importClassesFromDirectories = importClassesFromDirectories;
78
+ //# sourceMappingURL=importClassesFromDirectories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"importClassesFromDirectories.js","sourceRoot":"","sources":["../../../../src/infrastructure/commands/importClassesFromDirectories.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,kEAA6D;AAC7D,qEAAgE;AAEhE,0DAA6D;AAE7D,MAAM,aAAa;IAMf,KAAK,CAAC,EAAE,CAAC,WAAW;QAChB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACnB,MAAM,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,WAAW;QAClB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACnB,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,KAAK;;QACP,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACrB,MAAM,MAAM,GAAQ,MAAM,IAAA,iCAAmB,EAAC,6B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