chore(8.0): modernize toolchain + position Bun as a runtime

Consumer-invisible modernization pass — no public API or runtime-behavior
change; dist for the override-only files is byte-identical.

Toolchain:
- CI: GitHub Actions matrix — Node 22/24 (test:unit) + Bun latest (test:bun).
- engines: node ">=22" (was "22.x"), bun ">=1.1.0".
- tsconfig: isolatedModules + noImplicitOverride; add the 33 `override`
  modifiers the flag requires across storage/integrations/vfs/transaction.
- deps: @types/node ^22; add prettier; drop dead standard-version,
  @rollup/plugin-* and the redundant embedded eslintConfig (flat
  eslint.config.js is the active config — verified identical lint output).

paramValidation: replace the top-level `await import('node:os'/'node:fs')`
with static ESM imports. The top-level-await form poisoned the module graph;
static imports also drop the browser/edge fallback branches no supported
runtime reaches (8.0 is Node/Bun/Deno-only).

Bun positioning: recommend Bun as a runtime (`bun add` / `bun run`), which is
green (test:bun 8/8). Drop single-binary `bun build --compile` as a target —
native addons cannot embed into it, and Bun 1.3.10 has a `--compile` codegen
regression around top-level await. Rename the Bun test to bun-runtime-test.ts
and correct docs that overclaimed single-binary support.

Gates: typecheck 0, build 0, test:unit 1743/1743, test:bun 8/8.
This commit is contained in:
David Snelling 2026-07-01 09:16:46 -07:00
parent ae55d54cb5
commit ca9129a924
20 changed files with 159 additions and 2330 deletions

38
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,38 @@
name: CI
on:
push:
pull_request:
jobs:
node:
name: Node ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: ['22', '24']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
- run: npm run test:unit
bun:
name: Bun (latest)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: npm
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- run: npm ci
# Bun as a runtime is the supported Bun story (`bun add` / `bun run`).
- run: npm run test:bun

View file

@ -1,24 +0,0 @@
{
"types": [
{"type": "feat", "section": "✨ Features"},
{"type": "fix", "section": "🐛 Bug Fixes"},
{"type": "docs", "section": "📚 Documentation"},
{"type": "refactor", "section": "♻️ Code Refactoring"},
{"type": "perf", "section": "⚡ Performance Improvements"},
{"type": "test", "section": "✅ Tests"},
{"type": "build", "section": "🔧 Build System"},
{"type": "ci", "section": "🔄 CI/CD"},
{"type": "style", "hidden": true},
{"type": "chore", "hidden": true}
],
"compareUrlFormat": "https://github.com/soulcraftlabs/brainy/compare/{{previousTag}}...{{currentTag}}",
"commitUrlFormat": "https://github.com/soulcraftlabs/brainy/commit/{{hash}}",
"issueUrlFormat": "https://github.com/soulcraftlabs/brainy/issues/{{id}}",
"userUrlFormat": "https://github.com/{{user}}",
"releaseCommitMessageFormat": "chore(release): {{currentTag}}",
"issuePrefixes": ["#"],
"header": "# Changelog\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n",
"scripts": {
"postbump": "echo '✅ Version bumped to' $(node -p \"require('./package.json').version\")"
}
}

View file

@ -21,7 +21,8 @@ Built because we were tired of stitching together Pinecone + Neo4j + MongoDB and
## Install
```bash
npm install @soulcraft/brainy
bun add @soulcraft/brainy # fastest — recommended
npm install @soulcraft/brainy # Node.js — fully supported
```
## Quick Start
@ -387,10 +388,10 @@ Performance benchmarks and capacity planning in **[docs/PERFORMANCE.md](docs/PER
## Requirements
**Bun 1.0+** (recommended) or **Node.js 22 LTS**
**Bun 1.1+** (recommended) or **Node.js 22 LTS**
```bash
bun install @soulcraft/brainy # Bun — best performance
bun add @soulcraft/brainy # Bun — best performance
npm install @soulcraft/brainy # Node.js — fully supported
```

View file

@ -215,9 +215,9 @@ console.log('Server running on http://localhost:3000')
```
**Benefits:**
- ✅ Native Bun performance (~2x faster than Node.js)
- ✅ Native Bun runtime performance
- ✅ No framework dependencies
- ✅ Works with `bun --compile` for single-binary deployment
- ✅ Pure WASM — no native binaries, bundler-friendly
- ✅ Built-in TypeScript support
### Pattern 4: Express/Node.js Middleware (Legacy)

View file

@ -35,15 +35,18 @@ This single WASM file contains everything needed for sentence embeddings.
### Bun (Recommended)
```typescript
// Works with Bun runtime
```bash
# Bun as a runtime — supported and recommended
bun add @soulcraft/brainy
bun run server.ts
// Works with bun --compile (single binary deployment!)
bun build --compile --target=bun server.ts
./server // Self-contained binary with embedded model
```
Brainy is pure WebAssembly with no native binaries, so the module graph stays
bundler-friendly. Single-binary `bun build --compile` is **not a supported
target** at present: Bun 1.3.10 has a `--compile` codegen regression
(`__promiseAll is not defined`) triggered by top-level `await` in the bundled
graph. Run Brainy under the Bun runtime (above) instead.
### Node.js
```typescript
@ -164,7 +167,7 @@ await brain.init()
**What's new:**
- Faster initialization
- Works with `bun --compile`
- Bundler-friendly (pure WASM, no native binaries)
- No network requirements
### From Custom Embedding Functions
@ -216,9 +219,8 @@ export { brain }
### Deployment
```bash
# Option 1: Bun compile (single binary)
bun build --compile server.ts
./server # Contains everything
# Option 1: Bun runtime
bun run server.ts
# Option 2: Docker
docker build -t my-app .

2240
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -66,8 +66,8 @@
}
},
"engines": {
"node": "22.x",
"bun": ">=1.0.0"
"node": ">=22",
"bun": ">=1.1.0"
},
"scripts": {
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
@ -94,8 +94,7 @@
"test:ci-unit": "CI=true vitest run --config tests/configs/vitest.unit.config.ts",
"test:ci-integration": "NODE_OPTIONS='--max-old-space-size=16384' CI=true vitest run --config tests/configs/vitest.integration.config.ts",
"test:ci": "npm run test:ci-unit && npm run test:ci-integration",
"test:bun": "bun tests/integration/bun-compile-test.ts",
"test:bun:compile": "bun build tests/integration/bun-compile-test.ts --compile --outfile /tmp/brainy-bun-test && /tmp/brainy-bun-test",
"test:bun": "bun tests/integration/bun-runtime-test.ts",
"test:wasm": "npx vitest run tests/integration/wasm-embeddings.test.ts",
"typecheck": "tsc --noEmit",
"lint": "eslint --ext .ts,.js src/",
@ -106,11 +105,7 @@
"release:patch": "./scripts/release.sh patch",
"release:minor": "./scripts/release.sh minor",
"release:major": "./scripts/release.sh major",
"release:dry": "./scripts/release.sh patch --dry-run",
"release:standard-version": "standard-version",
"release:standard-version:patch": "standard-version --release-as patch",
"release:standard-version:minor": "standard-version --release-as minor",
"release:standard-version:major": "standard-version --release-as major"
"release:dry": "./scripts/release.sh patch --dry-run"
},
"keywords": [
"ai-database",
@ -157,14 +152,10 @@
"boolean": "3.2.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^28.0.6",
"@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-replace": "^6.0.2",
"@rollup/plugin-terser": "^0.4.4",
"@testcontainers/redis": "^11.5.1",
"@types/js-yaml": "^4.0.9",
"@types/mime": "^3.0.4",
"@types/node": "^20.11.30",
"@types/node": "^22",
"@types/uuid": "^10.0.0",
"@types/ws": "^8.18.1",
"@typescript-eslint/eslint-plugin": "^8.0.0",
@ -172,7 +163,7 @@
"@vitest/coverage-v8": "^3.2.4",
"jspdf": "^3.0.3",
"minio": "^8.0.5",
"standard-version": "^9.5.0",
"prettier": "^3.9.4",
"testcontainers": "^11.5.1",
"tsx": "^4.19.2",
"typescript": "^5.4.5",
@ -210,33 +201,5 @@
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"eslintConfig": {
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"args": "after-used",
"argsIgnorePattern": "^_"
}
],
"semi": "off",
"@typescript-eslint/semi": [
"error",
"never"
],
"no-extra-semi": "off"
}
}
}

View file

@ -253,7 +253,7 @@ export class ODataIntegration extends IntegrationBase implements HTTPIntegration
/**
* Get augmentation manifest
*/
getManifest(): Record<string, any> {
override getManifest(): Record<string, any> {
return {
id: 'odata',
name: 'OData Integration',

View file

@ -283,7 +283,7 @@ export class GoogleSheetsIntegration
/**
* Get manifest
*/
getManifest(): Record<string, any> {
override getManifest(): Record<string, any> {
return {
id: 'sheets',
name: 'Google Sheets Integration',

View file

@ -292,7 +292,7 @@ export class SSEIntegration
/**
* Get manifest
*/
getManifest(): Record<string, any> {
override getManifest(): Record<string, any> {
return {
id: 'sse',
name: 'SSE Streaming',

View file

@ -262,7 +262,7 @@ export class WebhookIntegration extends IntegrationBase {
/**
* Get manifest
*/
getManifest(): Record<string, any> {
override getManifest(): Record<string, any> {
return {
id: 'webhooks',
name: 'Webhooks',

View file

@ -164,7 +164,7 @@ export class FileSystemStorage extends BaseStorage {
*
* @returns FileSystem-optimized batch configuration
*/
public getBatchConfig(): StorageBatchConfig {
public override getBatchConfig(): StorageBatchConfig {
return {
maxBatchSize: 500,
batchDelayMs: 0,
@ -180,7 +180,7 @@ export class FileSystemStorage extends BaseStorage {
/**
* Initialize the storage adapter
*/
public async init(): Promise<void> {
public override async init(): Promise<void> {
if (this.isInitialized) {
return
}
@ -952,7 +952,7 @@ export class FileSystemStorage extends BaseStorage {
*
* @param prefix - Storage-root-relative directory prefix to remove.
*/
public async removeRawPrefix(prefix: string): Promise<void> {
public override async removeRawPrefix(prefix: string): Promise<void> {
await this.ensureInitialized()
await fs.promises.rm(path.join(this.rootDir, prefix), { recursive: true, force: true })
}
@ -966,7 +966,7 @@ export class FileSystemStorage extends BaseStorage {
*
* @param paths - Storage-root-relative object paths previously written.
*/
public async syncRawObjects(paths: string[]): Promise<void> {
public override async syncRawObjects(paths: string[]): Promise<void> {
await this.ensureInitialized()
const parentDirs = new Set<string>()
@ -1539,7 +1539,7 @@ export class FileSystemStorage extends BaseStorage {
// Removed 10 *_internal method overrides - now inherit from BaseStorage's type-first implementation
// Removed 2 pagination methods (getNounsWithPagination, getVerbsWithPagination) - use BaseStorage's implementation
public supportsMultiProcessLocking(): boolean {
public override supportsMultiProcessLocking(): boolean {
return true
}
@ -1557,7 +1557,7 @@ export class FileSystemStorage extends BaseStorage {
* `lastHeartbeat` is older than `WRITER_STALE_THRESHOLD_MS` (60s).
* Stale locks are overwritten with a warning. `force: true` overrides even live locks.
*/
public async acquireWriterLock(options?: { force?: boolean }): Promise<WriterLockInfo | null> {
public override async acquireWriterLock(options?: { force?: boolean }): Promise<WriterLockInfo | null> {
await this.ensureInitialized()
await this.ensureDirectoryExists(this.lockDir)
@ -1639,7 +1639,7 @@ export class FileSystemStorage extends BaseStorage {
return info
}
public async releaseWriterLock(): Promise<void> {
public override async releaseWriterLock(): Promise<void> {
if (this.writerLockHeartbeat) {
clearInterval(this.writerLockHeartbeat)
this.writerLockHeartbeat = undefined
@ -1664,7 +1664,7 @@ export class FileSystemStorage extends BaseStorage {
}
}
public async readWriterLock(): Promise<WriterLockInfo | null> {
public override async readWriterLock(): Promise<WriterLockInfo | null> {
await this.ensureInitialized()
const lockFile = path.join(this.lockDir, FileSystemStorage.WRITER_LOCK_FILE)
try {
@ -1749,7 +1749,7 @@ export class FileSystemStorage extends BaseStorage {
* `locks/_flush_responses/` with the same request ID. Stale `.req` files
* (>FLUSH_REQUEST_TTL_MS) are garbage-collected on every tick.
*/
public startFlushRequestWatcher(onRequest: () => Promise<void>): void {
public override startFlushRequestWatcher(onRequest: () => Promise<void>): void {
if (this.flushWatcherInterval) return // already watching
this.flushWatcherOnRequest = onRequest
@ -1772,7 +1772,7 @@ export class FileSystemStorage extends BaseStorage {
}
}
public stopFlushRequestWatcher(): void {
public override stopFlushRequestWatcher(): void {
if (this.flushWatcherInterval) {
clearInterval(this.flushWatcherInterval)
this.flushWatcherInterval = undefined
@ -1851,7 +1851,7 @@ export class FileSystemStorage extends BaseStorage {
* Inspector side: drop a `.req` file and poll for the corresponding `.ack`.
* Returns true if the writer acknowledged in time, false on timeout.
*/
public async requestFlushOverFilesystem(timeoutMs: number): Promise<boolean> {
public override async requestFlushOverFilesystem(timeoutMs: number): Promise<boolean> {
await this.ensureInitialized()
const reqDir = path.join(this.lockDir, FileSystemStorage.FLUSH_REQUEST_DIR)
const ackDir = path.join(this.lockDir, FileSystemStorage.FLUSH_RESPONSE_DIR)

View file

@ -69,7 +69,7 @@ export class MemoryStorage extends BaseStorage {
*
* @returns Memory-optimized batch configuration
*/
public getBatchConfig(): StorageBatchConfig {
public override getBatchConfig(): StorageBatchConfig {
return {
maxBatchSize: 1000,
batchDelayMs: 0,
@ -86,7 +86,7 @@ export class MemoryStorage extends BaseStorage {
* Initialize the storage adapter
* Calls super.init() to initialize GraphAdjacencyIndex and type statistics
*/
public async init(): Promise<void> {
public override async init(): Promise<void> {
await super.init()
}

View file

@ -1551,7 +1551,7 @@ export abstract class BaseStorage extends BaseStorageAdapter {
* - Early termination when offset + limit entities collected
* - Memory efficient: Never loads full dataset
*/
public async getNounsWithPagination(options: {
public override async getNounsWithPagination(options: {
limit: number
offset: number
cursor?: string // Opaque resume token from a prior page's nextCursor; when set it supersedes offset (O(N) walk, no re-scan)
@ -1717,7 +1717,7 @@ export abstract class BaseStorage extends BaseStorageAdapter {
* - Memory efficient: Never loads full dataset
* - Inline filtering for sourceId, targetId, verbType
*/
public async getVerbsWithPagination(options: {
public override async getVerbsWithPagination(options: {
limit: number
offset: number
cursor?: string // Opaque resume token from a prior page's nextCursor; when set it supersedes offset (O(N) walk, no re-scan)
@ -2442,13 +2442,13 @@ export abstract class BaseStorage extends BaseStorageAdapter {
* Clear all data from storage
* This method should be implemented by each specific adapter
*/
public abstract clear(): Promise<void>
public abstract override clear(): Promise<void>
/**
* Get information about storage usage and capacity
* This method should be implemented by each specific adapter
*/
public abstract getStorageStatus(): Promise<{
public abstract override getStorageStatus(): Promise<{
type: string
used: number
quota: number | null
@ -2957,7 +2957,7 @@ export abstract class BaseStorage extends BaseStorageAdapter {
*
* @public - Inherited from BaseStorageAdapter
*/
public getBatchConfig(): StorageBatchConfig {
public override getBatchConfig(): StorageBatchConfig {
// Conservative defaults - adapters should override with their actual limits
return {
maxBatchSize: 100,
@ -3513,7 +3513,7 @@ export abstract class BaseStorage extends BaseStorageAdapter {
* writer flush the same silent-stale failure mode that once produced
* zero counts from `brain.stats()`.
*/
public async flushCounts(): Promise<void> {
public override async flushCounts(): Promise<void> {
await super.flushCounts()
await this.saveTypeStatistics()
await this.saveSubtypeStatistics()
@ -4297,7 +4297,7 @@ export abstract class BaseStorage extends BaseStorageAdapter {
* Save statistics data to storage (public interface)
* @param statistics The statistics data to save
*/
public async saveStatistics(statistics: StatisticsData): Promise<void> {
public override async saveStatistics(statistics: StatisticsData): Promise<void> {
return this.saveStatisticsData(statistics)
}
@ -4305,7 +4305,7 @@ export abstract class BaseStorage extends BaseStorageAdapter {
* Get statistics data from storage (public interface)
* @returns Promise that resolves to the statistics data or null if not found
*/
public async getStatistics(): Promise<StatisticsData | null> {
public override async getStatistics(): Promise<StatisticsData | null> {
return this.getStatisticsData()
}
@ -4314,7 +4314,7 @@ export abstract class BaseStorage extends BaseStorageAdapter {
* This method should be implemented by each specific adapter
* @param statistics The statistics data to save
*/
protected abstract saveStatisticsData(
protected abstract override saveStatisticsData(
statistics: StatisticsData
): Promise<void>
@ -4323,5 +4323,5 @@ export abstract class BaseStorage extends BaseStorageAdapter {
* This method should be implemented by each specific adapter
* @returns Promise that resolves to the statistics data or null if not found
*/
protected abstract getStatisticsData(): Promise<StatisticsData | null>
protected abstract override getStatisticsData(): Promise<StatisticsData | null>
}

View file

@ -26,7 +26,7 @@ export class TransactionExecutionError extends TransactionError {
message: string,
public readonly operationIndex: number,
public readonly operationName: string | undefined,
public readonly cause: Error
public override readonly cause: Error
) {
super(message, {
operationIndex,

View file

@ -10,15 +10,13 @@ import { NounType, VerbType } from '../types/graphTypes.js'
import { prodLog } from './logger.js'
import { findCallerLocation } from './callerLocation.js'
// Dynamic import for Node.js os and fs modules
let os: any = null
let fs: any = null
try {
os = await import('node:os')
fs = await import('node:fs')
} catch (e) {
// OS/FS modules not available
}
// 8.0 is Node/Bun/Deno-only (no browser path), so `node:os` / `node:fs` are
// always present — static ESM imports instead of a top-level `await import()`.
// The TLA form poisoned the module graph with a top-level await, which `bun
// build --compile` refuses; the static form also drops the browser/edge
// fallback branches that no supported runtime can reach.
import * as os from 'node:os'
import * as fs from 'node:fs'
const getSystemMemory = (): number => {
if (os) {

View file

@ -25,7 +25,7 @@ export class VFSReadStream extends Readable {
this.position = options.start || 0
}
async _read(size: number): Promise<void> {
override async _read(size: number): Promise<void> {
try {
// Lazy load entity
if (!this.entity) {
@ -58,7 +58,7 @@ export class VFSReadStream extends Readable {
}
}
_destroy(error: Error | null, callback: (error?: Error | null) => void): void {
override _destroy(error: Error | null, callback: (error?: Error | null) => void): void {
// Clean up resources
this.entity = null
this.data = null

View file

@ -28,7 +28,7 @@ export class VFSWriteStream extends Writable {
}
}
async _write(
override async _write(
chunk: any,
encoding: BufferEncoding,
callback: (error?: Error | null) => void
@ -52,7 +52,7 @@ export class VFSWriteStream extends Writable {
}
}
async _final(callback: (error?: Error | null) => void): Promise<void> {
override async _final(callback: (error?: Error | null) => void): Promise<void> {
try {
await this._flush()
callback()
@ -78,7 +78,7 @@ export class VFSWriteStream extends Writable {
this.chunks = []
}
_destroy(error: Error | null, callback: (error?: Error | null) => void): void {
override _destroy(error: Error | null, callback: (error?: Error | null) => void): void {
// Clean up resources
this.chunks = []
this._closed = true

View file

@ -1,25 +1,24 @@
/**
* Bun Compile Test
* Bun Runtime Test
*
* Tests that Brainy works when compiled with `bun build --compile`.
* This verifies:
* Tests that Brainy runs correctly under the Bun runtime (`bun add` / `bun run`)
* the supported Bun story. Verifies:
* 1. No native binaries required (pure WASM)
* 2. Model is properly bundled
* 3. Embeddings work without network access
*
* To test manually:
* bun build tests/integration/bun-compile-test.ts --compile --outfile /tmp/brainy-bun-test
* /tmp/brainy-bun-test
* To run manually:
* bun tests/integration/bun-runtime-test.ts
*/
import { Brainy } from '../../dist/index.js'
import { embeddingManager } from '../../dist/embeddings/EmbeddingManager.js'
import { WASMEmbeddingEngine } from '../../dist/embeddings/wasm/index.js'
async function testBunCompile() {
async function testBunRuntime() {
const results: { test: string; passed: boolean; error?: string }[] = []
console.log('🚀 Brainy Bun Compile Test\n')
console.log('🚀 Brainy Bun Runtime Test\n')
console.log('Runtime:', typeof Bun !== 'undefined' ? `Bun ${Bun.version}` : `Node.js ${process.version}`)
console.log('')
@ -153,13 +152,13 @@ async function testBunCompile() {
console.log('\n❌ Some tests failed!')
process.exit(1)
} else {
console.log('\n✅ All tests passed! Brainy works with Bun compile.')
console.log('\n✅ All tests passed! Brainy runs under Bun.')
process.exit(0)
}
}
// Run tests
testBunCompile().catch(error => {
testBunRuntime().catch(error => {
console.error('Fatal error:', error)
process.exit(1)
})

View file

@ -19,7 +19,9 @@
"noEmit": false,
"preserveConstEnums": true,
"sourceMap": true,
"downlevelIteration": true
"downlevelIteration": true,
"isolatedModules": true,
"noImplicitOverride": true
},
"include": [
"src/**/*"