@affectively/dash 5.4.1 → 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.
Files changed (92) hide show
  1. package/README.md +8 -189
  2. package/dist/automerge_wasm_bg-4hg5vg2g.wasm +0 -0
  3. package/dist/engine/sqlite.d.ts +30 -0
  4. package/dist/engine/vec_extension.d.ts +2 -0
  5. package/dist/index.d.ts +73 -0
  6. package/dist/index.js +53895 -0
  7. package/dist/middleware/errorHandler.d.ts +60 -0
  8. package/dist/{src/sync → sync}/AeonDurableSync.d.ts +7 -9
  9. package/dist/sync/AeonDurableSync.js +1984 -0
  10. package/dist/{src/sync → sync}/AutomergeProvider.d.ts +8 -8
  11. package/dist/sync/AutomergeProvider.js +4421 -0
  12. package/dist/sync/HybridProvider.d.ts +124 -0
  13. package/dist/sync/HybridProvider.js +8328 -0
  14. package/dist/sync/connection/WebRTCConnection.d.ts +23 -0
  15. package/dist/sync/connection/WebRTCConnection.js +59 -0
  16. package/dist/sync/index.d.ts +13 -0
  17. package/dist/sync/index.js +12773 -0
  18. package/dist/sync/provider/YjsSqliteProvider.d.ts +17 -0
  19. package/dist/sync/provider/YjsSqliteProvider.js +54 -0
  20. package/dist/sync/types.d.ts +74 -0
  21. package/dist/sync/webtransport/WebTransportProvider.d.ts +16 -0
  22. package/dist/sync/webtransport/WebTransportProvider.js +55 -0
  23. package/package.json +62 -70
  24. package/dist/src/api/firebase/auth/index.d.ts +0 -137
  25. package/dist/src/api/firebase/auth/index.js +0 -352
  26. package/dist/src/api/firebase/auth/providers.d.ts +0 -254
  27. package/dist/src/api/firebase/auth/providers.js +0 -518
  28. package/dist/src/api/firebase/database/index.d.ts +0 -108
  29. package/dist/src/api/firebase/database/index.js +0 -368
  30. package/dist/src/api/firebase/errors.d.ts +0 -15
  31. package/dist/src/api/firebase/errors.js +0 -215
  32. package/dist/src/api/firebase/firestore/data-types.d.ts +0 -116
  33. package/dist/src/api/firebase/firestore/data-types.js +0 -280
  34. package/dist/src/api/firebase/firestore/index.d.ts +0 -7
  35. package/dist/src/api/firebase/firestore/index.js +0 -13
  36. package/dist/src/api/firebase/firestore/listeners.d.ts +0 -20
  37. package/dist/src/api/firebase/firestore/listeners.js +0 -50
  38. package/dist/src/api/firebase/firestore/operations.d.ts +0 -123
  39. package/dist/src/api/firebase/firestore/operations.js +0 -490
  40. package/dist/src/api/firebase/firestore/query.d.ts +0 -118
  41. package/dist/src/api/firebase/firestore/query.js +0 -418
  42. package/dist/src/api/firebase/index.d.ts +0 -11
  43. package/dist/src/api/firebase/index.js +0 -17
  44. package/dist/src/api/firebase/storage/index.d.ts +0 -100
  45. package/dist/src/api/firebase/storage/index.js +0 -286
  46. package/dist/src/api/firebase/types.d.ts +0 -341
  47. package/dist/src/api/firebase/types.js +0 -4
  48. package/dist/src/auth/manager.d.ts +0 -182
  49. package/dist/src/auth/manager.js +0 -598
  50. package/dist/src/engine/ai.js +0 -76
  51. package/dist/src/engine/sqlite.d.ts +0 -353
  52. package/dist/src/engine/sqlite.js +0 -1328
  53. package/dist/src/engine/vec_extension.d.ts +0 -5
  54. package/dist/src/engine/vec_extension.js +0 -10
  55. package/dist/src/index.d.ts +0 -21
  56. package/dist/src/index.js +0 -26
  57. package/dist/src/mcp/server.js +0 -87
  58. package/dist/src/reactivity/signal.js +0 -31
  59. package/dist/src/schema/lens.d.ts +0 -29
  60. package/dist/src/schema/lens.js +0 -122
  61. package/dist/src/sync/AeonDurableSync.js +0 -133
  62. package/dist/src/sync/AutomergeProvider.js +0 -153
  63. package/dist/src/sync/aeon/config.d.ts +0 -21
  64. package/dist/src/sync/aeon/config.js +0 -14
  65. package/dist/src/sync/aeon/delta-adapter.d.ts +0 -62
  66. package/dist/src/sync/aeon/delta-adapter.js +0 -98
  67. package/dist/src/sync/aeon/index.d.ts +0 -18
  68. package/dist/src/sync/aeon/index.js +0 -19
  69. package/dist/src/sync/aeon/offline-adapter.d.ts +0 -110
  70. package/dist/src/sync/aeon/offline-adapter.js +0 -227
  71. package/dist/src/sync/aeon/presence-adapter.d.ts +0 -114
  72. package/dist/src/sync/aeon/presence-adapter.js +0 -157
  73. package/dist/src/sync/aeon/schema-adapter.d.ts +0 -95
  74. package/dist/src/sync/aeon/schema-adapter.js +0 -163
  75. package/dist/src/sync/backup.d.ts +0 -12
  76. package/dist/src/sync/backup.js +0 -44
  77. package/dist/src/sync/connection.d.ts +0 -20
  78. package/dist/src/sync/connection.js +0 -50
  79. package/dist/src/sync/d1-provider.d.ts +0 -103
  80. package/dist/src/sync/d1-provider.js +0 -418
  81. package/dist/src/sync/hybrid-provider.d.ts +0 -307
  82. package/dist/src/sync/hybrid-provider.js +0 -1353
  83. package/dist/src/sync/provider.d.ts +0 -11
  84. package/dist/src/sync/provider.js +0 -67
  85. package/dist/src/sync/types.d.ts +0 -32
  86. package/dist/src/sync/types.js +0 -4
  87. package/dist/src/sync/verify.d.ts +0 -1
  88. package/dist/src/sync/verify.js +0 -23
  89. package/dist/tsconfig.tsbuildinfo +0 -1
  90. /package/dist/{src/engine → engine}/ai.d.ts +0 -0
  91. /package/dist/{src/mcp → mcp}/server.d.ts +0 -0
  92. /package/dist/{src/reactivity → reactivity}/signal.d.ts +0 -0
@@ -1,157 +0,0 @@
1
- /**
2
- * Presence Adapter for Dash
3
- *
4
- * Bridges Yjs awareness protocol with Aeon's AgentPresenceManager.
5
- * Provides rich presence features: cursor tracking, active sections, roles.
6
- */
7
- import { AgentPresenceManager, } from '@affectively/aeon';
8
- /**
9
- * Adapter that syncs Yjs awareness with Aeon presence
10
- */
11
- export class DashPresenceAdapter {
12
- aeonPresence;
13
- yjsAwareness;
14
- localAgentId;
15
- roomId;
16
- constructor(roomId, awareness) {
17
- this.roomId = roomId;
18
- this.yjsAwareness = awareness;
19
- this.localAgentId = `agent-${awareness.clientID}`;
20
- this.aeonPresence = new AgentPresenceManager(roomId);
21
- // Register local agent
22
- this.aeonPresence.agentJoined(this.localAgentId, `User ${awareness.clientID}`, 'user');
23
- // Bidirectional sync setup
24
- this.setupYjsToAeonSync();
25
- this.setupAeonToYjsSync();
26
- }
27
- /**
28
- * Sync Yjs awareness updates to Aeon presence
29
- */
30
- setupYjsToAeonSync() {
31
- this.yjsAwareness.on('update', ({ added, updated, removed }) => {
32
- const states = this.yjsAwareness.getStates();
33
- // Handle added/updated
34
- for (const clientId of [...added, ...updated]) {
35
- const state = states.get(clientId);
36
- if (state) {
37
- const agentId = `agent-${clientId}`;
38
- if (added.includes(clientId)) {
39
- this.aeonPresence.agentJoined(agentId, state.user?.name || `User ${clientId}`, state.user?.role || 'user', state.metadata);
40
- }
41
- // Sync cursor and section if present
42
- if (state.cursor) {
43
- this.aeonPresence.updateCursor(agentId, state.cursor.x ?? 0, state.cursor.y ?? 0, state.cursor.path ?? '');
44
- }
45
- if (state.activeSection) {
46
- this.aeonPresence.updateActiveSection(agentId, state.activeSection);
47
- }
48
- // Heartbeat to keep presence alive
49
- this.aeonPresence.heartbeat(agentId);
50
- }
51
- }
52
- // Handle removed
53
- for (const clientId of removed) {
54
- this.aeonPresence.agentLeft(`agent-${clientId}`);
55
- }
56
- });
57
- }
58
- /**
59
- * Sync Aeon presence updates back to Yjs awareness
60
- */
61
- setupAeonToYjsSync() {
62
- // When local presence updates via Aeon API, reflect to Yjs
63
- this.aeonPresence.on('cursor_updated', ({ agentId, cursorPosition }) => {
64
- if (agentId === this.localAgentId) {
65
- this.yjsAwareness.setLocalStateField('cursor', cursorPosition);
66
- }
67
- });
68
- this.aeonPresence.on('section_updated', ({ agentId, activeSection }) => {
69
- if (agentId === this.localAgentId) {
70
- this.yjsAwareness.setLocalStateField('activeSection', activeSection);
71
- }
72
- });
73
- }
74
- // ============================================
75
- // Rich Presence API
76
- // ============================================
77
- /**
78
- * Update local cursor position
79
- */
80
- updateCursor(x, y, path) {
81
- this.aeonPresence.updateCursor(this.localAgentId, x, y, path);
82
- }
83
- /**
84
- * Update local active section
85
- */
86
- updateActiveSection(section) {
87
- this.aeonPresence.updateActiveSection(this.localAgentId, section);
88
- }
89
- /**
90
- * Update local user info
91
- */
92
- updateUserInfo(name, role = 'user') {
93
- this.aeonPresence.updatePresence(this.localAgentId, {
94
- agentId: this.localAgentId,
95
- name,
96
- role,
97
- status: 'online',
98
- });
99
- // Also sync to Yjs awareness
100
- this.yjsAwareness.setLocalStateField('user', { name, role });
101
- }
102
- /**
103
- * Get all online agents
104
- */
105
- getOnlineAgents() {
106
- return this.aeonPresence.getOnlineAgents();
107
- }
108
- /**
109
- * Get all agents (including offline)
110
- */
111
- getAllAgents() {
112
- return this.aeonPresence.getAllAgents();
113
- }
114
- /**
115
- * Get presence for specific agent
116
- */
117
- getPresence(agentId) {
118
- return this.aeonPresence.getPresence(agentId);
119
- }
120
- /**
121
- * Get agents in a specific section
122
- */
123
- getAgentsInSection(section) {
124
- return this.aeonPresence.getInSection(section);
125
- }
126
- /**
127
- * Get presence statistics
128
- */
129
- getStats() {
130
- return this.aeonPresence.getPresenceStats();
131
- }
132
- /**
133
- * Get local agent ID
134
- */
135
- getLocalAgentId() {
136
- return this.localAgentId;
137
- }
138
- /**
139
- * Subscribe to presence events
140
- */
141
- on(event, handler) {
142
- this.aeonPresence.on(event, handler);
143
- }
144
- /**
145
- * Unsubscribe from presence events
146
- */
147
- off(event, handler) {
148
- this.aeonPresence.off(event, handler);
149
- }
150
- /**
151
- * Cleanup
152
- */
153
- destroy() {
154
- this.aeonPresence.agentLeft(this.localAgentId);
155
- this.aeonPresence.destroy();
156
- }
157
- }
@@ -1,95 +0,0 @@
1
- /**
2
- * Schema Adapter for Dash
3
- *
4
- * Bridges Aeon's SchemaVersionManager with Dash's LensEngine.
5
- * Provides migration tracking, version compatibility checks, and audit trails.
6
- */
7
- import { type SchemaVersion, type Migration, type MigrationResult } from '@affectively/aeon';
8
- import { LensEngine, type LensOp } from '../../schema/lens.js';
9
- /**
10
- * Adapter that bridges Aeon versioning with Dash's Lens system
11
- */
12
- export declare class DashSchemaAdapter {
13
- private versionManager;
14
- private migrationEngine;
15
- private migrationTracker;
16
- private lensEngine;
17
- constructor(lensEngine: LensEngine);
18
- /**
19
- * Register a schema version with associated Lens operations
20
- */
21
- registerVersion(version: string, description: string, lensOps?: LensOp[], breaking?: boolean): void;
22
- /**
23
- * Register a migration for a version upgrade
24
- */
25
- registerMigration(id: string, fromVersion: string, toVersion: string, migrate: (data: unknown) => unknown, rollback?: (data: unknown) => unknown): void;
26
- /**
27
- * Execute a migration on data
28
- */
29
- executeMigration(migrationId: string, data: unknown): Promise<MigrationResult>;
30
- /**
31
- * Rollback a migration
32
- */
33
- rollbackMigration(migrationId: string, data: unknown): Promise<MigrationResult>;
34
- /**
35
- * Migrate data using Lens transformations
36
- */
37
- migrateWithLens(data: Record<string, unknown>, fromVersion: number, toVersion: number): Record<string, unknown>;
38
- /**
39
- * Get current version
40
- */
41
- getCurrentVersion(): SchemaVersion;
42
- /**
43
- * Get a specific version by string
44
- */
45
- getVersion(version: string): SchemaVersion | undefined;
46
- /**
47
- * Get migration by ID
48
- */
49
- getMigration(id: string): Migration | undefined;
50
- /**
51
- * Check if migration is needed
52
- */
53
- needsMigration(fromVersion: string, toVersion: string): boolean;
54
- /**
55
- * Get migration path between versions
56
- */
57
- getMigrationPath(fromVersion: string, toVersion: string): SchemaVersion[];
58
- /**
59
- * Get pending migrations
60
- */
61
- getPendingMigrations(): Migration[];
62
- /**
63
- * Get migration statistics
64
- */
65
- getStatistics(): {
66
- engine: {
67
- totalExecuted: number;
68
- successful: number;
69
- failed: number;
70
- successRate: number;
71
- totalDurationMs: number;
72
- averageDurationMs: number;
73
- totalAffected: number;
74
- };
75
- tracker: {
76
- total: number;
77
- applied: number;
78
- failed: number;
79
- pending: number;
80
- rolledBack: number;
81
- successRate: number;
82
- totalDurationMs: number;
83
- averageDurationMs: number;
84
- totalItemsAffected: number;
85
- };
86
- };
87
- /**
88
- * Format version for display
89
- */
90
- formatVersion(version: SchemaVersion): string;
91
- }
92
- /**
93
- * Create a schema adapter from an existing LensEngine
94
- */
95
- export declare function createSchemaAdapter(lensEngine: LensEngine): DashSchemaAdapter;
@@ -1,163 +0,0 @@
1
- /**
2
- * Schema Adapter for Dash
3
- *
4
- * Bridges Aeon's SchemaVersionManager with Dash's LensEngine.
5
- * Provides migration tracking, version compatibility checks, and audit trails.
6
- */
7
- import { SchemaVersionManager, MigrationEngine, MigrationTracker, } from '@affectively/aeon';
8
- /**
9
- * Adapter that bridges Aeon versioning with Dash's Lens system
10
- */
11
- export class DashSchemaAdapter {
12
- versionManager;
13
- migrationEngine;
14
- migrationTracker;
15
- lensEngine;
16
- constructor(lensEngine) {
17
- this.versionManager = new SchemaVersionManager();
18
- this.migrationEngine = new MigrationEngine();
19
- this.migrationTracker = new MigrationTracker();
20
- this.lensEngine = lensEngine;
21
- }
22
- /**
23
- * Register a schema version with associated Lens operations
24
- */
25
- registerVersion(version, description, lensOps, breaking = false) {
26
- const [major, minor, patch] = version.split('.').map(Number);
27
- // Register with Aeon
28
- this.versionManager.registerVersion({
29
- major,
30
- minor,
31
- patch,
32
- timestamp: new Date().toISOString(),
33
- description,
34
- breaking,
35
- });
36
- // Register Lens if provided
37
- if (lensOps && major > 1) {
38
- this.lensEngine.registerLens(major - 1, major, lensOps);
39
- }
40
- }
41
- /**
42
- * Register a migration for a version upgrade
43
- */
44
- registerMigration(id, fromVersion, toVersion, migrate, rollback) {
45
- const migration = {
46
- id,
47
- name: `${fromVersion} -> ${toVersion}`,
48
- version: toVersion,
49
- description: `Migrate from ${fromVersion} to ${toVersion}`,
50
- timestamp: new Date().toISOString(),
51
- up: migrate,
52
- down: rollback,
53
- };
54
- this.migrationEngine.registerMigration(migration);
55
- }
56
- /**
57
- * Execute a migration on data
58
- */
59
- async executeMigration(migrationId, data) {
60
- const result = await this.migrationEngine.executeMigration(migrationId, data);
61
- // Track the migration
62
- const record = {
63
- id: `record-${Date.now()}`,
64
- migrationId,
65
- timestamp: new Date().toISOString(),
66
- version: result.migrationId,
67
- direction: 'up',
68
- status: result.success ? 'applied' : 'failed',
69
- duration: result.duration,
70
- itemsAffected: result.itemsAffected,
71
- errorMessage: result.errors.length > 0 ? result.errors.join(', ') : undefined,
72
- appliedBy: 'dash-schema-adapter',
73
- };
74
- this.migrationTracker.recordMigration(record);
75
- return result;
76
- }
77
- /**
78
- * Rollback a migration
79
- */
80
- async rollbackMigration(migrationId, data) {
81
- const result = await this.migrationEngine.rollbackMigration(migrationId, data);
82
- // Track the rollback
83
- const record = {
84
- id: `record-${Date.now()}`,
85
- migrationId,
86
- timestamp: new Date().toISOString(),
87
- version: result.migrationId,
88
- direction: 'down',
89
- status: result.success ? 'rolled-back' : 'failed',
90
- duration: result.duration,
91
- itemsAffected: result.itemsAffected,
92
- errorMessage: result.errors.length > 0 ? result.errors.join(', ') : undefined,
93
- appliedBy: 'dash-schema-adapter',
94
- };
95
- this.migrationTracker.recordMigration(record);
96
- return result;
97
- }
98
- /**
99
- * Migrate data using Lens transformations
100
- */
101
- migrateWithLens(data, fromVersion, toVersion) {
102
- return this.lensEngine.migrate(data, fromVersion, toVersion);
103
- }
104
- /**
105
- * Get current version
106
- */
107
- getCurrentVersion() {
108
- return this.versionManager.getCurrentVersion();
109
- }
110
- /**
111
- * Get a specific version by string
112
- */
113
- getVersion(version) {
114
- return this.versionManager.getVersion(version);
115
- }
116
- /**
117
- * Get migration by ID
118
- */
119
- getMigration(id) {
120
- return this.migrationEngine.getMigration(id);
121
- }
122
- /**
123
- * Check if migration is needed
124
- */
125
- needsMigration(fromVersion, toVersion) {
126
- return this.versionManager.canMigrate(fromVersion, toVersion);
127
- }
128
- /**
129
- * Get migration path between versions
130
- */
131
- getMigrationPath(fromVersion, toVersion) {
132
- const from = this.versionManager.parseVersion(fromVersion);
133
- const to = this.versionManager.parseVersion(toVersion);
134
- return this.versionManager.getMigrationPath(from, to);
135
- }
136
- /**
137
- * Get pending migrations
138
- */
139
- getPendingMigrations() {
140
- return this.migrationEngine.getPendingMigrations();
141
- }
142
- /**
143
- * Get migration statistics
144
- */
145
- getStatistics() {
146
- return {
147
- engine: this.migrationEngine.getStatistics(),
148
- tracker: this.migrationTracker.getStatistics(),
149
- };
150
- }
151
- /**
152
- * Format version for display
153
- */
154
- formatVersion(version) {
155
- return `${version.major}.${version.minor}.${version.patch}`;
156
- }
157
- }
158
- /**
159
- * Create a schema adapter from an existing LensEngine
160
- */
161
- export function createSchemaAdapter(lensEngine) {
162
- return new DashSchemaAdapter(lensEngine);
163
- }
@@ -1,12 +0,0 @@
1
- import * as Y from 'yjs';
2
- export interface CloudStorageAdapter {
3
- upload(name: string, data: Uint8Array): Promise<void>;
4
- download(name: string): Promise<Uint8Array | null>;
5
- }
6
- export declare function generateKey(): Promise<CryptoKey>;
7
- export declare function exportKey(key: CryptoKey): Promise<string>;
8
- export declare function importKey(jwkString: string): Promise<CryptoKey>;
9
- export declare function encrypt(data: Uint8Array, key: CryptoKey): Promise<Uint8Array>;
10
- export declare function decrypt(data: Uint8Array, key: CryptoKey): Promise<Uint8Array>;
11
- export declare function backup(roomName: string, doc: Y.Doc, key: CryptoKey, adapter: CloudStorageAdapter): Promise<void>;
12
- export declare function restore(roomName: string, doc: Y.Doc, key: CryptoKey, adapter: CloudStorageAdapter): Promise<void>;
@@ -1,44 +0,0 @@
1
- import * as Y from 'yjs';
2
- // AES-GCM Encryption
3
- export async function generateKey() {
4
- return await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']);
5
- }
6
- export async function exportKey(key) {
7
- const exported = await crypto.subtle.exportKey('jwk', key);
8
- return JSON.stringify(exported);
9
- }
10
- export async function importKey(jwkString) {
11
- const jwk = JSON.parse(jwkString);
12
- return await crypto.subtle.importKey('jwk', jwk, { name: 'AES-GCM' }, true, ['encrypt', 'decrypt']);
13
- }
14
- export async function encrypt(data, key) {
15
- const iv = crypto.getRandomValues(new Uint8Array(12));
16
- // Ensure we have a proper ArrayBuffer (not SharedArrayBuffer) by creating a copy
17
- const dataCopy = new Uint8Array(data);
18
- const encrypted = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, dataCopy);
19
- // Combine IV and Encrypted Data
20
- const combined = new Uint8Array(iv.length + encrypted.byteLength);
21
- combined.set(iv);
22
- combined.set(new Uint8Array(encrypted), iv.length);
23
- return combined;
24
- }
25
- export async function decrypt(data, key) {
26
- const iv = data.slice(0, 12);
27
- const ciphertext = data.slice(12);
28
- const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, ciphertext);
29
- return new Uint8Array(decrypted);
30
- }
31
- export async function backup(roomName, doc, key, adapter) {
32
- const state = Y.encodeStateAsUpdate(doc);
33
- const encrypted = await encrypt(state, key);
34
- await adapter.upload(`backup_${roomName}`, encrypted);
35
- }
36
- export async function restore(roomName, doc, key, adapter) {
37
- const encrypted = await adapter.download(`backup_${roomName}`);
38
- if (!encrypted) {
39
- console.warn(`[CloudBackup] No backup found for room ${roomName}`);
40
- return;
41
- }
42
- const state = await decrypt(encrypted, key);
43
- Y.applyUpdate(doc, state);
44
- }
@@ -1,20 +0,0 @@
1
- import * as Y from 'yjs';
2
- export interface SyncConnectionConfig {
3
- type?: 'webrtc' | 'webtransport';
4
- roomName: string;
5
- doc: Y.Doc;
6
- signalingServers?: string[];
7
- password?: string | null;
8
- url?: string;
9
- awareness?: any;
10
- }
11
- export declare class SyncConnection {
12
- private provider;
13
- roomName: string;
14
- constructor(config: SyncConnectionConfig);
15
- disconnect(): void;
16
- get awareness(): any;
17
- }
18
- export declare class WebRTCConnection extends SyncConnection {
19
- constructor(config: Omit<SyncConnectionConfig, 'type'>);
20
- }
@@ -1,50 +0,0 @@
1
- import { WebrtcProvider } from 'y-webrtc';
2
- import { HybridProvider } from './hybrid-provider.js';
3
- export class SyncConnection {
4
- provider;
5
- roomName;
6
- constructor(config) {
7
- this.roomName = config.roomName;
8
- const type = config.type || 'webrtc'; // Default to WebRTC for backward compatibility
9
- if (type === 'webtransport') {
10
- if (!config.url) {
11
- throw new Error('WebTransport requires a "url" in config');
12
- }
13
- this.provider = new HybridProvider(config.url, config.roomName, config.doc, { awareness: config.awareness });
14
- }
15
- else {
16
- // Default signaling servers if none provided
17
- // Note: In production, users should host their own signaling servers
18
- const signaling = config.signalingServers || [
19
- 'wss://signaling.yjs.dev',
20
- 'wss://y-webrtc-signaling-eu.herokuapp.com',
21
- 'wss://y-webrtc-signaling-us.herokuapp.com'
22
- ];
23
- this.provider = new WebrtcProvider(config.roomName, config.doc, {
24
- signaling,
25
- password: config.password || undefined,
26
- awareness: config.awareness
27
- });
28
- }
29
- this.provider.on('synced', (event) => {
30
- console.log(`[${type === 'webtransport' ? 'WebTransport' : 'WebRTC'}] Room: ${this.roomName}, Synced: ${event.synced}`);
31
- });
32
- // Relay status from provider if available
33
- this.provider.on('status', (event) => {
34
- // loose typing for event forwarding
35
- console.log(`[${type}] Status update:`, event);
36
- });
37
- }
38
- disconnect() {
39
- this.provider.destroy();
40
- }
41
- get awareness() {
42
- return this.provider.awareness;
43
- }
44
- }
45
- // Backward compatibility alias
46
- export class WebRTCConnection extends SyncConnection {
47
- constructor(config) {
48
- super({ ...config, type: 'webrtc' });
49
- }
50
- }
@@ -1,103 +0,0 @@
1
- /**
2
- * D1 Sync Provider
3
- *
4
- * Provides HTTP-based sync between local Dash SQLite (WASM) and Cloudflare D1.
5
- *
6
- * Unlike the HybridProvider which syncs Yjs CRDT documents over WebSocket,
7
- * this provider syncs regular SQL tables via HTTP REST API.
8
- *
9
- * Architecture:
10
- * - Local changes are tracked in a sync_queue table
11
- * - Sync runs periodically or on-demand
12
- * - Conflicts are resolved using last-write-wins with _lastModified timestamps
13
- *
14
- * Security:
15
- * - Table/column names are validated against allowed patterns
16
- * - All user data uses parameterized queries
17
- */
18
- export interface D1SyncConfig {
19
- /** Base URL for the sync endpoint (e.g., 'https://example.com/api') */
20
- baseUrl: string;
21
- /** Tables to sync (e.g., ['reflections', 'users']) */
22
- tables: string[];
23
- /** Auth token getter - called before each sync */
24
- getAuthToken: () => Promise<string | null>;
25
- /** Sync interval in ms (default: 30000 = 30s). Set to 0 to disable auto-sync. */
26
- syncInterval?: number;
27
- /** Callback when sync completes */
28
- onSyncComplete?: (result: SyncResult) => void;
29
- /** Callback when sync fails */
30
- onSyncError?: (error: Error) => void;
31
- }
32
- export interface SyncResult {
33
- pushed: number;
34
- pulled: number;
35
- errors: string[];
36
- timestamp: number;
37
- }
38
- export interface SyncQueueEntry {
39
- id: number;
40
- table_name: string;
41
- row_id: string;
42
- operation: 'create' | 'update' | 'delete';
43
- data: string | null;
44
- created_at: number;
45
- synced: number;
46
- }
47
- export declare class D1SyncProvider {
48
- private config;
49
- private syncTimer;
50
- private isSyncing;
51
- private lastSyncTime;
52
- private initialized;
53
- constructor(config: D1SyncConfig);
54
- /**
55
- * Initialize the sync provider - must be called before syncing
56
- */
57
- initialize(): Promise<void>;
58
- /**
59
- * Set up SQLite triggers to track changes for a table
60
- * Uses validated identifiers to prevent SQL injection
61
- */
62
- private setupTableTriggers;
63
- /**
64
- * Start automatic sync at the configured interval
65
- */
66
- startAutoSync(): void;
67
- /**
68
- * Stop automatic sync
69
- */
70
- stopAutoSync(): void;
71
- /**
72
- * Perform a sync operation
73
- */
74
- sync(): Promise<SyncResult>;
75
- /**
76
- * Apply changes received from the server with Last-Write-Wins (LWW) conflict resolution
77
- * Server changes only win if their _lastModified is newer than local
78
- */
79
- private applyServerChanges;
80
- /**
81
- * Queue a change manually (for cases where triggers can't be used)
82
- */
83
- queueChange(tableName: string, rowId: string, operation: 'create' | 'update' | 'delete', data?: any): void;
84
- /**
85
- * Get the current sync status
86
- */
87
- getStatus(): {
88
- initialized: boolean;
89
- syncing: boolean;
90
- lastSyncTime: number;
91
- pendingChanges: number;
92
- };
93
- /**
94
- * Force a full sync by resetting last sync time
95
- */
96
- forceFullSync(): Promise<SyncResult>;
97
- /**
98
- * Destroy the provider and clean up
99
- */
100
- destroy(): void;
101
- }
102
- export declare function getD1SyncProvider(config?: D1SyncConfig): D1SyncProvider;
103
- export declare function resetD1SyncProvider(): void;