@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.
Files changed (71) hide show
  1. package/dist/index.d.ts +62 -0
  2. package/dist/index.js +31 -0
  3. package/dist/sync/index.d.ts +6 -0
  4. package/dist/sync/index.js +4 -0
  5. package/package.json +45 -66
  6. package/README.md +0 -193
  7. package/dist/src/api/firebase/auth/index.d.ts +0 -137
  8. package/dist/src/api/firebase/auth/index.js +0 -352
  9. package/dist/src/api/firebase/auth/providers.d.ts +0 -254
  10. package/dist/src/api/firebase/auth/providers.js +0 -518
  11. package/dist/src/api/firebase/database/index.d.ts +0 -108
  12. package/dist/src/api/firebase/database/index.js +0 -368
  13. package/dist/src/api/firebase/errors.d.ts +0 -15
  14. package/dist/src/api/firebase/errors.js +0 -215
  15. package/dist/src/api/firebase/firestore/data-types.d.ts +0 -116
  16. package/dist/src/api/firebase/firestore/data-types.js +0 -280
  17. package/dist/src/api/firebase/firestore/index.d.ts +0 -7
  18. package/dist/src/api/firebase/firestore/index.js +0 -13
  19. package/dist/src/api/firebase/firestore/listeners.d.ts +0 -20
  20. package/dist/src/api/firebase/firestore/listeners.js +0 -50
  21. package/dist/src/api/firebase/firestore/operations.d.ts +0 -123
  22. package/dist/src/api/firebase/firestore/operations.js +0 -490
  23. package/dist/src/api/firebase/firestore/query.d.ts +0 -118
  24. package/dist/src/api/firebase/firestore/query.js +0 -418
  25. package/dist/src/api/firebase/index.d.ts +0 -11
  26. package/dist/src/api/firebase/index.js +0 -17
  27. package/dist/src/api/firebase/storage/index.d.ts +0 -100
  28. package/dist/src/api/firebase/storage/index.js +0 -286
  29. package/dist/src/api/firebase/types.d.ts +0 -341
  30. package/dist/src/api/firebase/types.js +0 -4
  31. package/dist/src/auth/manager.d.ts +0 -182
  32. package/dist/src/auth/manager.js +0 -598
  33. package/dist/src/engine/ai.d.ts +0 -10
  34. package/dist/src/engine/ai.js +0 -76
  35. package/dist/src/engine/sqlite.d.ts +0 -346
  36. package/dist/src/engine/sqlite.js +0 -1325
  37. package/dist/src/engine/vec_extension.d.ts +0 -5
  38. package/dist/src/engine/vec_extension.js +0 -10
  39. package/dist/src/index.d.ts +0 -15
  40. package/dist/src/index.js +0 -24
  41. package/dist/src/mcp/server.d.ts +0 -8
  42. package/dist/src/mcp/server.js +0 -87
  43. package/dist/src/reactivity/signal.d.ts +0 -3
  44. package/dist/src/reactivity/signal.js +0 -31
  45. package/dist/src/schema/lens.d.ts +0 -29
  46. package/dist/src/schema/lens.js +0 -122
  47. package/dist/src/sync/aeon/config.d.ts +0 -21
  48. package/dist/src/sync/aeon/config.js +0 -14
  49. package/dist/src/sync/aeon/delta-adapter.d.ts +0 -62
  50. package/dist/src/sync/aeon/delta-adapter.js +0 -98
  51. package/dist/src/sync/aeon/index.d.ts +0 -18
  52. package/dist/src/sync/aeon/index.js +0 -19
  53. package/dist/src/sync/aeon/offline-adapter.d.ts +0 -110
  54. package/dist/src/sync/aeon/offline-adapter.js +0 -227
  55. package/dist/src/sync/aeon/presence-adapter.d.ts +0 -114
  56. package/dist/src/sync/aeon/presence-adapter.js +0 -157
  57. package/dist/src/sync/aeon/schema-adapter.d.ts +0 -95
  58. package/dist/src/sync/aeon/schema-adapter.js +0 -163
  59. package/dist/src/sync/backup.d.ts +0 -12
  60. package/dist/src/sync/backup.js +0 -44
  61. package/dist/src/sync/connection.d.ts +0 -20
  62. package/dist/src/sync/connection.js +0 -50
  63. package/dist/src/sync/d1-provider.d.ts +0 -97
  64. package/dist/src/sync/d1-provider.js +0 -345
  65. package/dist/src/sync/hybrid-provider.d.ts +0 -172
  66. package/dist/src/sync/hybrid-provider.js +0 -477
  67. package/dist/src/sync/provider.d.ts +0 -11
  68. package/dist/src/sync/provider.js +0 -67
  69. package/dist/src/sync/verify.d.ts +0 -1
  70. package/dist/src/sync/verify.js +0 -23
  71. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -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,97 +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 timestamps
13
- */
14
- export interface D1SyncConfig {
15
- /** Base URL for the sync endpoint (e.g., 'https://example.com/api') */
16
- baseUrl: string;
17
- /** Tables to sync (e.g., ['reflections', 'users']) */
18
- tables: string[];
19
- /** Auth token getter - called before each sync */
20
- getAuthToken: () => Promise<string | null>;
21
- /** Sync interval in ms (default: 30000 = 30s). Set to 0 to disable auto-sync. */
22
- syncInterval?: number;
23
- /** Callback when sync completes */
24
- onSyncComplete?: (result: SyncResult) => void;
25
- /** Callback when sync fails */
26
- onSyncError?: (error: Error) => void;
27
- }
28
- export interface SyncResult {
29
- pushed: number;
30
- pulled: number;
31
- errors: string[];
32
- timestamp: number;
33
- }
34
- export interface SyncQueueEntry {
35
- id: number;
36
- table_name: string;
37
- row_id: string;
38
- operation: 'create' | 'update' | 'delete';
39
- data: string | null;
40
- created_at: number;
41
- synced: number;
42
- }
43
- export declare class D1SyncProvider {
44
- private config;
45
- private syncTimer;
46
- private isSyncing;
47
- private lastSyncTime;
48
- private initialized;
49
- constructor(config: D1SyncConfig);
50
- /**
51
- * Initialize the sync provider - must be called before syncing
52
- */
53
- initialize(): Promise<void>;
54
- /**
55
- * Set up SQLite triggers to track changes for a table
56
- */
57
- private setupTableTriggers;
58
- /**
59
- * Start automatic sync at the configured interval
60
- */
61
- startAutoSync(): void;
62
- /**
63
- * Stop automatic sync
64
- */
65
- stopAutoSync(): void;
66
- /**
67
- * Perform a sync operation
68
- */
69
- sync(): Promise<SyncResult>;
70
- /**
71
- * Apply changes received from the server
72
- */
73
- private applyServerChanges;
74
- /**
75
- * Queue a change manually (for cases where triggers can't be used)
76
- */
77
- queueChange(tableName: string, rowId: string, operation: 'create' | 'update' | 'delete', data?: any): void;
78
- /**
79
- * Get the current sync status
80
- */
81
- getStatus(): {
82
- initialized: boolean;
83
- syncing: boolean;
84
- lastSyncTime: number;
85
- pendingChanges: number;
86
- };
87
- /**
88
- * Force a full sync by resetting last sync time
89
- */
90
- forceFullSync(): Promise<SyncResult>;
91
- /**
92
- * Destroy the provider and clean up
93
- */
94
- destroy(): void;
95
- }
96
- export declare function getD1SyncProvider(config?: D1SyncConfig): D1SyncProvider;
97
- export declare function resetD1SyncProvider(): void;