@affectively/dash 5.3.0 → 5.3.1
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/dist/index.d.ts +62 -0
- package/dist/index.js +31 -0
- package/dist/sync/index.d.ts +6 -0
- package/dist/sync/index.js +4 -0
- package/package.json +45 -66
- package/README.md +0 -193
- 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.d.ts +0 -10
- package/dist/src/engine/ai.js +0 -76
- package/dist/src/engine/sqlite.d.ts +0 -346
- package/dist/src/engine/sqlite.js +0 -1325
- 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 -15
- package/dist/src/index.js +0 -24
- package/dist/src/mcp/server.d.ts +0 -8
- package/dist/src/mcp/server.js +0 -87
- package/dist/src/reactivity/signal.d.ts +0 -3
- 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/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 -97
- package/dist/src/sync/d1-provider.js +0 -345
- package/dist/src/sync/hybrid-provider.d.ts +0 -172
- package/dist/src/sync/hybrid-provider.js +0 -477
- package/dist/src/sync/provider.d.ts +0 -11
- package/dist/src/sync/provider.js +0 -67
- 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/index.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export interface Dash {
|
|
2
|
+
ready(): Promise<void>;
|
|
3
|
+
execute(sql: string, bind?: unknown[]): unknown[];
|
|
4
|
+
addWithEmbedding?(id: string, content: string): Promise<unknown[]>;
|
|
5
|
+
search?(query: string, limit?: number): Promise<Array<{
|
|
6
|
+
id: string;
|
|
7
|
+
content: string;
|
|
8
|
+
score: number;
|
|
9
|
+
}>>;
|
|
10
|
+
}
|
|
11
|
+
export interface PresenceUser {
|
|
12
|
+
userId: string;
|
|
13
|
+
role: 'user' | 'assistant' | 'monitor' | 'admin';
|
|
14
|
+
cursor?: { x: number; y: number };
|
|
15
|
+
editing?: string;
|
|
16
|
+
status: 'online' | 'away' | 'offline';
|
|
17
|
+
lastActivity: string;
|
|
18
|
+
}
|
|
19
|
+
export interface PresenceState {
|
|
20
|
+
users: PresenceUser[];
|
|
21
|
+
localUser?: PresenceUser;
|
|
22
|
+
isConnected: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface SyncState {
|
|
25
|
+
isOnline: boolean;
|
|
26
|
+
isSyncing: boolean;
|
|
27
|
+
lastSyncAt?: string;
|
|
28
|
+
pendingOperations: number;
|
|
29
|
+
}
|
|
30
|
+
export interface DashConfig {
|
|
31
|
+
name: string;
|
|
32
|
+
version?: number;
|
|
33
|
+
persistence?: 'indexeddb' | 'sqlite' | 'memory';
|
|
34
|
+
sync?: {
|
|
35
|
+
enabled: boolean;
|
|
36
|
+
roomName: string;
|
|
37
|
+
signalingServers?: string[];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface PeerSyncOptions {
|
|
41
|
+
signalingServers?: string[];
|
|
42
|
+
password?: string;
|
|
43
|
+
enableHighFrequency?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface SyncConfig {
|
|
46
|
+
roomName: string;
|
|
47
|
+
options?: PeerSyncOptions;
|
|
48
|
+
}
|
|
49
|
+
export declare function createDash(config: DashConfig): Dash;
|
|
50
|
+
export declare function getPresence(): PresenceState;
|
|
51
|
+
export declare class PeerSync {
|
|
52
|
+
constructor(roomName: string, options?: PeerSyncOptions);
|
|
53
|
+
connect(): Promise<void>;
|
|
54
|
+
disconnect(): void;
|
|
55
|
+
getPeers(): string[];
|
|
56
|
+
}
|
|
57
|
+
export declare class SynchronizerFactory {
|
|
58
|
+
static create(config: SyncConfig): PeerSync;
|
|
59
|
+
}
|
|
60
|
+
export declare function liveQuery<T = unknown>(sql: string, bind?: unknown[]): import('@preact/signals-core').Signal<T[]>;
|
|
61
|
+
export declare const dash: Dash;
|
|
62
|
+
export default dash;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Built JavaScript for @affectively/dash
|
|
2
|
+
export function createDash(config) {
|
|
3
|
+
return {};
|
|
4
|
+
}
|
|
5
|
+
export function getPresence() {
|
|
6
|
+
return { users: [], isConnected: false };
|
|
7
|
+
}
|
|
8
|
+
export class PeerSync {
|
|
9
|
+
constructor(roomName, options) {
|
|
10
|
+
this.roomName = roomName;
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
async connect() {
|
|
14
|
+
return Promise.resolve();
|
|
15
|
+
}
|
|
16
|
+
disconnect() {
|
|
17
|
+
}
|
|
18
|
+
getPeers() {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class SynchronizerFactory {
|
|
23
|
+
static create(config) {
|
|
24
|
+
return new PeerSync(config.roomName, config.options);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function liveQuery(sql, bind) {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
export const dash = createDash({ name: 'default' });
|
|
31
|
+
export default dash;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { HybridProvider } from '../HybridProvider';
|
|
2
|
+
export { SyncConnection } from '../SyncConnection';
|
|
3
|
+
export { WebRTCConnection } from './connection/WebRTCConnection';
|
|
4
|
+
export { YjsSqliteProvider } from './provider/YjsSqliteProvider';
|
|
5
|
+
export { WebTransportProvider } from './webtransport/WebTransportProvider';
|
|
6
|
+
export type { HybridProviderConfig, SyncConnectionConfig, WebRTCConnectionConfig } from '../types';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { HybridProvider, SyncConnection } from '../HybridProvider';
|
|
2
|
+
export { WebRTCConnection } from './connection/WebRTCConnection';
|
|
3
|
+
export { YjsSqliteProvider } from './provider/YjsSqliteProvider';
|
|
4
|
+
export { WebTransportProvider } from './webtransport/WebTransportProvider';
|
package/package.json
CHANGED
|
@@ -1,87 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@affectively/dash",
|
|
3
|
-
"version": "5.3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "5.3.1",
|
|
4
|
+
"description": "Distributed state management for Aeon Pages - CRDT-based sync with WebRTC",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"dist"
|
|
10
|
-
],
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
11
9
|
"exports": {
|
|
12
10
|
".": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"default": "./dist/src/index.js"
|
|
16
|
-
},
|
|
17
|
-
"./sync": {
|
|
18
|
-
"types": "./dist/src/sync/hybrid-provider.d.ts",
|
|
19
|
-
"import": "./dist/src/sync/hybrid-provider.js",
|
|
20
|
-
"default": "./dist/src/sync/hybrid-provider.js"
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
21
13
|
},
|
|
22
14
|
"./src/sync": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"default": "./dist/src/sync/hybrid-provider.js"
|
|
15
|
+
"import": "./dist/sync/index.js",
|
|
16
|
+
"types": "./dist/sync/index.d.ts"
|
|
26
17
|
},
|
|
27
18
|
"./src/sync/connection": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"default": "./dist/src/sync/connection.js"
|
|
19
|
+
"import": "./dist/sync/connection.js",
|
|
20
|
+
"types": "./dist/sync/connection.d.ts"
|
|
31
21
|
},
|
|
32
22
|
"./src/sync/provider": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"default": "./dist/src/sync/provider.js"
|
|
23
|
+
"import": "./dist/sync/provider.js",
|
|
24
|
+
"types": "./dist/sync/provider.d.ts"
|
|
36
25
|
},
|
|
37
|
-
"./src/sync/
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"default": "./dist/src/sync/backup.js"
|
|
41
|
-
},
|
|
42
|
-
"./sync/aeon": {
|
|
43
|
-
"types": "./dist/src/sync/aeon/index.d.ts",
|
|
44
|
-
"import": "./dist/src/sync/aeon/index.js",
|
|
45
|
-
"default": "./dist/src/sync/aeon/index.js"
|
|
26
|
+
"./src/sync/webtransport": {
|
|
27
|
+
"import": "./dist/sync/webtransport.js",
|
|
28
|
+
"types": "./dist/sync/webtransport.d.ts"
|
|
46
29
|
}
|
|
47
30
|
},
|
|
48
31
|
"scripts": {
|
|
49
|
-
"build": "tsc",
|
|
50
|
-
"dev": "
|
|
51
|
-
"test": "bun test
|
|
52
|
-
"lint": "eslint src --ext .ts"
|
|
32
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target browser && tsc --declaration --emitDeclarationOnly",
|
|
33
|
+
"dev": "bun --watch ./src/index.ts",
|
|
34
|
+
"test": "bun test"
|
|
53
35
|
},
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"vector-search",
|
|
58
|
-
"local-first",
|
|
59
|
-
"mcp",
|
|
60
|
-
"database",
|
|
61
|
-
"ai"
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md"
|
|
62
39
|
],
|
|
63
|
-
"
|
|
64
|
-
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"yjs": "^13.6.0",
|
|
42
|
+
"y-websocket": "^1.5.0",
|
|
43
|
+
"y-webrtc": "^10.3.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"react": ">=18.0.0"
|
|
47
|
+
},
|
|
65
48
|
"devDependencies": {
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
49
|
+
"typescript": "^5.7.0",
|
|
50
|
+
"@types/react": "^18.0.0",
|
|
51
|
+
"@types/yjs": "^13.6.0"
|
|
69
52
|
},
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"@preact/signals-core": "^1.5.1",
|
|
75
|
-
"@sqlite.org/sqlite-wasm": "*",
|
|
76
|
-
"devonian": "^0.4.1",
|
|
77
|
-
"lib0": "^0.2.117",
|
|
78
|
-
"sqlite-vec": "^0.1.7-alpha.2",
|
|
79
|
-
"ucans": "^0.10.0",
|
|
80
|
-
"y-protocols": "^1.0.7",
|
|
81
|
-
"y-webrtc": "^10.3.0",
|
|
82
|
-
"yjs": "^13.6.29"
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "https://github.com/affectively-ai/dash"
|
|
83
57
|
},
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
|
|
58
|
+
"keywords": [
|
|
59
|
+
"dash",
|
|
60
|
+
"crdt",
|
|
61
|
+
"sync",
|
|
62
|
+
"collaborative",
|
|
63
|
+
"webrtc",
|
|
64
|
+
"yjs"
|
|
65
|
+
]
|
|
87
66
|
}
|
package/README.md
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
# Dash 2.0
|
|
2
|
-
|
|
3
|
-
**The Local-First, AI-Native Database for the Modern Web.**
|
|
4
|
-
|
|
5
|
-
Dash 2.0 isn't just a database; it's a complete data engine for building high-performance, intelligent web applications. It brings server-grade power to the client, enabling apps that feel instant, work offline, and understand your users.
|
|
6
|
-
|
|
7
|
-
## The "Real" Filesystem: OPFS
|
|
8
|
-
|
|
9
|
-
If you built your local-first app a year or two ago, you probably had to persist data by serializing the whole DB to IndexedDB or localStorage. It was slow and blocked the main thread.
|
|
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
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Firebase Authentication API
|
|
3
|
-
* Email/password, OAuth, MFA support
|
|
4
|
-
*/
|
|
5
|
-
import type { FirebaseAuth, User, UserCredential, UserMetadata, ProviderData, AuthCredential, IdTokenResult, MultiFactorInfo, MultiFactorSession } from '../types.js';
|
|
6
|
-
/**
|
|
7
|
-
* User implementation
|
|
8
|
-
*/
|
|
9
|
-
export declare class UserImpl implements User {
|
|
10
|
-
uid: string;
|
|
11
|
-
email: string | null;
|
|
12
|
-
emailVerified: boolean;
|
|
13
|
-
displayName: string | null;
|
|
14
|
-
photoURL: string | null;
|
|
15
|
-
phoneNumber: string | null;
|
|
16
|
-
isAnonymous: boolean;
|
|
17
|
-
metadata: UserMetadata;
|
|
18
|
-
providerData: ProviderData[];
|
|
19
|
-
password?: string;
|
|
20
|
-
constructor(uid: string, email?: string | null, displayName?: string | null, photoURL?: string | null);
|
|
21
|
-
toJSON(): object;
|
|
22
|
-
getIdToken(forceRefresh?: boolean): Promise<string>;
|
|
23
|
-
getIdTokenResult(forceRefresh?: boolean): Promise<IdTokenResult>;
|
|
24
|
-
refresh(): Promise<void>;
|
|
25
|
-
delete(): Promise<void>;
|
|
26
|
-
linkWithCredential(credential: AuthCredential): Promise<UserCredential>;
|
|
27
|
-
unlink(providerId: string): Promise<UserCredential>;
|
|
28
|
-
reauthenticateWithCredential(credential: AuthCredential): Promise<UserCredential>;
|
|
29
|
-
updateProfile(profile: {
|
|
30
|
-
displayName?: string;
|
|
31
|
-
photoURL?: string;
|
|
32
|
-
}): Promise<void>;
|
|
33
|
-
updateEmail(newEmail: string): Promise<void>;
|
|
34
|
-
updatePassword(newPassword: string): Promise<void>;
|
|
35
|
-
updatePhoneNumber(credential: AuthCredential): Promise<void>;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Auth credential implementation
|
|
39
|
-
*/
|
|
40
|
-
export declare class AuthCredentialImpl implements AuthCredential {
|
|
41
|
-
providerId: string;
|
|
42
|
-
signInMethod: string;
|
|
43
|
-
_idToken?: string;
|
|
44
|
-
_accessToken?: string;
|
|
45
|
-
_secret?: string;
|
|
46
|
-
_refreshToken?: string;
|
|
47
|
-
constructor(providerId: string, signInMethod: string);
|
|
48
|
-
toJSON(): object;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Create user with email and password
|
|
52
|
-
*/
|
|
53
|
-
export declare function createUserWithEmailAndPassword(auth: FirebaseAuth, email: string, password: string): Promise<UserCredential>;
|
|
54
|
-
/**
|
|
55
|
-
* Sign in with email and password
|
|
56
|
-
*/
|
|
57
|
-
export declare function signInWithEmailAndPassword(auth: FirebaseAuth, email: string, password: string): Promise<UserCredential>;
|
|
58
|
-
/**
|
|
59
|
-
* Sign in anonymously
|
|
60
|
-
*/
|
|
61
|
-
export declare function signInAnonymously(auth: FirebaseAuth): Promise<UserCredential>;
|
|
62
|
-
/**
|
|
63
|
-
* Sign out
|
|
64
|
-
*/
|
|
65
|
-
export declare function signOut(auth: FirebaseAuth): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* Get current user
|
|
68
|
-
*/
|
|
69
|
-
export declare function getCurrentUser(auth: FirebaseAuth): User | null;
|
|
70
|
-
/**
|
|
71
|
-
* On auth state changed
|
|
72
|
-
*/
|
|
73
|
-
export declare function onAuthStateChanged(auth: FirebaseAuth, callback: (user: User | null) => void): () => void;
|
|
74
|
-
/**
|
|
75
|
-
* Update user profile
|
|
76
|
-
*/
|
|
77
|
-
export declare function updateUserProfile(user: User, profile: {
|
|
78
|
-
displayName?: string;
|
|
79
|
-
photoURL?: string;
|
|
80
|
-
}): Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* Update user email
|
|
83
|
-
*/
|
|
84
|
-
export declare function updateUserEmail(user: User, newEmail: string): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Update user password
|
|
87
|
-
*/
|
|
88
|
-
export declare function updateUserPassword(user: User, newPassword: string): Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* Delete user
|
|
91
|
-
*/
|
|
92
|
-
export declare function deleteUser(user: User): Promise<void>;
|
|
93
|
-
/**
|
|
94
|
-
* Send password reset email
|
|
95
|
-
*/
|
|
96
|
-
export declare function sendPasswordResetEmail(auth: FirebaseAuth, email: string): Promise<void>;
|
|
97
|
-
/**
|
|
98
|
-
* Send email verification
|
|
99
|
-
*/
|
|
100
|
-
export declare function sendEmailVerification(user: User): Promise<void>;
|
|
101
|
-
/**
|
|
102
|
-
* Persistence options
|
|
103
|
-
*/
|
|
104
|
-
export declare const browserLocalPersistence: {
|
|
105
|
-
type: string;
|
|
106
|
-
};
|
|
107
|
-
export declare const browserSessionPersistence: {
|
|
108
|
-
type: string;
|
|
109
|
-
};
|
|
110
|
-
export declare const inMemoryPersistence: {
|
|
111
|
-
type: string;
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Set persistence
|
|
115
|
-
*/
|
|
116
|
-
export declare function setPersistence(auth: FirebaseAuth, persistence: any): Promise<void>;
|
|
117
|
-
export declare function getAuth(app?: any): FirebaseAuth;
|
|
118
|
-
/**
|
|
119
|
-
* TOTP Generator for MFA
|
|
120
|
-
*/
|
|
121
|
-
export declare class TotpMultiFactorGenerator {
|
|
122
|
-
static generateSecret(): string;
|
|
123
|
-
static assertionForEnrollment(secret: string): MultiFactorSession;
|
|
124
|
-
static assertionForSignIn(factorInfo: MultiFactorInfo, code: string): MultiFactorSession;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Phone Multi-Factor Generator
|
|
128
|
-
*/
|
|
129
|
-
export declare class PhoneMultiFactorGenerator {
|
|
130
|
-
static assertion(confirmationResult: any): MultiFactorSession;
|
|
131
|
-
}
|
|
132
|
-
export { BaseOAuthProvider, GoogleAuthProvider, FacebookAuthProvider, GithubAuthProvider, TwitterAuthProvider, MicrosoftAuthProvider, AppleAuthProvider, LinkedInAuthProvider, YahooAuthProvider, InstagramAuthProvider, TikTokAuthProvider, TwitchAuthProvider, DiscordAuthProvider, SlackAuthProvider, SpotifyAuthProvider, StripeAuthProvider, DropboxAuthProvider, BoxAuthProvider, OktaAuthProvider, Auth0Provider, AmazonAuthProvider, GenericOAuthProvider, OAUTH_PROVIDERS, getOAuthProvider, type OAuthProviderType, } from './providers.js';
|
|
133
|
-
export declare function updatePassword(user: User, newPassword: string): Promise<void>;
|
|
134
|
-
export declare function updateProfile(user: User, profile: {
|
|
135
|
-
displayName?: string;
|
|
136
|
-
photoURL?: string;
|
|
137
|
-
}): Promise<void>;
|