@diaryx/wasm 0.11.0-dev.449d9b2

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.
@@ -0,0 +1,891 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Callbacks for JsAsyncFileSystem operations.
6
+ *
7
+ * All callbacks should return Promises. If a callback is not provided,
8
+ * the corresponding operation will fail with an error.
9
+ */
10
+ export interface JsFileSystemCallbacks {
11
+ /**
12
+ * Read a file's content as a string.
13
+ * @param path - The file path to read
14
+ * @returns Promise resolving to the file content
15
+ */
16
+ readToString?: (path: string) => Promise<string>;
17
+
18
+ /**
19
+ * Write content to a file, creating or overwriting it.
20
+ * @param path - The file path to write
21
+ * @param content - The content to write
22
+ */
23
+ writeFile?: (path: string, content: string) => Promise<void>;
24
+
25
+ /**
26
+ * Create a new file, failing if it already exists.
27
+ * @param path - The file path to create
28
+ * @param content - The initial content
29
+ */
30
+ createNew?: (path: string, content: string) => Promise<void>;
31
+
32
+ /**
33
+ * Delete a file.
34
+ * @param path - The file path to delete
35
+ */
36
+ deleteFile?: (path: string) => Promise<void>;
37
+
38
+ /**
39
+ * Check if a path exists.
40
+ * @param path - The path to check
41
+ * @returns Promise resolving to true if the path exists
42
+ */
43
+ exists?: (path: string) => Promise<boolean>;
44
+
45
+ /**
46
+ * Check if a path is a directory.
47
+ * @param path - The path to check
48
+ * @returns Promise resolving to true if the path is a directory
49
+ */
50
+ isDir?: (path: string) => Promise<boolean>;
51
+
52
+ /**
53
+ * List all files in a directory (not recursive).
54
+ * @param dir - The directory path
55
+ * @returns Promise resolving to array of file paths
56
+ */
57
+ listFiles?: (dir: string) => Promise<string[]>;
58
+
59
+ /**
60
+ * List markdown files in a directory (not recursive).
61
+ * @param dir - The directory path
62
+ * @returns Promise resolving to array of .md file paths
63
+ */
64
+ listMdFiles?: (dir: string) => Promise<string[]>;
65
+
66
+ /**
67
+ * Create a directory and all parent directories.
68
+ * @param path - The directory path to create
69
+ */
70
+ createDirAll?: (path: string) => Promise<void>;
71
+
72
+ /**
73
+ * Move/rename a file.
74
+ * @param from - The source path
75
+ * @param to - The destination path
76
+ */
77
+ moveFile?: (from: string, to: string) => Promise<void>;
78
+
79
+ /**
80
+ * Read binary file content.
81
+ * @param path - The file path to read
82
+ * @returns Promise resolving to file content as Uint8Array
83
+ */
84
+ readBinary?: (path: string) => Promise<Uint8Array>;
85
+
86
+ /**
87
+ * Write binary content to a file.
88
+ * @param path - The file path to write
89
+ * @param data - The binary content as Uint8Array
90
+ */
91
+ writeBinary?: (path: string, data: Uint8Array) => Promise<void>;
92
+ }
93
+
94
+
95
+
96
+ /**
97
+ * Unified async backend with native storage.
98
+ *
99
+ * This is the main entry point for all workspace operations in WASM.
100
+ * It wraps either OPFS or IndexedDB storage and provides a complete
101
+ * async API for workspace, entry, search, and validation operations.
102
+ *
103
+ * ## Usage
104
+ *
105
+ * All operations go through `execute()` or `executeJs()`:
106
+ *
107
+ * ```javascript
108
+ * const backend = await DiaryxBackend.createOpfs();
109
+ * const response = await backend.executeJs({
110
+ * type: 'GetEntry',
111
+ * params: { path: 'workspace/notes.md' }
112
+ * });
113
+ * ```
114
+ */
115
+ export class DiaryxBackend {
116
+ private constructor();
117
+ free(): void;
118
+ [Symbol.dispose](): void;
119
+ /**
120
+ * Create backend with specific storage type.
121
+ */
122
+ static create(storage_type: string): Promise<DiaryxBackend>;
123
+ /**
124
+ * Create a new DiaryxBackend from a user-selected directory handle.
125
+ *
126
+ * This uses the File System Access API to read/write files directly
127
+ * on the user's filesystem. The handle must be obtained from
128
+ * `window.showDirectoryPicker()` in JavaScript.
129
+ *
130
+ * ## Browser Support
131
+ * - Chrome/Edge: ✅ Supported
132
+ * - Firefox: ❌ Not supported
133
+ * - Safari: ❌ Not supported
134
+ *
135
+ * ## Example
136
+ * ```javascript
137
+ * // User must trigger this via a gesture (click/keypress)
138
+ * const dirHandle = await window.showDirectoryPicker();
139
+ * const backend = await DiaryxBackend.createFromDirectoryHandle(dirHandle);
140
+ * ```
141
+ */
142
+ static createFromDirectoryHandle(handle: FileSystemDirectoryHandle): DiaryxBackend;
143
+ /**
144
+ * Create a new DiaryxBackend with in-memory storage.
145
+ *
146
+ * This is used for guest mode in share sessions. Files are stored
147
+ * only in memory and are cleared when the session ends.
148
+ *
149
+ * ## Use Cases
150
+ * - Guest mode in share sessions (web)
151
+ * - Testing
152
+ *
153
+ * ## Example
154
+ * ```javascript
155
+ * const backend = DiaryxBackend.createInMemory();
156
+ * // Files are stored in memory only
157
+ * ```
158
+ */
159
+ static createInMemory(): DiaryxBackend;
160
+ /**
161
+ * Create a new DiaryxBackend with IndexedDB storage.
162
+ *
163
+ * This attempts to use persistent SQLite-based CRDT storage (via sql.js).
164
+ * If SQLite storage is not available, falls back to in-memory CRDT storage.
165
+ */
166
+ static createIndexedDb(): Promise<DiaryxBackend>;
167
+ /**
168
+ * Create a new DiaryxBackend with OPFS storage.
169
+ *
170
+ * This attempts to use persistent SQLite-based CRDT storage (via sql.js).
171
+ * If SQLite storage is not available (JS bridge not initialized), falls back
172
+ * to in-memory CRDT storage.
173
+ *
174
+ * For persistent CRDT storage, call `initializeSqliteStorage()` in JavaScript
175
+ * before creating the backend:
176
+ *
177
+ * ```javascript
178
+ * import { initializeSqliteStorage } from './lib/storage/sqliteStorageBridge.js';
179
+ * await initializeSqliteStorage();
180
+ * const backend = await DiaryxBackend.createOpfs();
181
+ * ```
182
+ */
183
+ static createOpfs(): Promise<DiaryxBackend>;
184
+ /**
185
+ * Create a new sync client for the given server and workspace.
186
+ *
187
+ * This creates a `WasmSyncClient` that wraps `SyncClient<CallbackTransport>`.
188
+ * JavaScript manages WebSocket connections while Rust handles all sync logic.
189
+ *
190
+ * ## Example
191
+ *
192
+ * ```javascript
193
+ * const client = backend.createSyncClient(
194
+ * 'wss://sync.example.com/sync',
195
+ * 'my-workspace-id',
196
+ * 'auth-token-optional'
197
+ * );
198
+ *
199
+ * // Get URLs and create WebSocket connections
200
+ * const metaUrl = client.getMetadataUrl();
201
+ * const bodyUrl = client.getBodyUrl();
202
+ *
203
+ * // Create WebSockets and connect them to the client
204
+ * const metaWs = new WebSocket(metaUrl);
205
+ * metaWs.binaryType = 'arraybuffer';
206
+ * metaWs.onopen = () => client.markMetadataConnected();
207
+ * metaWs.onclose = () => client.markMetadataDisconnected();
208
+ * metaWs.onmessage = async (e) => {
209
+ * const response = await client.injectMetadataMessage(new Uint8Array(e.data));
210
+ * if (response) metaWs.send(response);
211
+ * };
212
+ * // Similar for body WebSocket...
213
+ *
214
+ * // Poll for outgoing messages
215
+ * setInterval(() => {
216
+ * let msg;
217
+ * while ((msg = client.pollMetadataOutgoing())) metaWs.send(msg);
218
+ * while ((msg = client.pollBodyOutgoing())) bodyWs.send(msg);
219
+ * }, 50);
220
+ *
221
+ * // Start sync
222
+ * await client.start();
223
+ * ```
224
+ */
225
+ createSyncClient(server_url: string, workspace_id: string, auth_token?: string | null): WasmSyncClient;
226
+ /**
227
+ * Emit a filesystem event.
228
+ *
229
+ * This is primarily used internally but can be called from JavaScript
230
+ * to manually trigger events (e.g., for testing or manual sync scenarios).
231
+ *
232
+ * The event should be a JSON string matching the FileSystemEvent format.
233
+ *
234
+ * ## Example
235
+ *
236
+ * ```javascript
237
+ * backend.emitFileSystemEvent(JSON.stringify({
238
+ * type: 'FileCreated',
239
+ * path: 'workspace/notes.md',
240
+ * frontmatter: { title: 'Notes' }
241
+ * }));
242
+ * ```
243
+ */
244
+ emitFileSystemEvent(event_json: string): void;
245
+ /**
246
+ * Get the number of active event subscriptions.
247
+ */
248
+ eventSubscriberCount(): number;
249
+ /**
250
+ * Execute a command and return the response as JSON string.
251
+ *
252
+ * This is the primary unified API for all operations.
253
+ *
254
+ * ## Example
255
+ * ```javascript
256
+ * const command = { type: 'GetEntry', params: { path: 'workspace/notes.md' } };
257
+ * const responseJson = await backend.execute(JSON.stringify(command));
258
+ * const response = JSON.parse(responseJson);
259
+ * ```
260
+ */
261
+ execute(command_json: string): Promise<string>;
262
+ /**
263
+ * Execute a command from a JavaScript object directly.
264
+ *
265
+ * This avoids JSON serialization overhead for better performance.
266
+ */
267
+ executeJs(command: any): Promise<any>;
268
+ /**
269
+ * Get initial body sync step1 message for a document.
270
+ *
271
+ * Returns a Uint8Array containing the Y-sync step1 message for
272
+ * the specified document's body content.
273
+ *
274
+ * ## Example
275
+ * ```javascript
276
+ * const step1 = backend.getBodySyncStep1("notes/my-note.md");
277
+ * // Frame it for multiplexed connection and send
278
+ * ```
279
+ */
280
+ getBodySyncStep1(doc_name: string): Uint8Array;
281
+ /**
282
+ * Get the current configuration from root index frontmatter.
283
+ * Config keys are stored as `diaryx_*` properties.
284
+ */
285
+ getConfig(): Promise<any>;
286
+ /**
287
+ * Get initial workspace sync step1 message.
288
+ *
289
+ * Returns a Uint8Array containing the Y-sync step1 message to send
290
+ * over the WebSocket to initiate workspace metadata sync.
291
+ *
292
+ * ## Example
293
+ * ```javascript
294
+ * const step1 = backend.getWorkspaceSyncStep1();
295
+ * ws.send(step1);
296
+ * ```
297
+ */
298
+ getWorkspaceSyncStep1(): Uint8Array;
299
+ /**
300
+ * Check if this backend has native sync support.
301
+ *
302
+ * For WASM, this always returns false. The new `createSyncClient()` API
303
+ * provides a unified approach that works across all platforms.
304
+ */
305
+ hasNativeSync(): boolean;
306
+ /**
307
+ * Check if there are pending outgoing sync messages.
308
+ */
309
+ hasOutgoingSyncMessages(): boolean;
310
+ /**
311
+ * Inject an incoming body sync message.
312
+ *
313
+ * Call this when the WebSocket receives a message for a body document.
314
+ * The message should already be unframed (doc_name extracted separately).
315
+ * Returns a response message to send back, or null if no response is needed.
316
+ *
317
+ * ## Example
318
+ * ```javascript
319
+ * // After unframing the multiplexed message:
320
+ * const response = await backend.injectBodySyncMessage(docName, data, true);
321
+ * if (response) ws.send(frameBodyMessage(docName, response));
322
+ * ```
323
+ */
324
+ injectBodySyncMessage(doc_name: string, message: Uint8Array, write_to_disk: boolean): Promise<any>;
325
+ /**
326
+ * Inject an incoming workspace sync message.
327
+ *
328
+ * Call this when the WebSocket receives a message for the workspace
329
+ * (metadata) connection. Returns a response message to send back,
330
+ * or null if no response is needed.
331
+ *
332
+ * ## Example
333
+ * ```javascript
334
+ * ws.onmessage = (event) => {
335
+ * const data = new Uint8Array(event.data);
336
+ * const response = backend.injectWorkspaceSyncMessage(data, true);
337
+ * if (response) ws.send(response);
338
+ * };
339
+ * ```
340
+ */
341
+ injectWorkspaceSyncMessage(message: Uint8Array, write_to_disk: boolean): Promise<any>;
342
+ /**
343
+ * Unsubscribe from filesystem events.
344
+ *
345
+ * Returns `true` if the subscription was found and removed.
346
+ *
347
+ * ## Example
348
+ *
349
+ * ```javascript
350
+ * const id = backend.onFileSystemEvent(handler);
351
+ * // ... later ...
352
+ * const removed = backend.offFileSystemEvent(id);
353
+ * console.log('Subscription removed:', removed);
354
+ * ```
355
+ */
356
+ offFileSystemEvent(id: bigint): boolean;
357
+ /**
358
+ * Subscribe to filesystem events.
359
+ *
360
+ * The callback will be invoked with a JSON-serialized FileSystemEvent
361
+ * whenever filesystem operations occur (create, delete, rename, move, etc.).
362
+ *
363
+ * Returns a subscription ID that can be used to unsubscribe later.
364
+ *
365
+ * ## Example
366
+ *
367
+ * ```javascript
368
+ * const id = backend.onFileSystemEvent((eventJson) => {
369
+ * const event = JSON.parse(eventJson);
370
+ * console.log('File event:', event.type, event.path);
371
+ * });
372
+ *
373
+ * // Later, to unsubscribe:
374
+ * backend.offFileSystemEvent(id);
375
+ * ```
376
+ */
377
+ onFileSystemEvent(callback: Function): bigint;
378
+ /**
379
+ * Get count of pending outgoing sync messages.
380
+ */
381
+ outgoingSyncMessageCount(): number;
382
+ /**
383
+ * Poll for an outgoing sync message.
384
+ *
385
+ * Returns the next outgoing message as a JavaScript object with:
386
+ * - `docName`: Document name ("workspace" or file path)
387
+ * - `message`: Uint8Array message data
388
+ * - `isBody`: Boolean indicating body (true) or workspace (false)
389
+ *
390
+ * Returns null if no messages are queued.
391
+ *
392
+ * ## Example
393
+ * ```javascript
394
+ * setInterval(() => {
395
+ * let msg;
396
+ * while ((msg = backend.pollOutgoingSyncMessage()) !== null) {
397
+ * if (msg.isBody) {
398
+ * bodyWs.send(frameBodyMessage(msg.docName, msg.message));
399
+ * } else {
400
+ * workspaceWs.send(msg.message);
401
+ * }
402
+ * }
403
+ * }, 50);
404
+ * ```
405
+ */
406
+ pollOutgoingSyncMessage(): any;
407
+ /**
408
+ * Read binary file.
409
+ *
410
+ * Returns data as Uint8Array for efficient handling without base64 encoding.
411
+ */
412
+ readBinary(path: string): Promise<any>;
413
+ /**
414
+ * Save configuration to root index frontmatter.
415
+ * Config keys are stored as `diaryx_*` properties.
416
+ */
417
+ saveConfig(config_js: any): Promise<any>;
418
+ /**
419
+ * Start sync session and set up event bridge.
420
+ *
421
+ * This wires up the sync manager's event callback to queue outgoing
422
+ * messages. Call this before connecting WebSocket.
423
+ *
424
+ * ## Example
425
+ * ```javascript
426
+ * backend.startSync();
427
+ * const ws = new WebSocket(url);
428
+ * // ... rest of setup
429
+ * ```
430
+ */
431
+ startSync(): void;
432
+ /**
433
+ * Stop sync session.
434
+ *
435
+ * Clears the outgoing message queue. Call after disconnecting WebSocket.
436
+ */
437
+ stopSync(): void;
438
+ /**
439
+ * Write binary file.
440
+ *
441
+ * Accepts Uint8Array for efficient handling without base64 encoding.
442
+ */
443
+ writeBinary(path: string, data: Uint8Array): Promise<any>;
444
+ }
445
+
446
+ /**
447
+ * AsyncFileSystem implementation backed by File System Access API.
448
+ *
449
+ * Allows editing files directly on the user's filesystem in a directory
450
+ * they select via `showDirectoryPicker()`.
451
+ */
452
+ export class FsaFileSystem {
453
+ private constructor();
454
+ free(): void;
455
+ [Symbol.dispose](): void;
456
+ /**
457
+ * Create a new FsaFileSystem from a user-selected directory handle.
458
+ *
459
+ * The handle must be obtained from `window.showDirectoryPicker()` in JavaScript.
460
+ */
461
+ static fromHandle(handle: FileSystemDirectoryHandle): FsaFileSystem;
462
+ }
463
+
464
+ /**
465
+ * AsyncFileSystem implementation backed by IndexedDB.
466
+ *
467
+ * Used as a fallback for browsers that don't support OPFS or when
468
+ * running outside a Web Worker context (where OPFS sync access isn't available).
469
+ */
470
+ export class IndexedDbFileSystem {
471
+ private constructor();
472
+ free(): void;
473
+ [Symbol.dispose](): void;
474
+ /**
475
+ * Create a new IndexedDbFileSystem.
476
+ *
477
+ * Opens or creates the IndexedDB database with the required object stores.
478
+ */
479
+ static create(): Promise<IndexedDbFileSystem>;
480
+ }
481
+
482
+ /**
483
+ * An `AsyncFileSystem` implementation backed by JavaScript callbacks.
484
+ *
485
+ * This struct allows Rust code to use the async filesystem interface while
486
+ * delegating actual storage operations to JavaScript. This is useful for:
487
+ *
488
+ * - Using IndexedDB for persistent storage in browsers
489
+ * - Using OPFS (Origin Private File System) for better performance
490
+ * - Integrating with existing JavaScript storage solutions
491
+ * - Testing with mock filesystems
492
+ *
493
+ * ## Thread Safety
494
+ *
495
+ * This type is designed for single-threaded WASM environments. The callbacks
496
+ * JsValue is cloned into each async operation to satisfy Send requirements,
497
+ * but actual execution remains single-threaded.
498
+ */
499
+ export class JsAsyncFileSystem {
500
+ free(): void;
501
+ [Symbol.dispose](): void;
502
+ /**
503
+ * Check if the filesystem has a specific callback.
504
+ */
505
+ has_callback(name: string): boolean;
506
+ /**
507
+ * Create a new JsAsyncFileSystem with the provided callbacks.
508
+ *
509
+ * The callbacks object should implement the `JsFileSystemCallbacks` interface.
510
+ * All callbacks are optional - missing callbacks will cause operations to fail
511
+ * with appropriate errors.
512
+ */
513
+ constructor(callbacks: any);
514
+ }
515
+
516
+ /**
517
+ * AsyncFileSystem implementation backed by OPFS (Origin Private File System).
518
+ *
519
+ * Uses the browser's private file system for persistent storage.
520
+ * All operations are async and work directly with browser storage.
521
+ */
522
+ export class OpfsFileSystem {
523
+ private constructor();
524
+ free(): void;
525
+ [Symbol.dispose](): void;
526
+ /**
527
+ * Create a new OpfsFileSystem with the default app directory.
528
+ *
529
+ * This creates a "diaryx" directory in the origin-private file system.
530
+ */
531
+ static create(): Promise<OpfsFileSystem>;
532
+ /**
533
+ * Create a new OpfsFileSystem with a custom root directory name.
534
+ */
535
+ static createWithName(root_name: string): Promise<OpfsFileSystem>;
536
+ }
537
+
538
+ /**
539
+ * WASM sync client wrapper for JavaScript integration.
540
+ *
541
+ * This struct wraps a `SyncClient<CallbackTransport>` and exposes its
542
+ * functionality to JavaScript via wasm-bindgen. It manages two transports
543
+ * (metadata and body) and provides methods for:
544
+ *
545
+ * - Getting WebSocket URLs for connection
546
+ * - Notifying connection status changes
547
+ * - Injecting incoming messages
548
+ * - Polling for outgoing messages
549
+ * - Starting and stopping sync
550
+ */
551
+ export class WasmSyncClient {
552
+ private constructor();
553
+ free(): void;
554
+ [Symbol.dispose](): void;
555
+ /**
556
+ * Focus on specific files for sync.
557
+ *
558
+ * Sends a focus message to the server indicating which files the client
559
+ * is currently interested in syncing. Other clients will receive a
560
+ * `focus_list_changed` notification and can subscribe to sync updates
561
+ * for these files.
562
+ *
563
+ * Call this when a file is opened in the editor.
564
+ *
565
+ * ## Example
566
+ * ```javascript
567
+ * // User opens a file
568
+ * client.focusFiles(["workspace/notes.md"]);
569
+ * ```
570
+ */
571
+ focusFiles(files: string[]): void;
572
+ /**
573
+ * Get the initial SyncStep1 message for a body document.
574
+ *
575
+ * Returns a Uint8Array containing the framed message to send via WebSocket.
576
+ */
577
+ getBodySyncStep1(doc_name: string): Uint8Array;
578
+ /**
579
+ * Get the WebSocket URL for the body connection.
580
+ *
581
+ * Returns null if sync hasn't been configured.
582
+ */
583
+ getBodyUrl(): string | undefined;
584
+ /**
585
+ * Get the WebSocket URL for the metadata connection.
586
+ *
587
+ * Returns null if sync hasn't been configured.
588
+ */
589
+ getMetadataUrl(): string | undefined;
590
+ /**
591
+ * Get the server URL.
592
+ */
593
+ getServerUrl(): string;
594
+ /**
595
+ * Get the workspace ID.
596
+ */
597
+ getWorkspaceId(): string;
598
+ /**
599
+ * Get the initial SyncStep1 message for workspace sync.
600
+ *
601
+ * Returns a Uint8Array containing the message to send via WebSocket.
602
+ */
603
+ getWorkspaceSyncStep1(): Uint8Array;
604
+ /**
605
+ * Check if there are pending body outgoing messages.
606
+ */
607
+ hasBodyOutgoing(): boolean;
608
+ /**
609
+ * Check if there are pending body outgoing text messages.
610
+ */
611
+ hasBodyOutgoingText(): boolean;
612
+ /**
613
+ * Check if there are pending metadata outgoing messages.
614
+ */
615
+ hasMetadataOutgoing(): boolean;
616
+ /**
617
+ * Inject an incoming body message.
618
+ *
619
+ * Call this when the body WebSocket receives a message.
620
+ * The message should already be unframed (doc_name extracted separately).
621
+ * Returns a Promise that resolves to a Uint8Array response (or null).
622
+ */
623
+ injectBodyMessage(doc_name: string, message: Uint8Array): Promise<any>;
624
+ /**
625
+ * Inject an incoming metadata message.
626
+ *
627
+ * Call this when the metadata WebSocket receives a message.
628
+ * Returns a Promise that resolves to a Uint8Array response (or null).
629
+ *
630
+ * The response should be sent back via the WebSocket if not null.
631
+ */
632
+ injectMetadataMessage(message: Uint8Array): Promise<any>;
633
+ /**
634
+ * Check if the body connection is established.
635
+ */
636
+ isBodyConnected(): boolean;
637
+ /**
638
+ * Check if both connections are established.
639
+ */
640
+ isConnected(): boolean;
641
+ /**
642
+ * Check if the metadata connection is established.
643
+ */
644
+ isMetadataConnected(): boolean;
645
+ /**
646
+ * Check if the sync client is running.
647
+ */
648
+ isRunning(): boolean;
649
+ /**
650
+ * Mark the body connection as connected.
651
+ *
652
+ * Call this when the body WebSocket opens.
653
+ */
654
+ markBodyConnected(): void;
655
+ /**
656
+ * Mark the body connection as disconnected.
657
+ *
658
+ * Call this when the body WebSocket closes.
659
+ */
660
+ markBodyDisconnected(): void;
661
+ /**
662
+ * Mark the metadata connection as connected.
663
+ *
664
+ * Call this when the metadata WebSocket opens.
665
+ */
666
+ markMetadataConnected(): void;
667
+ /**
668
+ * Mark the metadata connection as disconnected.
669
+ *
670
+ * Call this when the metadata WebSocket closes.
671
+ */
672
+ markMetadataDisconnected(): void;
673
+ /**
674
+ * Poll for an outgoing body message.
675
+ *
676
+ * Returns a Uint8Array if there's a message to send, null otherwise.
677
+ * The message is already framed with the document name.
678
+ */
679
+ pollBodyOutgoing(): Uint8Array | undefined;
680
+ /**
681
+ * Poll for an outgoing body text message (for focus/unfocus).
682
+ *
683
+ * Returns a string if there's a text message to send, null otherwise.
684
+ * JavaScript should call this in a polling loop and send any messages
685
+ * via the body WebSocket as text frames.
686
+ */
687
+ pollBodyOutgoingText(): string | undefined;
688
+ /**
689
+ * Poll for an outgoing metadata message.
690
+ *
691
+ * Returns a Uint8Array if there's a message to send, null otherwise.
692
+ * JavaScript should call this in a polling loop and send any messages
693
+ * via the metadata WebSocket.
694
+ */
695
+ pollMetadataOutgoing(): Uint8Array | undefined;
696
+ /**
697
+ * Queue a body update message for sending.
698
+ *
699
+ * This creates a Y-sync Update message for the given document
700
+ * and queues it for sending via the body WebSocket.
701
+ */
702
+ queueBodyUpdate(doc_name: string, content: string): void;
703
+ /**
704
+ * Queue a workspace update message for sending.
705
+ *
706
+ * This creates a Y-sync Update message from the current workspace state
707
+ * and queues it for sending via the metadata WebSocket.
708
+ */
709
+ queueWorkspaceUpdate(): void;
710
+ /**
711
+ * Start the sync session.
712
+ *
713
+ * This should be called after both WebSocket connections are established.
714
+ * It sends the initial SyncStep1 messages and subscribes to all body docs.
715
+ *
716
+ * Returns a Promise that resolves when initial sync messages are sent.
717
+ */
718
+ start(): Promise<any>;
719
+ /**
720
+ * Stop the sync session.
721
+ *
722
+ * Clears all pending messages and resets state.
723
+ */
724
+ stop(): void;
725
+ /**
726
+ * Subscribe to body sync for the currently focused files.
727
+ *
728
+ * This sends SyncStep1 messages for all files in the provided list.
729
+ * Call this after receiving a `focus_list_changed` message from the server.
730
+ *
731
+ * ## Example
732
+ * ```javascript
733
+ * // Received focus_list_changed event
734
+ * const files = event.files;
735
+ * client.subscribeBodies(files);
736
+ * ```
737
+ */
738
+ subscribeBodies(files: string[]): void;
739
+ /**
740
+ * Subscribe to body sync for a specific document.
741
+ *
742
+ * This queues a SyncStep1 message for the given document.
743
+ * Call this when a new file is created or when opening a file for editing.
744
+ */
745
+ subscribeBody(doc_name: string): void;
746
+ /**
747
+ * Unfocus specific files.
748
+ *
749
+ * Sends an unfocus message to the server indicating the client is no
750
+ * longer interested in syncing these files.
751
+ *
752
+ * Call this when a file is closed in the editor.
753
+ *
754
+ * ## Example
755
+ * ```javascript
756
+ * // User closes a file
757
+ * client.unfocusFiles(["workspace/notes.md"]);
758
+ * ```
759
+ */
760
+ unfocusFiles(files: string[]): void;
761
+ }
762
+
763
+ /**
764
+ * Initialize the WASM module. Called automatically on module load.
765
+ */
766
+ export function init(): void;
767
+
768
+ /**
769
+ * Generate an ISO 8601 timestamp for the current time.
770
+ */
771
+ export function now_timestamp(): string;
772
+
773
+ /**
774
+ * Generate a formatted date string for the current date.
775
+ */
776
+ export function today_formatted(format: string): string;
777
+
778
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
779
+
780
+ export interface InitOutput {
781
+ readonly memory: WebAssembly.Memory;
782
+ readonly __wbg_indexeddbfilesystem_free: (a: number, b: number) => void;
783
+ readonly __wbg_jsasyncfilesystem_free: (a: number, b: number) => void;
784
+ readonly indexeddbfilesystem_create: () => any;
785
+ readonly jsasyncfilesystem_has_callback: (a: number, b: number, c: number) => number;
786
+ readonly jsasyncfilesystem_new: (a: any) => number;
787
+ readonly __wbg_fsafilesystem_free: (a: number, b: number) => void;
788
+ readonly __wbg_opfsfilesystem_free: (a: number, b: number) => void;
789
+ readonly opfsfilesystem_create: () => any;
790
+ readonly opfsfilesystem_createWithName: (a: number, b: number) => any;
791
+ readonly fsafilesystem_fromHandle: (a: any) => number;
792
+ readonly now_timestamp: () => [number, number];
793
+ readonly today_formatted: (a: number, b: number) => [number, number];
794
+ readonly __wbg_diaryxbackend_free: (a: number, b: number) => void;
795
+ readonly diaryxbackend_create: (a: number, b: number) => any;
796
+ readonly diaryxbackend_createFromDirectoryHandle: (a: any) => [number, number, number];
797
+ readonly diaryxbackend_createInMemory: () => [number, number, number];
798
+ readonly diaryxbackend_createIndexedDb: () => any;
799
+ readonly diaryxbackend_createOpfs: () => any;
800
+ readonly diaryxbackend_createSyncClient: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
801
+ readonly diaryxbackend_emitFileSystemEvent: (a: number, b: number, c: number) => [number, number];
802
+ readonly diaryxbackend_eventSubscriberCount: (a: number) => number;
803
+ readonly diaryxbackend_execute: (a: number, b: number, c: number) => any;
804
+ readonly diaryxbackend_executeJs: (a: number, b: any) => any;
805
+ readonly diaryxbackend_getBodySyncStep1: (a: number, b: number, c: number) => any;
806
+ readonly diaryxbackend_getConfig: (a: number) => any;
807
+ readonly diaryxbackend_getWorkspaceSyncStep1: (a: number) => any;
808
+ readonly diaryxbackend_hasNativeSync: (a: number) => number;
809
+ readonly diaryxbackend_hasOutgoingSyncMessages: (a: number) => number;
810
+ readonly diaryxbackend_injectBodySyncMessage: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
811
+ readonly diaryxbackend_injectWorkspaceSyncMessage: (a: number, b: number, c: number, d: number) => any;
812
+ readonly diaryxbackend_offFileSystemEvent: (a: number, b: bigint) => number;
813
+ readonly diaryxbackend_onFileSystemEvent: (a: number, b: any) => bigint;
814
+ readonly diaryxbackend_outgoingSyncMessageCount: (a: number) => number;
815
+ readonly diaryxbackend_pollOutgoingSyncMessage: (a: number) => any;
816
+ readonly diaryxbackend_readBinary: (a: number, b: number, c: number) => any;
817
+ readonly diaryxbackend_saveConfig: (a: number, b: any) => any;
818
+ readonly diaryxbackend_startSync: (a: number) => void;
819
+ readonly diaryxbackend_stopSync: (a: number) => void;
820
+ readonly diaryxbackend_writeBinary: (a: number, b: number, c: number, d: any) => any;
821
+ readonly init: () => void;
822
+ readonly __wbg_wasmsyncclient_free: (a: number, b: number) => void;
823
+ readonly wasmsyncclient_focusFiles: (a: number, b: number, c: number) => void;
824
+ readonly wasmsyncclient_getBodySyncStep1: (a: number, b: number, c: number) => any;
825
+ readonly wasmsyncclient_getBodyUrl: (a: number) => [number, number];
826
+ readonly wasmsyncclient_getMetadataUrl: (a: number) => [number, number];
827
+ readonly wasmsyncclient_getServerUrl: (a: number) => [number, number];
828
+ readonly wasmsyncclient_getWorkspaceId: (a: number) => [number, number];
829
+ readonly wasmsyncclient_getWorkspaceSyncStep1: (a: number) => any;
830
+ readonly wasmsyncclient_hasBodyOutgoing: (a: number) => number;
831
+ readonly wasmsyncclient_hasBodyOutgoingText: (a: number) => number;
832
+ readonly wasmsyncclient_hasMetadataOutgoing: (a: number) => number;
833
+ readonly wasmsyncclient_injectBodyMessage: (a: number, b: number, c: number, d: number, e: number) => any;
834
+ readonly wasmsyncclient_injectMetadataMessage: (a: number, b: number, c: number) => any;
835
+ readonly wasmsyncclient_isBodyConnected: (a: number) => number;
836
+ readonly wasmsyncclient_isConnected: (a: number) => number;
837
+ readonly wasmsyncclient_isMetadataConnected: (a: number) => number;
838
+ readonly wasmsyncclient_isRunning: (a: number) => number;
839
+ readonly wasmsyncclient_markBodyConnected: (a: number) => void;
840
+ readonly wasmsyncclient_markBodyDisconnected: (a: number) => void;
841
+ readonly wasmsyncclient_markMetadataConnected: (a: number) => void;
842
+ readonly wasmsyncclient_markMetadataDisconnected: (a: number) => void;
843
+ readonly wasmsyncclient_pollBodyOutgoing: (a: number) => any;
844
+ readonly wasmsyncclient_pollBodyOutgoingText: (a: number) => [number, number];
845
+ readonly wasmsyncclient_pollMetadataOutgoing: (a: number) => any;
846
+ readonly wasmsyncclient_queueBodyUpdate: (a: number, b: number, c: number, d: number, e: number) => [number, number];
847
+ readonly wasmsyncclient_queueWorkspaceUpdate: (a: number) => [number, number];
848
+ readonly wasmsyncclient_start: (a: number) => any;
849
+ readonly wasmsyncclient_stop: (a: number) => void;
850
+ readonly wasmsyncclient_subscribeBodies: (a: number, b: number, c: number) => void;
851
+ readonly wasmsyncclient_subscribeBody: (a: number, b: number, c: number) => void;
852
+ readonly wasmsyncclient_unfocusFiles: (a: number, b: number, c: number) => void;
853
+ readonly wasm_bindgen__closure__destroy__h137d52471f521a66: (a: number, b: number) => void;
854
+ readonly wasm_bindgen__closure__destroy__h4b2a5ceca2370348: (a: number, b: number) => void;
855
+ readonly wasm_bindgen__closure__destroy__hf59ea51dfabf38c5: (a: number, b: number) => void;
856
+ readonly wasm_bindgen__convert__closures_____invoke__h23e9ca6af2643a78: (a: number, b: number, c: any) => [number, number];
857
+ readonly wasm_bindgen__convert__closures_____invoke__hcef8d709b492a91f: (a: number, b: number, c: any, d: any) => void;
858
+ readonly wasm_bindgen__convert__closures_____invoke__hb2c8b70415be0174: (a: number, b: number, c: any) => void;
859
+ readonly wasm_bindgen__convert__closures_____invoke__h1598c516b2d5b326: (a: number, b: number, c: any) => void;
860
+ readonly wasm_bindgen__convert__closures_____invoke__ha6231ef7710d1c67: (a: number, b: number, c: any) => void;
861
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
862
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
863
+ readonly __wbindgen_exn_store: (a: number) => void;
864
+ readonly __externref_table_alloc: () => number;
865
+ readonly __wbindgen_externrefs: WebAssembly.Table;
866
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
867
+ readonly __externref_table_dealloc: (a: number) => void;
868
+ readonly __wbindgen_start: () => void;
869
+ }
870
+
871
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
872
+
873
+ /**
874
+ * Instantiates the given `module`, which can either be bytes or
875
+ * a precompiled `WebAssembly.Module`.
876
+ *
877
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
878
+ *
879
+ * @returns {InitOutput}
880
+ */
881
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
882
+
883
+ /**
884
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
885
+ * for everything else, calls `WebAssembly.instantiate` directly.
886
+ *
887
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
888
+ *
889
+ * @returns {Promise<InitOutput>}
890
+ */
891
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;