22
33import { DataLayerProvider } from './core/interfaces' ;
44
5+ interface DBEnv {
6+ COUCHDB_SERVER_URL : string ; // URL of CouchDB server
7+ COUCHDB_SERVER_PROTOCOL : string ; // Protocol of CouchDB server (http or https)
8+ }
9+
10+ export const ENV : DBEnv = {
11+ COUCHDB_SERVER_PROTOCOL : 'NOT_SET' ,
12+ COUCHDB_SERVER_URL : 'NOT_SET' ,
13+ } ;
14+
515// Configuration type for data layer initialization
616export interface DataLayerConfig {
717 type : 'pouch' | 'static' ;
8- options ? : {
18+ options : {
919 staticContentPath ?: string ; // Path to static content JSON files
1020 localStoragePrefix ?: string ; // Prefix for IndexedDB storage names
21+ COUCHDB_SERVER_URL ?: string ;
22+ COUCHDB_SERVER_PROTOCOL ?: string ;
1123 } ;
1224}
1325
@@ -23,8 +35,14 @@ export async function initializeDataLayer(config: DataLayerConfig): Promise<Data
2335 return dataLayerInstance ;
2436 }
2537
26- // Dynamic import to avoid loading both implementations when only one is needed
2738 if ( config . type === 'pouch' ) {
39+ if ( ! config . options . COUCHDB_SERVER_URL || ! config . options . COUCHDB_SERVER_PROTOCOL ) {
40+ throw new Error ( 'Missing CouchDB server URL or protocol' ) ;
41+ }
42+ ENV . COUCHDB_SERVER_PROTOCOL = config . options . COUCHDB_SERVER_PROTOCOL ;
43+ ENV . COUCHDB_SERVER_URL = config . options . COUCHDB_SERVER_URL ;
44+
45+ // Dynamic import to avoid loading both implementations when only one is needed
2846 const { PouchDataLayerProvider } = await import ( './impl/pouch/PouchDataLayerProvider' ) ;
2947 dataLayerInstance = new PouchDataLayerProvider ( ) ;
3048 } else {
0 commit comments