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.
This commit is contained in:
parent
6e8869ecb7
commit
93804be354
31 changed files with 2120 additions and 2028 deletions
48
package.json
48
package.json
|
|
@ -15,8 +15,17 @@
|
|||
"./src/setup.ts",
|
||||
"./src/utils/textEncoding.ts"
|
||||
],
|
||||
"browser": {
|
||||
"fs": false,
|
||||
"fs/promises": false,
|
||||
"path": "path-browserify",
|
||||
"crypto": "crypto-browserify",
|
||||
"./dist/cortex/cortex.js": "./dist/browserFramework.js"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"browser": "./dist/browserFramework.js",
|
||||
"node": "./dist/index.js",
|
||||
"import": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
|
|
@ -43,6 +52,34 @@
|
|||
"./dist/setup.js": {
|
||||
"import": "./dist/setup.js",
|
||||
"types": "./dist/setup.d.ts"
|
||||
},
|
||||
"./browserFramework": {
|
||||
"import": "./dist/browserFramework.js",
|
||||
"types": "./dist/browserFramework.d.ts"
|
||||
},
|
||||
"./universal": {
|
||||
"import": "./dist/universal/index.js",
|
||||
"types": "./dist/universal/index.d.ts"
|
||||
},
|
||||
"./universal/uuid": {
|
||||
"import": "./dist/universal/uuid.js",
|
||||
"types": "./dist/universal/uuid.d.ts"
|
||||
},
|
||||
"./universal/crypto": {
|
||||
"import": "./dist/universal/crypto.js",
|
||||
"types": "./dist/universal/crypto.d.ts"
|
||||
},
|
||||
"./universal/fs": {
|
||||
"import": "./dist/universal/fs.js",
|
||||
"types": "./dist/universal/fs.d.ts"
|
||||
},
|
||||
"./universal/path": {
|
||||
"import": "./dist/universal/path.js",
|
||||
"types": "./dist/universal/path.d.ts"
|
||||
},
|
||||
"./universal/events": {
|
||||
"import": "./dist/universal/events.js",
|
||||
"types": "./dist/universal/events.d.ts"
|
||||
}
|
||||
},
|
||||
"engines": {
|
||||
|
|
@ -51,6 +88,7 @@
|
|||
"scripts": {
|
||||
"prebuild": "echo 'Prebuild step - no version generation needed'",
|
||||
"build": "tsc",
|
||||
"build:browser": "npm run build && vite build --config vite.browser.config.ts",
|
||||
"build:framework": "tsc",
|
||||
"start": "node dist/framework.js",
|
||||
"demo": "npm run build && cd demo/brainy-angular-demo && npm run build && npm run serve",
|
||||
|
|
@ -137,6 +175,10 @@
|
|||
"OFFLINE_MODELS.md"
|
||||
],
|
||||
"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",
|
||||
"@types/express": "^5.0.3",
|
||||
"@types/jsdom": "^21.1.7",
|
||||
"@types/node": "^20.11.30",
|
||||
|
|
@ -144,17 +186,22 @@
|
|||
"@types/uuid": "^10.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
||||
"@typescript-eslint/parser": "^8.0.0",
|
||||
"@vitejs/plugin-basic-ssl": "^2.1.0",
|
||||
"@vitest/coverage-v8": "^3.2.4",
|
||||
"@vitest/ui": "^3.2.4",
|
||||
"buffer": "^6.0.3",
|
||||
"crypto-browserify": "^3.12.1",
|
||||
"eslint": "^9.0.0",
|
||||
"express": "^5.1.0",
|
||||
"happy-dom": "^18.0.1",
|
||||
"jsdom": "^26.1.0",
|
||||
"node-fetch": "^3.3.2",
|
||||
"process": "^0.11.10",
|
||||
"puppeteer": "^22.15.0",
|
||||
"standard-version": "^9.5.0",
|
||||
"tslib": "^2.6.2",
|
||||
"typescript": "^5.4.5",
|
||||
"vite": "^7.1.1",
|
||||
"vitest": "^3.2.4"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
@ -162,7 +209,6 @@
|
|||
"@huggingface/transformers": "^3.1.0",
|
||||
"@smithy/node-http-handler": "^4.1.1",
|
||||
"boxen": "^7.1.1",
|
||||
"buffer": "^6.0.3",
|
||||
"chalk": "^5.3.0",
|
||||
"cli-table3": "^0.6.3",
|
||||
"commander": "^11.1.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue