@affectively/dash 5.4.0 → 5.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -189
- package/dist/automerge_wasm_bg-4hg5vg2g.wasm +0 -0
- package/dist/engine/sqlite.d.ts +30 -0
- package/dist/engine/vec_extension.d.ts +2 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +53895 -0
- package/dist/middleware/errorHandler.d.ts +60 -0
- package/dist/{src/sync → sync}/AeonDurableSync.d.ts +8 -9
- package/dist/sync/AeonDurableSync.js +1984 -0
- package/dist/{src/sync → sync}/AutomergeProvider.d.ts +8 -8
- package/dist/sync/AutomergeProvider.js +4421 -0
- package/dist/sync/HybridProvider.d.ts +124 -0
- package/dist/sync/HybridProvider.js +8328 -0
- package/dist/sync/connection/WebRTCConnection.d.ts +23 -0
- package/dist/sync/connection/WebRTCConnection.js +59 -0
- package/dist/sync/index.d.ts +13 -0
- package/dist/sync/index.js +12773 -0
- package/dist/sync/provider/YjsSqliteProvider.d.ts +17 -0
- package/dist/sync/provider/YjsSqliteProvider.js +54 -0
- package/dist/sync/types.d.ts +74 -0
- package/dist/sync/webtransport/WebTransportProvider.d.ts +16 -0
- package/dist/sync/webtransport/WebTransportProvider.js +55 -0
- package/package.json +62 -70
- package/dist/src/api/firebase/auth/index.d.ts +0 -137
- package/dist/src/api/firebase/auth/index.js +0 -352
- package/dist/src/api/firebase/auth/providers.d.ts +0 -254
- package/dist/src/api/firebase/auth/providers.js +0 -518
- package/dist/src/api/firebase/database/index.d.ts +0 -108
- package/dist/src/api/firebase/database/index.js +0 -368
- package/dist/src/api/firebase/errors.d.ts +0 -15
- package/dist/src/api/firebase/errors.js +0 -215
- package/dist/src/api/firebase/firestore/data-types.d.ts +0 -116
- package/dist/src/api/firebase/firestore/data-types.js +0 -280
- package/dist/src/api/firebase/firestore/index.d.ts +0 -7
- package/dist/src/api/firebase/firestore/index.js +0 -13
- package/dist/src/api/firebase/firestore/listeners.d.ts +0 -20
- package/dist/src/api/firebase/firestore/listeners.js +0 -50
- package/dist/src/api/firebase/firestore/operations.d.ts +0 -123
- package/dist/src/api/firebase/firestore/operations.js +0 -490
- package/dist/src/api/firebase/firestore/query.d.ts +0 -118
- package/dist/src/api/firebase/firestore/query.js +0 -418
- package/dist/src/api/firebase/index.d.ts +0 -11
- package/dist/src/api/firebase/index.js +0 -17
- package/dist/src/api/firebase/storage/index.d.ts +0 -100
- package/dist/src/api/firebase/storage/index.js +0 -286
- package/dist/src/api/firebase/types.d.ts +0 -341
- package/dist/src/api/firebase/types.js +0 -4
- package/dist/src/auth/manager.d.ts +0 -182
- package/dist/src/auth/manager.js +0 -598
- package/dist/src/engine/ai.js +0 -76
- package/dist/src/engine/sqlite.d.ts +0 -353
- package/dist/src/engine/sqlite.js +0 -1328
- package/dist/src/engine/vec_extension.d.ts +0 -5
- package/dist/src/engine/vec_extension.js +0 -10
- package/dist/src/index.d.ts +0 -21
- package/dist/src/index.js +0 -26
- package/dist/src/mcp/server.js +0 -87
- package/dist/src/reactivity/signal.js +0 -31
- package/dist/src/schema/lens.d.ts +0 -29
- package/dist/src/schema/lens.js +0 -122
- package/dist/src/sync/AeonDurableSync.js +0 -67
- package/dist/src/sync/AutomergeProvider.js +0 -153
- package/dist/src/sync/aeon/config.d.ts +0 -21
- package/dist/src/sync/aeon/config.js +0 -14
- package/dist/src/sync/aeon/delta-adapter.d.ts +0 -62
- package/dist/src/sync/aeon/delta-adapter.js +0 -98
- package/dist/src/sync/aeon/index.d.ts +0 -18
- package/dist/src/sync/aeon/index.js +0 -19
- package/dist/src/sync/aeon/offline-adapter.d.ts +0 -110
- package/dist/src/sync/aeon/offline-adapter.js +0 -227
- package/dist/src/sync/aeon/presence-adapter.d.ts +0 -114
- package/dist/src/sync/aeon/presence-adapter.js +0 -157
- package/dist/src/sync/aeon/schema-adapter.d.ts +0 -95
- package/dist/src/sync/aeon/schema-adapter.js +0 -163
- package/dist/src/sync/backup.d.ts +0 -12
- package/dist/src/sync/backup.js +0 -44
- package/dist/src/sync/connection.d.ts +0 -20
- package/dist/src/sync/connection.js +0 -50
- package/dist/src/sync/d1-provider.d.ts +0 -103
- package/dist/src/sync/d1-provider.js +0 -418
- package/dist/src/sync/hybrid-provider.d.ts +0 -307
- package/dist/src/sync/hybrid-provider.js +0 -1353
- package/dist/src/sync/provider.d.ts +0 -11
- package/dist/src/sync/provider.js +0 -67
- package/dist/src/sync/types.d.ts +0 -32
- package/dist/src/sync/types.js +0 -4
- package/dist/src/sync/verify.d.ts +0 -1
- package/dist/src/sync/verify.js +0 -23
- package/dist/tsconfig.tsbuildinfo +0 -1
- /package/dist/{src/engine → engine}/ai.d.ts +0 -0
- /package/dist/{src/mcp → mcp}/server.d.ts +0 -0
- /package/dist/{src/reactivity → reactivity}/signal.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,193 +1,12 @@
|
|
|
1
|
-
# Dash
|
|
1
|
+
# Dash
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Key Files
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
| File | Size |
|
|
6
|
+
|------|------|
|
|
7
|
+
| `package.json` | 2.3 KB |
|
|
8
|
+
| `tsconfig.json` | 0.6 KB |
|
|
6
9
|
|
|
7
|
-
##
|
|
10
|
+
## Subdirectories
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
### The Shift
|
|
12
|
-
|
|
13
|
-
The new standard is **SQLite over OPFS** (Origin Private File System).
|
|
14
|
-
|
|
15
|
-
### Why it’s sexy
|
|
16
|
-
|
|
17
|
-
It gives the browser direct, performant handle access to a virtual file system optimized for random access.
|
|
18
|
-
|
|
19
|
-
### The Result
|
|
20
|
-
|
|
21
|
-
You can run full ACID transactions on a **multi-gigabyte SQLite file** in the browser with **near-native desktop performance**, without ever blocking the UI thread (thanks to SharedArrayBuffer).
|
|
22
|
-
|
|
23
|
-
Combined with **Zero-Copy (BYOB)** readers and **UCAN**-based Zero-Trust Auth, Dash isn't just a database—it's a local-first operating system.
|
|
24
|
-
|
|
25
|
-
## Features
|
|
26
|
-
|
|
27
|
-
### 🚀 Production-Grade Storage
|
|
28
|
-
|
|
29
|
-
- **Stateful Serverless**: Powered by Cloudflare Durable Objects and Native SQLite.
|
|
30
|
-
- **Zero-Copy IO (BYOB)**: "Bring Your Own Buffer" readers for max throughput.
|
|
31
|
-
- **ACID Compliant**: Full transactional integrity in the browser.
|
|
32
|
-
|
|
33
|
-
### 🧠 Hardware-Accelerated AI
|
|
34
|
-
|
|
35
|
-
- **Vector Search**: Built-in vector embeddings and search.
|
|
36
|
-
- **3-Tier Acceleration**:
|
|
37
|
-
1. **WebNN**: NPU acceleration (Apple Neural Engine, etc.)
|
|
38
|
-
2. **WebGPU**: High-performance GPU parallelization.
|
|
39
|
-
3. **WASM/CPU**: Universal fallback.
|
|
40
|
-
- **Semantic Queries**: Find data by _meaning_ at native speeds.
|
|
41
|
-
|
|
42
|
-
### 🔄 Modern Sync
|
|
43
|
-
|
|
44
|
-
- **Hybrid Transport**:
|
|
45
|
-
- **WebSocket**: Supports Cloudflare Durable Object Hibernation ($0 idle cost).
|
|
46
|
-
- **WebTransport**: UDP-like high-frequency streams (perfect for cursors/games).
|
|
47
|
-
- **Zero-Trust Auth (UCANs)**: Decentralized authorization via User Controlled Authorization Networks.
|
|
48
|
-
- **Lens**: Bidirectional schema migrations for infinite backward compatibility.
|
|
49
|
-
|
|
50
|
-
### 🎨 Graphics Ready
|
|
51
|
-
|
|
52
|
-
- **Direct Buffers**: Zero-copy bindings allow piping data directly into 3D engines like Three.js.
|
|
53
|
-
- **Spatial Indexing**: R-Tree support for massive 3D visualizations.
|
|
54
|
-
|
|
55
|
-
### 🔥 Firebase-Compatible API
|
|
56
|
-
|
|
57
|
-
- **Drop-In Replacement**: Use Firebase imports, Dash implementation. All your code works unchanged.
|
|
58
|
-
- **All 4 Modules**: Firestore, Realtime Database, Auth, Cloud Storage.
|
|
59
|
-
- **100% Compatible**: 150+ Firebase APIs with identical behavior.
|
|
60
|
-
- **10-50x Faster**: Local-first queries at 0ms latency vs 15-25ms network round-trips.
|
|
61
|
-
- **Unique Advantages**: Vector search, E2E encryption, offline-first, AI/ML built-in.
|
|
62
|
-
|
|
63
|
-
```typescript
|
|
64
|
-
// Before (Firebase)
|
|
65
|
-
import { collection, getDocs } from 'firebase/firestore';
|
|
66
|
-
|
|
67
|
-
// After (Dash - your code unchanged!)
|
|
68
|
-
import { collection, getDocs } from '@affectively/dash';
|
|
69
|
-
|
|
70
|
-
// Same code, 10-50x faster, fully offline ✅
|
|
71
|
-
const docs = await getDocs(collection(db, 'users'));
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
**Learn more**: [Firebase Compatibility Guide](../../documentation/firebase.md)
|
|
75
|
-
|
|
76
|
-
## Installation
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
npm install @affectively/dash
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Quick Start
|
|
83
|
-
|
|
84
|
-
### 1. Store & Query (Standard SQL)
|
|
85
|
-
|
|
86
|
-
Dash provides a familiar SQL interface with Promise-based execution.
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
import { dash } from "@affectively/dash";
|
|
90
|
-
|
|
91
|
-
await dash.ready();
|
|
92
|
-
|
|
93
|
-
// Standard SQL execution
|
|
94
|
-
await dash.execute("CREATE TABLE IF NOT EXISTS todos (id TEXT, text TEXT)");
|
|
95
|
-
await dash.execute("INSERT INTO todos VALUES (?, ?)", ["1", "Buy milk"]);
|
|
96
|
-
|
|
97
|
-
const rows = await dash.execute("SELECT * FROM todos");
|
|
98
|
-
console.log(rows);
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### 2. Semantic Search (AI)
|
|
102
|
-
|
|
103
|
-
Store content with automatic vector embeddings and query by meaning.
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
// Add an item (automatically generates and stores vector embedding)
|
|
107
|
-
await dash.addWithEmbedding("1", "Buy almond milk and eggs");
|
|
108
|
-
|
|
109
|
-
// Search by meaning - "breakfast ingredients" matches "eggs" and "milk"!
|
|
110
|
-
const results = await dash.search("breakfast ingredients");
|
|
111
|
-
// Result: [{ id: '1', content: '...', score: 0.85 }]
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### 3. Spatial Queries (3D R-Tree)
|
|
115
|
-
|
|
116
|
-
Filter items by 3D bounds for high-performance spatial lookups.
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
// Query a 3D bounding box
|
|
120
|
-
const items = await dash.spatialQuery({
|
|
121
|
-
minX: 0,
|
|
122
|
-
maxX: 100,
|
|
123
|
-
minY: 0,
|
|
124
|
-
maxY: 100,
|
|
125
|
-
minZ: 0,
|
|
126
|
-
maxZ: 100,
|
|
127
|
-
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### 4. Reactivity (Signals)
|
|
131
|
-
|
|
132
|
-
Bind query results directly to your application state.
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
import { liveQuery, effect } from "@affectively/dash";
|
|
136
|
-
|
|
137
|
-
// This signal automatically updates whenever the 'todos' table changes
|
|
138
|
-
const todos = liveQuery("SELECT * FROM todos");
|
|
139
|
-
|
|
140
|
-
effect(() => {
|
|
141
|
-
console.log("Current Todos:", todos.value);
|
|
142
|
-
});
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### 5. Sync & Backup (Local-First)
|
|
146
|
-
|
|
147
|
-
Enable collaboration and data safety with a single line.
|
|
148
|
-
|
|
149
|
-
```typescript
|
|
150
|
-
import { SyncConnection, backup } from "@affectively/dash";
|
|
151
|
-
|
|
152
|
-
// 1. Peer-to-Peer Sync (WebTransport - Recommended)
|
|
153
|
-
// Requires a WebTransport Relay Server (Star Topology)
|
|
154
|
-
const connection = new SyncConnection({
|
|
155
|
-
type: "webtransport",
|
|
156
|
-
roomName: "my-room",
|
|
157
|
-
url: "https://relay.dash.dev/sync",
|
|
158
|
-
doc,
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// OR: Peer-to-Peer Sync (WebRTC - Legacy)
|
|
162
|
-
// Mesh Topology (Client-to-Client)
|
|
163
|
-
const p2p = new SyncConnection({
|
|
164
|
-
type: "webrtc",
|
|
165
|
-
roomName: "my-room",
|
|
166
|
-
doc,
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
// 2. Encrypted Cloud Backup
|
|
170
|
-
await backup("my-room", doc, mySecretKey, cloudAdapter);
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## Architecture
|
|
174
|
-
|
|
175
|
-
Dash uses `@sqlite.org/sqlite-wasm` with the OPFS backend to ensure main-thread responsiveness. Large data operations occur in the WASM heap, avoiding the serialization overhead of IndexedDB.
|
|
176
|
-
|
|
177
|
-
Vector operations utilize `sqlite-vec` (WASM) for high-performance similarity search.
|
|
178
|
-
|
|
179
|
-
For a deep dive into our "Stateful Serverless" Client-Relay topology using Cloudflare Durable Objects, read the [Sync Architecture Guide](./docs/SYNC_ARCHITECTURE.md).
|
|
180
|
-
|
|
181
|
-
## Development
|
|
182
|
-
|
|
183
|
-
```bash
|
|
184
|
-
# Build the project
|
|
185
|
-
npm run build
|
|
186
|
-
|
|
187
|
-
# Run tests
|
|
188
|
-
npm test
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
## License
|
|
192
|
-
|
|
193
|
-
MIT
|
|
12
|
+
- `src/`
|
|
Binary file
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare class DashEngine {
|
|
2
|
+
private db;
|
|
3
|
+
private readyPromise;
|
|
4
|
+
private listeners;
|
|
5
|
+
constructor();
|
|
6
|
+
private init;
|
|
7
|
+
private initializeSchema;
|
|
8
|
+
ready(): Promise<void>;
|
|
9
|
+
private tableListeners;
|
|
10
|
+
subscribe(table: string, callback: () => void): () => void;
|
|
11
|
+
private notify;
|
|
12
|
+
private notifyChanges;
|
|
13
|
+
execute(sql: string, bind?: any[]): any[];
|
|
14
|
+
addWithEmbedding(id: string, content: string, spatial?: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
z: number;
|
|
18
|
+
}): Promise<any[]>;
|
|
19
|
+
search(query: string, limit?: number): Promise<any[]>;
|
|
20
|
+
spatialQuery(bounds: {
|
|
21
|
+
minX: number;
|
|
22
|
+
maxX: number;
|
|
23
|
+
minY: number;
|
|
24
|
+
maxY: number;
|
|
25
|
+
minZ: number;
|
|
26
|
+
maxZ: number;
|
|
27
|
+
}): Promise<any[]>;
|
|
28
|
+
close(): void;
|
|
29
|
+
}
|
|
30
|
+
export declare const dash: DashEngine;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @affectively/dash
|
|
3
|
+
*
|
|
4
|
+
* Multi-layer edge storage and CRDT sync engine —
|
|
5
|
+
* Yjs, Automerge, WebSocket, WebTransport, and WebRTC.
|
|
6
|
+
*/
|
|
7
|
+
export interface Dash {
|
|
8
|
+
ready: () => Promise<void>;
|
|
9
|
+
execute: (sql: string, bind?: unknown[]) => unknown[];
|
|
10
|
+
addWithEmbedding?: (id: string, content: string) => Promise<unknown[]>;
|
|
11
|
+
search?: (query: string, limit?: number) => Promise<Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
content: string;
|
|
14
|
+
score: number;
|
|
15
|
+
}>>;
|
|
16
|
+
}
|
|
17
|
+
export interface PresenceUser {
|
|
18
|
+
userId: string;
|
|
19
|
+
role: 'user' | 'assistant' | 'monitor' | 'admin';
|
|
20
|
+
cursor?: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
};
|
|
24
|
+
editing?: string;
|
|
25
|
+
status: 'online' | 'away' | 'offline';
|
|
26
|
+
lastActivity: string;
|
|
27
|
+
}
|
|
28
|
+
export interface PresenceState {
|
|
29
|
+
users: PresenceUser[];
|
|
30
|
+
localUser?: PresenceUser;
|
|
31
|
+
isConnected: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface SyncState {
|
|
34
|
+
isOnline: boolean;
|
|
35
|
+
isSyncing: boolean;
|
|
36
|
+
lastSyncAt?: string;
|
|
37
|
+
pendingOperations: number;
|
|
38
|
+
}
|
|
39
|
+
export declare const dash: import("./engine/sqlite").DashEngine;
|
|
40
|
+
export { mcpServer } from './mcp/server';
|
|
41
|
+
export { liveQuery, signal, effect, computed } from './reactivity/signal';
|
|
42
|
+
export declare function createDash(config: DashConfig): Dash;
|
|
43
|
+
export declare function getPresence(): PresenceState;
|
|
44
|
+
export declare class PeerSync {
|
|
45
|
+
constructor(roomName: string, options?: PeerSyncOptions);
|
|
46
|
+
connect(): Promise<void>;
|
|
47
|
+
disconnect(): void;
|
|
48
|
+
getPeers(): string[];
|
|
49
|
+
}
|
|
50
|
+
export declare class SynchronizerFactory {
|
|
51
|
+
static create(config: SyncConfig): PeerSync;
|
|
52
|
+
}
|
|
53
|
+
export interface DashConfig {
|
|
54
|
+
name: string;
|
|
55
|
+
version?: number;
|
|
56
|
+
persistence?: 'indexeddb' | 'sqlite' | 'memory';
|
|
57
|
+
sync?: {
|
|
58
|
+
enabled: boolean;
|
|
59
|
+
roomName: string;
|
|
60
|
+
signalingServers?: string[];
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export interface PeerSyncOptions {
|
|
64
|
+
signalingServers?: string[];
|
|
65
|
+
password?: string;
|
|
66
|
+
enableHighFrequency?: boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface SyncConfig {
|
|
69
|
+
roomName: string;
|
|
70
|
+
options?: PeerSyncOptions;
|
|
71
|
+
}
|
|
72
|
+
export { DashErrorHandler, defaultErrorHandler, withRetry, withRateLimit, withErrorHandling, type ErrorHandlerConfig, type RetryConfig, type RateLimitConfig, } from './middleware/errorHandler';
|
|
73
|
+
export default dash;
|