**feat: add browser-compatible exports and define BrainyData interface**

### Changes:
- Created `examples/browser_compatible_exports.ts`:
  - Introduced browser-friendly exports with polyfill for `Buffer` in browser environments.
  - Implemented shims for Node.js modules (`fs`, `util`, and `path`) to avoid compatibility issues.
  - Exported browser-compatible types and utilities: `BrainyData`, `NounType`, `VerbType`, graph types, core types, distance functions, embedding utilities, and storage adapters.
  - Explicitly excluded Node.js/CLI-specific parts to focus on browser compatibility.
- Added `src/types/brainyDataInterface.ts`:
  - Defined `BrainyDataInterface` to break the circular dependency between `brainyData.ts` and `serverSearchAugmentations.ts`.
  - Provided methods for managing nodes, relationships, initialization, search, and adding vector data with metadata.

### Purpose:
- Enhanced the codebase to support browser environments by introducing browser-specific exports and avoiding Node.js dependencies.
- Established clearer separation of concerns and modularity by introducing the `BrainyDataInterface` for dependency management, improving maintainability and flexibility.
This commit is contained in:
David Snelling 2025-06-19 15:00:41 -07:00
parent cbc007b6cf
commit 755b1a6fc1
2 changed files with 116 additions and 0 deletions

View file

@ -0,0 +1,47 @@
/**
* BrainyDataInterface
*
* This interface defines the methods from BrainyData that are used by serverSearchAugmentations.ts.
* It's used to break the circular dependency between brainyData.ts and serverSearchAugmentations.ts.
*/
import { Vector } from '../coreTypes.js'
export interface BrainyDataInterface<T = unknown> {
/**
* Initialize the database
*/
init(): Promise<void>
/**
* Get a noun by ID
* @param id The ID of the noun to get
*/
get(id: string): Promise<unknown>
/**
* Add a vector or data to the database
* @param vectorOrData Vector or data to add
* @param metadata Optional metadata to associate with the vector
* @returns The ID of the added vector
*/
add(vectorOrData: Vector | unknown, metadata?: T): Promise<string>
/**
* Search for text in the database
* @param text The text to search for
* @param limit Maximum number of results to return
* @returns Search results
*/
searchText(text: string, limit?: number): Promise<unknown[]>
/**
* Create a relationship between two entities
* @param sourceId The ID of the source entity
* @param targetId The ID of the target entity
* @param relationType The type of relationship
* @param metadata Optional metadata about the relationship
* @returns The ID of the created relationship
*/
relate(sourceId: string, targetId: string, relationType: string, metadata?: unknown): Promise<string>
}