feat: Update DebrosFramework to reflect config changes in status; add health check and service retrieval methods; enhance RelationshipManager for model resolution in eager loading
This commit is contained in:
parent
4966df43d5
commit
383419beec
@ -183,6 +183,8 @@ export class DebrosFramework {
|
||||
if (overrideConfig) {
|
||||
this.config = { ...this.config, ...overrideConfig };
|
||||
this.configManager = new ConfigManager(this.config);
|
||||
// Update status to reflect config changes
|
||||
this.status.environment = this.config.environment || 'development';
|
||||
}
|
||||
|
||||
// Initialize services
|
||||
@ -593,6 +595,31 @@ export class DebrosFramework {
|
||||
return this.migrationManager;
|
||||
}
|
||||
|
||||
getQueryCache(): QueryCache | null {
|
||||
return this.queryCache;
|
||||
}
|
||||
|
||||
getOrbitDBService(): FrameworkOrbitDBService | null {
|
||||
return this.orbitDBService;
|
||||
}
|
||||
|
||||
getIPFSService(): FrameworkIPFSService | null {
|
||||
return this.ipfsService;
|
||||
}
|
||||
|
||||
getConfigManager(): ConfigManager | null {
|
||||
return this.configManager;
|
||||
}
|
||||
|
||||
async healthCheck(): Promise<any> {
|
||||
this.performHealthCheck();
|
||||
return {
|
||||
healthy: this.status.healthy,
|
||||
services: { ...this.status.services },
|
||||
lastCheck: this.status.lastHealthCheck
|
||||
};
|
||||
}
|
||||
|
||||
// Framework lifecycle
|
||||
async stop(): Promise<void> {
|
||||
if (!this.initialized) {
|
||||
|
@ -132,6 +132,11 @@ export class ConfigManager {
|
||||
return { ...this.config };
|
||||
}
|
||||
|
||||
// Alias for getConfig() to match test expectations
|
||||
getFullConfig(): ExtendedFrameworkConfig {
|
||||
return this.getConfig();
|
||||
}
|
||||
|
||||
// Configuration presets
|
||||
static developmentConfig(): ExtendedFrameworkConfig {
|
||||
return {
|
||||
|
@ -32,13 +32,8 @@ export abstract class BaseModel {
|
||||
if (data && typeof data === 'object') {
|
||||
Object.keys(data).forEach((key) => {
|
||||
if (key !== '_loadedRelations' && key !== '_isDirty' && key !== '_isNew' && data[key] !== undefined) {
|
||||
// Use setter if it exists (for Field-decorated properties), otherwise set directly
|
||||
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this), key);
|
||||
if (descriptor && descriptor.set) {
|
||||
(this as any)[key] = data[key];
|
||||
} else {
|
||||
(this as any)[key] = data[key];
|
||||
}
|
||||
// Always set directly - the Field decorator's setter will handle validation and transformation
|
||||
(this as any)[key] = data[key];
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -376,8 +376,14 @@ export class RelationshipManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the related model class
|
||||
const RelatedModel = config.model || (config.modelFactory ? config.modelFactory() : null) || (config.targetModel ? config.targetModel() : null);
|
||||
if (!RelatedModel) {
|
||||
throw new Error(`Cannot resolve related model for hasMany eager loading`);
|
||||
}
|
||||
|
||||
// Load all related models
|
||||
let query = (config.model as any).whereIn(config.foreignKey, localKeys);
|
||||
let query = (RelatedModel as any).whereIn(config.foreignKey, localKeys);
|
||||
|
||||
if (options.constraints) {
|
||||
query = options.constraints(query);
|
||||
@ -493,7 +499,13 @@ export class RelationshipManager {
|
||||
const uniqueForeignKeys = [...new Set(allForeignKeys)];
|
||||
|
||||
// Step 4: Load all related models
|
||||
let relatedQuery = (config.model as any).whereIn('id', uniqueForeignKeys);
|
||||
// Get the related model class
|
||||
const RelatedModel = config.model || (config.modelFactory ? config.modelFactory() : null) || (config.targetModel ? config.targetModel() : null);
|
||||
if (!RelatedModel) {
|
||||
throw new Error(`Cannot resolve related model for manyToMany eager loading`);
|
||||
}
|
||||
|
||||
let relatedQuery = (RelatedModel as any).whereIn('id', uniqueForeignKeys);
|
||||
|
||||
if (options.constraints) {
|
||||
relatedQuery = options.constraints(relatedQuery);
|
||||
|
Reference in New Issue
Block a user