From 1481bd8594f2820649382d67b7eff9a76b42c756 Mon Sep 17 00:00:00 2001 From: anonpenguin Date: Wed, 2 Jul 2025 07:45:55 +0300 Subject: [PATCH] fix: Enhance initialization checks in FrameworkOrbitDBService and FrameworkIPFSService; add tsconfig.docker.json for integration tests --- src/framework/services/OrbitDBService.ts | 28 +++++++++++++++++-- .../blog-scenario/docker/tsconfig.docker.json | 25 +++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/real-integration/blog-scenario/docker/tsconfig.docker.json diff --git a/src/framework/services/OrbitDBService.ts b/src/framework/services/OrbitDBService.ts index 30a6651..4f539a5 100644 --- a/src/framework/services/OrbitDBService.ts +++ b/src/framework/services/OrbitDBService.ts @@ -21,9 +21,18 @@ export interface IPFSInstance { export class FrameworkOrbitDBService { private orbitDBService: OrbitDBInstance; + private initialized: boolean = false; constructor(orbitDBService: OrbitDBInstance) { this.orbitDBService = orbitDBService; + // Check if the service is already initialized by trying to get OrbitDB + try { + if (orbitDBService.getOrbitDB && orbitDBService.getOrbitDB()) { + this.initialized = true; + } + } catch (error) { + // Service not initialized yet + } } async openDatabase(name: string, type: StoreType): Promise { @@ -31,7 +40,10 @@ export class FrameworkOrbitDBService { } async init(): Promise { - await this.orbitDBService.init(); + if (!this.initialized) { + await this.orbitDBService.init(); + this.initialized = true; + } } async stop(): Promise { @@ -47,13 +59,25 @@ export class FrameworkOrbitDBService { export class FrameworkIPFSService { private ipfsService: IPFSInstance; + private initialized: boolean = false; constructor(ipfsService: IPFSInstance) { this.ipfsService = ipfsService; + // Check if the service is already initialized by trying to get Helia + try { + if (ipfsService.getHelia && ipfsService.getHelia()) { + this.initialized = true; + } + } catch (error) { + // Service not initialized yet + } } async init(): Promise { - await this.ipfsService.init(); + if (!this.initialized) { + await this.ipfsService.init(); + this.initialized = true; + } } async stop(): Promise { diff --git a/tests/real-integration/blog-scenario/docker/tsconfig.docker.json b/tests/real-integration/blog-scenario/docker/tsconfig.docker.json new file mode 100644 index 0000000..e6ca8f2 --- /dev/null +++ b/tests/real-integration/blog-scenario/docker/tsconfig.docker.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ES2020", + "moduleResolution": "bundler", + "esModuleInterop": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "strictPropertyInitialization": false, + "skipLibCheck": true, + "outDir": "dist", + "isolatedModules": true, + "removeComments": true, + "inlineSources": true, + "sourceMap": true, + "allowJs": true, + "strict": true, + "importsNotUsedAsValues": "remove", + "baseUrl": "../../../../" + }, + "include": ["blog-api-server.ts", "../../../../src/**/*"], + "ts-node": { + "esm": true + } +}