feat: Add static count method to BaseModel and enhance OrbitDBService with debugging logs

This commit is contained in:
anonpenguin 2025-07-09 16:00:00 +03:00
parent 9877ddf5ec
commit 9d8a8b1c2c
3 changed files with 43 additions and 7 deletions

View File

@ -306,6 +306,12 @@ export abstract class BaseModel {
return results.length > 0 ? results[0] : null;
}
static async count<T extends BaseModel>(
this: typeof BaseModel & (new (data?: any) => T),
): Promise<number> {
return await new QueryBuilder<T>(this as any).count();
}
// Relationship operations
async load(relationships: string[]): Promise<this> {
const framework = this.getFrameworkInstance();

View File

@ -36,6 +36,15 @@ export class FrameworkOrbitDBService {
}
async openDatabase(name: string, type: StoreType): Promise<any> {
console.log('FrameworkOrbitDBService.openDatabase called with:', { name, type });
console.log('this.orbitDBService:', this.orbitDBService);
console.log('typeof this.orbitDBService.openDB:', typeof this.orbitDBService.openDB);
console.log('this.orbitDBService methods:', Object.getOwnPropertyNames(Object.getPrototypeOf(this.orbitDBService)));
if (typeof this.orbitDBService.openDB !== 'function') {
throw new Error(`openDB is not a function. Service type: ${typeof this.orbitDBService}, methods: ${Object.getOwnPropertyNames(Object.getPrototypeOf(this.orbitDBService))}`);
}
return await this.orbitDBService.openDB(name, type);
}

View File

@ -627,9 +627,6 @@ class BlogAPIServer {
const { OrbitDBService } = await import(
'../../../../src/framework/services/RealOrbitDBService'
);
const { FrameworkIPFSService, FrameworkOrbitDBService } = await import(
'../../../../src/framework/services/OrbitDBService'
);
// Initialize IPFS service
const ipfsService = new IPFSService({
@ -648,9 +645,9 @@ class BlogAPIServer {
await orbitDBService.init();
console.log(`[${this.nodeId}] OrbitDB service initialized`);
// Wrap services for framework
const frameworkIPFS = new FrameworkIPFSService(ipfsService);
const frameworkOrbitDB = new FrameworkOrbitDBService(orbitDBService);
// Debug: Check OrbitDB service methods
console.log(`[${this.nodeId}] OrbitDB service methods:`, Object.getOwnPropertyNames(Object.getPrototypeOf(orbitDBService)));
console.log(`[${this.nodeId}] Has openDB method:`, typeof orbitDBService.openDB === 'function');
// Initialize framework
this.framework = new DebrosFramework({
@ -669,8 +666,32 @@ class BlogAPIServer {
},
});
// Pass raw services to framework - it will wrap them itself
await this.framework.initialize(orbitDBService, ipfsService);
console.log(`[${this.nodeId}] DebrosFramework initialized successfully`);
// Register models with framework
this.framework.registerModel(User, {
scope: 'global',
type: 'docstore'
});
this.framework.registerModel(UserProfile, {
scope: 'global',
type: 'docstore'
});
this.framework.registerModel(Category, {
scope: 'global',
type: 'docstore'
});
this.framework.registerModel(Post, {
scope: 'user',
type: 'docstore'
});
this.framework.registerModel(Comment, {
scope: 'user',
type: 'docstore'
});
console.log(`[${this.nodeId}] Models registered with framework`);
}
}