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) {
|
if (overrideConfig) {
|
||||||
this.config = { ...this.config, ...overrideConfig };
|
this.config = { ...this.config, ...overrideConfig };
|
||||||
this.configManager = new ConfigManager(this.config);
|
this.configManager = new ConfigManager(this.config);
|
||||||
|
// Update status to reflect config changes
|
||||||
|
this.status.environment = this.config.environment || 'development';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize services
|
// Initialize services
|
||||||
@ -593,6 +595,31 @@ export class DebrosFramework {
|
|||||||
return this.migrationManager;
|
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
|
// Framework lifecycle
|
||||||
async stop(): Promise<void> {
|
async stop(): Promise<void> {
|
||||||
if (!this.initialized) {
|
if (!this.initialized) {
|
||||||
|
@ -132,6 +132,11 @@ export class ConfigManager {
|
|||||||
return { ...this.config };
|
return { ...this.config };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Alias for getConfig() to match test expectations
|
||||||
|
getFullConfig(): ExtendedFrameworkConfig {
|
||||||
|
return this.getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
// Configuration presets
|
// Configuration presets
|
||||||
static developmentConfig(): ExtendedFrameworkConfig {
|
static developmentConfig(): ExtendedFrameworkConfig {
|
||||||
return {
|
return {
|
||||||
|
@ -32,13 +32,8 @@ export abstract class BaseModel {
|
|||||||
if (data && typeof data === 'object') {
|
if (data && typeof data === 'object') {
|
||||||
Object.keys(data).forEach((key) => {
|
Object.keys(data).forEach((key) => {
|
||||||
if (key !== '_loadedRelations' && key !== '_isDirty' && key !== '_isNew' && data[key] !== undefined) {
|
if (key !== '_loadedRelations' && key !== '_isDirty' && key !== '_isNew' && data[key] !== undefined) {
|
||||||
// Use setter if it exists (for Field-decorated properties), otherwise set directly
|
// Always set directly - the Field decorator's setter will handle validation and transformation
|
||||||
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this), key);
|
|
||||||
if (descriptor && descriptor.set) {
|
|
||||||
(this as any)[key] = data[key];
|
(this as any)[key] = data[key];
|
||||||
} else {
|
|
||||||
(this as any)[key] = data[key];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -376,8 +376,14 @@ export class RelationshipManager {
|
|||||||
return;
|
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
|
// 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) {
|
if (options.constraints) {
|
||||||
query = options.constraints(query);
|
query = options.constraints(query);
|
||||||
@ -493,7 +499,13 @@ export class RelationshipManager {
|
|||||||
const uniqueForeignKeys = [...new Set(allForeignKeys)];
|
const uniqueForeignKeys = [...new Set(allForeignKeys)];
|
||||||
|
|
||||||
// Step 4: Load all related models
|
// 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) {
|
if (options.constraints) {
|
||||||
relatedQuery = options.constraints(relatedQuery);
|
relatedQuery = options.constraints(relatedQuery);
|
||||||
|
Reference in New Issue
Block a user