@diaryx/wasm-node 0.11.0 → 0.11.1-dev.193efc4
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.
- package/diaryx_wasm.d.ts +90 -342
- package/diaryx_wasm.js +122 -450
- package/diaryx_wasm_bg.wasm +0 -0
- package/diaryx_wasm_bg.wasm.d.ts +21 -43
- package/package.json +1 -1
- package/diaryx_wasm_bg.js +0 -1600
package/diaryx_wasm.js
CHANGED
|
@@ -75,42 +75,43 @@ export class DiaryxBackend {
|
|
|
75
75
|
/**
|
|
76
76
|
* Create a new sync client for the given server and workspace.
|
|
77
77
|
*
|
|
78
|
-
*
|
|
79
|
-
* JavaScript manages WebSocket
|
|
78
|
+
* Creates a `WasmSyncClient` backed by the shared `SyncSession` protocol
|
|
79
|
+
* handler. JavaScript manages the WebSocket while Rust handles all sync
|
|
80
|
+
* protocol logic (handshake, message routing, framing).
|
|
80
81
|
*
|
|
81
82
|
* ## Example
|
|
82
83
|
*
|
|
83
84
|
* ```javascript
|
|
84
85
|
* const client = backend.createSyncClient(
|
|
85
|
-
* '
|
|
86
|
+
* 'https://sync.example.com',
|
|
86
87
|
* 'my-workspace-id',
|
|
87
88
|
* 'auth-token-optional'
|
|
88
89
|
* );
|
|
89
90
|
*
|
|
90
|
-
* // Get
|
|
91
|
-
* const
|
|
92
|
-
* const
|
|
91
|
+
* // Get the WebSocket URL
|
|
92
|
+
* const wsUrl = client.getWsUrl();
|
|
93
|
+
* const ws = new WebSocket(wsUrl);
|
|
94
|
+
* ws.binaryType = 'arraybuffer';
|
|
93
95
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* const response = await client.injectMetadataMessage(new Uint8Array(e.data));
|
|
101
|
-
* if (response) metaWs.send(response);
|
|
96
|
+
* ws.onopen = async () => {
|
|
97
|
+
* await client.onConnected();
|
|
98
|
+
* // Drain outgoing messages
|
|
99
|
+
* let msg;
|
|
100
|
+
* while ((msg = client.pollOutgoingBinary())) ws.send(msg);
|
|
101
|
+
* while ((msg = client.pollOutgoingText())) ws.send(msg);
|
|
102
102
|
* };
|
|
103
|
-
* // Similar for body WebSocket...
|
|
104
103
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
104
|
+
* ws.onmessage = async (e) => {
|
|
105
|
+
* if (typeof e.data === 'string') {
|
|
106
|
+
* await client.onTextMessage(e.data);
|
|
107
|
+
* } else {
|
|
108
|
+
* await client.onBinaryMessage(new Uint8Array(e.data));
|
|
109
|
+
* }
|
|
110
|
+
* // Drain outgoing messages and events
|
|
107
111
|
* let msg;
|
|
108
|
-
* while ((msg = client.
|
|
109
|
-
* while ((msg = client.
|
|
110
|
-
* }
|
|
111
|
-
*
|
|
112
|
-
* // Start sync
|
|
113
|
-
* await client.start();
|
|
112
|
+
* while ((msg = client.pollOutgoingBinary())) ws.send(msg);
|
|
113
|
+
* while ((msg = client.pollOutgoingText())) ws.send(msg);
|
|
114
|
+
* };
|
|
114
115
|
* ```
|
|
115
116
|
* @param {string} server_url
|
|
116
117
|
* @param {string} workspace_id
|
|
@@ -193,26 +194,6 @@ export class DiaryxBackend {
|
|
|
193
194
|
const ret = wasm.diaryxbackend_executeJs(this.__wbg_ptr, command);
|
|
194
195
|
return ret;
|
|
195
196
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Get initial body sync step1 message for a document.
|
|
198
|
-
*
|
|
199
|
-
* Returns a Uint8Array containing the Y-sync step1 message for
|
|
200
|
-
* the specified document's body content.
|
|
201
|
-
*
|
|
202
|
-
* ## Example
|
|
203
|
-
* ```javascript
|
|
204
|
-
* const step1 = backend.getBodySyncStep1("notes/my-note.md");
|
|
205
|
-
* // Frame it for multiplexed connection and send
|
|
206
|
-
* ```
|
|
207
|
-
* @param {string} doc_name
|
|
208
|
-
* @returns {Uint8Array}
|
|
209
|
-
*/
|
|
210
|
-
getBodySyncStep1(doc_name) {
|
|
211
|
-
const ptr0 = passStringToWasm0(doc_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
212
|
-
const len0 = WASM_VECTOR_LEN;
|
|
213
|
-
const ret = wasm.diaryxbackend_getBodySyncStep1(this.__wbg_ptr, ptr0, len0);
|
|
214
|
-
return ret;
|
|
215
|
-
}
|
|
216
197
|
/**
|
|
217
198
|
* Get the current configuration from root index frontmatter.
|
|
218
199
|
* Config keys are stored as `diaryx_*` properties.
|
|
@@ -222,23 +203,6 @@ export class DiaryxBackend {
|
|
|
222
203
|
const ret = wasm.diaryxbackend_getConfig(this.__wbg_ptr);
|
|
223
204
|
return ret;
|
|
224
205
|
}
|
|
225
|
-
/**
|
|
226
|
-
* Get initial workspace sync step1 message.
|
|
227
|
-
*
|
|
228
|
-
* Returns a Uint8Array containing the Y-sync step1 message to send
|
|
229
|
-
* over the WebSocket to initiate workspace metadata sync.
|
|
230
|
-
*
|
|
231
|
-
* ## Example
|
|
232
|
-
* ```javascript
|
|
233
|
-
* const step1 = backend.getWorkspaceSyncStep1();
|
|
234
|
-
* ws.send(step1);
|
|
235
|
-
* ```
|
|
236
|
-
* @returns {Uint8Array}
|
|
237
|
-
*/
|
|
238
|
-
getWorkspaceSyncStep1() {
|
|
239
|
-
const ret = wasm.diaryxbackend_getWorkspaceSyncStep1(this.__wbg_ptr);
|
|
240
|
-
return ret;
|
|
241
|
-
}
|
|
242
206
|
/**
|
|
243
207
|
* Check if this backend has native sync support.
|
|
244
208
|
*
|
|
@@ -250,65 +214,6 @@ export class DiaryxBackend {
|
|
|
250
214
|
const ret = wasm.diaryxbackend_hasNativeSync(this.__wbg_ptr);
|
|
251
215
|
return ret !== 0;
|
|
252
216
|
}
|
|
253
|
-
/**
|
|
254
|
-
* Check if there are pending outgoing sync messages.
|
|
255
|
-
* @returns {boolean}
|
|
256
|
-
*/
|
|
257
|
-
hasOutgoingSyncMessages() {
|
|
258
|
-
const ret = wasm.diaryxbackend_hasOutgoingSyncMessages(this.__wbg_ptr);
|
|
259
|
-
return ret !== 0;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Inject an incoming body sync message.
|
|
263
|
-
*
|
|
264
|
-
* Call this when the WebSocket receives a message for a body document.
|
|
265
|
-
* The message should already be unframed (doc_name extracted separately).
|
|
266
|
-
* Returns a response message to send back, or null if no response is needed.
|
|
267
|
-
*
|
|
268
|
-
* ## Example
|
|
269
|
-
* ```javascript
|
|
270
|
-
* // After unframing the multiplexed message:
|
|
271
|
-
* const response = await backend.injectBodySyncMessage(docName, data, true);
|
|
272
|
-
* if (response) ws.send(frameBodyMessage(docName, response));
|
|
273
|
-
* ```
|
|
274
|
-
* @param {string} doc_name
|
|
275
|
-
* @param {Uint8Array} message
|
|
276
|
-
* @param {boolean} write_to_disk
|
|
277
|
-
* @returns {Promise<any>}
|
|
278
|
-
*/
|
|
279
|
-
injectBodySyncMessage(doc_name, message, write_to_disk) {
|
|
280
|
-
const ptr0 = passStringToWasm0(doc_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
281
|
-
const len0 = WASM_VECTOR_LEN;
|
|
282
|
-
const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
|
|
283
|
-
const len1 = WASM_VECTOR_LEN;
|
|
284
|
-
const ret = wasm.diaryxbackend_injectBodySyncMessage(this.__wbg_ptr, ptr0, len0, ptr1, len1, write_to_disk);
|
|
285
|
-
return ret;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Inject an incoming workspace sync message.
|
|
289
|
-
*
|
|
290
|
-
* Call this when the WebSocket receives a message for the workspace
|
|
291
|
-
* (metadata) connection. Returns a response message to send back,
|
|
292
|
-
* or null if no response is needed.
|
|
293
|
-
*
|
|
294
|
-
* ## Example
|
|
295
|
-
* ```javascript
|
|
296
|
-
* ws.onmessage = (event) => {
|
|
297
|
-
* const data = new Uint8Array(event.data);
|
|
298
|
-
* const response = backend.injectWorkspaceSyncMessage(data, true);
|
|
299
|
-
* if (response) ws.send(response);
|
|
300
|
-
* };
|
|
301
|
-
* ```
|
|
302
|
-
* @param {Uint8Array} message
|
|
303
|
-
* @param {boolean} write_to_disk
|
|
304
|
-
* @returns {Promise<any>}
|
|
305
|
-
*/
|
|
306
|
-
injectWorkspaceSyncMessage(message, write_to_disk) {
|
|
307
|
-
const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
|
|
308
|
-
const len0 = WASM_VECTOR_LEN;
|
|
309
|
-
const ret = wasm.diaryxbackend_injectWorkspaceSyncMessage(this.__wbg_ptr, ptr0, len0, write_to_disk);
|
|
310
|
-
return ret;
|
|
311
|
-
}
|
|
312
217
|
/**
|
|
313
218
|
* Unsubscribe from filesystem events.
|
|
314
219
|
*
|
|
@@ -355,43 +260,6 @@ export class DiaryxBackend {
|
|
|
355
260
|
const ret = wasm.diaryxbackend_onFileSystemEvent(this.__wbg_ptr, callback);
|
|
356
261
|
return BigInt.asUintN(64, ret);
|
|
357
262
|
}
|
|
358
|
-
/**
|
|
359
|
-
* Get count of pending outgoing sync messages.
|
|
360
|
-
* @returns {number}
|
|
361
|
-
*/
|
|
362
|
-
outgoingSyncMessageCount() {
|
|
363
|
-
const ret = wasm.diaryxbackend_outgoingSyncMessageCount(this.__wbg_ptr);
|
|
364
|
-
return ret >>> 0;
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Poll for an outgoing sync message.
|
|
368
|
-
*
|
|
369
|
-
* Returns the next outgoing message as a JavaScript object with:
|
|
370
|
-
* - `docName`: Document name ("workspace" or file path)
|
|
371
|
-
* - `message`: Uint8Array message data
|
|
372
|
-
* - `isBody`: Boolean indicating body (true) or workspace (false)
|
|
373
|
-
*
|
|
374
|
-
* Returns null if no messages are queued.
|
|
375
|
-
*
|
|
376
|
-
* ## Example
|
|
377
|
-
* ```javascript
|
|
378
|
-
* setInterval(() => {
|
|
379
|
-
* let msg;
|
|
380
|
-
* while ((msg = backend.pollOutgoingSyncMessage()) !== null) {
|
|
381
|
-
* if (msg.isBody) {
|
|
382
|
-
* bodyWs.send(frameBodyMessage(msg.docName, msg.message));
|
|
383
|
-
* } else {
|
|
384
|
-
* workspaceWs.send(msg.message);
|
|
385
|
-
* }
|
|
386
|
-
* }
|
|
387
|
-
* }, 50);
|
|
388
|
-
* ```
|
|
389
|
-
* @returns {any}
|
|
390
|
-
*/
|
|
391
|
-
pollOutgoingSyncMessage() {
|
|
392
|
-
const ret = wasm.diaryxbackend_pollOutgoingSyncMessage(this.__wbg_ptr);
|
|
393
|
-
return ret;
|
|
394
|
-
}
|
|
395
263
|
/**
|
|
396
264
|
* Read binary file.
|
|
397
265
|
*
|
|
@@ -415,30 +283,6 @@ export class DiaryxBackend {
|
|
|
415
283
|
const ret = wasm.diaryxbackend_saveConfig(this.__wbg_ptr, config_js);
|
|
416
284
|
return ret;
|
|
417
285
|
}
|
|
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() {
|
|
432
|
-
wasm.diaryxbackend_startSync(this.__wbg_ptr);
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Stop sync session.
|
|
436
|
-
*
|
|
437
|
-
* Clears the outgoing message queue. Call after disconnecting WebSocket.
|
|
438
|
-
*/
|
|
439
|
-
stopSync() {
|
|
440
|
-
wasm.diaryxbackend_stopSync(this.__wbg_ptr);
|
|
441
|
-
}
|
|
442
286
|
/**
|
|
443
287
|
* Write binary file.
|
|
444
288
|
*
|
|
@@ -513,17 +357,11 @@ export class JsAsyncFileSystem {
|
|
|
513
357
|
if (Symbol.dispose) JsAsyncFileSystem.prototype[Symbol.dispose] = JsAsyncFileSystem.prototype.free;
|
|
514
358
|
|
|
515
359
|
/**
|
|
516
|
-
* WASM sync client
|
|
360
|
+
* WASM sync client backed by the shared SyncSession protocol handler.
|
|
517
361
|
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
* - Getting WebSocket URLs for connection
|
|
523
|
-
* - Notifying connection status changes
|
|
524
|
-
* - Injecting incoming messages
|
|
525
|
-
* - Polling for outgoing messages
|
|
526
|
-
* - Starting and stopping sync
|
|
362
|
+
* JavaScript feeds WebSocket events in via `onConnected()`, `onBinaryMessage()`,
|
|
363
|
+
* etc. The client processes them through `SyncSession` and queues outgoing
|
|
364
|
+
* messages/events for JavaScript to poll.
|
|
527
365
|
*/
|
|
528
366
|
export class WasmSyncClient {
|
|
529
367
|
static __wrap(ptr) {
|
|
@@ -544,20 +382,9 @@ export class WasmSyncClient {
|
|
|
544
382
|
wasm.__wbg_wasmsyncclient_free(ptr, 0);
|
|
545
383
|
}
|
|
546
384
|
/**
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
* Sends a focus message to the server indicating which files the client
|
|
550
|
-
* is currently interested in syncing. Other clients will receive a
|
|
551
|
-
* `focus_list_changed` notification and can subscribe to sync updates
|
|
552
|
-
* for these files.
|
|
385
|
+
* Send a focus message for specific files.
|
|
553
386
|
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
* ## Example
|
|
557
|
-
* ```javascript
|
|
558
|
-
* // User opens a file
|
|
559
|
-
* client.focusFiles(["workspace/notes.md"]);
|
|
560
|
-
* ```
|
|
387
|
+
* Other clients will be notified which files this client is interested in.
|
|
561
388
|
* @param {string[]} files
|
|
562
389
|
*/
|
|
563
390
|
focusFiles(files) {
|
|
@@ -565,49 +392,6 @@ export class WasmSyncClient {
|
|
|
565
392
|
const len0 = WASM_VECTOR_LEN;
|
|
566
393
|
wasm.wasmsyncclient_focusFiles(this.__wbg_ptr, ptr0, len0);
|
|
567
394
|
}
|
|
568
|
-
/**
|
|
569
|
-
* Get the initial SyncStep1 message for a body document.
|
|
570
|
-
*
|
|
571
|
-
* Returns a Uint8Array containing the framed message to send via WebSocket.
|
|
572
|
-
* @param {string} doc_name
|
|
573
|
-
* @returns {Uint8Array}
|
|
574
|
-
*/
|
|
575
|
-
getBodySyncStep1(doc_name) {
|
|
576
|
-
const ptr0 = passStringToWasm0(doc_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
577
|
-
const len0 = WASM_VECTOR_LEN;
|
|
578
|
-
const ret = wasm.wasmsyncclient_getBodySyncStep1(this.__wbg_ptr, ptr0, len0);
|
|
579
|
-
return ret;
|
|
580
|
-
}
|
|
581
|
-
/**
|
|
582
|
-
* Get the WebSocket URL for the body connection.
|
|
583
|
-
*
|
|
584
|
-
* Returns null if sync hasn't been configured.
|
|
585
|
-
* @returns {string | undefined}
|
|
586
|
-
*/
|
|
587
|
-
getBodyUrl() {
|
|
588
|
-
const ret = wasm.wasmsyncclient_getBodyUrl(this.__wbg_ptr);
|
|
589
|
-
let v1;
|
|
590
|
-
if (ret[0] !== 0) {
|
|
591
|
-
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
592
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
593
|
-
}
|
|
594
|
-
return v1;
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* Get the WebSocket URL for the metadata connection.
|
|
598
|
-
*
|
|
599
|
-
* Returns null if sync hasn't been configured.
|
|
600
|
-
* @returns {string | undefined}
|
|
601
|
-
*/
|
|
602
|
-
getMetadataUrl() {
|
|
603
|
-
const ret = wasm.wasmsyncclient_getMetadataUrl(this.__wbg_ptr);
|
|
604
|
-
let v1;
|
|
605
|
-
if (ret[0] !== 0) {
|
|
606
|
-
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
607
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
608
|
-
}
|
|
609
|
-
return v1;
|
|
610
|
-
}
|
|
611
395
|
/**
|
|
612
396
|
* Get the server URL.
|
|
613
397
|
* @returns {string}
|
|
@@ -641,158 +425,103 @@ export class WasmSyncClient {
|
|
|
641
425
|
}
|
|
642
426
|
}
|
|
643
427
|
/**
|
|
644
|
-
* Get the
|
|
428
|
+
* Get the WebSocket URL for the v2 sync connection.
|
|
645
429
|
*
|
|
646
|
-
* Returns a
|
|
647
|
-
* @returns {
|
|
648
|
-
*/
|
|
649
|
-
getWorkspaceSyncStep1() {
|
|
650
|
-
const ret = wasm.wasmsyncclient_getWorkspaceSyncStep1(this.__wbg_ptr);
|
|
651
|
-
return ret;
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Check if there are pending body outgoing messages.
|
|
655
|
-
* @returns {boolean}
|
|
430
|
+
* Returns a URL like `wss://sync.example.com/sync2?token=...&session=...`
|
|
431
|
+
* @returns {string}
|
|
656
432
|
*/
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
433
|
+
getWsUrl() {
|
|
434
|
+
let deferred1_0;
|
|
435
|
+
let deferred1_1;
|
|
436
|
+
try {
|
|
437
|
+
const ret = wasm.wasmsyncclient_getWsUrl(this.__wbg_ptr);
|
|
438
|
+
deferred1_0 = ret[0];
|
|
439
|
+
deferred1_1 = ret[1];
|
|
440
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
441
|
+
} finally {
|
|
442
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
443
|
+
}
|
|
660
444
|
}
|
|
661
445
|
/**
|
|
662
|
-
* Check if there are pending
|
|
446
|
+
* Check if there are pending events.
|
|
663
447
|
* @returns {boolean}
|
|
664
448
|
*/
|
|
665
|
-
|
|
666
|
-
const ret = wasm.
|
|
449
|
+
hasEvents() {
|
|
450
|
+
const ret = wasm.wasmsyncclient_hasEvents(this.__wbg_ptr);
|
|
667
451
|
return ret !== 0;
|
|
668
452
|
}
|
|
669
453
|
/**
|
|
670
|
-
* Check if there are pending
|
|
454
|
+
* Check if there are pending outgoing messages or events.
|
|
671
455
|
* @returns {boolean}
|
|
672
456
|
*/
|
|
673
|
-
|
|
674
|
-
const ret = wasm.
|
|
457
|
+
hasOutgoing() {
|
|
458
|
+
const ret = wasm.wasmsyncclient_hasOutgoing(this.__wbg_ptr);
|
|
675
459
|
return ret !== 0;
|
|
676
460
|
}
|
|
677
461
|
/**
|
|
678
|
-
* Inject an incoming
|
|
462
|
+
* Inject an incoming binary WebSocket message.
|
|
679
463
|
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
* @param {string} doc_name
|
|
684
|
-
* @param {Uint8Array} message
|
|
464
|
+
* Returns a Promise that resolves when processing is complete.
|
|
465
|
+
* After this, poll outgoing queues.
|
|
466
|
+
* @param {Uint8Array} data
|
|
685
467
|
* @returns {Promise<any>}
|
|
686
468
|
*/
|
|
687
|
-
|
|
688
|
-
const ptr0 =
|
|
469
|
+
onBinaryMessage(data) {
|
|
470
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
689
471
|
const len0 = WASM_VECTOR_LEN;
|
|
690
|
-
const
|
|
691
|
-
const len1 = WASM_VECTOR_LEN;
|
|
692
|
-
const ret = wasm.wasmsyncclient_injectBodyMessage(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
472
|
+
const ret = wasm.wasmsyncclient_onBinaryMessage(this.__wbg_ptr, ptr0, len0);
|
|
693
473
|
return ret;
|
|
694
474
|
}
|
|
695
475
|
/**
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
* Call this when the metadata WebSocket receives a message.
|
|
699
|
-
* Returns a Promise that resolves to a Uint8Array response (or null).
|
|
476
|
+
* Notify that the WebSocket connected.
|
|
700
477
|
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
478
|
+
* Triggers workspace SyncStep1 and handshake. After calling this,
|
|
479
|
+
* poll `pollOutgoingBinary()` / `pollOutgoingText()` to get messages to send.
|
|
703
480
|
* @returns {Promise<any>}
|
|
704
481
|
*/
|
|
705
|
-
|
|
706
|
-
const
|
|
707
|
-
const len0 = WASM_VECTOR_LEN;
|
|
708
|
-
const ret = wasm.wasmsyncclient_injectMetadataMessage(this.__wbg_ptr, ptr0, len0);
|
|
482
|
+
onConnected() {
|
|
483
|
+
const ret = wasm.wasmsyncclient_onConnected(this.__wbg_ptr);
|
|
709
484
|
return ret;
|
|
710
485
|
}
|
|
711
486
|
/**
|
|
712
|
-
*
|
|
713
|
-
* @returns {
|
|
714
|
-
*/
|
|
715
|
-
isBodyConnected() {
|
|
716
|
-
const ret = wasm.wasmsyncclient_isBodyConnected(this.__wbg_ptr);
|
|
717
|
-
return ret !== 0;
|
|
718
|
-
}
|
|
719
|
-
/**
|
|
720
|
-
* Check if both connections are established.
|
|
721
|
-
* @returns {boolean}
|
|
722
|
-
*/
|
|
723
|
-
isConnected() {
|
|
724
|
-
const ret = wasm.wasmsyncclient_isConnected(this.__wbg_ptr);
|
|
725
|
-
return ret !== 0;
|
|
726
|
-
}
|
|
727
|
-
/**
|
|
728
|
-
* Check if the metadata connection is established.
|
|
729
|
-
* @returns {boolean}
|
|
730
|
-
*/
|
|
731
|
-
isMetadataConnected() {
|
|
732
|
-
const ret = wasm.wasmsyncclient_isMetadataConnected(this.__wbg_ptr);
|
|
733
|
-
return ret !== 0;
|
|
734
|
-
}
|
|
735
|
-
/**
|
|
736
|
-
* Check if the sync client is running.
|
|
737
|
-
* @returns {boolean}
|
|
738
|
-
*/
|
|
739
|
-
isRunning() {
|
|
740
|
-
const ret = wasm.wasmsyncclient_isRunning(this.__wbg_ptr);
|
|
741
|
-
return ret !== 0;
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* Mark the body connection as connected.
|
|
745
|
-
*
|
|
746
|
-
* Call this when the body WebSocket opens.
|
|
747
|
-
*/
|
|
748
|
-
markBodyConnected() {
|
|
749
|
-
wasm.wasmsyncclient_markBodyConnected(this.__wbg_ptr);
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Mark the body connection as disconnected.
|
|
753
|
-
*
|
|
754
|
-
* Call this when the body WebSocket closes.
|
|
755
|
-
*/
|
|
756
|
-
markBodyDisconnected() {
|
|
757
|
-
wasm.wasmsyncclient_markBodyDisconnected(this.__wbg_ptr);
|
|
758
|
-
}
|
|
759
|
-
/**
|
|
760
|
-
* Mark the metadata connection as connected.
|
|
761
|
-
*
|
|
762
|
-
* Call this when the metadata WebSocket opens.
|
|
487
|
+
* Notify that the WebSocket disconnected.
|
|
488
|
+
* @returns {Promise<any>}
|
|
763
489
|
*/
|
|
764
|
-
|
|
765
|
-
wasm.
|
|
490
|
+
onDisconnected() {
|
|
491
|
+
const ret = wasm.wasmsyncclient_onDisconnected(this.__wbg_ptr);
|
|
492
|
+
return ret;
|
|
766
493
|
}
|
|
767
494
|
/**
|
|
768
|
-
*
|
|
495
|
+
* Notify that a snapshot was downloaded and imported.
|
|
769
496
|
*
|
|
770
|
-
* Call this
|
|
497
|
+
* Call this after handling a `downloadSnapshot` event.
|
|
498
|
+
* @returns {Promise<any>}
|
|
771
499
|
*/
|
|
772
|
-
|
|
773
|
-
wasm.
|
|
500
|
+
onSnapshotImported() {
|
|
501
|
+
const ret = wasm.wasmsyncclient_onSnapshotImported(this.__wbg_ptr);
|
|
502
|
+
return ret;
|
|
774
503
|
}
|
|
775
504
|
/**
|
|
776
|
-
*
|
|
505
|
+
* Inject an incoming text WebSocket message (JSON control message).
|
|
777
506
|
*
|
|
778
|
-
* Returns a
|
|
779
|
-
*
|
|
780
|
-
* @returns {
|
|
507
|
+
* Returns a Promise that resolves when processing is complete.
|
|
508
|
+
* @param {string} text
|
|
509
|
+
* @returns {Promise<any>}
|
|
781
510
|
*/
|
|
782
|
-
|
|
783
|
-
const
|
|
511
|
+
onTextMessage(text) {
|
|
512
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
513
|
+
const len0 = WASM_VECTOR_LEN;
|
|
514
|
+
const ret = wasm.wasmsyncclient_onTextMessage(this.__wbg_ptr, ptr0, len0);
|
|
784
515
|
return ret;
|
|
785
516
|
}
|
|
786
517
|
/**
|
|
787
|
-
* Poll for
|
|
518
|
+
* Poll for a JSON-serialized event.
|
|
788
519
|
*
|
|
789
|
-
* Returns a string
|
|
790
|
-
* JavaScript should call this in a polling loop and send any messages
|
|
791
|
-
* via the body WebSocket as text frames.
|
|
520
|
+
* Returns a JSON string representing a SyncEvent, or null.
|
|
792
521
|
* @returns {string | undefined}
|
|
793
522
|
*/
|
|
794
|
-
|
|
795
|
-
const ret = wasm.
|
|
523
|
+
pollEvent() {
|
|
524
|
+
const ret = wasm.wasmsyncclient_pollEvent(this.__wbg_ptr);
|
|
796
525
|
let v1;
|
|
797
526
|
if (ret[0] !== 0) {
|
|
798
527
|
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
@@ -801,112 +530,59 @@ export class WasmSyncClient {
|
|
|
801
530
|
return v1;
|
|
802
531
|
}
|
|
803
532
|
/**
|
|
804
|
-
* Poll for an outgoing
|
|
533
|
+
* Poll for an outgoing binary message.
|
|
805
534
|
*
|
|
806
535
|
* Returns a Uint8Array if there's a message to send, null otherwise.
|
|
807
|
-
* JavaScript should call this in a polling loop and send any messages
|
|
808
|
-
* via the metadata WebSocket.
|
|
809
536
|
* @returns {Uint8Array | undefined}
|
|
810
537
|
*/
|
|
811
|
-
|
|
812
|
-
const ret = wasm.
|
|
538
|
+
pollOutgoingBinary() {
|
|
539
|
+
const ret = wasm.wasmsyncclient_pollOutgoingBinary(this.__wbg_ptr);
|
|
813
540
|
return ret;
|
|
814
541
|
}
|
|
815
542
|
/**
|
|
816
|
-
*
|
|
543
|
+
* Poll for an outgoing text message.
|
|
817
544
|
*
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
* @param {string} doc_name
|
|
821
|
-
* @param {string} content
|
|
822
|
-
*/
|
|
823
|
-
queueBodyUpdate(doc_name, content) {
|
|
824
|
-
const ptr0 = passStringToWasm0(doc_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
825
|
-
const len0 = WASM_VECTOR_LEN;
|
|
826
|
-
const ptr1 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
827
|
-
const len1 = WASM_VECTOR_LEN;
|
|
828
|
-
const ret = wasm.wasmsyncclient_queueBodyUpdate(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
829
|
-
if (ret[1]) {
|
|
830
|
-
throw takeFromExternrefTable0(ret[0]);
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
/**
|
|
834
|
-
* Queue a workspace update message for sending.
|
|
835
|
-
*
|
|
836
|
-
* This creates a Y-sync Update message from the current workspace state
|
|
837
|
-
* and queues it for sending via the metadata WebSocket.
|
|
545
|
+
* Returns a string if there's a message to send, null otherwise.
|
|
546
|
+
* @returns {string | undefined}
|
|
838
547
|
*/
|
|
839
|
-
|
|
840
|
-
const ret = wasm.
|
|
841
|
-
|
|
842
|
-
|
|
548
|
+
pollOutgoingText() {
|
|
549
|
+
const ret = wasm.wasmsyncclient_pollOutgoingText(this.__wbg_ptr);
|
|
550
|
+
let v1;
|
|
551
|
+
if (ret[0] !== 0) {
|
|
552
|
+
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
553
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
843
554
|
}
|
|
555
|
+
return v1;
|
|
844
556
|
}
|
|
845
557
|
/**
|
|
846
|
-
*
|
|
558
|
+
* Queue a local CRDT update for sending to the server.
|
|
847
559
|
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
*
|
|
851
|
-
* Returns a Promise that resolves when initial sync messages are sent.
|
|
560
|
+
* Call this when local CRDT changes need to be synced.
|
|
561
|
+
* @param {string} doc_id
|
|
562
|
+
* @param {Uint8Array} data
|
|
852
563
|
* @returns {Promise<any>}
|
|
853
564
|
*/
|
|
854
|
-
|
|
855
|
-
const
|
|
856
|
-
return ret;
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* Stop the sync session.
|
|
860
|
-
*
|
|
861
|
-
* Clears all pending messages and resets state.
|
|
862
|
-
*/
|
|
863
|
-
stop() {
|
|
864
|
-
wasm.wasmsyncclient_stop(this.__wbg_ptr);
|
|
865
|
-
}
|
|
866
|
-
/**
|
|
867
|
-
* Subscribe to body sync for the currently focused files.
|
|
868
|
-
*
|
|
869
|
-
* This sends SyncStep1 messages for all files in the provided list.
|
|
870
|
-
* Call this after receiving a `focus_list_changed` message from the server.
|
|
871
|
-
*
|
|
872
|
-
* ## Example
|
|
873
|
-
* ```javascript
|
|
874
|
-
* // Received focus_list_changed event
|
|
875
|
-
* const files = event.files;
|
|
876
|
-
* client.subscribeBodies(files);
|
|
877
|
-
* ```
|
|
878
|
-
* @param {string[]} files
|
|
879
|
-
*/
|
|
880
|
-
subscribeBodies(files) {
|
|
881
|
-
const ptr0 = passArrayJsValueToWasm0(files, wasm.__wbindgen_malloc);
|
|
565
|
+
queueLocalUpdate(doc_id, data) {
|
|
566
|
+
const ptr0 = passStringToWasm0(doc_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
882
567
|
const len0 = WASM_VECTOR_LEN;
|
|
883
|
-
|
|
568
|
+
const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
569
|
+
const len1 = WASM_VECTOR_LEN;
|
|
570
|
+
const ret = wasm.wasmsyncclient_queueLocalUpdate(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
571
|
+
return ret;
|
|
884
572
|
}
|
|
885
573
|
/**
|
|
886
|
-
*
|
|
574
|
+
* Set a share session code.
|
|
887
575
|
*
|
|
888
|
-
*
|
|
889
|
-
*
|
|
890
|
-
* @param {string} doc_name
|
|
576
|
+
* Call this before connecting to join a share session.
|
|
577
|
+
* @param {string} code
|
|
891
578
|
*/
|
|
892
|
-
|
|
893
|
-
const ptr0 = passStringToWasm0(
|
|
579
|
+
setSessionCode(code) {
|
|
580
|
+
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
894
581
|
const len0 = WASM_VECTOR_LEN;
|
|
895
|
-
wasm.
|
|
582
|
+
wasm.wasmsyncclient_setSessionCode(this.__wbg_ptr, ptr0, len0);
|
|
896
583
|
}
|
|
897
584
|
/**
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
* Sends an unfocus message to the server indicating the client is no
|
|
901
|
-
* longer interested in syncing these files.
|
|
902
|
-
*
|
|
903
|
-
* Call this when a file is closed in the editor.
|
|
904
|
-
*
|
|
905
|
-
* ## Example
|
|
906
|
-
* ```javascript
|
|
907
|
-
* // User closes a file
|
|
908
|
-
* client.unfocusFiles(["workspace/notes.md"]);
|
|
909
|
-
* ```
|
|
585
|
+
* Send an unfocus message for specific files.
|
|
910
586
|
* @param {string[]} files
|
|
911
587
|
*/
|
|
912
588
|
unfocusFiles(files) {
|
|
@@ -1186,7 +862,7 @@ function __wbg_get_imports() {
|
|
|
1186
862
|
const a = state0.a;
|
|
1187
863
|
state0.a = 0;
|
|
1188
864
|
try {
|
|
1189
|
-
return
|
|
865
|
+
return wasm_bindgen__convert__closures_____invoke__h4e796b59e8c15a06(a, state0.b, arg0, arg1);
|
|
1190
866
|
} finally {
|
|
1191
867
|
state0.a = a;
|
|
1192
868
|
}
|
|
@@ -1265,10 +941,6 @@ function __wbg_get_imports() {
|
|
|
1265
941
|
__wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
|
|
1266
942
|
arg0[arg1] = arg2;
|
|
1267
943
|
},
|
|
1268
|
-
__wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
|
|
1269
|
-
const ret = Reflect.set(arg0, arg1, arg2);
|
|
1270
|
-
return ret;
|
|
1271
|
-
}, arguments); },
|
|
1272
944
|
__wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
|
|
1273
945
|
arg0[arg1 >>> 0] = arg2;
|
|
1274
946
|
},
|
|
@@ -1312,8 +984,8 @@ function __wbg_get_imports() {
|
|
|
1312
984
|
console.warn(arg0, arg1, arg2, arg3);
|
|
1313
985
|
},
|
|
1314
986
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
1315
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1316
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
987
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 594, function: Function { arguments: [Externref], shim_idx: 595, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
988
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h676385b1ad3ac0e9, wasm_bindgen__convert__closures_____invoke__he720d3228b6c7e0b);
|
|
1317
989
|
return ret;
|
|
1318
990
|
},
|
|
1319
991
|
__wbindgen_cast_0000000000000002: function(arg0) {
|
|
@@ -1357,12 +1029,12 @@ function __wbg_get_imports() {
|
|
|
1357
1029
|
};
|
|
1358
1030
|
}
|
|
1359
1031
|
|
|
1360
|
-
function
|
|
1361
|
-
wasm.
|
|
1032
|
+
function wasm_bindgen__convert__closures_____invoke__he720d3228b6c7e0b(arg0, arg1, arg2) {
|
|
1033
|
+
wasm.wasm_bindgen__convert__closures_____invoke__he720d3228b6c7e0b(arg0, arg1, arg2);
|
|
1362
1034
|
}
|
|
1363
1035
|
|
|
1364
|
-
function
|
|
1365
|
-
wasm.
|
|
1036
|
+
function wasm_bindgen__convert__closures_____invoke__h4e796b59e8c15a06(arg0, arg1, arg2, arg3) {
|
|
1037
|
+
wasm.wasm_bindgen__convert__closures_____invoke__h4e796b59e8c15a06(arg0, arg1, arg2, arg3);
|
|
1366
1038
|
}
|
|
1367
1039
|
|
|
1368
1040
|
const DiaryxBackendFinalization = (typeof FinalizationRegistry === 'undefined')
|