feat: update import statements to use TypeScript file extensions

This commit is contained in:
David Snelling 2025-05-29 08:27:59 -07:00
parent 61d86c98a7
commit 7d2b695ea0
10 changed files with 35 additions and 35 deletions

View file

@ -4,19 +4,19 @@
*/ */
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { HNSWIndex } from './hnsw/hnswIndex.js' import { HNSWIndex } from './hnsw/hnswIndex.ts'
import { createStorage } from './storage/opfsStorage.js' import { createStorage } from './storage/opfsStorage.ts'
import { import {
DistanceFunction, DistanceFunction,
Edge, Edge,
EmbeddingFunction, EmbeddingFunction,
HNSWConfig, HNSWConfig, HNSWNode,
SearchResult, SearchResult,
StorageAdapter, StorageAdapter,
Vector, Vector,
VectorDocument VectorDocument
} from './coreTypes.js' } from './coreTypes.ts'
import { cosineDistance, defaultEmbeddingFunction, euclideanDistance } from './utils/index.js' import { cosineDistance, defaultEmbeddingFunction, euclideanDistance } from './utils/index.ts'
export interface BrainyDataConfig { export interface BrainyDataConfig {
/** /**
@ -94,7 +94,7 @@ export class BrainyData<T = any> {
await this.storage!.init() await this.storage!.init()
// Load all nodes from storage // Load all nodes from storage
const nodes = await this.storage!.getAllNodes() const nodes: HNSWNode[] = await this.storage!.getAllNodes()
// Clear the index and add all nodes // Clear the index and add all nodes
this.index.clear() this.index.clear()
@ -631,12 +631,12 @@ export class BrainyData<T = any> {
// Check if the storage adapter has a getStorageStatus method // Check if the storage adapter has a getStorageStatus method
if (typeof this.storage.getStorageStatus !== 'function') { if (typeof this.storage.getStorageStatus !== 'function') {
// If not, determine the storage type based on the constructor name // If not, determine the storage type based on the constructor name
const storageType = this.storage.constructor.name.toLowerCase().replace('storage', ''); const storageType = this.storage.constructor.name.toLowerCase().replace('storage', '')
return { return {
type: storageType || 'unknown', type: storageType || 'unknown',
used: 0, used: 0,
quota: null, quota: null,
details: { details: {
error: 'Storage adapter does not implement getStorageStatus method', error: 'Storage adapter does not implement getStorageStatus method',
storageAdapter: this.storage.constructor.name, storageAdapter: this.storage.constructor.name,
indexSize: this.size() indexSize: this.size()
@ -666,13 +666,13 @@ export class BrainyData<T = any> {
console.error('Failed to get storage status:', error) console.error('Failed to get storage status:', error)
// Determine the storage type based on the constructor name // Determine the storage type based on the constructor name
const storageType = this.storage.constructor.name.toLowerCase().replace('storage', ''); const storageType = this.storage.constructor.name.toLowerCase().replace('storage', '')
return { return {
type: storageType || 'unknown', type: storageType || 'unknown',
used: 0, used: 0,
quota: null, quota: null,
details: { details: {
error: String(error), error: String(error),
storageAdapter: this.storage.constructor.name, storageAdapter: this.storage.constructor.name,
indexSize: this.size() indexSize: this.size()

View file

@ -2,7 +2,7 @@
* Basic usage example for the Soulcraft Brainy database * Basic usage example for the Soulcraft Brainy database
*/ */
import { BrainyData } from '../brainyData.js' import { BrainyData } from '../brainyData.ts'
// Example data - word embeddings // Example data - word embeddings
const wordEmbeddings = { const wordEmbeddings = {

View file

@ -3,8 +3,8 @@
* Based on the paper: "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs" * Based on the paper: "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs"
*/ */
import { DistanceFunction, HNSWConfig, HNSWNode, Vector, VectorDocument } from '../coreTypes.js' import { DistanceFunction, HNSWConfig, HNSWNode, Vector, VectorDocument } from '../coreTypes.ts'
import { euclideanDistance } from '../utils/index.js' import { euclideanDistance } from '../utils/index.ts'
// Default HNSW parameters // Default HNSW parameters
const DEFAULT_CONFIG: HNSWConfig = { const DEFAULT_CONFIG: HNSWConfig = {

View file

@ -4,7 +4,7 @@
*/ */
// Export main BrainyData class and related types // Export main BrainyData class and related types
import { BrainyData, BrainyDataConfig } from './brainyData.js' import { BrainyData, BrainyDataConfig } from './brainyData.ts'
export { BrainyData } export { BrainyData }
export type { BrainyDataConfig } export type { BrainyDataConfig }
@ -14,7 +14,7 @@ import {
cosineDistance, cosineDistance,
manhattanDistance, manhattanDistance,
dotProductDistance dotProductDistance
} from './utils/index.js' } from './utils/index.ts'
export { export {
euclideanDistance, euclideanDistance,
cosineDistance, cosineDistance,
@ -30,7 +30,7 @@ import {
createTensorFlowEmbeddingFunction, createTensorFlowEmbeddingFunction,
createSimpleEmbeddingFunction, createSimpleEmbeddingFunction,
defaultEmbeddingFunction defaultEmbeddingFunction
} from './utils/embedding.js' } from './utils/embedding.ts'
export { export {
SimpleEmbedding, SimpleEmbedding,
UniversalSentenceEncoder, UniversalSentenceEncoder,
@ -45,7 +45,7 @@ import {
OPFSStorage, OPFSStorage,
MemoryStorage, MemoryStorage,
createStorage createStorage
} from './storage/opfsStorage.js' } from './storage/opfsStorage.ts'
export { export {
OPFSStorage, OPFSStorage,
MemoryStorage, MemoryStorage,
@ -58,7 +58,7 @@ import {
augmentationPipeline, augmentationPipeline,
ExecutionMode, ExecutionMode,
PipelineOptions PipelineOptions
} from './augmentationPipeline.js' } from './augmentationPipeline.ts'
export { export {
AugmentationPipeline, AugmentationPipeline,
augmentationPipeline, augmentationPipeline,
@ -72,12 +72,12 @@ import {
configureAndStartPipeline, configureAndStartPipeline,
createSensePluginConfig, createSensePluginConfig,
createConduitPluginConfig createConduitPluginConfig
} from './pluginLoader.js' } from './pluginLoader.ts'
import type { import type {
PluginLoaderOptions, PluginLoaderOptions,
PluginConfig, PluginConfig,
PluginLoadResult PluginLoadResult
} from './pluginLoader.js' } from './pluginLoader.ts'
export { export {
loadPlugins, loadPlugins,
configureAndStartPipeline, configureAndStartPipeline,
@ -102,7 +102,7 @@ import type {
Edge, Edge,
HNSWConfig, HNSWConfig,
StorageAdapter StorageAdapter
} from './coreTypes.js' } from './coreTypes.ts'
export type { export type {
Vector, Vector,
VectorDocument, VectorDocument,
@ -128,8 +128,8 @@ import type {
IPerceptionAugmentation, IPerceptionAugmentation,
IDialogAugmentation, IDialogAugmentation,
IActivationAugmentation IActivationAugmentation
} from './types/augmentations.js' } from './types/augmentations.ts'
import { AugmentationType, BrainyAugmentations } from './types/augmentations.js' import { AugmentationType, BrainyAugmentations } from './types/augmentations.ts'
export type { export type {
IAugmentation, IAugmentation,
AugmentationResponse, AugmentationResponse,
@ -156,7 +156,7 @@ export type {
IWebSocketDialogAugmentation, IWebSocketDialogAugmentation,
IWebSocketConduitAugmentation, IWebSocketConduitAugmentation,
IWebSocketMemoryAugmentation IWebSocketMemoryAugmentation
} from './types/augmentations.js' } from './types/augmentations.ts'
// Export graph types // Export graph types
import type { import type {
@ -169,8 +169,8 @@ import type {
Event, Event,
Concept, Concept,
Content Content
} from './types/graphTypes.js' } from './types/graphTypes.ts'
import { NounType, VerbType } from './types/graphTypes.js' import { NounType, VerbType } from './types/graphTypes.ts'
export type { export type {
GraphNoun, GraphNoun,
GraphVerb, GraphVerb,

View file

@ -1,4 +1,4 @@
import { Edge, HNSWNode, StorageAdapter } from '../coreTypes.js' import { Edge, HNSWNode, StorageAdapter } from '../coreTypes.ts'
// We'll dynamically import Node.js built-in modules // We'll dynamically import Node.js built-in modules
let fs: any let fs: any

View file

@ -3,7 +3,7 @@
* Provides persistent storage for the vector database using the Origin Private File System API * Provides persistent storage for the vector database using the Origin Private File System API
*/ */
import { Edge, HNSWNode, StorageAdapter } from '../coreTypes.js' import { Edge, HNSWNode, StorageAdapter } from '../coreTypes.ts'
// Directory and file names // Directory and file names
const ROOT_DIR = 'opfs-vector-db' const ROOT_DIR = 'opfs-vector-db'
@ -902,7 +902,7 @@ export async function createStorage(options: {
if (isNode) { if (isNode) {
// In Node.js, use FileSystemStorage first, then fall back to memory // In Node.js, use FileSystemStorage first, then fall back to memory
try { try {
const fileSystemModule = await import('./fileSystemStorage.js') const fileSystemModule = await import('./fileSystemStorage.ts')
return new fileSystemModule.FileSystemStorage() return new fileSystemModule.FileSystemStorage()
} catch (error) { } catch (error) {
console.warn('Failed to load FileSystemStorage, falling back to in-memory storage:', error) console.warn('Failed to load FileSystemStorage, falling back to in-memory storage:', error)
@ -928,7 +928,7 @@ export async function createStorage(options: {
try { try {
// Try to load FileSystemStorage for browser environments // Try to load FileSystemStorage for browser environments
// Note: This will likely fail as FileSystemStorage is designed for Node.js // Note: This will likely fail as FileSystemStorage is designed for Node.js
const fileSystemModule = await import('./fileSystemStorage.js') const fileSystemModule = await import('./fileSystemStorage.ts')
return new fileSystemModule.FileSystemStorage() return new fileSystemModule.FileSystemStorage()
} catch (error) { } catch (error) {
console.warn('FileSystem storage is not available, falling back to in-memory storage') console.warn('FileSystem storage is not available, falling back to in-memory storage')

View file

@ -2,7 +2,7 @@
* Distance functions for vector similarity calculations * Distance functions for vector similarity calculations
*/ */
import { DistanceFunction, Vector } from '../coreTypes.js' import { DistanceFunction, Vector } from '../coreTypes.ts'
/** /**
* Calculates the Euclidean distance between two vectors * Calculates the Euclidean distance between two vectors

View file

@ -2,7 +2,7 @@
* Embedding functions for converting data to vectors * Embedding functions for converting data to vectors
*/ */
import { EmbeddingFunction, EmbeddingModel, Vector } from '../coreTypes.js' import { EmbeddingFunction, EmbeddingModel, Vector } from '../coreTypes.ts'
/** /**
* Simple character-based embedding function * Simple character-based embedding function

View file

@ -1,2 +1,2 @@
export * from './distance.js' export * from './distance.ts'
export * from './embedding.js' export * from './embedding.ts'

View file

@ -14,7 +14,7 @@
], ],
"skipLibCheck": true, "skipLibCheck": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"allowImportingTsExtensions": false, "allowImportingTsExtensions": true,
"noEmit": false, "noEmit": false,
"preserveConstEnums": true, "preserveConstEnums": true,
"sourceMap": true "sourceMap": true