This repository has been archived on 2026-09-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
open-brainy/src/browserFramework.minimal.ts
David Snelling 93804be354 feat: add universal adapters for browser compatibility
- Create universal adapters for cross-platform support (browser/Node/serverless)
- Replace Node.js-specific imports with universal implementations
- Add OPFS support for browser persistent storage
- Maintain same BrainyData interface across all environments
- Enable real Brainy usage in browser console UI
- Keep package size optimized (no bloat)

Universal adapters in /src/universal/:
- uuid.ts: Cross-platform UUID generation
- crypto.ts: Browser/Node crypto operations
- fs.ts: OPFS/FileSystem/Memory storage adapter
- path.ts: Universal path operations
- events.ts: EventEmitter compatibility layer

This enables 'write once, run anywhere' for Brainy while maintaining
the exact same API. No breaking changes to existing code.
2025-08-08 15:22:38 -07:00

35 lines
No EOL
1.2 KiB
TypeScript

/**
* Minimal Browser Framework Entry Point for Brainy
* Core MIT open source functionality only - no enterprise features
* Optimized for browser usage with all dependencies bundled
*/
import { BrainyData } from './brainyData.js'
import { VerbType, NounType } from './types/graphTypes.js'
/**
* Create a BrainyData instance optimized for browser usage
* Auto-detects environment and selects optimal storage and settings
*/
export async function createBrowserBrainyData(config = {}) {
// BrainyData already has environment detection and will automatically:
// - Use OPFS storage in browsers with fallback to Memory
// - Use FileSystem storage in Node.js
// - Request persistent storage when appropriate
const browserConfig = {
storage: {
requestPersistentStorage: true // Request persistent storage for better performance
},
...config
}
const brainyData = new BrainyData(browserConfig)
await brainyData.init()
return brainyData
}
// Re-export core types and classes for browser use
export { VerbType, NounType, BrainyData }
// Default export for easy importing
export default createBrowserBrainyData