@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,5 +0,0 @@
1
- import sqlite3InitModule from "@sqlite.org/sqlite-wasm";
2
- type Sqlite3Module = Awaited<ReturnType<typeof sqlite3InitModule>>;
3
- type Database = Sqlite3Module['oo1']['OpfsDb'] | Sqlite3Module['oo1']['DB'];
4
- export declare function loadVectorExtension(db: Database): Promise<void>;
5
- export {};
@@ -1,10 +0,0 @@
1
- export async function loadVectorExtension(db) {
2
- // Hypothetical API for loading WASM extension if sqlite-wasm supports it.
3
- // Currently sqlite-wasm static builds don't easily support dynamic extension loading
4
- // without a custom build.
5
- // For this 'cutting edge' roadmap implementation, we will simulate the
6
- // extension's presence or use a polyfill pattern if the raw WASM isn't present.
7
- console.log("Loading sqlite-vec extension...");
8
- // register native functions if possible
9
- // db.createFunction(...)
10
- }
@@ -1,15 +0,0 @@
1
- export { dash } from './engine/sqlite.js';
2
- export type { CloudConfig, CloudSyncResult } from './engine/sqlite.js';
3
- export { liveQuery, signal, effect, computed } from './reactivity/signal.js';
4
- export { mcpServer } from './mcp/server.js';
5
- export { YjsSqliteProvider } from './sync/provider.js';
6
- export { backup, restore, generateKey, exportKey, importKey } from './sync/backup.js';
7
- export type { CloudStorageAdapter } from './sync/backup.js';
8
- export { HybridProvider } from './sync/hybrid-provider.js';
9
- export { D1SyncProvider, getD1SyncProvider, resetD1SyncProvider } from './sync/d1-provider.js';
10
- export type { D1SyncConfig, SyncResult, SyncQueueEntry } from './sync/d1-provider.js';
11
- export * as firebase from './api/firebase/index.js';
12
- export { collection, doc, query, where, orderBy, limit, limitToLast, startAt, startAfter, endAt, endBefore, offset, Timestamp, GeoPoint, serverTimestamp, deleteField, arrayUnion, arrayRemove, increment, getDoc, getDocs, setDoc, updateDoc, deleteDoc, writeBatch, runTransaction, onSnapshot, } from './api/firebase/index.js';
13
- export { ref, child, set, update, remove, push, get, onDisconnect, onValue, off, } from './api/firebase/index.js';
14
- export { createUserWithEmailAndPassword, signInWithEmailAndPassword, signInAnonymously, signOut, getAuth, onAuthStateChanged, updateUserProfile, updateUserEmail, updateUserPassword, deleteUser, sendPasswordResetEmail, sendEmailVerification, GoogleAuthProvider, GithubAuthProvider, FacebookAuthProvider, TwitterAuthProvider, DiscordAuthProvider, TotpMultiFactorGenerator, PhoneMultiFactorGenerator, setPersistence, browserLocalPersistence, browserSessionPersistence, inMemoryPersistence, } from './api/firebase/index.js';
15
- export { ref as storageRef, refFromURL, child as storageChild, uploadBytes, uploadBytesResumable, uploadString, getBytes, getDownloadURL, getMetadata, updateMetadata, deleteObject, list as listFiles, listAll, } from './api/firebase/storage/index.js';
package/dist/src/index.js DELETED
@@ -1,24 +0,0 @@
1
- export { dash } from './engine/sqlite.js';
2
- export { liveQuery, signal, effect, computed } from './reactivity/signal.js';
3
- export { mcpServer } from './mcp/server.js';
4
- // Sync exports
5
- export { YjsSqliteProvider } from './sync/provider.js';
6
- export { backup, restore, generateKey, exportKey, importKey } from './sync/backup.js';
7
- export { HybridProvider } from './sync/hybrid-provider.js';
8
- // D1 HTTP Sync (legacy - prefer dash.enableCloudSync())
9
- export { D1SyncProvider, getD1SyncProvider, resetD1SyncProvider } from './sync/d1-provider.js';
10
- // Firebase Compatibility API exports
11
- export * as firebase from './api/firebase/index.js';
12
- // Firestore
13
- export { collection, doc, query, where, orderBy, limit, limitToLast, startAt, startAfter, endAt, endBefore, offset, serverTimestamp, deleteField, arrayUnion, arrayRemove, increment, getDoc, getDocs, setDoc, updateDoc, deleteDoc, writeBatch, runTransaction, onSnapshot, } from './api/firebase/index.js';
14
- // Realtime Database
15
- export { ref, child, set, update, remove, push, get, onDisconnect, onValue,
16
- // onChildAdded,
17
- // onChildChanged,
18
- // onChildRemoved,
19
- // onChildMoved,
20
- off, } from './api/firebase/index.js';
21
- // Authentication
22
- export { createUserWithEmailAndPassword, signInWithEmailAndPassword, signInAnonymously, signOut, getAuth, onAuthStateChanged, updateUserProfile, updateUserEmail, updateUserPassword, deleteUser, sendPasswordResetEmail, sendEmailVerification, GoogleAuthProvider, GithubAuthProvider, FacebookAuthProvider, TwitterAuthProvider, DiscordAuthProvider, TotpMultiFactorGenerator, PhoneMultiFactorGenerator, setPersistence, browserLocalPersistence, browserSessionPersistence, inMemoryPersistence, } from './api/firebase/index.js';
23
- // Storage
24
- export { ref as storageRef, refFromURL, child as storageChild, uploadBytes, uploadBytesResumable, uploadString, getBytes, getDownloadURL, getMetadata, updateMetadata, deleteObject, list as listFiles, listAll, } from './api/firebase/storage/index.js';
@@ -1,8 +0,0 @@
1
- import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
2
- export declare class DashMCPServer {
3
- private server;
4
- constructor();
5
- private setupHandlers;
6
- connect(transport: SSEServerTransport): Promise<void>;
7
- }
8
- export declare const mcpServer: DashMCPServer;
@@ -1,87 +0,0 @@
1
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
- import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema } from '@modelcontextprotocol/sdk/types.js';
3
- import { dash } from '../engine/sqlite.js';
4
- export class DashMCPServer {
5
- server;
6
- constructor() {
7
- this.server = new Server({
8
- name: 'dash-local-db',
9
- version: '2.0.0',
10
- }, {
11
- capabilities: {
12
- resources: {},
13
- tools: {},
14
- },
15
- });
16
- this.setupHandlers();
17
- }
18
- setupHandlers() {
19
- // List Resources: Expose all tables as resources
20
- this.server.setRequestHandler(ListResourcesRequestSchema, async () => {
21
- await dash.ready();
22
- // Get all table names
23
- const tables = dash.execute("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'");
24
- return {
25
- resources: tables.map((t) => ({
26
- uri: `mcp://local/dash/${t.name}`,
27
- name: t.name,
28
- mimeType: 'application/json',
29
- description: `Table: ${t.name}`,
30
- })),
31
- };
32
- });
33
- // Read Resource: Return table content
34
- this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
35
- const uri = request.params.uri;
36
- const tableName = uri.split('/').pop();
37
- if (!tableName)
38
- throw new Error('Invalid URI');
39
- const rows = dash.execute(`SELECT * FROM ${tableName} LIMIT 100`);
40
- return {
41
- contents: [{
42
- uri: uri,
43
- mimeType: 'application/json',
44
- text: JSON.stringify(rows, null, 2),
45
- }],
46
- };
47
- });
48
- // List Tools: Expose Semantic Search
49
- this.server.setRequestHandler(ListToolsRequestSchema, async () => {
50
- return {
51
- tools: [{
52
- name: 'semantic_search',
53
- description: 'Search the Dash database using vector similarity (semantic search).',
54
- inputSchema: {
55
- type: 'object',
56
- properties: {
57
- query: { type: 'string', description: 'The search query string.' },
58
- },
59
- required: ['query'],
60
- },
61
- }],
62
- };
63
- });
64
- // Call Tool: Execute Semantic Search
65
- this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
66
- if (request.params.name === 'semantic_search') {
67
- const query = request.params.arguments?.query;
68
- if (!query)
69
- throw new Error('Missing query argument');
70
- const results = await dash.search(query);
71
- return {
72
- content: [{
73
- type: 'text',
74
- text: JSON.stringify(results, null, 2),
75
- }],
76
- };
77
- }
78
- throw new Error('Tool not found');
79
- });
80
- }
81
- // Method to connect to a transport (e.g., SSE for web)
82
- async connect(transport) {
83
- await this.server.connect(transport);
84
- console.log('Dash MCP Server Connected');
85
- }
86
- }
87
- export const mcpServer = new DashMCPServer();
@@ -1,3 +0,0 @@
1
- import { Signal } from '@preact/signals-core';
2
- export declare function liveQuery<T = any>(sql: string, bind?: any[]): Signal<T[]>;
3
- export { signal, effect, computed } from '@preact/signals-core';
@@ -1,31 +0,0 @@
1
- import { signal } from '@preact/signals-core';
2
- import { dash } from '../engine/sqlite.js';
3
- export function liveQuery(sql, bind) {
4
- const data = signal([]);
5
- const run = async () => {
6
- await dash.ready();
7
- try {
8
- const result = dash.execute(sql, bind);
9
- data.value = result;
10
- }
11
- catch (e) {
12
- console.error('Dash LiveQuery Error:', e);
13
- }
14
- };
15
- // Run immediately
16
- run();
17
- // Subscribe to database changes
18
- // Parse table name naively
19
- const match = sql.match(/FROM\s+([a-zA-Z0-9_]+)/i);
20
- const table = match ? match[1] : null;
21
- if (table) {
22
- dash.subscribe(table, () => {
23
- run();
24
- });
25
- }
26
- else {
27
- console.warn('Dash: Could not identify table for liveQuery', sql);
28
- }
29
- return data;
30
- }
31
- export { signal, effect, computed } from '@preact/signals-core';
@@ -1,29 +0,0 @@
1
- export type LensOp = {
2
- kind: 'rename';
3
- source: string;
4
- target: string;
5
- } | {
6
- kind: 'hoist';
7
- host: string;
8
- name: string;
9
- } | {
10
- kind: 'wrap';
11
- name: string;
12
- };
13
- export interface SchemaLens {
14
- from: number;
15
- to: number;
16
- ops: LensOp[];
17
- }
18
- export declare class LensEngine {
19
- private lenses;
20
- private currentVersion;
21
- constructor(currentVersion: number);
22
- registerLens(from: number, to: number, ops: LensOp[]): void;
23
- private findPath;
24
- migrate(data: any, from: number, to?: number): any;
25
- private normalizeOps;
26
- private invertOp;
27
- private applyOp;
28
- }
29
- export declare const schema: LensEngine;
@@ -1,122 +0,0 @@
1
- // Native Bidirectional Lens Implementation
2
- // Inspired by Project Cambria
3
- export class LensEngine {
4
- lenses = [];
5
- currentVersion;
6
- constructor(currentVersion) {
7
- this.currentVersion = currentVersion;
8
- }
9
- registerLens(from, to, ops) {
10
- this.lenses.push({ from, to, ops });
11
- }
12
- // Find path from V_start to V_end
13
- findPath(from, to) {
14
- // BFS to find shortest path
15
- const queue = [{ version: from, path: [] }];
16
- const visited = new Set([from]);
17
- while (queue.length > 0) {
18
- const { version, path } = queue.shift();
19
- if (version === to)
20
- return path;
21
- // Find neighbors
22
- // Forward lenses
23
- const forward = this.lenses.filter(l => l.from === version);
24
- for (const lens of forward) {
25
- if (!visited.has(lens.to)) {
26
- visited.add(lens.to);
27
- queue.push({ version: lens.to, path: [...path, lens] });
28
- }
29
- }
30
- // Reverse lenses (Implicit)
31
- const backward = this.lenses.filter(l => l.to === version);
32
- for (const lens of backward) {
33
- if (!visited.has(lens.from)) {
34
- visited.add(lens.from);
35
- // Create synthetic reverse lens
36
- const reverseLens = {
37
- from: lens.to,
38
- to: lens.from,
39
- ops: [...lens.ops].reverse() // Ops must be reversed!
40
- };
41
- queue.push({ version: lens.from, path: [...path, reverseLens] });
42
- }
43
- }
44
- }
45
- throw new Error(`No translation path found from v${from} to v${to}`);
46
- }
47
- migrate(data, from, to = this.currentVersion) {
48
- if (from === to)
49
- return data;
50
- const path = this.findPath(from, to);
51
- let doc = JSON.parse(JSON.stringify(data)); // Deep clone to avoid mutation
52
- for (const step of path) {
53
- const isForward = step.from < step.to; // Heuristic: Assuming localized version jumps
54
- // Actually we should just apply the ops in the step direction.
55
- // But we need to know if the step is a "Forward Lens" or a "Reverse Lens"
56
- // because ops like 'rename' need to swap source/target if reversed.
57
- // The path finding creates "synthetic" lenses for reverse steps where from > to.
58
- // So we just need to apply 'step.ops' carefully.
59
- // But wait! in findPath, I just reversed the ARRAY of ops.
60
- // I ALSO need to invert the OPERATORS themselves.
61
- const opsToApply = this.normalizeOps(step);
62
- for (const op of opsToApply) {
63
- doc = this.applyOp(doc, op);
64
- }
65
- }
66
- return doc;
67
- }
68
- normalizeOps(step) {
69
- // If this lens was registered as from=1, to=2
70
- // And we are using it as from=1, to=2. No change.
71
- // If we are traversing 2->1.
72
- // The findPath constructed a lens { from: 2, to: 1, ops: ops.reverse() }
73
- // But the ops inside are still { kind: 'rename', source: 'old', target: 'new' }
74
- // We need to invert them to { kind: 'rename', source: 'new', target: 'old' }
75
- // We need to know the *registred* direction to know if inversion is needed?
76
- // Actually findPath constructs a fresh object. We can check if it exists in this.lenses.
77
- const registered = this.lenses.find(l => l.from === step.from && l.to === step.to);
78
- if (registered) {
79
- return step.ops; // Direct match, use as is
80
- }
81
- // Must be a reverse step constructed by findPath
82
- return step.ops.map(op => this.invertOp(op));
83
- }
84
- invertOp(op) {
85
- switch (op.kind) {
86
- case 'rename': return { kind: 'rename', source: op.target, target: op.source };
87
- // Invert Hoist: Wrap?
88
- // Hoist: host='meta', name='key' (moves doc.meta.key -> doc.key)
89
- // Inverse: Wrap (moves doc.key -> doc.meta.key)
90
- // Use 'wrap' as simplified inverse of simple hoist
91
- case 'hoist': return { kind: 'wrap', name: op.name }; // Simplified
92
- case 'wrap': return { kind: 'hoist', host: 'container', name: op.name }; // Naive inverse
93
- default: return op;
94
- }
95
- }
96
- applyOp(doc, op) {
97
- switch (op.kind) {
98
- case 'rename': {
99
- if (doc[op.source] !== undefined) {
100
- doc[op.target] = doc[op.source];
101
- delete doc[op.source];
102
- }
103
- return doc;
104
- }
105
- case 'hoist': {
106
- // Extract property from scalar host? Or object?
107
- // Assume simple object flattening: { data: { val: 1 } } -> hoist 'data', 'val' -> { val: 1 }
108
- // doc[op.host][op.name] -> doc[op.name]
109
- if (doc[op.host] && doc[op.host][op.name] !== undefined) {
110
- doc[op.name] = doc[op.host][op.name];
111
- delete doc[op.host][op.name];
112
- if (Object.keys(doc[op.host]).length === 0)
113
- delete doc[op.host];
114
- }
115
- return doc;
116
- }
117
- default: return doc;
118
- }
119
- }
120
- }
121
- export const schema = new LensEngine(1);
122
- // Default to v1 until configured
@@ -1,21 +0,0 @@
1
- /**
2
- * Aeon Integration Configuration
3
- *
4
- * Configuration for Aeon sync features in Dash.
5
- * All features enabled by default.
6
- */
7
- export interface AeonConfig {
8
- /** Enable delta sync optimization (70-80% bandwidth reduction) */
9
- enableDeltaSync: boolean;
10
- /** Enable rich presence tracking (cursors, sections, activity) */
11
- enableRichPresence: boolean;
12
- /** Enable offline operation queuing */
13
- enableOfflineQueue: boolean;
14
- /** Bytes threshold before falling back to full sync instead of delta */
15
- deltaThreshold: number;
16
- /** Maximum operations to hold in offline queue */
17
- maxOfflineQueueSize: number;
18
- /** Maximum retries for failed offline operations */
19
- maxOfflineRetries: number;
20
- }
21
- export declare const defaultAeonConfig: AeonConfig;
@@ -1,14 +0,0 @@
1
- /**
2
- * Aeon Integration Configuration
3
- *
4
- * Configuration for Aeon sync features in Dash.
5
- * All features enabled by default.
6
- */
7
- export const defaultAeonConfig = {
8
- enableDeltaSync: true,
9
- enableRichPresence: true,
10
- enableOfflineQueue: true,
11
- deltaThreshold: 1000,
12
- maxOfflineQueueSize: 1000,
13
- maxOfflineRetries: 3,
14
- };
@@ -1,62 +0,0 @@
1
- /**
2
- * Delta Adapter for Dash
3
- *
4
- * Wraps Aeon's DeltaSyncOptimizer to provide delta compression
5
- * for Yjs document updates. Achieves 70-80% bandwidth reduction.
6
- */
7
- import { type DeltaOperation, type DeltaStats } from '@affectively/aeon';
8
- /**
9
- * Adapter that wraps Yjs updates with delta compression
10
- */
11
- export declare class DashDeltaAdapter {
12
- private optimizer;
13
- private roomId;
14
- private updateCounter;
15
- constructor(roomId: string, threshold?: number);
16
- /**
17
- * Wrap a Yjs update with delta compression
18
- * Returns a delta payload ready for transmission
19
- */
20
- wrapUpdate(update: Uint8Array, origin?: string): DeltaPayload;
21
- /**
22
- * Unwrap a delta payload back to Yjs update
23
- */
24
- unwrapDelta(payload: DeltaPayload): Uint8Array;
25
- /**
26
- * Encode delta payload for wire transmission
27
- */
28
- encodePayload(payload: DeltaPayload): Uint8Array;
29
- /**
30
- * Decode delta payload from wire
31
- */
32
- decodePayload(data: Uint8Array): DeltaPayload;
33
- /**
34
- * Get compression statistics
35
- */
36
- getStats(): DeltaStats;
37
- /**
38
- * Reset statistics
39
- */
40
- resetStats(): void;
41
- /**
42
- * Get memory footprint estimate
43
- */
44
- getMemoryEstimate(): number;
45
- /**
46
- * Clear operation history
47
- */
48
- clearHistory(): void;
49
- }
50
- /**
51
- * Delta payload structure for wire transmission
52
- */
53
- export interface DeltaPayload {
54
- type: 'delta';
55
- delta: DeltaOperation;
56
- originalSize: number;
57
- deltaSize: number;
58
- }
59
- /**
60
- * Check if a payload is a delta payload
61
- */
62
- export declare function isDeltaPayload(data: unknown): data is DeltaPayload;
@@ -1,98 +0,0 @@
1
- /**
2
- * Delta Adapter for Dash
3
- *
4
- * Wraps Aeon's DeltaSyncOptimizer to provide delta compression
5
- * for Yjs document updates. Achieves 70-80% bandwidth reduction.
6
- */
7
- import { DeltaSyncOptimizer, } from '@affectively/aeon';
8
- /**
9
- * Adapter that wraps Yjs updates with delta compression
10
- */
11
- export class DashDeltaAdapter {
12
- optimizer;
13
- roomId;
14
- updateCounter = 0;
15
- constructor(roomId, threshold = 1000) {
16
- this.roomId = roomId;
17
- this.optimizer = new DeltaSyncOptimizer(threshold);
18
- }
19
- /**
20
- * Wrap a Yjs update with delta compression
21
- * Returns a delta payload ready for transmission
22
- */
23
- wrapUpdate(update, origin) {
24
- const operationId = `${this.roomId}-${this.updateCounter++}`;
25
- // Create an Aeon Operation from the Yjs update
26
- const operation = {
27
- id: operationId,
28
- type: 'update',
29
- sessionId: this.roomId,
30
- data: {
31
- update: Array.from(update),
32
- origin: origin ?? 'local',
33
- },
34
- status: 'pending',
35
- createdAt: Date.now(),
36
- };
37
- const delta = this.optimizer.computeDelta(operation);
38
- return {
39
- type: 'delta',
40
- delta,
41
- originalSize: update.byteLength,
42
- deltaSize: new TextEncoder().encode(JSON.stringify(delta)).byteLength,
43
- };
44
- }
45
- /**
46
- * Unwrap a delta payload back to Yjs update
47
- */
48
- unwrapDelta(payload) {
49
- const operation = this.optimizer.decompressDelta(payload.delta);
50
- return new Uint8Array(operation.data.update);
51
- }
52
- /**
53
- * Encode delta payload for wire transmission
54
- */
55
- encodePayload(payload) {
56
- return new TextEncoder().encode(JSON.stringify(payload));
57
- }
58
- /**
59
- * Decode delta payload from wire
60
- */
61
- decodePayload(data) {
62
- return JSON.parse(new TextDecoder().decode(data));
63
- }
64
- /**
65
- * Get compression statistics
66
- */
67
- getStats() {
68
- return this.optimizer.getStats();
69
- }
70
- /**
71
- * Reset statistics
72
- */
73
- resetStats() {
74
- this.optimizer.resetStats();
75
- }
76
- /**
77
- * Get memory footprint estimate
78
- */
79
- getMemoryEstimate() {
80
- return this.optimizer.getMemoryEstimate();
81
- }
82
- /**
83
- * Clear operation history
84
- */
85
- clearHistory() {
86
- this.optimizer.resetStats();
87
- }
88
- }
89
- /**
90
- * Check if a payload is a delta payload
91
- */
92
- export function isDeltaPayload(data) {
93
- return (typeof data === 'object' &&
94
- data !== null &&
95
- 'type' in data &&
96
- data.type === 'delta' &&
97
- 'delta' in data);
98
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * Aeon Integration for Dash
3
- *
4
- * Provides enhanced sync capabilities through Aeon:
5
- * - Delta compression (70-80% bandwidth reduction)
6
- * - Rich presence tracking (cursors, sections, activity)
7
- * - Offline operation queuing with persistence
8
- * - Schema versioning and migrations
9
- */
10
- export { defaultAeonConfig, type AeonConfig } from './config.js';
11
- export { DashDeltaAdapter, isDeltaPayload, type DeltaPayload, } from './delta-adapter.js';
12
- export { DashPresenceAdapter, type PresenceEvents, } from './presence-adapter.js';
13
- export { DashOfflineAdapter, type ProcessQueueResult, type OfflineQueueEvents, } from './offline-adapter.js';
14
- export { DashSchemaAdapter, createSchemaAdapter, } from './schema-adapter.js';
15
- export type { DeltaOperation, DeltaStats, DeltaBatch, } from '@affectively/aeon';
16
- export type { AgentPresence, } from '@affectively/aeon';
17
- export type { OfflineOperation, OfflineQueueStats, OperationPriority, } from '@affectively/aeon';
18
- export type { SchemaVersion, Migration, MigrationResult, MigrationRecord, } from '@affectively/aeon';
@@ -1,19 +0,0 @@
1
- /**
2
- * Aeon Integration for Dash
3
- *
4
- * Provides enhanced sync capabilities through Aeon:
5
- * - Delta compression (70-80% bandwidth reduction)
6
- * - Rich presence tracking (cursors, sections, activity)
7
- * - Offline operation queuing with persistence
8
- * - Schema versioning and migrations
9
- */
10
- // Configuration
11
- export { defaultAeonConfig } from './config.js';
12
- // Delta compression adapter
13
- export { DashDeltaAdapter, isDeltaPayload, } from './delta-adapter.js';
14
- // Presence adapter
15
- export { DashPresenceAdapter, } from './presence-adapter.js';
16
- // Offline queue adapter
17
- export { DashOfflineAdapter, } from './offline-adapter.js';
18
- // Schema versioning adapter
19
- export { DashSchemaAdapter, createSchemaAdapter, } from './schema-adapter.js';