wasm-ripple 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/wasm_ripple.js ADDED
@@ -0,0 +1,1039 @@
1
+ let wasm;
2
+
3
+ function addHeapObject(obj) {
4
+ if (heap_next === heap.length) heap.push(heap.length + 1);
5
+ const idx = heap_next;
6
+ heap_next = heap[idx];
7
+
8
+ heap[idx] = obj;
9
+ return idx;
10
+ }
11
+
12
+ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
13
+ ? { register: () => {}, unregister: () => {} }
14
+ : new FinalizationRegistry(state => state.dtor(state.a, state.b));
15
+
16
+ function dropObject(idx) {
17
+ if (idx < 132) return;
18
+ heap[idx] = heap_next;
19
+ heap_next = idx;
20
+ }
21
+
22
+ let cachedDataViewMemory0 = null;
23
+ function getDataViewMemory0() {
24
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
25
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
26
+ }
27
+ return cachedDataViewMemory0;
28
+ }
29
+
30
+ function getStringFromWasm0(ptr, len) {
31
+ ptr = ptr >>> 0;
32
+ return decodeText(ptr, len);
33
+ }
34
+
35
+ let cachedUint8ArrayMemory0 = null;
36
+ function getUint8ArrayMemory0() {
37
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
38
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
39
+ }
40
+ return cachedUint8ArrayMemory0;
41
+ }
42
+
43
+ function getObject(idx) { return heap[idx]; }
44
+
45
+ function handleError(f, args) {
46
+ try {
47
+ return f.apply(this, args);
48
+ } catch (e) {
49
+ wasm.__wbindgen_export3(addHeapObject(e));
50
+ }
51
+ }
52
+
53
+ let heap = new Array(128).fill(undefined);
54
+ heap.push(undefined, null, true, false);
55
+
56
+ let heap_next = heap.length;
57
+
58
+ function isLikeNone(x) {
59
+ return x === undefined || x === null;
60
+ }
61
+
62
+ function makeMutClosure(arg0, arg1, dtor, f) {
63
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
64
+ const real = (...args) => {
65
+
66
+ // First up with a closure we increment the internal reference
67
+ // count. This ensures that the Rust closure environment won't
68
+ // be deallocated while we're invoking it.
69
+ state.cnt++;
70
+ const a = state.a;
71
+ state.a = 0;
72
+ try {
73
+ return f(a, state.b, ...args);
74
+ } finally {
75
+ state.a = a;
76
+ real._wbg_cb_unref();
77
+ }
78
+ };
79
+ real._wbg_cb_unref = () => {
80
+ if (--state.cnt === 0) {
81
+ state.dtor(state.a, state.b);
82
+ state.a = 0;
83
+ CLOSURE_DTORS.unregister(state);
84
+ }
85
+ };
86
+ CLOSURE_DTORS.register(real, state, state);
87
+ return real;
88
+ }
89
+
90
+ function passStringToWasm0(arg, malloc, realloc) {
91
+ if (realloc === undefined) {
92
+ const buf = cachedTextEncoder.encode(arg);
93
+ const ptr = malloc(buf.length, 1) >>> 0;
94
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
95
+ WASM_VECTOR_LEN = buf.length;
96
+ return ptr;
97
+ }
98
+
99
+ let len = arg.length;
100
+ let ptr = malloc(len, 1) >>> 0;
101
+
102
+ const mem = getUint8ArrayMemory0();
103
+
104
+ let offset = 0;
105
+
106
+ for (; offset < len; offset++) {
107
+ const code = arg.charCodeAt(offset);
108
+ if (code > 0x7F) break;
109
+ mem[ptr + offset] = code;
110
+ }
111
+ if (offset !== len) {
112
+ if (offset !== 0) {
113
+ arg = arg.slice(offset);
114
+ }
115
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
116
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
117
+ const ret = cachedTextEncoder.encodeInto(arg, view);
118
+
119
+ offset += ret.written;
120
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
121
+ }
122
+
123
+ WASM_VECTOR_LEN = offset;
124
+ return ptr;
125
+ }
126
+
127
+ function takeObject(idx) {
128
+ const ret = getObject(idx);
129
+ dropObject(idx);
130
+ return ret;
131
+ }
132
+
133
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
134
+ cachedTextDecoder.decode();
135
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
136
+ let numBytesDecoded = 0;
137
+ function decodeText(ptr, len) {
138
+ numBytesDecoded += len;
139
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
140
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
141
+ cachedTextDecoder.decode();
142
+ numBytesDecoded = len;
143
+ }
144
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
145
+ }
146
+
147
+ const cachedTextEncoder = new TextEncoder();
148
+
149
+ if (!('encodeInto' in cachedTextEncoder)) {
150
+ cachedTextEncoder.encodeInto = function (arg, view) {
151
+ const buf = cachedTextEncoder.encode(arg);
152
+ view.set(buf);
153
+ return {
154
+ read: arg.length,
155
+ written: buf.length
156
+ };
157
+ }
158
+ }
159
+
160
+ let WASM_VECTOR_LEN = 0;
161
+
162
+ function __wasm_bindgen_func_elem_144(arg0, arg1, arg2) {
163
+ wasm.__wasm_bindgen_func_elem_144(arg0, arg1, addHeapObject(arg2));
164
+ }
165
+
166
+ function __wasm_bindgen_func_elem_528(arg0, arg1, arg2, arg3) {
167
+ wasm.__wasm_bindgen_func_elem_528(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
168
+ }
169
+
170
+ const MessageQueueFinalization = (typeof FinalizationRegistry === 'undefined')
171
+ ? { register: () => {}, unregister: () => {} }
172
+ : new FinalizationRegistry(ptr => wasm.__wbg_messagequeue_free(ptr >>> 0, 1));
173
+
174
+ /**
175
+ * A WebAssembly-based message queue with support for:
176
+ * - Topic-based pub/sub messaging
177
+ * - Cross-tab communication via BroadcastChannel
178
+ * - Synchronous and asynchronous publishing
179
+ * - Zero-copy message passing (using JsValue)
180
+ */
181
+ export class MessageQueue {
182
+ __destroy_into_raw() {
183
+ const ptr = this.__wbg_ptr;
184
+ this.__wbg_ptr = 0;
185
+ MessageQueueFinalization.unregister(this);
186
+ return ptr;
187
+ }
188
+ free() {
189
+ const ptr = this.__destroy_into_raw();
190
+ wasm.__wbg_messagequeue_free(ptr, 0);
191
+ }
192
+ /**
193
+ * Check if a topic has buffering enabled
194
+ * @param topic_id - ID of the topic
195
+ * @param {number} topic_id
196
+ * @returns {boolean}
197
+ */
198
+ has_buffer(topic_id) {
199
+ const ret = wasm.messagequeue_has_buffer(this.__wbg_ptr, topic_id);
200
+ return ret !== 0;
201
+ }
202
+ /**
203
+ * Get the number of topics
204
+ * @returns {number}
205
+ */
206
+ topic_count() {
207
+ const ret = wasm.messagequeue_topic_count(this.__wbg_ptr);
208
+ return ret >>> 0;
209
+ }
210
+ /**
211
+ * Unsubscribe from a topic using its ID
212
+ * @param {number} topic_id
213
+ * @param {number} sub_id
214
+ * @returns {boolean}
215
+ */
216
+ unsubscribe(topic_id, sub_id) {
217
+ const ret = wasm.messagequeue_unsubscribe(this.__wbg_ptr, topic_id, sub_id);
218
+ return ret !== 0;
219
+ }
220
+ /**
221
+ * Clear all buffered messages for a topic
222
+ * @param topic_id - ID of the topic
223
+ * @returns Number of messages cleared
224
+ * @param {number} topic_id
225
+ * @returns {number}
226
+ */
227
+ clear_buffer(topic_id) {
228
+ const ret = wasm.messagequeue_clear_buffer(this.__wbg_ptr, topic_id);
229
+ return ret >>> 0;
230
+ }
231
+ /**
232
+ * @param {string} topic_name
233
+ * @returns {boolean}
234
+ */
235
+ create_topic(topic_name) {
236
+ const ptr0 = passStringToWasm0(topic_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
237
+ const len0 = WASM_VECTOR_LEN;
238
+ const ret = wasm.messagequeue_create_topic(this.__wbg_ptr, ptr0, len0);
239
+ return ret !== 0;
240
+ }
241
+ /**
242
+ * @param {number} topic_id
243
+ * @returns {boolean}
244
+ */
245
+ destroy_topic(topic_id) {
246
+ const ret = wasm.messagequeue_destroy_topic(this.__wbg_ptr, topic_id);
247
+ return ret !== 0;
248
+ }
249
+ /**
250
+ * @returns {string}
251
+ */
252
+ get_client_id() {
253
+ let deferred1_0;
254
+ let deferred1_1;
255
+ try {
256
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
257
+ wasm.messagequeue_get_client_id(retptr, this.__wbg_ptr);
258
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
259
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
260
+ deferred1_0 = r0;
261
+ deferred1_1 = r1;
262
+ return getStringFromWasm0(r0, r1);
263
+ } finally {
264
+ wasm.__wbindgen_add_to_stack_pointer(16);
265
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
266
+ }
267
+ }
268
+ /**
269
+ * Publish a message asynchronously using Promise/microtask
270
+ * This returns immediately and delivers the message in the next microtask
271
+ * Useful for non-blocking operations and better browser responsiveness
272
+ * @param {number} topic_id
273
+ * @param {any} payload
274
+ * @returns {Promise<any>}
275
+ */
276
+ publish_async(topic_id, payload) {
277
+ try {
278
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
279
+ wasm.messagequeue_publish_async(retptr, this.__wbg_ptr, topic_id, addHeapObject(payload));
280
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
281
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
282
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
283
+ if (r2) {
284
+ throw takeObject(r1);
285
+ }
286
+ return takeObject(r0);
287
+ } finally {
288
+ wasm.__wbindgen_add_to_stack_pointer(16);
289
+ }
290
+ }
291
+ /**
292
+ * Register a topic and get its ID (handle) for fast publishing
293
+ * Returns the topic ID that can be used with publish_by_id
294
+ * @param {string} topic_name
295
+ * @returns {number}
296
+ */
297
+ register_topic(topic_name) {
298
+ const ptr0 = passStringToWasm0(topic_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
299
+ const len0 = WASM_VECTOR_LEN;
300
+ const ret = wasm.messagequeue_register_topic(this.__wbg_ptr, ptr0, len0);
301
+ return ret >>> 0;
302
+ }
303
+ /**
304
+ * Get the current size of the message buffer for a topic
305
+ * @param topic_id - ID of the topic
306
+ * @returns Number of messages currently buffered, or -1 if buffering is not enabled
307
+ * @param {number} topic_id
308
+ * @returns {number}
309
+ */
310
+ get_buffer_size(topic_id) {
311
+ const ret = wasm.messagequeue_get_buffer_size(this.__wbg_ptr, topic_id);
312
+ return ret;
313
+ }
314
+ /**
315
+ * Unsubscribe all subscribers from a topic
316
+ * @param {number} topic_id
317
+ * @returns {number}
318
+ */
319
+ unsubscribe_all(topic_id) {
320
+ const ret = wasm.messagequeue_unsubscribe_all(this.__wbg_ptr, topic_id);
321
+ return ret >>> 0;
322
+ }
323
+ /**
324
+ * Get the number of subscribers for a specific topic
325
+ * @param {number} topic_id
326
+ * @returns {number}
327
+ */
328
+ subscriber_count(topic_id) {
329
+ const ret = wasm.messagequeue_subscriber_count(this.__wbg_ptr, topic_id);
330
+ return ret >>> 0;
331
+ }
332
+ /**
333
+ * Enable message buffering for a specific topic
334
+ * Messages will be cached in a ring buffer for later retrieval
335
+ * @param topic_id - ID of the topic
336
+ * @param capacity - Maximum number of messages to buffer (default: 100)
337
+ * @param {number} topic_id
338
+ * @param {number | null} [capacity]
339
+ */
340
+ enable_topic_buffer(topic_id, capacity) {
341
+ try {
342
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
343
+ wasm.messagequeue_enable_topic_buffer(retptr, this.__wbg_ptr, topic_id, isLikeNone(capacity) ? 0x100000001 : (capacity) >>> 0);
344
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
345
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
346
+ if (r1) {
347
+ throw takeObject(r0);
348
+ }
349
+ } finally {
350
+ wasm.__wbindgen_add_to_stack_pointer(16);
351
+ }
352
+ }
353
+ /**
354
+ * Get the buffer capacity for a topic
355
+ * @param topic_id - ID of the topic
356
+ * @returns Maximum buffer capacity, or 0 if buffering is not enabled
357
+ * @param {number} topic_id
358
+ * @returns {number}
359
+ */
360
+ get_buffer_capacity(topic_id) {
361
+ const ret = wasm.messagequeue_get_buffer_capacity(this.__wbg_ptr, topic_id);
362
+ return ret >>> 0;
363
+ }
364
+ /**
365
+ * Publish multiple messages by ID (handle) efficiently
366
+ * This is the fastest way to publish multiple messages
367
+ * @param {number} topic_id
368
+ * @param {Array<any>} payloads
369
+ */
370
+ publish_batch_by_id(topic_id, payloads) {
371
+ try {
372
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
373
+ wasm.messagequeue_publish_batch_by_id(retptr, this.__wbg_ptr, topic_id, addHeapObject(payloads));
374
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
375
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
376
+ if (r1) {
377
+ throw takeObject(r0);
378
+ }
379
+ } finally {
380
+ wasm.__wbindgen_add_to_stack_pointer(16);
381
+ }
382
+ }
383
+ /**
384
+ * Disable message buffering for a specific topic
385
+ * Clears all buffered messages
386
+ * @param topic_id - ID of the topic
387
+ * @param {number} topic_id
388
+ */
389
+ disable_topic_buffer(topic_id) {
390
+ try {
391
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
392
+ wasm.messagequeue_disable_topic_buffer(retptr, this.__wbg_ptr, topic_id);
393
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
394
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
395
+ if (r1) {
396
+ throw takeObject(r0);
397
+ }
398
+ } finally {
399
+ wasm.__wbindgen_add_to_stack_pointer(16);
400
+ }
401
+ }
402
+ /**
403
+ * Get buffered messages for a topic as a JavaScript array
404
+ * @param topic_id - ID of the topic
405
+ * @returns Array of buffered messages (oldest first), or empty array if no buffer
406
+ * @param {number} topic_id
407
+ * @returns {Array<any>}
408
+ */
409
+ get_buffered_messages(topic_id) {
410
+ try {
411
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
412
+ wasm.messagequeue_get_buffered_messages(retptr, this.__wbg_ptr, topic_id);
413
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
414
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
415
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
416
+ if (r2) {
417
+ throw takeObject(r1);
418
+ }
419
+ return takeObject(r0);
420
+ } finally {
421
+ wasm.__wbindgen_add_to_stack_pointer(16);
422
+ }
423
+ }
424
+ /**
425
+ * @param {string | null} [channel_name]
426
+ */
427
+ constructor(channel_name) {
428
+ try {
429
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
430
+ var ptr0 = isLikeNone(channel_name) ? 0 : passStringToWasm0(channel_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
431
+ var len0 = WASM_VECTOR_LEN;
432
+ wasm.messagequeue_new(retptr, ptr0, len0);
433
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
434
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
435
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
436
+ if (r2) {
437
+ throw takeObject(r1);
438
+ }
439
+ this.__wbg_ptr = r0 >>> 0;
440
+ MessageQueueFinalization.register(this, this.__wbg_ptr, this);
441
+ return this;
442
+ } finally {
443
+ wasm.__wbindgen_add_to_stack_pointer(16);
444
+ }
445
+ }
446
+ close() {
447
+ try {
448
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
449
+ wasm.messagequeue_close(retptr, this.__wbg_ptr);
450
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
451
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
452
+ if (r1) {
453
+ throw takeObject(r0);
454
+ }
455
+ } finally {
456
+ wasm.__wbindgen_add_to_stack_pointer(16);
457
+ }
458
+ }
459
+ /**
460
+ * Publish using a topic ID (handle)
461
+ * This is O(1) and avoids string hashing/copying - significantly faster for high frequency
462
+ * @param {number} topic_id
463
+ * @param {any} payload
464
+ */
465
+ publish(topic_id, payload) {
466
+ try {
467
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
468
+ wasm.messagequeue_publish(retptr, this.__wbg_ptr, topic_id, addHeapObject(payload));
469
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
470
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
471
+ if (r1) {
472
+ throw takeObject(r0);
473
+ }
474
+ } finally {
475
+ wasm.__wbindgen_add_to_stack_pointer(16);
476
+ }
477
+ }
478
+ /**
479
+ * Check if a topic exists
480
+ * @param {number} topic_id
481
+ * @returns {boolean}
482
+ */
483
+ has_topic(topic_id) {
484
+ const ret = wasm.messagequeue_has_topic(this.__wbg_ptr, topic_id);
485
+ return ret !== 0;
486
+ }
487
+ /**
488
+ * Subscribe to a topic using its ID
489
+ * Callback signature: (payload, topic_id, timestamp, message_id)
490
+ * @param {number} topic_id
491
+ * @param {Function} callback
492
+ * @returns {number}
493
+ */
494
+ subscribe(topic_id, callback) {
495
+ try {
496
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
497
+ wasm.messagequeue_subscribe(retptr, this.__wbg_ptr, topic_id, addHeapObject(callback));
498
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
499
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
500
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
501
+ if (r2) {
502
+ throw takeObject(r1);
503
+ }
504
+ return r0 >>> 0;
505
+ } finally {
506
+ wasm.__wbindgen_add_to_stack_pointer(16);
507
+ }
508
+ }
509
+ }
510
+ if (Symbol.dispose) MessageQueue.prototype[Symbol.dispose] = MessageQueue.prototype.free;
511
+
512
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
513
+
514
+ async function __wbg_load(module, imports) {
515
+ if (typeof Response === 'function' && module instanceof Response) {
516
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
517
+ try {
518
+ return await WebAssembly.instantiateStreaming(module, imports);
519
+ } catch (e) {
520
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
521
+
522
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
523
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
524
+
525
+ } else {
526
+ throw e;
527
+ }
528
+ }
529
+ }
530
+
531
+ const bytes = await module.arrayBuffer();
532
+ return await WebAssembly.instantiate(bytes, imports);
533
+ } else {
534
+ const instance = await WebAssembly.instantiate(module, imports);
535
+
536
+ if (instance instanceof WebAssembly.Instance) {
537
+ return { instance, module };
538
+ } else {
539
+ return instance;
540
+ }
541
+ }
542
+ }
543
+
544
+ function __wbg_get_imports() {
545
+ const imports = {};
546
+ imports.wbg = {};
547
+ imports.wbg.__wbg___wbindgen_is_null_dfda7d66506c95b5 = function(arg0) {
548
+ const ret = getObject(arg0) === null;
549
+ return ret;
550
+ };
551
+ imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) {
552
+ const val = getObject(arg0);
553
+ const ret = typeof(val) === 'object' && val !== null;
554
+ return ret;
555
+ };
556
+ imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
557
+ const ret = getObject(arg0) === undefined;
558
+ return ret;
559
+ };
560
+ imports.wbg.__wbg___wbindgen_number_get_9619185a74197f95 = function(arg0, arg1) {
561
+ const obj = getObject(arg1);
562
+ const ret = typeof(obj) === 'number' ? obj : undefined;
563
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
564
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
565
+ };
566
+ imports.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42 = function(arg0, arg1) {
567
+ const obj = getObject(arg1);
568
+ const ret = typeof(obj) === 'string' ? obj : undefined;
569
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
570
+ var len1 = WASM_VECTOR_LEN;
571
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
572
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
573
+ };
574
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
575
+ throw new Error(getStringFromWasm0(arg0, arg1));
576
+ };
577
+ imports.wbg.__wbg__wbg_cb_unref_87dfb5aaa0cbcea7 = function(arg0) {
578
+ getObject(arg0)._wbg_cb_unref();
579
+ };
580
+ imports.wbg.__wbg_call_3020136f7a2d6e44 = function() { return handleError(function (arg0, arg1, arg2) {
581
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
582
+ return addHeapObject(ret);
583
+ }, arguments) };
584
+ imports.wbg.__wbg_call_760a3f0ff6ecdb31 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
585
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3), getObject(arg4), getObject(arg5), getObject(arg6));
586
+ return addHeapObject(ret);
587
+ }, arguments) };
588
+ imports.wbg.__wbg_call_985cbf350d9ec0e5 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
589
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3), getObject(arg4), getObject(arg5));
590
+ return addHeapObject(ret);
591
+ }, arguments) };
592
+ imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) {
593
+ const ret = getObject(arg0).call(getObject(arg1));
594
+ return addHeapObject(ret);
595
+ }, arguments) };
596
+ imports.wbg.__wbg_close_c956ddbf0426a990 = function(arg0) {
597
+ getObject(arg0).close();
598
+ };
599
+ imports.wbg.__wbg_crypto_59726e04573101a0 = function() { return handleError(function (arg0) {
600
+ const ret = getObject(arg0).crypto;
601
+ return addHeapObject(ret);
602
+ }, arguments) };
603
+ imports.wbg.__wbg_data_8bf4ae669a78a688 = function(arg0) {
604
+ const ret = getObject(arg0).data;
605
+ return addHeapObject(ret);
606
+ };
607
+ imports.wbg.__wbg_from_29a8414a7a7cd19d = function(arg0) {
608
+ const ret = Array.from(getObject(arg0));
609
+ return addHeapObject(ret);
610
+ };
611
+ imports.wbg.__wbg_get_6b7bd52aca3f9671 = function(arg0, arg1) {
612
+ const ret = getObject(arg0)[arg1 >>> 0];
613
+ return addHeapObject(ret);
614
+ };
615
+ imports.wbg.__wbg_instanceof_Window_b5cf7783caa68180 = function(arg0) {
616
+ let result;
617
+ try {
618
+ result = getObject(arg0) instanceof Window;
619
+ } catch (_) {
620
+ result = false;
621
+ }
622
+ const ret = result;
623
+ return ret;
624
+ };
625
+ imports.wbg.__wbg_isArray_ca6bc609f742df3f = function(arg0) {
626
+ const ret = Array.isArray(getObject(arg0));
627
+ return ret;
628
+ };
629
+ imports.wbg.__wbg_length_d45040a40c570362 = function(arg0) {
630
+ const ret = getObject(arg0).length;
631
+ return ret;
632
+ };
633
+ imports.wbg.__wbg_new_25f239778d6112b9 = function() {
634
+ const ret = new Array();
635
+ return addHeapObject(ret);
636
+ };
637
+ imports.wbg.__wbg_new_b3dd747604c3c93e = function() { return handleError(function (arg0, arg1) {
638
+ const ret = new BroadcastChannel(getStringFromWasm0(arg0, arg1));
639
+ return addHeapObject(ret);
640
+ }, arguments) };
641
+ imports.wbg.__wbg_new_ff12d2b041fb48f1 = function(arg0, arg1) {
642
+ try {
643
+ var state0 = {a: arg0, b: arg1};
644
+ var cb0 = (arg0, arg1) => {
645
+ const a = state0.a;
646
+ state0.a = 0;
647
+ try {
648
+ return __wasm_bindgen_func_elem_528(a, state0.b, arg0, arg1);
649
+ } finally {
650
+ state0.a = a;
651
+ }
652
+ };
653
+ const ret = new Promise(cb0);
654
+ return addHeapObject(ret);
655
+ } finally {
656
+ state0.a = state0.b = 0;
657
+ }
658
+ };
659
+ imports.wbg.__wbg_new_no_args_cb138f77cf6151ee = function(arg0, arg1) {
660
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
661
+ return addHeapObject(ret);
662
+ };
663
+ imports.wbg.__wbg_new_with_args_df9e7125ffe55248 = function(arg0, arg1, arg2, arg3) {
664
+ const ret = new Function(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
665
+ return addHeapObject(ret);
666
+ };
667
+ imports.wbg.__wbg_now_69d776cd24f5215b = function() {
668
+ const ret = Date.now();
669
+ return ret;
670
+ };
671
+ imports.wbg.__wbg_postMessage_ee7b4e76cd1ed685 = function() { return handleError(function (arg0, arg1) {
672
+ getObject(arg0).postMessage(getObject(arg1));
673
+ }, arguments) };
674
+ imports.wbg.__wbg_push_7d9be8f38fc13975 = function(arg0, arg1) {
675
+ const ret = getObject(arg0).push(getObject(arg1));
676
+ return ret;
677
+ };
678
+ imports.wbg.__wbg_randomUUID_9f549a1cc1e2b0bf = function(arg0, arg1) {
679
+ const ret = getObject(arg1).randomUUID();
680
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
681
+ const len1 = WASM_VECTOR_LEN;
682
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
683
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
684
+ };
685
+ imports.wbg.__wbg_random_cc1f9237d866d212 = function() {
686
+ const ret = Math.random();
687
+ return ret;
688
+ };
689
+ imports.wbg.__wbg_resolve_fd5bfbaa4ce36e1e = function(arg0) {
690
+ const ret = Promise.resolve(getObject(arg0));
691
+ return addHeapObject(ret);
692
+ };
693
+ imports.wbg.__wbg_set_onmessage_6fa00f5d8f1c055a = function(arg0, arg1) {
694
+ getObject(arg0).onmessage = getObject(arg1);
695
+ };
696
+ imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
697
+ const ret = typeof global === 'undefined' ? null : global;
698
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
699
+ };
700
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1 = function() {
701
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
702
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
703
+ };
704
+ imports.wbg.__wbg_static_accessor_SELF_08f5a74c69739274 = function() {
705
+ const ret = typeof self === 'undefined' ? null : self;
706
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
707
+ };
708
+ imports.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024 = function() {
709
+ const ret = typeof window === 'undefined' ? null : window;
710
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
711
+ };
712
+ imports.wbg.__wbg_then_4f95312d68691235 = function(arg0, arg1) {
713
+ const ret = getObject(arg0).then(getObject(arg1));
714
+ return addHeapObject(ret);
715
+ };
716
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
717
+ // Cast intrinsic for `Ref(String) -> Externref`.
718
+ const ret = getStringFromWasm0(arg0, arg1);
719
+ return addHeapObject(ret);
720
+ };
721
+ imports.wbg.__wbindgen_cast_32bc49bfb4050e32 = function(arg0, arg1) {
722
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 1, function: Function { arguments: [Externref], shim_idx: 2, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
723
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_43, __wasm_bindgen_func_elem_144);
724
+ return addHeapObject(ret);
725
+ };
726
+ imports.wbg.__wbindgen_cast_46d6ccd6e2a13afa = function(arg0, arg1) {
727
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 1, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 2, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
728
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_43, __wasm_bindgen_func_elem_144);
729
+ return addHeapObject(ret);
730
+ };
731
+ imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
732
+ // Cast intrinsic for `F64 -> Externref`.
733
+ const ret = arg0;
734
+ return addHeapObject(ret);
735
+ };
736
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
737
+ const ret = getObject(arg0);
738
+ return addHeapObject(ret);
739
+ };
740
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
741
+ takeObject(arg0);
742
+ };
743
+
744
+ return imports;
745
+ }
746
+
747
+ function __wbg_finalize_init(instance, module) {
748
+ wasm = instance.exports;
749
+ __wbg_init.__wbindgen_wasm_module = module;
750
+ cachedDataViewMemory0 = null;
751
+ cachedUint8ArrayMemory0 = null;
752
+
753
+
754
+
755
+ return wasm;
756
+ }
757
+
758
+ function initSync(module) {
759
+ if (wasm !== undefined) return wasm;
760
+
761
+
762
+ if (typeof module !== 'undefined') {
763
+ if (Object.getPrototypeOf(module) === Object.prototype) {
764
+ ({module} = module)
765
+ } else {
766
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
767
+ }
768
+ }
769
+
770
+ const imports = __wbg_get_imports();
771
+ if (!(module instanceof WebAssembly.Module)) {
772
+ module = new WebAssembly.Module(module);
773
+ }
774
+ const instance = new WebAssembly.Instance(module, imports);
775
+ return __wbg_finalize_init(instance, module);
776
+ }
777
+
778
+ async function __wbg_init(module_or_path) {
779
+ if (wasm !== undefined) return wasm;
780
+
781
+
782
+ if (typeof module_or_path !== 'undefined') {
783
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
784
+ ({module_or_path} = module_or_path)
785
+ } else {
786
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
787
+ }
788
+ }
789
+
790
+ if (typeof module_or_path === 'undefined') {
791
+ module_or_path = new URL('wasm_ripple_bg.wasm', import.meta.url);
792
+ }
793
+ const imports = __wbg_get_imports();
794
+
795
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
796
+ module_or_path = fetch(module_or_path);
797
+ }
798
+
799
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
800
+
801
+ return __wbg_finalize_init(instance, module);
802
+ }
803
+
804
+
805
+ /**
806
+ * A lightweight Stream implementation for fluent message processing
807
+ */
808
+ export class Stream {
809
+ constructor(subscribeFn) {
810
+ this._subscribe = subscribeFn;
811
+ }
812
+
813
+ /**
814
+ * Subscribe to the stream
815
+ * @param {Function} callback
816
+ * @returns {{ unsubscribe: Function }} Subscription object
817
+ */
818
+ subscribe(callback) {
819
+ const unsubscribeFn = this._subscribe(callback);
820
+ return { unsubscribe: unsubscribeFn };
821
+ }
822
+
823
+ /**
824
+ * Transform values in the stream
825
+ * @param {Function} transform - (value) => newValue
826
+ * @returns {Stream}
827
+ */
828
+ map(transform) {
829
+ return new Stream(next => {
830
+ return this._subscribe((payload, ...args) => {
831
+ next(transform(payload), ...args);
832
+ });
833
+ });
834
+ }
835
+
836
+ /**
837
+ * Filter values in the stream
838
+ * @param {Function} predicate - (value) => boolean
839
+ * @returns {Stream}
840
+ */
841
+ filter(predicate) {
842
+ return new Stream(next => {
843
+ return this._subscribe((payload, ...args) => {
844
+ if (predicate(payload)) next(payload, ...args);
845
+ });
846
+ });
847
+ }
848
+
849
+ /**
850
+ * Perform side-effect without changing the value
851
+ * @param {Function} effect - (value) => void
852
+ * @returns {Stream}
853
+ */
854
+ tap(effect) {
855
+ return new Stream(next => {
856
+ return this._subscribe((payload, ...args) => {
857
+ effect(payload);
858
+ next(payload, ...args);
859
+ });
860
+ });
861
+ }
862
+
863
+ /**
864
+ * Debounce values by a specified time
865
+ * @param {number} ms - milliseconds
866
+ * @returns {Stream}
867
+ */
868
+ debounce(ms) {
869
+ return new Stream(next => {
870
+ let timeout;
871
+ const cleanup = this._subscribe((payload, ...args) => {
872
+ clearTimeout(timeout);
873
+ timeout = setTimeout(() => next(payload, ...args), ms);
874
+ });
875
+ return () => {
876
+ clearTimeout(timeout);
877
+ cleanup();
878
+ };
879
+ });
880
+ }
881
+ }
882
+
883
+
884
+ /**
885
+ * A wrapper class for topic operations
886
+ */
887
+ export class Topic {
888
+ constructor(mq, name, id) {
889
+ this.mq = mq;
890
+ this.name = name;
891
+ this.id = id;
892
+ }
893
+
894
+ /**
895
+ * Create a Stream from this topic for fluent processing
896
+ * @returns {Stream}
897
+ */
898
+ stream() {
899
+ return new Stream(callback => {
900
+ const subId = this.subscribe(callback);
901
+ return () => this.unsubscribe(subId);
902
+ });
903
+ }
904
+
905
+ /**
906
+ * Publish a message to this topic
907
+ * @param {any} payload
908
+ */
909
+ publish(payload) {
910
+ this.mq.publish(this.id, payload);
911
+ }
912
+
913
+ /**
914
+ * Publish a message asynchronously
915
+ * @param {any} payload
916
+ * @returns {Promise<any>}
917
+ */
918
+ async publishAsync(payload) {
919
+ return this.mq.publish_async(this.id, payload);
920
+ }
921
+
922
+ /**
923
+ * Publish multiple messages efficiently
924
+ * @param {Array<any>} payloads
925
+ */
926
+ publishBatch(payloads) {
927
+ this.mq.publish_batch_by_id(this.id, payloads);
928
+ }
929
+
930
+ /**
931
+ * Subscribe to this topic
932
+ * @param {Function} callback - (payload, topic_id, timestamp, message_id) => void
933
+ * @returns {number} subscription ID
934
+ */
935
+ subscribe(callback) {
936
+ return this.mq.subscribe(this.id, callback);
937
+ }
938
+
939
+ /**
940
+ * Unsubscribe from this topic
941
+ * @param {number} sub_id
942
+ * @returns {boolean}
943
+ */
944
+ unsubscribe(sub_id) {
945
+ return this.mq.unsubscribe(this.id, sub_id);
946
+ }
947
+
948
+ /**
949
+ * Unsubscribe all subscribers from this topic
950
+ * @returns {number} number of subscribers removed
951
+ */
952
+ unsubscribeAll() {
953
+ return this.mq.unsubscribe_all(this.id);
954
+ }
955
+
956
+ /**
957
+ * Get the number of subscribers
958
+ * @returns {number}
959
+ */
960
+ get subscriberCount() {
961
+ return this.mq.subscriber_count(this.id);
962
+ }
963
+
964
+ /**
965
+ * Enable buffering for this topic
966
+ * @param {number} [capacity]
967
+ */
968
+ enableBuffer(capacity) {
969
+ this.mq.enable_topic_buffer(this.id, capacity);
970
+ }
971
+
972
+ /**
973
+ * Disable buffering for this topic
974
+ */
975
+ disableBuffer() {
976
+ this.mq.disable_topic_buffer(this.id);
977
+ }
978
+
979
+ /**
980
+ * Clear the buffer
981
+ * @returns {number} number of messages cleared
982
+ */
983
+ clearBuffer() {
984
+ return this.mq.clear_buffer(this.id);
985
+ }
986
+
987
+ /**
988
+ * Get buffered messages
989
+ * @returns {Array<any>}
990
+ */
991
+ getBufferedMessages() {
992
+ return this.mq.get_buffered_messages(this.id);
993
+ }
994
+
995
+ /**
996
+ * Get buffer size
997
+ * @returns {number}
998
+ */
999
+ get bufferSize() {
1000
+ return this.mq.get_buffer_size(this.id);
1001
+ }
1002
+
1003
+ /**
1004
+ * Get buffer capacity
1005
+ * @returns {number}
1006
+ */
1007
+ get bufferCapacity() {
1008
+ return this.mq.get_buffer_capacity(this.id);
1009
+ }
1010
+
1011
+ /**
1012
+ * Check if buffering is enabled
1013
+ * @returns {boolean}
1014
+ */
1015
+ get hasBuffer() {
1016
+ return this.mq.has_buffer(this.id);
1017
+ }
1018
+
1019
+ /**
1020
+ * Destroy this topic
1021
+ * @returns {boolean}
1022
+ */
1023
+ destroy() {
1024
+ return this.mq.destroy_topic(this.id);
1025
+ }
1026
+ }
1027
+
1028
+ /**
1029
+ * Get or create a topic wrapper
1030
+ * @param {string} name
1031
+ * @returns {Topic}
1032
+ */
1033
+ MessageQueue.prototype.topic = function(name) {
1034
+ const id = this.register_topic(name);
1035
+ return new Topic(this, name, id);
1036
+ };
1037
+
1038
+ export { initSync };
1039
+ export default __wbg_init;