@alpha.consultings/eloquent-orm.js 1.0.10 → 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 +9 -0
- package/PACKAGE-UPDATE-SUMMARY.md +10 -10
- 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 +18 -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 +26 -2
- 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
|
@@ -35,12 +35,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.QueryCacheMixin = QueryCacheMixin;
|
|
37
37
|
const crypto = __importStar(require("crypto"));
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
38
|
+
const CacheManager_js_1 = require("../../cache/CacheManager.js");
|
|
39
|
+
const CacheRegistry_js_1 = require("../../cache/CacheRegistry.js");
|
|
40
|
+
const CacheFallbackManager_js_1 = require("../../cache/CacheFallbackManager.js");
|
|
41
|
+
const CacheAnalytics_js_1 = require("../../cache/CacheAnalytics.js");
|
|
42
|
+
const HookStore_js_1 = require("./utils/HookStore.js");
|
|
43
|
+
const ModelRegistry_js_1 = require("./utils/ModelRegistry.js");
|
|
44
44
|
const CACHE_INVALIDATION_EVENTS = ["created", "updated", "deleted"];
|
|
45
45
|
function QueryCacheMixin(Base) {
|
|
46
46
|
const cacheHooksRegistered = new WeakSet();
|
|
@@ -57,7 +57,7 @@ function QueryCacheMixin(Base) {
|
|
|
57
57
|
}
|
|
58
58
|
ensureCacheInvalidationHooks() {
|
|
59
59
|
const modelCtor = this.constructor;
|
|
60
|
-
if (!
|
|
60
|
+
if (!ModelRegistry_js_1.ModelRegistry.isGranted(modelCtor) && ModelRegistry_js_1.ModelRegistry.isStrictMode()) {
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
if (cacheHooksRegistered.has(modelCtor)) {
|
|
@@ -65,10 +65,10 @@ function QueryCacheMixin(Base) {
|
|
|
65
65
|
}
|
|
66
66
|
const modelName = this.constructor.name || "Model";
|
|
67
67
|
const clearModelCache = async () => {
|
|
68
|
-
await
|
|
68
|
+
await CacheRegistry_js_1.CacheRegistry.clearModel(modelName);
|
|
69
69
|
};
|
|
70
70
|
for (const event of CACHE_INVALIDATION_EVENTS) {
|
|
71
|
-
|
|
71
|
+
HookStore_js_1.HookStore.add(modelCtor, event, clearModelCache);
|
|
72
72
|
}
|
|
73
73
|
cacheHooksRegistered.add(modelCtor);
|
|
74
74
|
}
|
|
@@ -92,14 +92,14 @@ function QueryCacheMixin(Base) {
|
|
|
92
92
|
}
|
|
93
93
|
get cacheAPI() {
|
|
94
94
|
try {
|
|
95
|
-
const fallbackActive = typeof
|
|
96
|
-
|
|
95
|
+
const fallbackActive = typeof CacheFallbackManager_js_1.CacheFallbackManager?.getActiveDriver === "function" &&
|
|
96
|
+
CacheFallbackManager_js_1.CacheFallbackManager.getActiveDriver();
|
|
97
97
|
return fallbackActive
|
|
98
|
-
?
|
|
99
|
-
:
|
|
98
|
+
? CacheFallbackManager_js_1.CacheFallbackManager
|
|
99
|
+
: CacheManager_js_1.CacheManager;
|
|
100
100
|
}
|
|
101
101
|
catch {
|
|
102
|
-
return
|
|
102
|
+
return CacheManager_js_1.CacheManager;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
resolveTTL(payload, group) {
|
|
@@ -137,21 +137,21 @@ function QueryCacheMixin(Base) {
|
|
|
137
137
|
const cached = await this.cacheAPI.get(key);
|
|
138
138
|
if (cached !== null && typeof cached !== "undefined") {
|
|
139
139
|
try {
|
|
140
|
-
|
|
140
|
+
CacheAnalytics_js_1.CacheAnalytics.hit(modelName, ttl);
|
|
141
141
|
}
|
|
142
142
|
catch { }
|
|
143
143
|
return cached;
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
CacheAnalytics_js_1.CacheAnalytics.miss(modelName, ttl);
|
|
146
146
|
}
|
|
147
147
|
catch (err) {
|
|
148
148
|
console.warn(`[Cache] Read failed for ${key}:`, err);
|
|
149
|
-
|
|
149
|
+
CacheAnalytics_js_1.CacheAnalytics.miss(modelName, ttl);
|
|
150
150
|
}
|
|
151
151
|
const result = await executeFn();
|
|
152
152
|
try {
|
|
153
153
|
await this.cacheAPI.set(key, result, ttl);
|
|
154
|
-
await
|
|
154
|
+
await CacheRegistry_js_1.CacheRegistry.addKey(modelName, group, key);
|
|
155
155
|
}
|
|
156
156
|
catch (err) {
|
|
157
157
|
console.warn(`[Cache] Write failed for ${key}:`, err);
|
|
@@ -160,11 +160,11 @@ function QueryCacheMixin(Base) {
|
|
|
160
160
|
}
|
|
161
161
|
async invalidateModelCache() {
|
|
162
162
|
const modelName = this.constructor.name || "Model";
|
|
163
|
-
await
|
|
163
|
+
await CacheRegistry_js_1.CacheRegistry.clearModel(modelName);
|
|
164
164
|
}
|
|
165
165
|
async invalidateCacheGroup(group) {
|
|
166
166
|
const modelName = this.constructor.name || "Model";
|
|
167
|
-
await
|
|
167
|
+
await CacheRegistry_js_1.CacheRegistry.clearGroup(modelName, group);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
return CachedModel;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ScopeMixin = ScopeMixin;
|
|
4
|
-
const
|
|
4
|
+
const BaseMethodResolver_js_1 = require("./utils/BaseMethodResolver.js");
|
|
5
5
|
function ScopeMixin(Base) {
|
|
6
|
-
const resolveBaseMethod = (0,
|
|
6
|
+
const resolveBaseMethod = (0, BaseMethodResolver_js_1.createBaseMethodResolver)(Base);
|
|
7
7
|
class ScopedModel extends Base {
|
|
8
8
|
constructor(...args) {
|
|
9
9
|
super(...args);
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.SoftDeletesMixin = SoftDeletesMixin;
|
|
10
|
-
const
|
|
10
|
+
const BaseMethodResolver_js_1 = require("./utils/BaseMethodResolver.js");
|
|
11
11
|
function SoftDeletesMixin(Base) {
|
|
12
|
-
const resolveBaseMethod = (0,
|
|
12
|
+
const resolveBaseMethod = (0, BaseMethodResolver_js_1.createBaseMethodResolver)(Base);
|
|
13
13
|
class SoftDeletableModel extends Base {
|
|
14
14
|
supportsSoftDeletes() {
|
|
15
15
|
const ctor = this.constructor;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ModelConstructor } from "./ModelRegistry";
|
|
1
|
+
import { type ModelConstructor } from "./ModelRegistry.js";
|
|
2
2
|
export type LifecycleEvent = "creating" | "created" | "updating" | "updated" | "deleting" | "deleted";
|
|
3
3
|
export type HookHandler<TPayload = unknown> = (payload: TPayload) => Promise<void> | void;
|
|
4
4
|
type HookBucket = Record<LifecycleEvent, HookHandler<unknown>[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EMPTY_HOOKS = exports.HookStore = void 0;
|
|
4
|
-
const
|
|
4
|
+
const ModelRegistry_js_1 = require("./ModelRegistry.js");
|
|
5
5
|
const EMPTY_HOOKS = {
|
|
6
6
|
creating: [],
|
|
7
7
|
created: [],
|
|
@@ -28,7 +28,7 @@ function makeHookBucket() {
|
|
|
28
28
|
*/
|
|
29
29
|
class HookStore {
|
|
30
30
|
static add(modelCtor, event, handler) {
|
|
31
|
-
|
|
31
|
+
ModelRegistry_js_1.ModelRegistry.ensureGranted(modelCtor, "registration");
|
|
32
32
|
const bucket = this.ensureBucket(modelCtor);
|
|
33
33
|
bucket[event].push(handler);
|
|
34
34
|
}
|
|
@@ -4,22 +4,22 @@ exports.registerModels = registerModels;
|
|
|
4
4
|
exports.isModelRegistered = isModelRegistered;
|
|
5
5
|
exports.setModelRegistryStrictMode = setModelRegistryStrictMode;
|
|
6
6
|
exports.isModelRegistryStrictMode = isModelRegistryStrictMode;
|
|
7
|
-
const
|
|
7
|
+
const ModelRegistry_js_1 = require("./ModelRegistry.js");
|
|
8
8
|
function registerModels(modelCtors, options = {}) {
|
|
9
9
|
if (!Array.isArray(modelCtors)) {
|
|
10
10
|
throw new Error("registerModels expects an array of model constructors.");
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
ModelRegistry_js_1.ModelRegistry.grantMany(modelCtors);
|
|
13
13
|
if (options.strict !== false) {
|
|
14
|
-
|
|
14
|
+
ModelRegistry_js_1.ModelRegistry.setStrictMode(true);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
function isModelRegistered(modelCtor) {
|
|
18
|
-
return
|
|
18
|
+
return ModelRegistry_js_1.ModelRegistry.isGranted(modelCtor);
|
|
19
19
|
}
|
|
20
20
|
function setModelRegistryStrictMode(enabled) {
|
|
21
|
-
|
|
21
|
+
ModelRegistry_js_1.ModelRegistry.setStrictMode(enabled);
|
|
22
22
|
}
|
|
23
23
|
function isModelRegistryStrictMode() {
|
|
24
|
-
return
|
|
24
|
+
return ModelRegistry_js_1.ModelRegistry.isStrictMode();
|
|
25
25
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BelongsTo = void 0;
|
|
4
|
-
const
|
|
5
|
-
class BelongsTo extends
|
|
4
|
+
const Relation_js_1 = require("../Relation.js");
|
|
5
|
+
class BelongsTo extends Relation_js_1.Relation {
|
|
6
6
|
async getResults(parent) {
|
|
7
7
|
const RelatedModel = this.relatedModel;
|
|
8
8
|
if (!RelatedModel)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BelongsToMany = void 0;
|
|
4
|
-
const
|
|
5
|
-
class BelongsToMany extends
|
|
4
|
+
const Relation_js_1 = require("../Relation.js");
|
|
5
|
+
class BelongsToMany extends Relation_js_1.Relation {
|
|
6
6
|
constructor(relatedModel, pivotTable, foreignPivotKey, relatedPivotKey, parentLocalKey = "id", relatedLocalKey = "id") {
|
|
7
7
|
super(relatedModel, foreignPivotKey, parentLocalKey);
|
|
8
8
|
this.pivotTable = pivotTable;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HasMany = void 0;
|
|
4
|
-
const
|
|
5
|
-
class HasMany extends
|
|
4
|
+
const Relation_js_1 = require("../Relation.js");
|
|
5
|
+
class HasMany extends Relation_js_1.Relation {
|
|
6
6
|
async getResults(parent) {
|
|
7
7
|
const RelatedModel = this.relatedModel;
|
|
8
8
|
if (!RelatedModel)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HasOne = void 0;
|
|
4
|
-
const
|
|
5
|
-
class HasOne extends
|
|
4
|
+
const Relation_js_1 = require("../Relation.js");
|
|
5
|
+
class HasOne extends Relation_js_1.Relation {
|
|
6
6
|
async getResults(parent) {
|
|
7
7
|
const RelatedModel = this.relatedModel;
|
|
8
8
|
if (!RelatedModel)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MorphMany = void 0;
|
|
4
|
-
const
|
|
5
|
-
class MorphMany extends
|
|
4
|
+
const Relation_js_1 = require("../Relation.js");
|
|
5
|
+
class MorphMany extends Relation_js_1.Relation {
|
|
6
6
|
constructor(relatedModel, morphType, morphId) {
|
|
7
7
|
super(relatedModel, morphId, "id");
|
|
8
8
|
this.morphType = morphType;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MorphOne = void 0;
|
|
4
|
-
const
|
|
5
|
-
class MorphOne extends
|
|
4
|
+
const Relation_js_1 = require("../Relation.js");
|
|
5
|
+
class MorphOne extends Relation_js_1.Relation {
|
|
6
6
|
constructor(relatedModel, morphType, morphId) {
|
|
7
7
|
super(relatedModel, morphId, "id");
|
|
8
8
|
this.morphType = morphType;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MorphTo = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
class MorphTo extends
|
|
4
|
+
const Relation_js_1 = require("../Relation.js");
|
|
5
|
+
const MorphRegistry_js_1 = require("../mixins/MorphRegistry.js");
|
|
6
|
+
class MorphTo extends Relation_js_1.Relation {
|
|
7
7
|
constructor(morphType, morphId) {
|
|
8
8
|
// The related model is determined dynamically at runtime
|
|
9
9
|
super(null, morphId, "id");
|
|
@@ -14,7 +14,7 @@ class MorphTo extends Relation_1.Relation {
|
|
|
14
14
|
const modelClassName = parent[this.morphType];
|
|
15
15
|
if (!modelClassName)
|
|
16
16
|
return null;
|
|
17
|
-
const Model =
|
|
17
|
+
const Model = MorphRegistry_js_1.MorphRegistry.resolve(modelClassName);
|
|
18
18
|
const relatedInstance = new Model();
|
|
19
19
|
const db = await relatedInstance.getDB();
|
|
20
20
|
let row;
|
|
@@ -44,7 +44,7 @@ class MorphTo extends Relation_1.Relation {
|
|
|
44
44
|
groups[type].push(parent);
|
|
45
45
|
}
|
|
46
46
|
for (const [type, models] of Object.entries(groups)) {
|
|
47
|
-
const Model =
|
|
47
|
+
const Model = MorphRegistry_js_1.MorphRegistry.resolve(type);
|
|
48
48
|
const relatedInstance = new Model();
|
|
49
49
|
const db = await relatedInstance.getDB();
|
|
50
50
|
const ids = models.map((m) => m[this.morphId]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SchemaField } from "./SchemaBlueprint";
|
|
2
|
-
import { Dialect } from "./SQLDialect";
|
|
1
|
+
import { SchemaField } from "./SchemaBlueprint.js";
|
|
2
|
+
import { Dialect } from "./SQLDialect.js";
|
|
3
3
|
export interface SchemaBuildResult {
|
|
4
4
|
mainSQL: string;
|
|
5
5
|
extraTables: string[];
|
|
@@ -38,17 +38,17 @@ exports.SchemaBuilder = void 0;
|
|
|
38
38
|
* SchemaBuilder v4.0
|
|
39
39
|
* Auto-detects CREATE / ALTER / DROP COLUMN schema differences
|
|
40
40
|
* ============================================================ */
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
41
|
+
const SchemaBlueprint_js_1 = require("./SchemaBlueprint.js");
|
|
42
|
+
const SQLDialect_js_1 = require("./SQLDialect.js");
|
|
43
|
+
const database_js_1 = require("../../config/database.js");
|
|
44
44
|
class SchemaBuilder {
|
|
45
45
|
static async toCreateSQL(tableName, schema, explicitDialect, smartUpdate = false, connectionNameOverride, forceCreate = false) {
|
|
46
46
|
const supportedDialects = ["mysql", "pg", "sqlite"];
|
|
47
47
|
let dialectName = supportedDialects.includes(explicitDialect)
|
|
48
48
|
? explicitDialect
|
|
49
|
-
: (
|
|
49
|
+
: (database_js_1.dbConfig.default || "mysql");
|
|
50
50
|
if (!supportedDialects.includes(dialectName)) {
|
|
51
|
-
const maybe = explicitDialect ?
|
|
51
|
+
const maybe = explicitDialect ? database_js_1.dbConfig.connections[explicitDialect] : undefined;
|
|
52
52
|
const driver = maybe?.driver;
|
|
53
53
|
if (driver && supportedDialects.includes(driver)) {
|
|
54
54
|
dialectName = driver;
|
|
@@ -57,8 +57,8 @@ class SchemaBuilder {
|
|
|
57
57
|
if (!supportedDialects.includes(dialectName)) {
|
|
58
58
|
throw new Error(`ERROR: Unsupported dialect: ${explicitDialect}`);
|
|
59
59
|
}
|
|
60
|
-
const dialect = new
|
|
61
|
-
const errors = (0,
|
|
60
|
+
const dialect = new SQLDialect_js_1.SQLDialect(dialectName);
|
|
61
|
+
const errors = (0, SchemaBlueprint_js_1.validateSchema)(schema);
|
|
62
62
|
if (errors.length > 0)
|
|
63
63
|
throw new Error(`ERROR: Schema validation failed for ${tableName}:\n${errors.join("\n")}`);
|
|
64
64
|
const columns = [];
|
|
@@ -137,7 +137,7 @@ class SchemaBuilder {
|
|
|
137
137
|
let introspectionAdapter = null;
|
|
138
138
|
if (!forceCreate) {
|
|
139
139
|
try {
|
|
140
|
-
const { getAdapter } = await Promise.resolve().then(() => __importStar(require("../connection/ConnectionFactory")));
|
|
140
|
+
const { getAdapter } = await Promise.resolve().then(() => __importStar(require("../connection/ConnectionFactory.js")));
|
|
141
141
|
const adapter = await getAdapter((connectionNameOverride || dialectName));
|
|
142
142
|
introspectionAdapter = adapter;
|
|
143
143
|
if (dialectName === "mysql") {
|
|
@@ -321,7 +321,7 @@ class SchemaBuilder {
|
|
|
321
321
|
static toDropSQL(tableName, schema, dialectName = "mysql") {
|
|
322
322
|
const dropSQL = [];
|
|
323
323
|
const pivotTables = [];
|
|
324
|
-
const dialect = new
|
|
324
|
+
const dialect = new SQLDialect_js_1.SQLDialect(dialectName);
|
|
325
325
|
for (const [, field] of Object.entries(schema)) {
|
|
326
326
|
if (field.kind === "relation" && field.relation === "belongsToMany" && field.model) {
|
|
327
327
|
const modelA = tableName.toLowerCase();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 🧠 SchemaValidator
|
|
3
3
|
* Runtime validation engine for models with hooks and custom rules.
|
|
4
4
|
*/
|
|
5
|
-
import type { ValidationRule } from "./SchemaBlueprint";
|
|
5
|
+
import type { ValidationRule } from "./SchemaBlueprint.js";
|
|
6
6
|
export interface ValidationError {
|
|
7
7
|
field: string;
|
|
8
8
|
message: string;
|
|
@@ -7,12 +7,12 @@ exports.EnvKeySecurity = void 0;
|
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
9
|
const readline_1 = __importDefault(require("readline"));
|
|
10
|
-
const
|
|
10
|
+
const AbstractSecurity_js_1 = require("./AbstractSecurity.js");
|
|
11
11
|
/**
|
|
12
12
|
* 🔑 EnvKeySecurity
|
|
13
13
|
* Requires a migration key from environment and user confirmation.
|
|
14
14
|
*/
|
|
15
|
-
class EnvKeySecurity extends
|
|
15
|
+
class EnvKeySecurity extends AbstractSecurity_js_1.AbstractSecurity {
|
|
16
16
|
async init() {
|
|
17
17
|
this.hashKey = process.env.ELOQUENT_MIGRATION_KEY
|
|
18
18
|
? crypto_1.default.createHash("sha256").update(process.env.ELOQUENT_MIGRATION_KEY).digest("hex")
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NoSecurity = void 0;
|
|
4
|
-
const
|
|
4
|
+
const AbstractSecurity_js_1 = require("./AbstractSecurity.js");
|
|
5
5
|
/**
|
|
6
6
|
* 🚧 NoSecurity
|
|
7
7
|
* Used when no security checks are required (e.g., local dev or testing).
|
|
8
8
|
*/
|
|
9
|
-
class NoSecurity extends
|
|
9
|
+
class NoSecurity extends AbstractSecurity_js_1.AbstractSecurity {
|
|
10
10
|
async confirmPrivilege() {
|
|
11
11
|
return true; // Always allow
|
|
12
12
|
}
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SecurityFactory = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const EnvKeySecurity_js_1 = require("./EnvKeySecurity.js");
|
|
8
|
+
const NoSecurity_js_1 = require("./NoSecurity.js");
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
10
|
/**
|
|
11
11
|
* 🧠 SecurityFactory
|
|
@@ -17,11 +17,11 @@ class SecurityFactory {
|
|
|
17
17
|
switch (mode.toLowerCase()) {
|
|
18
18
|
case "envkey":
|
|
19
19
|
console.log(chalk_1.default.gray("🔐 Security mode: EnvKey"));
|
|
20
|
-
return new
|
|
20
|
+
return new EnvKeySecurity_js_1.EnvKeySecurity();
|
|
21
21
|
case "none":
|
|
22
22
|
default:
|
|
23
23
|
console.log(chalk_1.default.gray("🔓 Security mode: Disabled (NoSecurity)"));
|
|
24
|
-
return new
|
|
24
|
+
return new NoSecurity_js_1.NoSecurity();
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from "./SecurityContract";
|
|
2
|
-
export * from "./AbstractSecurity";
|
|
3
|
-
export * from "./NoSecurity";
|
|
4
|
-
export * from "./EnvKeySecurity";
|
|
5
|
-
export * from "./SecurityFactory";
|
|
1
|
+
export * from "./SecurityContract.js";
|
|
2
|
+
export * from "./AbstractSecurity.js";
|
|
3
|
+
export * from "./NoSecurity.js";
|
|
4
|
+
export * from "./EnvKeySecurity.js";
|
|
5
|
+
export * from "./SecurityFactory.js";
|
|
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./SecurityContract"), exports);
|
|
18
|
-
__exportStar(require("./AbstractSecurity"), exports);
|
|
19
|
-
__exportStar(require("./NoSecurity"), exports);
|
|
20
|
-
__exportStar(require("./EnvKeySecurity"), exports);
|
|
21
|
-
__exportStar(require("./SecurityFactory"), exports);
|
|
17
|
+
__exportStar(require("./SecurityContract.js"), exports);
|
|
18
|
+
__exportStar(require("./AbstractSecurity.js"), exports);
|
|
19
|
+
__exportStar(require("./NoSecurity.js"), exports);
|
|
20
|
+
__exportStar(require("./EnvKeySecurity.js"), exports);
|
|
21
|
+
__exportStar(require("./SecurityFactory.js"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* Only exports from this file are semver-tracked and supported for consumers.
|
|
4
4
|
* Deep imports into internal `dist/core/*`, `dist/cli/*`, or `src/*` paths are private.
|
|
5
5
|
*/
|
|
6
|
-
export { BaseModel, Model, SqlModel, MongoModel, MorphRegistry, type ORMRecord, type ModelAttrs, type ModelInstance, type TypedRelation, type PivotRelation, } from "./core/model/BaseModel";
|
|
7
|
-
export { PivotHelperMixin } from "./core/orm/mixins/PivotHelperMixin";
|
|
8
|
-
export { Factory, type PlainObject, type ModelCtor, type FactoryCtor, } from "./cli/utils/factories/Factory";
|
|
9
|
-
export { CoreModel, type ModelEventHooks, } from "./core/model/CoreModel";
|
|
10
|
-
export { column, validate, relation, mixin, validateSchema, type ColumnType, type ColumnOptions, type ValidationRule, type RelationType, type RelationOptions, type MixinName, type MixinDefinition, type ColumnDefinition, type RelationDefinition, type SchemaField, } from "./core/schema/SchemaBlueprint";
|
|
11
|
-
export { SchemaValidator, type ValidationError, type SchemaValidatorOptions, type ValidationHooks, type CustomRuleFunction, type CustomRuleResult, } from "./core/schema/SchemaValidator";
|
|
12
|
-
export { SchemaBuilder, type SchemaBuildResult } from "./core/schema/SchemaBuilder";
|
|
13
|
-
export { CacheManager } from "./core/cache/CacheManager";
|
|
14
|
-
export { setupCache } from "./core/cache/setupCache";
|
|
15
|
-
export { registerModels, isModelRegistered, setModelRegistryStrictMode, isModelRegistryStrictMode, type RegisterModelsOptions, } from "./core/orm/mixins/utils/modelRegistration";
|
|
6
|
+
export { BaseModel, Model, SqlModel, MongoModel, MorphRegistry, type ORMRecord, type ModelAttrs, type ModelInstance, type TypedRelation, type PivotRelation, } from "./core/model/BaseModel.js";
|
|
7
|
+
export { PivotHelperMixin } from "./core/orm/mixins/PivotHelperMixin.js";
|
|
8
|
+
export { Factory, type PlainObject, type ModelCtor, type FactoryCtor, } from "./cli/utils/factories/Factory.js";
|
|
9
|
+
export { CoreModel, type ModelEventHooks, } from "./core/model/CoreModel.js";
|
|
10
|
+
export { column, validate, relation, mixin, validateSchema, type ColumnType, type ColumnOptions, type ValidationRule, type RelationType, type RelationOptions, type MixinName, type MixinDefinition, type ColumnDefinition, type RelationDefinition, type SchemaField, } from "./core/schema/SchemaBlueprint.js";
|
|
11
|
+
export { SchemaValidator, type ValidationError, type SchemaValidatorOptions, type ValidationHooks, type CustomRuleFunction, type CustomRuleResult, } from "./core/schema/SchemaValidator.js";
|
|
12
|
+
export { SchemaBuilder, type SchemaBuildResult } from "./core/schema/SchemaBuilder.js";
|
|
13
|
+
export { CacheManager } from "./core/cache/CacheManager.js";
|
|
14
|
+
export { setupCache } from "./core/cache/setupCache.js";
|
|
15
|
+
export { registerModels, isModelRegistered, setModelRegistryStrictMode, isModelRegistryStrictMode, type RegisterModelsOptions, } from "./core/orm/mixins/utils/modelRegistration.js";
|