@alpha.consultings/eloquent-orm.js 1.0.9 → 1.0.11
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/CHANGELOG.md +17 -0
- package/PACKAGE-UPDATE-SUMMARY.md +18 -11
- package/README.md +5 -5
- package/dist/Model.d.ts +1 -1
- package/dist/Model.js +3 -3
- package/dist/cli/commands/cacheClear.js +12 -12
- package/dist/cli/commands/cacheStats.js +12 -12
- package/dist/cli/commands/dbSeed.d.ts +1 -1
- package/dist/cli/commands/dbSeed.js +23 -23
- package/dist/cli/commands/dbSeedBootstrapPrecheck.d.ts +1 -1
- package/dist/cli/commands/dbSeedBootstrapPrecheck.js +2 -2
- package/dist/cli/commands/dbSeedFresh.d.ts +1 -1
- package/dist/cli/commands/dbSeedFresh.js +10 -10
- package/dist/cli/commands/demoScenario.js +11 -11
- package/dist/cli/commands/factoryStatus.js +13 -13
- package/dist/cli/commands/makeController.js +11 -11
- package/dist/cli/commands/makeFactory.js +21 -21
- package/dist/cli/commands/makeMigration.d.ts +1 -1
- package/dist/cli/commands/makeMigration.js +31 -17
- package/dist/cli/commands/makeModel.js +30 -30
- package/dist/cli/commands/makeRegistry.d.ts +5 -8
- package/dist/cli/commands/makeRegistry.js +18 -68
- package/dist/cli/commands/makeScenario.js +49 -43
- package/dist/cli/commands/makeSeed.js +12 -9
- package/dist/cli/commands/makeService.js +10 -10
- package/dist/cli/commands/migrateFresh.d.ts +1 -1
- package/dist/cli/commands/migrateFresh.js +14 -14
- package/dist/cli/commands/migrateReset.d.ts +1 -1
- package/dist/cli/commands/migrateReset.js +4 -4
- package/dist/cli/commands/migrateRollback.d.ts +1 -1
- package/dist/cli/commands/migrateRollback.js +36 -36
- package/dist/cli/commands/migrateRun.d.ts +2 -2
- package/dist/cli/commands/migrateRun.js +34 -34
- package/dist/cli/commands/migrateStatus.d.ts +1 -1
- package/dist/cli/commands/migrateStatus.js +16 -16
- package/dist/cli/eloquent.d.ts +1 -1
- package/dist/cli/eloquent.js +30 -30
- package/dist/cli/utils/ArtifactRoutingReport.d.ts +1 -1
- package/dist/cli/utils/ArtifactRoutingReport.js +3 -3
- package/dist/cli/utils/ArtifactStorage.d.ts +2 -2
- package/dist/cli/utils/ArtifactStorage.js +17 -17
- package/dist/cli/utils/AuditTrail.js +2 -2
- package/dist/cli/utils/CliBootstrapSupport.d.ts +1 -1
- package/dist/cli/utils/CliCommandTargets.d.ts +2 -2
- package/dist/cli/utils/CliCommandTargets.js +2 -2
- package/dist/cli/utils/CliMakeArtifactCommandRegistration.js +15 -15
- package/dist/cli/utils/CliMigrationCommandRegistration.js +29 -29
- package/dist/cli/utils/CliProductionGuards.d.ts +1 -1
- package/dist/cli/utils/CliProductionGuards.js +6 -6
- package/dist/cli/utils/CliScaffoldCommandRegistration.js +13 -13
- package/dist/cli/utils/CliSeedScenarioCommandRegistration.js +23 -23
- package/dist/cli/utils/CliSupportCommandRegistration.js +8 -8
- package/dist/cli/utils/ImportResolver.d.ts +12 -3
- package/dist/cli/utils/ImportResolver.js +76 -17
- package/dist/cli/utils/ModelIntrospector.d.ts +1 -1
- package/dist/cli/utils/ModelIntrospector.js +4 -4
- package/dist/cli/utils/ScaffoldGeneratorSupport.js +2 -2
- package/dist/cli/utils/ScenarioMorphAliasRouting.js +8 -8
- package/dist/cli/utils/SeedBootstrapPrecheck.d.ts +1 -1
- package/dist/cli/utils/SeedBootstrapPrecheck.js +10 -10
- package/dist/cli/utils/TemplateEngine.js +2 -2
- package/dist/cli/utils/factories/Factory.d.ts +1 -1
- package/dist/cli/utils/factories/FactoryDisplay.d.ts +1 -1
- package/dist/cli/utils/factories/FactoryGraph.js +5 -5
- package/dist/cli/utils/factories/FactoryLoader.d.ts +1 -1
- package/dist/cli/utils/factories/FactoryLoader.js +4 -4
- package/dist/cli/utils/factories/FactoryRegistry.d.ts +3 -3
- package/dist/cli/utils/factories/FactoryRegistry.js +10 -10
- package/dist/cli/utils/migrations/MigrationLockStrategy.d.ts +1 -1
- package/dist/cli/utils/migrations/MigrationLockStrategy.js +2 -2
- package/dist/cli/utils/migrations/MigrationTracker.d.ts +2 -2
- package/dist/cli/utils/migrations/MigrationTracker.js +6 -6
- package/dist/cli/utils/migrations/MongoMigrationTracker.js +3 -3
- package/dist/cli/utils/resolveConnectionFlags.d.ts +1 -1
- package/dist/cli/utils/resolveConnectionFlags.js +3 -3
- package/dist/cli/utils/resolveSqlConnectionFlags.d.ts +1 -1
- package/dist/cli/utils/typescript/BaseCommand.d.ts +1 -1
- package/dist/cli/utils/typescript/BaseCommand.js +3 -3
- package/dist/cli/utils/typescript/tsRuntime.js +62 -9
- package/dist/config/database.js +9 -9
- package/dist/core/cache/CacheFallbackManager.d.ts +1 -1
- package/dist/core/cache/CacheManager.d.ts +1 -1
- package/dist/core/cache/CacheManager.js +2 -2
- package/dist/core/cache/CacheRegistry.js +4 -4
- package/dist/core/cache/drivers/FileCacheDriver.d.ts +1 -1
- package/dist/core/cache/drivers/FileCacheDriver.js +2 -2
- package/dist/core/cache/drivers/MemcachedCacheDriver.d.ts +1 -1
- package/dist/core/cache/drivers/MemcachedCacheDriver.js +2 -2
- package/dist/core/cache/drivers/MemoryCacheDriver.d.ts +1 -1
- package/dist/core/cache/drivers/MemoryCacheDriver.js +2 -2
- package/dist/core/cache/setupCache.js +12 -12
- package/dist/core/connection/ConnectionFactory.d.ts +2 -2
- package/dist/core/connection/ConnectionFactory.js +9 -9
- package/dist/core/connection/DatabaseConnection.d.ts +2 -2
- package/dist/core/connection/DatabaseConnection.js +4 -4
- package/dist/core/connection/DriverAdapter.d.ts +1 -1
- package/dist/core/connection/DriverAdapter.js +2 -2
- package/dist/core/connection/resolveConnectionName.d.ts +1 -1
- package/dist/core/connection/resolveConnectionName.js +7 -7
- package/dist/core/model/BaseModel.d.ts +29 -29
- package/dist/core/model/BaseModel.js +38 -38
- package/dist/core/model/BaseModelSafeFinderStatics.d.ts +1 -1
- package/dist/core/model/BaseModelSafeFinderStatics.js +19 -19
- package/dist/core/model/CoreModel.d.ts +4 -4
- package/dist/core/model/CoreModel.js +28 -28
- package/dist/core/model/CoreModelPersistenceState.d.ts +1 -1
- package/dist/core/model/CoreModelSafeFinderSupport.d.ts +2 -2
- package/dist/core/model/CoreModelSafeFinderSupport.js +2 -2
- package/dist/core/model/CoreModelValidationEvents.d.ts +2 -2
- package/dist/core/model/CoreModelValidationEvents.js +2 -2
- package/dist/core/model/SafeFinder.d.ts +1 -1
- package/dist/core/model/SafeFinder.js +2 -2
- package/dist/core/orm/mixins/CastsMixin.js +2 -2
- package/dist/core/orm/mixins/HooksMixin.js +8 -8
- package/dist/core/orm/mixins/MorphableMixin.js +4 -4
- package/dist/core/orm/mixins/PivotHelperMixin.js +3 -3
- package/dist/core/orm/mixins/QueryCacheMixin.js +20 -20
- package/dist/core/orm/mixins/ScopeMixin.js +2 -2
- package/dist/core/orm/mixins/SoftDeletesMixin.js +2 -2
- package/dist/core/orm/mixins/utils/HookStore.d.ts +1 -1
- package/dist/core/orm/mixins/utils/HookStore.js +2 -2
- package/dist/core/orm/mixins/utils/modelRegistration.d.ts +1 -1
- package/dist/core/orm/mixins/utils/modelRegistration.js +6 -6
- package/dist/core/orm/relations/BelongsTo.d.ts +1 -1
- package/dist/core/orm/relations/BelongsTo.js +2 -2
- package/dist/core/orm/relations/BelongsToMany.d.ts +1 -1
- package/dist/core/orm/relations/BelongsToMany.js +2 -2
- package/dist/core/orm/relations/HasMany.d.ts +1 -1
- package/dist/core/orm/relations/HasMany.js +2 -2
- package/dist/core/orm/relations/HasOne.d.ts +1 -1
- package/dist/core/orm/relations/HasOne.js +2 -2
- package/dist/core/orm/relations/MorphMany.d.ts +1 -1
- package/dist/core/orm/relations/MorphMany.js +2 -2
- package/dist/core/orm/relations/MorphOne.d.ts +1 -1
- package/dist/core/orm/relations/MorphOne.js +2 -2
- package/dist/core/orm/relations/MorphTo.d.ts +1 -1
- package/dist/core/orm/relations/MorphTo.js +5 -5
- package/dist/core/schema/SchemaBuilder.d.ts +2 -2
- package/dist/core/schema/SchemaBuilder.js +9 -9
- package/dist/core/schema/SchemaValidator.d.ts +1 -1
- package/dist/core/security/AbstractSecurity.d.ts +1 -1
- package/dist/core/security/EnvKeySecurity.d.ts +1 -1
- package/dist/core/security/EnvKeySecurity.js +2 -2
- package/dist/core/security/NoSecurity.d.ts +1 -1
- package/dist/core/security/NoSecurity.js +2 -2
- package/dist/core/security/SecurityFactory.d.ts +1 -1
- package/dist/core/security/SecurityFactory.js +4 -4
- package/dist/core/security/index.d.ts +5 -5
- package/dist/core/security/index.js +5 -5
- package/dist/index.d.ts +10 -10
- package/dist/index.js +30 -30
- package/esm/Factory.mjs +113 -136
- package/esm/Model.mjs +4 -0
- package/esm/index.mjs +23 -28
- package/package.json +14 -5
- package/src/cli/templates/factory.tpl +1 -1
- package/src/cli/templates/seed.tpl +1 -1
|
@@ -6,17 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ModelIntrospector = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const PathMap_js_1 = require("./PathMap.js");
|
|
10
|
+
const tsRuntime_js_1 = require("./typescript/tsRuntime.js");
|
|
11
11
|
class ModelIntrospector {
|
|
12
12
|
static async analyze(modelName, options = {}) {
|
|
13
|
-
const modelsDir =
|
|
13
|
+
const modelsDir = PathMap_js_1.PathMap.models(!!options.test);
|
|
14
14
|
const modelPath = path_1.default.resolve(modelsDir, `${modelName}.ts`);
|
|
15
15
|
if (!fs_1.default.existsSync(modelPath)) {
|
|
16
16
|
throw new Error(`Model file not found: ${modelPath}`);
|
|
17
17
|
}
|
|
18
18
|
this.clearModelModuleCache(modelPath);
|
|
19
|
-
const importedModule = (0,
|
|
19
|
+
const importedModule = (0, tsRuntime_js_1.loadModule)(modelPath);
|
|
20
20
|
const ModelClass = importedModule[modelName];
|
|
21
21
|
if (!ModelClass) {
|
|
22
22
|
throw new Error(`Could not load model class: ${modelName}`);
|
|
@@ -11,7 +11,7 @@ exports.logScaffoldCreated = logScaffoldCreated;
|
|
|
11
11
|
exports.logScaffoldFailure = logScaffoldFailure;
|
|
12
12
|
const path_1 = __importDefault(require("path"));
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
-
const
|
|
14
|
+
const PathMap_js_1 = require("./PathMap.js");
|
|
15
15
|
function scaffoldKindLabel(kind) {
|
|
16
16
|
return kind === "controller" ? "Controller" : "Service";
|
|
17
17
|
}
|
|
@@ -52,7 +52,7 @@ function resolveScaffoldArtifact(kind, modelName, options = {}) {
|
|
|
52
52
|
modelClassName,
|
|
53
53
|
className,
|
|
54
54
|
fileName,
|
|
55
|
-
outputPath: path_1.default.resolve(
|
|
55
|
+
outputPath: path_1.default.resolve(PathMap_js_1.PathMap.root, relativeDir, fileName),
|
|
56
56
|
relativePath: `${relativeDir}/${fileName}`.replace(/\\/g, "/"),
|
|
57
57
|
};
|
|
58
58
|
}
|
|
@@ -7,9 +7,9 @@ exports.resolveTargetedMorphAlias = resolveTargetedMorphAlias;
|
|
|
7
7
|
exports.resolveScenarioMorphAliases = resolveScenarioMorphAliases;
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
10
|
+
const PathMap_js_1 = require("./PathMap.js");
|
|
11
|
+
const ArtifactStorage_js_1 = require("./ArtifactStorage.js");
|
|
12
|
+
const tsRuntime_js_1 = require("./typescript/tsRuntime.js");
|
|
13
13
|
function resolveExistingModelPath(modelsDir, modelName) {
|
|
14
14
|
const basePath = path_1.default.join(modelsDir, modelName);
|
|
15
15
|
for (const ext of [".ts", ".js"]) {
|
|
@@ -21,18 +21,18 @@ function resolveExistingModelPath(modelsDir, modelName) {
|
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
23
|
function resolveTargetedMorphAlias(options) {
|
|
24
|
-
const targetKind = (0,
|
|
25
|
-
const modelKind = (0,
|
|
26
|
-
if (modelKind !== "unknown" && !(0,
|
|
24
|
+
const targetKind = (0, ArtifactStorage_js_1.targetStorageKindForConnection)(options.connectionName);
|
|
25
|
+
const modelKind = (0, ArtifactStorage_js_1.resolveModelStorageKind)(options.modelName, options.isTest);
|
|
26
|
+
if (modelKind !== "unknown" && !(0, ArtifactStorage_js_1.matchesTargetStorageKind)(modelKind, targetKind)) {
|
|
27
27
|
return options.fallback;
|
|
28
28
|
}
|
|
29
|
-
const modelsDir =
|
|
29
|
+
const modelsDir = PathMap_js_1.PathMap.models(options.isTest);
|
|
30
30
|
const modelPath = resolveExistingModelPath(modelsDir, options.modelName);
|
|
31
31
|
if (!modelPath) {
|
|
32
32
|
return options.fallback;
|
|
33
33
|
}
|
|
34
34
|
try {
|
|
35
|
-
const mod = (0,
|
|
35
|
+
const mod = (0, tsRuntime_js_1.loadModule)(modelPath);
|
|
36
36
|
const modelCtor = mod[options.modelName];
|
|
37
37
|
if (modelCtor && typeof modelCtor.getMorphClass === "function") {
|
|
38
38
|
return String(modelCtor.getMorphClass());
|
|
@@ -8,10 +8,10 @@ exports.printSeedBootstrapPrecheck = printSeedBootstrapPrecheck;
|
|
|
8
8
|
exports.assertSeedBootstrapPrecheck = assertSeedBootstrapPrecheck;
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
11
|
+
const ConnectionFactory_js_1 = require("../../core/connection/ConnectionFactory.js");
|
|
12
|
+
const resolveConnectionName_js_1 = require("../../core/connection/resolveConnectionName.js");
|
|
13
|
+
const database_js_1 = require("../../config/database.js");
|
|
14
|
+
const PathMap_js_1 = require("./PathMap.js");
|
|
15
15
|
function listMigrationFiles(migrationsDir) {
|
|
16
16
|
return fs_1.default
|
|
17
17
|
.readdirSync(migrationsDir)
|
|
@@ -19,13 +19,13 @@ function listMigrationFiles(migrationsDir) {
|
|
|
19
19
|
.sort();
|
|
20
20
|
}
|
|
21
21
|
async function inspectConnection(connectionName, isTest) {
|
|
22
|
-
const migrationsDir =
|
|
22
|
+
const migrationsDir = PathMap_js_1.PathMap.migrations(isTest, connectionName);
|
|
23
23
|
const reasons = [];
|
|
24
24
|
let pendingMigrations = [];
|
|
25
|
-
const driver =
|
|
25
|
+
const driver = database_js_1.dbConfig.connections[connectionName]?.driver;
|
|
26
26
|
if (driver === "mongo") {
|
|
27
27
|
try {
|
|
28
|
-
await (0,
|
|
28
|
+
await (0, ConnectionFactory_js_1.getConnection)(connectionName);
|
|
29
29
|
}
|
|
30
30
|
catch (error) {
|
|
31
31
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -64,7 +64,7 @@ async function inspectConnection(connectionName, isTest) {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
try {
|
|
67
|
-
const db = await (0,
|
|
67
|
+
const db = await (0, ConnectionFactory_js_1.getAdapter)(connectionName);
|
|
68
68
|
const rows = await db.query("SELECT name FROM migrations ORDER BY id");
|
|
69
69
|
const appliedNames = new Set(rows.map((row) => row.name));
|
|
70
70
|
if (appliedNames.size === 0) {
|
|
@@ -91,7 +91,7 @@ async function runSeedBootstrapPrecheck(options = {}) {
|
|
|
91
91
|
const isTest = !!options.test;
|
|
92
92
|
const connectionNames = options.connectionNames && options.connectionNames.length > 0
|
|
93
93
|
? options.connectionNames
|
|
94
|
-
: [(0,
|
|
94
|
+
: [(0, resolveConnectionName_js_1.resolveConnectionName)(undefined, { test: isTest })];
|
|
95
95
|
const checks = [];
|
|
96
96
|
try {
|
|
97
97
|
for (const connectionName of connectionNames) {
|
|
@@ -99,7 +99,7 @@ async function runSeedBootstrapPrecheck(options = {}) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
finally {
|
|
102
|
-
await (0,
|
|
102
|
+
await (0, ConnectionFactory_js_1.closeAllConnections)();
|
|
103
103
|
}
|
|
104
104
|
return {
|
|
105
105
|
clean: checks.every((check) => check.clean),
|
|
@@ -7,7 +7,7 @@ exports.TemplateEngine = void 0;
|
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
const
|
|
10
|
+
const PathMap_js_1 = require("./PathMap.js");
|
|
11
11
|
/**
|
|
12
12
|
* 🧩 TemplateEngine
|
|
13
13
|
* Lightweight TypeScript-safe engine for .tpl rendering
|
|
@@ -21,7 +21,7 @@ const PathMap_1 = require("./PathMap");
|
|
|
21
21
|
*/
|
|
22
22
|
class TemplateEngine {
|
|
23
23
|
static load(templateName) {
|
|
24
|
-
const tplPath =
|
|
24
|
+
const tplPath = PathMap_js_1.PathMap.template(templateName);
|
|
25
25
|
if (!fs_1.default.existsSync(tplPath)) {
|
|
26
26
|
console.error(chalk_1.default.red(`❌ Template not found: ${tplPath}`));
|
|
27
27
|
throw new Error(`Template missing: ${templateName}.tpl`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RelationDefinition } from "../../../core/schema/SchemaBlueprint";
|
|
1
|
+
import type { RelationDefinition } from "../../../core/schema/SchemaBlueprint.js";
|
|
2
2
|
export declare const FACTORY_EMPTY_MARK = "-";
|
|
3
3
|
export declare const FACTORY_STATUS_FOOTER = "\nUse factories directly via FactoryRegistry.make(<name>)\n";
|
|
4
4
|
export declare const FACTORY_GRAPH_HEADER = "\nModel Relationship Graph\n\n";
|
|
@@ -9,8 +9,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.generateFactoryGraph = generateFactoryGraph;
|
|
11
11
|
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const FactoryDisplay_js_1 = require("./FactoryDisplay.js");
|
|
13
|
+
const FactoryRegistry_js_1 = require("./FactoryRegistry.js");
|
|
14
14
|
function hasSchema(modelCtor) {
|
|
15
15
|
return (typeof modelCtor === "function" &&
|
|
16
16
|
Object.prototype.hasOwnProperty.call(modelCtor, "schema"));
|
|
@@ -18,7 +18,7 @@ function hasSchema(modelCtor) {
|
|
|
18
18
|
function collectLinks(factoryNames) {
|
|
19
19
|
const links = [];
|
|
20
20
|
for (const factoryName of factoryNames) {
|
|
21
|
-
const factory =
|
|
21
|
+
const factory = FactoryRegistry_js_1.FactoryRegistry.make(factoryName);
|
|
22
22
|
const modelCtor = factory.model;
|
|
23
23
|
const modelName = modelCtor.name.replace("Factory", "");
|
|
24
24
|
const modelInstance = new modelCtor();
|
|
@@ -45,7 +45,7 @@ function dedupeLinks(links) {
|
|
|
45
45
|
(candidate.from === link.to && candidate.to === link.from)));
|
|
46
46
|
}
|
|
47
47
|
function generateFactoryGraph(factoryNames) {
|
|
48
|
-
let output = chalk_1.default.cyanBright(
|
|
48
|
+
let output = chalk_1.default.cyanBright(FactoryDisplay_js_1.FACTORY_GRAPH_HEADER);
|
|
49
49
|
if (factoryNames.length === 0) {
|
|
50
50
|
return output + chalk_1.default.gray("No factories registered.\n");
|
|
51
51
|
}
|
|
@@ -63,7 +63,7 @@ function generateFactoryGraph(factoryNames) {
|
|
|
63
63
|
for (const [node, relations] of grouped.entries()) {
|
|
64
64
|
output += chalk_1.default.greenBright(`${node}\n`);
|
|
65
65
|
for (const { to, rel } of relations) {
|
|
66
|
-
output += `${chalk_1.default.gray(` ${(0,
|
|
66
|
+
output += `${chalk_1.default.gray(` ${(0, FactoryDisplay_js_1.getFactoryRelationArrow)(rel)} `)}${chalk_1.default.cyan(to)} ${chalk_1.default.gray(`(${rel})`)}\n`;
|
|
67
67
|
}
|
|
68
68
|
output += "\n";
|
|
69
69
|
}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.loadFactories = loadFactories;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const
|
|
8
|
+
const FactoryRegistry_js_1 = require("./FactoryRegistry.js");
|
|
9
9
|
/**
|
|
10
10
|
* FactoryLoader
|
|
11
11
|
* Automatically discovers and registers all factories at runtime.
|
|
@@ -20,9 +20,9 @@ const FactoryRegistry_1 = require("./FactoryRegistry");
|
|
|
20
20
|
async function loadFactories(isTest = false, options = {}) {
|
|
21
21
|
console.log(chalk_1.default.cyanBright("Initializing FactoryRegistry..."));
|
|
22
22
|
try {
|
|
23
|
-
|
|
24
|
-
await
|
|
25
|
-
const count =
|
|
23
|
+
FactoryRegistry_js_1.FactoryRegistry.clear();
|
|
24
|
+
await FactoryRegistry_js_1.FactoryRegistry.autoDiscover(isTest, options);
|
|
25
|
+
const count = FactoryRegistry_js_1.FactoryRegistry.list().length;
|
|
26
26
|
console.log(chalk_1.default.greenBright(`Loaded ${count} factories.`));
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { BaseModel } from "../../../core/model/BaseModel";
|
|
2
|
-
import { type StorageKind } from "../ArtifactStorage";
|
|
3
|
-
import type { Factory } from "./Factory";
|
|
1
|
+
import type { BaseModel } from "../../../core/model/BaseModel.js";
|
|
2
|
+
import { type StorageKind } from "../ArtifactStorage.js";
|
|
3
|
+
import type { Factory } from "./Factory.js";
|
|
4
4
|
export declare class FactoryRegistry {
|
|
5
5
|
private static registry;
|
|
6
6
|
static register<T extends Factory<BaseModel>>(name: string, factory: new () => T): void;
|
|
@@ -7,10 +7,10 @@ exports.FactoryRegistry = void 0;
|
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
10
|
+
const ArtifactRoutingReport_js_1 = require("../ArtifactRoutingReport.js");
|
|
11
|
+
const ArtifactStorage_js_1 = require("../ArtifactStorage.js");
|
|
12
|
+
const PathMap_js_1 = require("../PathMap.js");
|
|
13
|
+
const tsRuntime_js_1 = require("../typescript/tsRuntime.js");
|
|
14
14
|
class FactoryRegistry {
|
|
15
15
|
static register(name, factory) {
|
|
16
16
|
if (this.registry.has(name)) {
|
|
@@ -38,7 +38,7 @@ class FactoryRegistry {
|
|
|
38
38
|
return this.make(pivotName);
|
|
39
39
|
}
|
|
40
40
|
static async autoDiscover(isTest = false, options = {}) {
|
|
41
|
-
const dir =
|
|
41
|
+
const dir = PathMap_js_1.PathMap.factories(isTest);
|
|
42
42
|
if (!fs_1.default.existsSync(dir)) {
|
|
43
43
|
console.log(chalk_1.default.gray(`No factories folder found at: ${dir}`));
|
|
44
44
|
return;
|
|
@@ -47,17 +47,17 @@ class FactoryRegistry {
|
|
|
47
47
|
for (const file of files) {
|
|
48
48
|
const fullPath = path_1.default.join(dir, file);
|
|
49
49
|
try {
|
|
50
|
-
const importedModule = (0,
|
|
50
|
+
const importedModule = (0, tsRuntime_js_1.loadModule)(fullPath);
|
|
51
51
|
for (const [name, exported] of Object.entries(importedModule)) {
|
|
52
52
|
if (typeof exported !== "function" ||
|
|
53
53
|
!exported.name.endsWith("Factory")) {
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
|
-
const factoryStorageKind = (0,
|
|
56
|
+
const factoryStorageKind = (0, ArtifactStorage_js_1.resolveFactoryStorageKindFromCtor)(exported);
|
|
57
57
|
if (options.storageKind &&
|
|
58
|
-
!(0,
|
|
59
|
-
const message = (0,
|
|
60
|
-
(0,
|
|
58
|
+
!(0, ArtifactStorage_js_1.matchesTargetStorageKind)(factoryStorageKind, options.storageKind)) {
|
|
59
|
+
const message = (0, ArtifactRoutingReport_js_1.summarizeSkippedArtifacts)("factory", [
|
|
60
|
+
(0, ArtifactRoutingReport_js_1.createTargetedArtifactDecision)(name, factoryStorageKind, options.storageKind),
|
|
61
61
|
], options.storageKind);
|
|
62
62
|
console.warn(chalk_1.default.yellow(message));
|
|
63
63
|
continue;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DriverAdapter } from "../../../core/connection/DriverAdapter";
|
|
1
|
+
import type { DriverAdapter } from "../../../core/connection/DriverAdapter.js";
|
|
2
2
|
export type SqlMigrationDriver = "mysql" | "pg" | "sqlite";
|
|
3
3
|
export interface MigrationLockStrategy {
|
|
4
4
|
ensureBootstrap(db: DriverAdapter, driver: SqlMigrationDriver): Promise<void>;
|
|
@@ -4,10 +4,10 @@ exports.NativeSqlMigrationLockStrategy = void 0;
|
|
|
4
4
|
exports.getMigrationLockStrategy = getMigrationLockStrategy;
|
|
5
5
|
exports.setMigrationLockStrategy = setMigrationLockStrategy;
|
|
6
6
|
exports.resetMigrationLockStrategy = resetMigrationLockStrategy;
|
|
7
|
-
const
|
|
7
|
+
const database_js_1 = require("../../../config/database.js");
|
|
8
8
|
const SQLITE_LOCK_OWNERS = new Map();
|
|
9
9
|
function resolveDriver(db) {
|
|
10
|
-
const configuredDriver =
|
|
10
|
+
const configuredDriver = database_js_1.dbConfig.connections[db.name]?.driver;
|
|
11
11
|
if (configuredDriver === "mysql" || configuredDriver === "pg" || configuredDriver === "sqlite") {
|
|
12
12
|
return configuredDriver;
|
|
13
13
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DriverAdapter } from "../../../core/connection/DriverAdapter";
|
|
2
|
-
import { type SqlMigrationDriver } from "./MigrationLockStrategy";
|
|
1
|
+
import type { DriverAdapter } from "../../../core/connection/DriverAdapter.js";
|
|
2
|
+
import { type SqlMigrationDriver } from "./MigrationLockStrategy.js";
|
|
3
3
|
export type { SqlMigrationDriver };
|
|
4
4
|
export type MigrationRow = {
|
|
5
5
|
id?: number;
|
|
@@ -18,12 +18,12 @@ exports.validateMigrationHistory = validateMigrationHistory;
|
|
|
18
18
|
const fs_1 = __importDefault(require("fs"));
|
|
19
19
|
const crypto_1 = __importDefault(require("crypto"));
|
|
20
20
|
const path_1 = __importDefault(require("path"));
|
|
21
|
-
const
|
|
22
|
-
const
|
|
21
|
+
const database_js_1 = require("../../../config/database.js");
|
|
22
|
+
const MigrationLockStrategy_js_1 = require("./MigrationLockStrategy.js");
|
|
23
23
|
const AUTO_GENERATED_MIGRATION_RE = /^\d+_(create|update)_[A-Za-z0-9_]+_table\.(ts|js)$/;
|
|
24
24
|
const AUTO_GENERATED_CREATE_MIGRATION_RE = /^\d+_create_([A-Za-z0-9_]+)_table\.(ts|js)$/;
|
|
25
25
|
function resolveDriver(db) {
|
|
26
|
-
const driver =
|
|
26
|
+
const driver = database_js_1.dbConfig.connections[db.name]?.driver ?? db.name;
|
|
27
27
|
if (driver === "mysql" || driver === "pg" || driver === "sqlite") {
|
|
28
28
|
return driver;
|
|
29
29
|
}
|
|
@@ -94,7 +94,7 @@ async function ensureMigrationTables(db) {
|
|
|
94
94
|
const driver = resolveDriver(db);
|
|
95
95
|
await db.execute(trackerTableSQL(driver));
|
|
96
96
|
await ensureChecksumColumn(db, driver);
|
|
97
|
-
await (0,
|
|
97
|
+
await (0, MigrationLockStrategy_js_1.getMigrationLockStrategy)().ensureBootstrap(db, driver);
|
|
98
98
|
return driver;
|
|
99
99
|
}
|
|
100
100
|
function computeMigrationChecksum(filePath) {
|
|
@@ -180,10 +180,10 @@ async function tryPruneStaleGeneratedCreateMigration(db, migrationName) {
|
|
|
180
180
|
return true;
|
|
181
181
|
}
|
|
182
182
|
async function acquireMigrationLock(db, owner) {
|
|
183
|
-
await (0,
|
|
183
|
+
await (0, MigrationLockStrategy_js_1.getMigrationLockStrategy)().acquire(db, owner);
|
|
184
184
|
}
|
|
185
185
|
async function releaseMigrationLock(db, owner, outcome) {
|
|
186
|
-
await (0,
|
|
186
|
+
await (0, MigrationLockStrategy_js_1.getMigrationLockStrategy)().release(db, owner, outcome);
|
|
187
187
|
}
|
|
188
188
|
async function readAppliedMigrations(db) {
|
|
189
189
|
return await db.query(`SELECT ${db.wrapId("id")} AS id, ${db.wrapId("name")} AS name, ${db.wrapId("batch")} AS batch, ${db.wrapId("checksum")} AS checksum, ${db.wrapId("run_at")} AS run_at FROM ${db.wrapId("migrations")} ORDER BY ${db.wrapId("id")}`);
|
|
@@ -14,7 +14,7 @@ exports.validateMigrationHistory = validateMigrationHistory;
|
|
|
14
14
|
exports.doesCollectionExist = doesCollectionExist;
|
|
15
15
|
const fs_1 = __importDefault(require("fs"));
|
|
16
16
|
const path_1 = __importDefault(require("path"));
|
|
17
|
-
const
|
|
17
|
+
const MigrationTracker_js_1 = require("./MigrationTracker.js");
|
|
18
18
|
const MIGRATIONS_COLLECTION = "migrations";
|
|
19
19
|
const HISTORY_KIND = "history";
|
|
20
20
|
const LOCK_DOC_ID = "__eloquent_migration_lock__";
|
|
@@ -222,7 +222,7 @@ async function backfillMissingChecksums(db, rows, migrationsDir) {
|
|
|
222
222
|
}
|
|
223
223
|
throw new Error(`Applied migration "${row.name}" is missing from disk and cannot be checksum-validated.`);
|
|
224
224
|
}
|
|
225
|
-
const checksum = (0,
|
|
225
|
+
const checksum = (0, MigrationTracker_js_1.computeMigrationChecksum)(resolved.filePath);
|
|
226
226
|
if (resolved.relinked) {
|
|
227
227
|
await relinkAppliedMigration(db, row.name, resolved.fileName, checksum);
|
|
228
228
|
updatedRows.push({ ...row, name: resolved.fileName, checksum });
|
|
@@ -255,7 +255,7 @@ async function validateMigrationHistory(db, migrationsDir) {
|
|
|
255
255
|
}
|
|
256
256
|
throw new Error(`Applied migration "${row.name}" is missing from disk.`);
|
|
257
257
|
}
|
|
258
|
-
const currentChecksum = (0,
|
|
258
|
+
const currentChecksum = (0, MigrationTracker_js_1.computeMigrationChecksum)(resolved.filePath);
|
|
259
259
|
if (resolved.relinked) {
|
|
260
260
|
await relinkAppliedMigration(db, row.name, resolved.fileName, currentChecksum);
|
|
261
261
|
row.name = resolved.fileName;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveConnectionNamesFromFlags = resolveConnectionNamesFromFlags;
|
|
4
|
-
const
|
|
4
|
+
const database_js_1 = require("../../config/database.js");
|
|
5
5
|
function mapDriverToConnectionName(driver, isTest) {
|
|
6
6
|
if (isTest) {
|
|
7
7
|
const testName = `${driver}_test`;
|
|
8
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
8
|
+
if (Object.prototype.hasOwnProperty.call(database_js_1.dbConfig.connections, testName)) {
|
|
9
9
|
return testName;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(database_js_1.dbConfig.connections, driver)) {
|
|
13
13
|
return driver;
|
|
14
14
|
}
|
|
15
15
|
return null;
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BaseCommand = void 0;
|
|
7
|
-
const
|
|
7
|
+
const TypeScriptCompiler_js_1 = require("./TypeScriptCompiler.js");
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
/**
|
|
10
10
|
* 🧩 BaseCommand
|
|
@@ -13,9 +13,9 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
13
13
|
*/
|
|
14
14
|
class BaseCommand {
|
|
15
15
|
constructor() {
|
|
16
|
-
this.compiler =
|
|
16
|
+
this.compiler = TypeScriptCompiler_js_1.TypeScriptCompiler;
|
|
17
17
|
// ✅ Ensure ts-node runtime is ready for all CLI commands
|
|
18
|
-
|
|
18
|
+
TypeScriptCompiler_js_1.TypeScriptCompiler.ensureRuntime();
|
|
19
19
|
}
|
|
20
20
|
success(message) {
|
|
21
21
|
console.log(chalk_1.default.greenBright(`✅ ${message}`));
|
|
@@ -22,14 +22,57 @@ const PACKAGE_NAME = (() => {
|
|
|
22
22
|
return "";
|
|
23
23
|
}
|
|
24
24
|
})();
|
|
25
|
+
const PACKAGE_SOURCE_ROOT = path_1.default.join(PACKAGE_ROOT, "src") + path_1.default.sep;
|
|
26
|
+
const PACKAGE_BIN_ROOT = path_1.default.join(PACKAGE_ROOT, "bin") + path_1.default.sep;
|
|
27
|
+
function isPackageSourceTreeFile(filePath) {
|
|
28
|
+
const normalized = path_1.default.resolve(filePath);
|
|
29
|
+
return (normalized.startsWith(PACKAGE_SOURCE_ROOT) ||
|
|
30
|
+
normalized.startsWith(PACKAGE_BIN_ROOT));
|
|
31
|
+
}
|
|
32
|
+
function isTypeScriptSourceFile(filePath) {
|
|
33
|
+
return /\.(?:[cm]?ts|tsx)$/i.test(filePath);
|
|
34
|
+
}
|
|
35
|
+
function runningInsideJest() {
|
|
36
|
+
return typeof process.env.JEST_WORKER_ID === "string";
|
|
37
|
+
}
|
|
25
38
|
function resolveExistingModulePath(basePath) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
const extension = path_1.default.extname(basePath).toLowerCase();
|
|
40
|
+
const withoutExtension = extension.length > 0 ? basePath.slice(0, -extension.length) : basePath;
|
|
41
|
+
const candidates = [];
|
|
42
|
+
const seen = new Set();
|
|
43
|
+
const addCandidate = (candidate) => {
|
|
44
|
+
/* istanbul ignore next -- defensive guard; current candidate generation is unique */
|
|
45
|
+
if (seen.has(candidate)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
seen.add(candidate);
|
|
49
|
+
candidates.push(candidate);
|
|
50
|
+
};
|
|
51
|
+
if (extension === ".js" || extension === ".mjs" || extension === ".cjs") {
|
|
52
|
+
// NodeNext TypeScript source commonly imports local modules using `.js`
|
|
53
|
+
// specifiers even though the source file on disk is `.ts`.
|
|
54
|
+
addCandidate(`${withoutExtension}.ts`);
|
|
55
|
+
addCandidate(`${withoutExtension}.tsx`);
|
|
56
|
+
addCandidate(`${withoutExtension}.mts`);
|
|
57
|
+
addCandidate(`${withoutExtension}.cts`);
|
|
58
|
+
}
|
|
59
|
+
addCandidate(basePath);
|
|
60
|
+
if (!extension) {
|
|
61
|
+
addCandidate(`${basePath}.ts`);
|
|
62
|
+
addCandidate(`${basePath}.tsx`);
|
|
63
|
+
addCandidate(`${basePath}.mts`);
|
|
64
|
+
addCandidate(`${basePath}.cts`);
|
|
65
|
+
addCandidate(`${basePath}.js`);
|
|
66
|
+
addCandidate(`${basePath}.mjs`);
|
|
67
|
+
addCandidate(`${basePath}.cjs`);
|
|
68
|
+
addCandidate(path_1.default.join(basePath, "index.ts"));
|
|
69
|
+
addCandidate(path_1.default.join(basePath, "index.tsx"));
|
|
70
|
+
addCandidate(path_1.default.join(basePath, "index.mts"));
|
|
71
|
+
addCandidate(path_1.default.join(basePath, "index.cts"));
|
|
72
|
+
addCandidate(path_1.default.join(basePath, "index.js"));
|
|
73
|
+
addCandidate(path_1.default.join(basePath, "index.mjs"));
|
|
74
|
+
addCandidate(path_1.default.join(basePath, "index.cjs"));
|
|
75
|
+
}
|
|
33
76
|
return candidates.find((candidate) => fs_1.default.existsSync(candidate)) ?? null;
|
|
34
77
|
}
|
|
35
78
|
function resolveLocalRequest(request, fromFilePath) {
|
|
@@ -114,7 +157,8 @@ function requireFromFile(filePath) {
|
|
|
114
157
|
function loadTypeScriptModule(filePath, runtimeAvailable = ensureTsRuntime()) {
|
|
115
158
|
const absolutePath = path_1.default.resolve(filePath);
|
|
116
159
|
const forceTranspileReload = forceTranspileReloadPaths.delete(absolutePath);
|
|
117
|
-
|
|
160
|
+
const preferManualTranspile = isPackageSourceTreeFile(absolutePath);
|
|
161
|
+
if (runtimeAvailable && !forceTranspileReload && !preferManualTranspile) {
|
|
118
162
|
try {
|
|
119
163
|
return requireFromFile(filePath);
|
|
120
164
|
}
|
|
@@ -163,7 +207,16 @@ function loadTranspiledTsModule(filePath, runtimeAvailable) {
|
|
|
163
207
|
}
|
|
164
208
|
const resolved = resolveLocalRequest(request, absolutePath);
|
|
165
209
|
if (resolved) {
|
|
166
|
-
if (resolved
|
|
210
|
+
if (isTypeScriptSourceFile(resolved)) {
|
|
211
|
+
if (runningInsideJest()) {
|
|
212
|
+
try {
|
|
213
|
+
return fallbackRequire(request);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
// Keep the manual transpile fallback for NodeNext-style local source
|
|
217
|
+
// imports that Jest/ts-node cannot resolve directly.
|
|
218
|
+
}
|
|
219
|
+
}
|
|
167
220
|
return loadTypeScriptModule(resolved, runtimeAvailable);
|
|
168
221
|
}
|
|
169
222
|
return requireFromFile(resolved);
|
package/dist/config/database.js
CHANGED
|
@@ -36,16 +36,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.dbConfig = void 0;
|
|
37
37
|
// src/config/database.ts
|
|
38
38
|
const dotenv = __importStar(require("dotenv"));
|
|
39
|
-
const
|
|
39
|
+
const dbRoleEnv_js_1 = require("./dbRoleEnv.js");
|
|
40
40
|
dotenv.config();
|
|
41
|
-
const mysqlRuntime = (0,
|
|
42
|
-
const mysqlTest = (0,
|
|
43
|
-
const pgRuntime = (0,
|
|
44
|
-
const pgTest = (0,
|
|
45
|
-
const sqliteRuntimePath = (0,
|
|
46
|
-
const sqliteTestPath = (0,
|
|
47
|
-
const mongoRuntime = (0,
|
|
48
|
-
const mongoTest = (0,
|
|
41
|
+
const mysqlRuntime = (0, dbRoleEnv_js_1.resolveMysqlEnv)(process.env, { test: false });
|
|
42
|
+
const mysqlTest = (0, dbRoleEnv_js_1.resolveMysqlEnv)(process.env, { test: true });
|
|
43
|
+
const pgRuntime = (0, dbRoleEnv_js_1.resolvePgEnv)(process.env, { test: false });
|
|
44
|
+
const pgTest = (0, dbRoleEnv_js_1.resolvePgEnv)(process.env, { test: true });
|
|
45
|
+
const sqliteRuntimePath = (0, dbRoleEnv_js_1.resolveSqlitePath)(process.env, { test: false });
|
|
46
|
+
const sqliteTestPath = (0, dbRoleEnv_js_1.resolveSqlitePath)(process.env, { test: true });
|
|
47
|
+
const mongoRuntime = (0, dbRoleEnv_js_1.resolveMongoEnv)(process.env, { test: false });
|
|
48
|
+
const mongoTest = (0, dbRoleEnv_js_1.resolveMongoEnv)(process.env, { test: true });
|
|
49
49
|
exports.dbConfig = {
|
|
50
50
|
default: process.env.DB_CONNECTION || "mysql",
|
|
51
51
|
connections: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CacheManager = void 0;
|
|
4
|
-
const
|
|
4
|
+
const MemoryCacheDriver_js_1 = require("./drivers/MemoryCacheDriver.js");
|
|
5
5
|
class CacheManager {
|
|
6
6
|
static use(driver) {
|
|
7
7
|
this.driver = driver;
|
|
@@ -23,4 +23,4 @@ class CacheManager {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.CacheManager = CacheManager;
|
|
26
|
-
CacheManager.driver = new
|
|
26
|
+
CacheManager.driver = new MemoryCacheDriver_js_1.MemoryCacheDriver();
|