@affectively/dash 5.1.0 → 5.2.0

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 (36) hide show
  1. package/README.md +21 -0
  2. package/dist/src/api/firebase/auth/index.d.ts +137 -0
  3. package/dist/src/api/firebase/auth/index.js +352 -0
  4. package/dist/src/api/firebase/auth/providers.d.ts +254 -0
  5. package/dist/src/api/firebase/auth/providers.js +518 -0
  6. package/dist/src/api/firebase/database/index.d.ts +108 -0
  7. package/dist/src/api/firebase/database/index.js +368 -0
  8. package/dist/src/api/firebase/errors.d.ts +15 -0
  9. package/dist/src/api/firebase/errors.js +215 -0
  10. package/dist/src/api/firebase/firestore/data-types.d.ts +116 -0
  11. package/dist/src/api/firebase/firestore/data-types.js +280 -0
  12. package/dist/src/api/firebase/firestore/index.d.ts +7 -0
  13. package/dist/src/api/firebase/firestore/index.js +13 -0
  14. package/dist/src/api/firebase/firestore/listeners.d.ts +20 -0
  15. package/dist/src/api/firebase/firestore/listeners.js +50 -0
  16. package/dist/src/api/firebase/firestore/operations.d.ts +123 -0
  17. package/dist/src/api/firebase/firestore/operations.js +490 -0
  18. package/dist/src/api/firebase/firestore/query.d.ts +118 -0
  19. package/dist/src/api/firebase/firestore/query.js +418 -0
  20. package/dist/src/api/firebase/index.d.ts +11 -0
  21. package/dist/src/api/firebase/index.js +17 -0
  22. package/dist/src/api/firebase/storage/index.d.ts +100 -0
  23. package/dist/src/api/firebase/storage/index.js +286 -0
  24. package/dist/src/api/firebase/types.d.ts +341 -0
  25. package/dist/src/api/firebase/types.js +4 -0
  26. package/dist/src/auth/manager.d.ts +5 -1
  27. package/dist/src/auth/manager.js +19 -6
  28. package/dist/src/engine/sqlite.d.ts +129 -0
  29. package/dist/src/engine/sqlite.js +525 -0
  30. package/dist/src/index.d.ts +8 -0
  31. package/dist/src/index.js +17 -0
  32. package/dist/src/sync/aeon/offline-adapter.js +12 -8
  33. package/dist/src/sync/d1-provider.d.ts +97 -0
  34. package/dist/src/sync/d1-provider.js +345 -0
  35. package/dist/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +1 -1
@@ -1,12 +1,63 @@
1
1
  import { LensEngine } from '../schema/lens.js';
2
+ /**
3
+ * Cloud sync configuration - enables automatic D1/R2 sync
4
+ *
5
+ * Cloud sync is ON BY DEFAULT when:
6
+ * - Running in a Cloudflare environment (detected via env vars)
7
+ * - A sync endpoint is available
8
+ *
9
+ * It gracefully degrades if sync fails - local data still works.
10
+ */
11
+ export interface CloudConfig {
12
+ /** Base URL for the sync endpoint (e.g., 'https://api.example.com'). Auto-detected from env if not provided. */
13
+ baseUrl?: string;
14
+ /** Auth token getter - called before each sync */
15
+ getAuthToken?: () => Promise<string | null>;
16
+ /** Sync interval in ms (default: 30000 = 30s). Set to 0 to disable auto-sync. */
17
+ syncInterval?: number;
18
+ /** Tables to exclude from sync (internal tables are always excluded) */
19
+ excludeTables?: string[];
20
+ /** Callback when sync completes */
21
+ onSyncComplete?: (result: CloudSyncResult) => void;
22
+ /** Callback when sync fails */
23
+ onSyncError?: (error: Error) => void;
24
+ /** Explicitly disable cloud sync (default: false - sync is enabled if endpoint available) */
25
+ disabled?: boolean;
26
+ }
27
+ export interface CloudSyncResult {
28
+ pushed: number;
29
+ pulled: number;
30
+ errors: string[];
31
+ timestamp: number;
32
+ }
2
33
  export declare class DashEngine {
3
34
  private db;
4
35
  private readyPromise;
5
36
  private listeners;
6
37
  lens: LensEngine;
7
38
  currentSchemaVersion: number;
39
+ private cloudConfig;
40
+ private cloudSyncTimer;
41
+ private isCloudSyncing;
42
+ private lastCloudSyncTime;
43
+ private cloudSyncEnabled;
44
+ private syncedTables;
45
+ private readonly INTERNAL_TABLES;
8
46
  constructor();
9
47
  private init;
48
+ /**
49
+ * Try to auto-enable cloud sync from environment
50
+ * Cloud sync is ON BY DEFAULT when a sync endpoint is detected
51
+ */
52
+ private tryAutoEnableCloudSync;
53
+ /**
54
+ * Detect sync endpoint from environment variables
55
+ */
56
+ private detectSyncEndpoint;
57
+ /**
58
+ * Get default auth token from common auth patterns
59
+ */
60
+ private getDefaultAuthToken;
10
61
  private initializeSchema;
11
62
  ready(): Promise<void>;
12
63
  private tableListeners;
@@ -30,6 +81,84 @@ export declare class DashEngine {
30
81
  maxZ: number;
31
82
  }): Promise<any[]>;
32
83
  close(): void;
84
+ /**
85
+ * Enable cloud sync - changes automatically sync to D1/R2
86
+ * Just call this once with your config, and sync happens magically.
87
+ *
88
+ * Cloud sync is ON BY DEFAULT when running in a Cloudflare environment.
89
+ * Call this to customize the config or explicitly enable/disable.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * await dash.ready();
94
+ * // Option 1: Use auto-detected endpoint (default)
95
+ * // Cloud sync is already enabled if DASH_SYNC_URL env var is set
96
+ *
97
+ * // Option 2: Explicit config
98
+ * dash.enableCloudSync({
99
+ * baseUrl: 'https://api.example.com',
100
+ * getAuthToken: async () => auth.token,
101
+ * });
102
+ *
103
+ * // Option 3: Disable cloud sync
104
+ * dash.enableCloudSync({ disabled: true });
105
+ * ```
106
+ */
107
+ enableCloudSync(config?: CloudConfig): void;
108
+ /**
109
+ * Initialize cloud sync schema (queue and metadata tables)
110
+ */
111
+ private initializeCloudSyncSchema;
112
+ /**
113
+ * Set up sync triggers for all user tables
114
+ */
115
+ private setupAllTableTriggers;
116
+ /**
117
+ * Check if a table should be synced
118
+ */
119
+ private shouldSyncTable;
120
+ /**
121
+ * Set up sync triggers for a specific table
122
+ */
123
+ private setupTableSyncTriggers;
124
+ /**
125
+ * Build json_object() arguments for a table's columns
126
+ */
127
+ private buildJsonObjectArgs;
128
+ /**
129
+ * Start automatic cloud sync
130
+ */
131
+ private startCloudSync;
132
+ /**
133
+ * Stop automatic cloud sync
134
+ */
135
+ stopCloudSync(): void;
136
+ /**
137
+ * Perform a sync to cloud (D1/R2)
138
+ */
139
+ syncToCloud(): Promise<CloudSyncResult>;
140
+ /**
141
+ * Apply a single server change locally
142
+ */
143
+ private applyServerChange;
144
+ /**
145
+ * Force a full cloud sync (reset last sync time)
146
+ */
147
+ forceCloudSync(): Promise<CloudSyncResult>;
148
+ /**
149
+ * Get cloud sync status
150
+ */
151
+ getCloudSyncStatus(): {
152
+ enabled: boolean;
153
+ syncing: boolean;
154
+ lastSyncTime: number;
155
+ pendingChanges: number;
156
+ syncedTables: string[];
157
+ };
158
+ /**
159
+ * Disable cloud sync
160
+ */
161
+ disableCloudSync(): void;
33
162
  /**
34
163
  * Get information about all tables in the database
35
164
  */