@alpha.consultings/eloquent-orm.js 1.0.10 → 1.1.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.
- package/CHANGELOG.md +16 -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 +19 -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 +30 -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/TypeScriptCompiler.js +0 -1
- package/dist/cli/utils/typescript/tsRuntime.js +26 -4
- 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 +31 -30
- 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 +6 -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/SchemaBlueprint.d.ts +21 -0
- package/dist/core/schema/SchemaBuilder.d.ts +16 -3
- package/dist/core/schema/SchemaBuilder.js +191 -48
- 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]);
|
|
@@ -35,6 +35,27 @@ export interface RelationOptions {
|
|
|
35
35
|
idColumn?: string;
|
|
36
36
|
cascade?: boolean;
|
|
37
37
|
}
|
|
38
|
+
export type RelationalAction = "CASCADE" | "RESTRICT" | "SET NULL" | "NO ACTION" | "SET DEFAULT";
|
|
39
|
+
export interface DatabaseForeignKeyDefinition {
|
|
40
|
+
name?: string;
|
|
41
|
+
column: string;
|
|
42
|
+
references: {
|
|
43
|
+
table: string;
|
|
44
|
+
column?: string;
|
|
45
|
+
};
|
|
46
|
+
onDelete?: RelationalAction;
|
|
47
|
+
onUpdate?: RelationalAction;
|
|
48
|
+
}
|
|
49
|
+
export interface DatabaseIndexDefinition {
|
|
50
|
+
name?: string;
|
|
51
|
+
columns: string[];
|
|
52
|
+
unique?: boolean;
|
|
53
|
+
where?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface ModelDatabaseDefinition {
|
|
56
|
+
foreignKeys?: DatabaseForeignKeyDefinition[];
|
|
57
|
+
indexes?: DatabaseIndexDefinition[];
|
|
58
|
+
}
|
|
38
59
|
export type MixinName = "SoftDeletes" | "Casts" | "EagerLoading" | "Hooks" | "Scope" | "QueryCache" | "Serialize" | "PivotHelper";
|
|
39
60
|
export interface MixinDefinition {
|
|
40
61
|
kind: "mixin";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SchemaField } from "./SchemaBlueprint";
|
|
2
|
-
import { Dialect } from "./SQLDialect";
|
|
1
|
+
import { SchemaField, ModelDatabaseDefinition } from "./SchemaBlueprint.js";
|
|
2
|
+
import { Dialect } from "./SQLDialect.js";
|
|
3
3
|
export interface SchemaBuildResult {
|
|
4
4
|
mainSQL: string;
|
|
5
5
|
extraTables: string[];
|
|
@@ -7,7 +7,7 @@ export interface SchemaBuildResult {
|
|
|
7
7
|
rollbackExtraTables: string[];
|
|
8
8
|
}
|
|
9
9
|
export declare class SchemaBuilder {
|
|
10
|
-
static toCreateSQL(tableName: string, schema: Record<string, SchemaField>, explicitDialect?: Dialect | string, smartUpdate?: boolean, connectionNameOverride?: string, forceCreate?: boolean): Promise<SchemaBuildResult>;
|
|
10
|
+
static toCreateSQL(tableName: string, schema: Record<string, SchemaField>, explicitDialect?: Dialect | string, smartUpdate?: boolean, connectionNameOverride?: string, forceCreate?: boolean, database?: ModelDatabaseDefinition): Promise<SchemaBuildResult>;
|
|
11
11
|
static toDropSQL(tableName: string, schema: Record<string, SchemaField>, dialectName?: Dialect): string[];
|
|
12
12
|
private static columnSQL;
|
|
13
13
|
private static relationSQL;
|
|
@@ -19,10 +19,23 @@ export declare class SchemaBuilder {
|
|
|
19
19
|
private static referencedTableName;
|
|
20
20
|
private static foreignKeyConstraintName;
|
|
21
21
|
private static foreignKeyConstraintKey;
|
|
22
|
+
private static normalizeRelationalAction;
|
|
23
|
+
private static appendForeignKeyActions;
|
|
22
24
|
private static foreignKeyConstraintDefinition;
|
|
25
|
+
private static databaseForeignKeyConstraintDefinition;
|
|
26
|
+
private static indexKey;
|
|
27
|
+
private static defaultIndexName;
|
|
28
|
+
private static indexDefinition;
|
|
23
29
|
private static mysqlForeignKeys;
|
|
24
30
|
private static pgForeignKeys;
|
|
31
|
+
private static mysqlIndexes;
|
|
32
|
+
private static parsePgIndexDefinition;
|
|
33
|
+
private static pgIndexes;
|
|
25
34
|
private static sqliteForeignKeys;
|
|
35
|
+
private static sqliteIndexes;
|
|
36
|
+
private static sqliteExistingIndex;
|
|
37
|
+
private static sqliteIndexColumnNames;
|
|
38
|
+
private static compareSqliteIndexColumnSeqno;
|
|
26
39
|
private static pivotTableExists;
|
|
27
40
|
private static mixinSQL;
|
|
28
41
|
}
|