@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.
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 +8 -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 -67
  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,353 +0,0 @@
1
- import { LensEngine } from '../schema/lens.js';
2
- import type { RelayDiscoveryConfig, RelayPerformanceConfig, RelayPrivacyConfig } from '../sync/hybrid-provider.js';
3
- /**
4
- * Cloud sync configuration - enables automatic D1/R2 AND Relay sync
5
- *
6
- * Dash uses DUAL SYNC by default:
7
- * - Relay: Real-time sync to other connected clients (WebSocket/WebTransport)
8
- * - D1: Persistent cloud storage (HTTP, batched)
9
- *
10
- * Both run simultaneously - Relay for speed, D1 for durability.
11
- * Gracefully degrades if either fails - local data always works.
12
- */
13
- export interface CloudConfig {
14
- /** Base URL for D1 sync endpoint (e.g., 'https://api.example.com'). Auto-detected from env if not provided. */
15
- baseUrl?: string;
16
- /** D1 sync interval in ms (default: 30000 = 30s). Set to 0 to disable. */
17
- syncInterval?: number;
18
- /** Relay WebSocket URL (e.g., 'wss://relay.example.com'). Auto-detected from env if not provided. */
19
- relayUrl?: string;
20
- /** Relay room name. Defaults to 'dash-{userId}' */
21
- relayRoom?: string;
22
- /** Enable high-frequency mode for Relay (uses WebTransport if available) */
23
- relayHighFrequency?: boolean;
24
- /** Optional peer discovery settings for Relay endpoint routing */
25
- relayDiscovery?: RelayDiscoveryConfig;
26
- /** Optional performance settings (adaptive compression + batching) */
27
- relayPerformance?: RelayPerformanceConfig;
28
- /** Optional privacy settings (room-scoped payload encryption) */
29
- relayPrivacy?: RelayPrivacyConfig;
30
- /** Auth token getter - called before each sync */
31
- getAuthToken?: () => Promise<string | null>;
32
- /** User ID for relay room naming */
33
- userId?: string;
34
- /** Tables to exclude from sync (internal tables are always excluded) */
35
- excludeTables?: string[];
36
- /** Callback when sync completes (D1 or Relay) */
37
- onSyncComplete?: (result: CloudSyncResult) => void;
38
- /** Callback when sync fails */
39
- onSyncError?: (error: Error) => void;
40
- /** Explicitly disable all cloud sync (default: false) */
41
- disabled?: boolean;
42
- /** Disable D1 sync only (default: false) */
43
- disableD1?: boolean;
44
- /** Disable Relay sync only (default: false) */
45
- disableRelay?: boolean;
46
- }
47
- export interface CloudSyncResult {
48
- pushed: number;
49
- pulled: number;
50
- errors: string[];
51
- timestamp: number;
52
- }
53
- export declare class DashEngine {
54
- private db;
55
- private readyPromise;
56
- private listeners;
57
- lens: LensEngine;
58
- currentSchemaVersion: number;
59
- private cloudConfig;
60
- private cloudSyncTimer;
61
- private isCloudSyncing;
62
- private lastCloudSyncTime;
63
- private cloudSyncEnabled;
64
- private syncedTables;
65
- private relayProvider;
66
- private relayDoc;
67
- private relaySyncEnabled;
68
- private readonly INTERNAL_TABLES;
69
- constructor();
70
- private init;
71
- /**
72
- * Try to auto-enable cloud sync from environment
73
- * Cloud sync is ON BY DEFAULT when a sync endpoint is detected
74
- */
75
- private tryAutoEnableCloudSync;
76
- /**
77
- * Detect sync endpoint from environment variables or same-origin
78
- */
79
- private detectSyncEndpoint;
80
- /**
81
- * Detect relay endpoint from environment variables
82
- */
83
- private detectRelayEndpoint;
84
- /**
85
- * Get default auth token from common auth patterns
86
- */
87
- private getDefaultAuthToken;
88
- private initializeSchema;
89
- ready(): Promise<void>;
90
- private tableListeners;
91
- subscribe(table: string, callback: () => void): () => void;
92
- private notify;
93
- private notifyChanges;
94
- execute(sql: string, bind?: any[]): any[];
95
- getFloat32(sql: string, bind?: any[]): Float32Array | null;
96
- addWithEmbedding(id: string, content: string, spatial?: {
97
- x: number;
98
- y: number;
99
- z: number;
100
- }): Promise<never[]>;
101
- search(query: string, limit?: number): Promise<any[]>;
102
- spatialQuery(bounds: {
103
- minX: number;
104
- maxX: number;
105
- minY: number;
106
- maxY: number;
107
- minZ: number;
108
- maxZ: number;
109
- }): Promise<any[]>;
110
- close(): void;
111
- /**
112
- * Stop Relay sync
113
- */
114
- stopRelaySync(): void;
115
- /**
116
- * Enable cloud sync - changes automatically sync to D1/R2
117
- * Just call this once with your config, and sync happens magically.
118
- *
119
- * Cloud sync is ON BY DEFAULT when running in a Cloudflare environment.
120
- * Call this to customize the config or explicitly enable/disable.
121
- *
122
- * @example
123
- * ```ts
124
- * await dash.ready();
125
- * // Option 1: Use auto-detected endpoint (default)
126
- * // Cloud sync is already enabled if DASH_SYNC_URL env var is set
127
- *
128
- * // Option 2: Explicit config
129
- * dash.enableCloudSync({
130
- * baseUrl: 'https://api.example.com',
131
- * getAuthToken: async () => auth.token,
132
- * });
133
- *
134
- * // Option 3: Disable cloud sync
135
- * dash.enableCloudSync({ disabled: true });
136
- * ```
137
- */
138
- enableCloudSync(config?: CloudConfig): void;
139
- /**
140
- * Initialize Relay sync for real-time updates
141
- */
142
- private initializeRelaySync;
143
- /**
144
- * Apply an update from Relay to local SQLite
145
- */
146
- private applyRelayUpdate;
147
- /**
148
- * Broadcast a local change to Relay
149
- */
150
- private broadcastToRelay;
151
- /**
152
- * Initialize cloud sync schema (queue and metadata tables)
153
- */
154
- private initializeCloudSyncSchema;
155
- /**
156
- * Set up sync triggers for all user tables
157
- */
158
- private setupAllTableTriggers;
159
- /**
160
- * Check if a table should be synced
161
- */
162
- private shouldSyncTable;
163
- /**
164
- * Set up sync triggers for a specific table
165
- */
166
- private setupTableSyncTriggers;
167
- /**
168
- * Build json_object() arguments for a table's columns
169
- */
170
- private buildJsonObjectArgs;
171
- /**
172
- * Start automatic cloud sync
173
- */
174
- private startCloudSync;
175
- /**
176
- * Stop automatic cloud sync
177
- */
178
- stopCloudSync(): void;
179
- /**
180
- * Perform a sync to cloud (D1/R2)
181
- */
182
- syncToCloud(): Promise<CloudSyncResult>;
183
- /**
184
- * Apply a single server change locally
185
- */
186
- private applyServerChange;
187
- /**
188
- * Force a full cloud sync (reset last sync time)
189
- */
190
- forceCloudSync(): Promise<CloudSyncResult>;
191
- /**
192
- * Get cloud sync status (D1 and Relay)
193
- */
194
- getCloudSyncStatus(): {
195
- enabled: boolean;
196
- syncing: boolean;
197
- lastSyncTime: number;
198
- pendingChanges: number;
199
- syncedTables: string[];
200
- d1: {
201
- enabled: boolean;
202
- syncing: boolean;
203
- lastSyncTime: number;
204
- pendingChanges: number;
205
- };
206
- relay: {
207
- enabled: boolean;
208
- connected: boolean;
209
- roomName: string | null;
210
- peerCount: number;
211
- };
212
- };
213
- /**
214
- * Disable cloud sync (both D1 and Relay)
215
- */
216
- disableCloudSync(): void;
217
- /**
218
- * Get information about all tables in the database
219
- */
220
- getAllTables(): TableInfo[];
221
- /**
222
- * Get detailed schema information for a specific table
223
- */
224
- getTableSchema(tableName: string): TableSchema | null;
225
- /**
226
- * Get the row count for a specific table
227
- */
228
- getTableRowCount(tableName: string): number;
229
- /**
230
- * Get statistics about the vector index
231
- */
232
- getVectorIndexStats(): VectorIndexStats;
233
- /**
234
- * Get all embeddings from the vector index
235
- */
236
- getAllEmbeddings(limit?: number, offset?: number): EmbeddingEntry[];
237
- /**
238
- * Search for similar vectors given a raw vector
239
- */
240
- searchSimilarByVector(vector: number[], k?: number): SimilarityResult[];
241
- /**
242
- * Get statistics about the spatial R-Tree index
243
- */
244
- getSpatialIndexStats(): SpatialIndexStats;
245
- /**
246
- * Get all spatial bounds from the R-Tree index
247
- */
248
- getAllSpatialBounds(limit?: number, offset?: number): SpatialBound[];
249
- /**
250
- * Get information about active table subscriptions
251
- */
252
- getActiveSubscriptions(): SubscriptionInfo[];
253
- /**
254
- * Get table listener counts as a map
255
- */
256
- getTableListenerCounts(): Record<string, number>;
257
- /**
258
- * Check if the database is ready
259
- */
260
- isReady(): boolean;
261
- /**
262
- * Get database metadata
263
- */
264
- getDatabaseInfo(): DatabaseInfo;
265
- }
266
- export interface TableInfo {
267
- name: string;
268
- type: 'table' | 'virtual';
269
- rowCount: number;
270
- isVirtual: boolean;
271
- }
272
- export interface TableSchema {
273
- name: string;
274
- columns: ColumnInfo[];
275
- indexes: IndexInfo[];
276
- foreignKeys: ForeignKeyInfo[];
277
- rowCount: number;
278
- }
279
- export interface ColumnInfo {
280
- cid: number;
281
- name: string;
282
- type: string;
283
- notNull: boolean;
284
- defaultValue: string | null;
285
- isPrimaryKey: boolean;
286
- }
287
- export interface IndexInfo {
288
- name: string;
289
- unique: boolean;
290
- origin: string;
291
- }
292
- export interface ForeignKeyInfo {
293
- id: number;
294
- table: string;
295
- from: string;
296
- to: string;
297
- }
298
- export interface VectorIndexStats {
299
- totalEmbeddings: number;
300
- dimensions: number;
301
- indexExists: boolean;
302
- tableName?: string;
303
- error?: string;
304
- }
305
- export interface EmbeddingEntry {
306
- id: string;
307
- content: string | null;
308
- embedding: number[] | null;
309
- }
310
- export interface SimilarityResult {
311
- id: string;
312
- content: string | null;
313
- distance: number;
314
- score: number;
315
- }
316
- export interface SpatialIndexStats {
317
- totalEntries: number;
318
- indexExists: boolean;
319
- tableName?: string;
320
- globalBounds?: {
321
- minX: number;
322
- maxX: number;
323
- minY: number;
324
- maxY: number;
325
- minZ: number;
326
- maxZ: number;
327
- };
328
- error?: string;
329
- }
330
- export interface SpatialBound {
331
- id: string;
332
- rowid: number;
333
- bounds: {
334
- minX: number;
335
- maxX: number;
336
- minY: number;
337
- maxY: number;
338
- minZ: number;
339
- maxZ: number;
340
- };
341
- content: string | null;
342
- }
343
- export interface SubscriptionInfo {
344
- table: string;
345
- listenerCount: number;
346
- }
347
- export interface DatabaseInfo {
348
- ready: boolean;
349
- schemaVersion: number;
350
- tableCount: number;
351
- tables?: string[];
352
- }
353
- export declare const dash: DashEngine;