import { BasicDB, Collection, RemoteDBConfig } from './types' import { RemoteCollection } from './RemoteCollection' /** * RemoteDB - REST API based implementation of BasicDB * Creates RemoteCollection instances for each table */ export class RemoteDB implements BasicDB { private config: RemoteDBConfig private collections: Map> = new Map() constructor(config: RemoteDBConfig) { this.config = config } /** * Get a collection by name * Collections are cached for reuse */ collection & { id: string }>( name: string ): Collection { // Return cached collection if exists if (this.collections.has(name)) { return this.collections.get(name) as RemoteCollection } // Validate table exists in schema if schema is provided if (this.config.schema?.tables && !this.config.schema.tables[name]) { throw new Error(`Table "${name}" not found in schema`) } // Create and cache new collection const collection = new RemoteCollection(name, this.config) this.collections.set(name, collection) return collection } }