@loro-dev/flock-wasm 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.
Files changed (42) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +26 -0
  3. package/base64/event-batcher.d.ts +37 -0
  4. package/base64/event-batcher.js +204 -0
  5. package/base64/flock_wasm.js +1158 -0
  6. package/base64/index.d.ts +268 -0
  7. package/base64/index.js +1012 -0
  8. package/base64/wasm.d.ts +37 -0
  9. package/base64/wasm.js +15 -0
  10. package/bundler/event-batcher.d.ts +37 -0
  11. package/bundler/event-batcher.js +204 -0
  12. package/bundler/flock_wasm.d.ts +313 -0
  13. package/bundler/flock_wasm.js +5 -0
  14. package/bundler/flock_wasm_bg.js +1119 -0
  15. package/bundler/flock_wasm_bg.wasm +0 -0
  16. package/bundler/flock_wasm_bg.wasm.d.ts +40 -0
  17. package/bundler/index.d.ts +268 -0
  18. package/bundler/index.js +1012 -0
  19. package/bundler/wasm.d.ts +37 -0
  20. package/bundler/wasm.js +4 -0
  21. package/nodejs/event-batcher.d.ts +37 -0
  22. package/nodejs/event-batcher.js +208 -0
  23. package/nodejs/flock_wasm.d.ts +313 -0
  24. package/nodejs/flock_wasm.js +1126 -0
  25. package/nodejs/flock_wasm_bg.wasm +0 -0
  26. package/nodejs/flock_wasm_bg.wasm.d.ts +40 -0
  27. package/nodejs/index.d.ts +268 -0
  28. package/nodejs/index.js +1018 -0
  29. package/nodejs/package.json +1 -0
  30. package/nodejs/wasm.d.ts +37 -0
  31. package/nodejs/wasm.js +2 -0
  32. package/package.json +50 -0
  33. package/web/event-batcher.d.ts +37 -0
  34. package/web/event-batcher.js +204 -0
  35. package/web/flock_wasm.d.ts +377 -0
  36. package/web/flock_wasm.js +1158 -0
  37. package/web/flock_wasm_bg.wasm +0 -0
  38. package/web/flock_wasm_bg.wasm.d.ts +40 -0
  39. package/web/index.d.ts +268 -0
  40. package/web/index.js +1012 -0
  41. package/web/wasm.d.ts +37 -0
  42. package/web/wasm.js +4 -0
@@ -0,0 +1,1158 @@
1
+ let wasm;
2
+
3
+ let WASM_VECTOR_LEN = 0;
4
+
5
+ let cachedUint8ArrayMemory0 = null;
6
+
7
+ function getUint8ArrayMemory0() {
8
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
9
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
10
+ }
11
+ return cachedUint8ArrayMemory0;
12
+ }
13
+
14
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
15
+
16
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
17
+ ? function (arg, view) {
18
+ return cachedTextEncoder.encodeInto(arg, view);
19
+ }
20
+ : function (arg, view) {
21
+ const buf = cachedTextEncoder.encode(arg);
22
+ view.set(buf);
23
+ return {
24
+ read: arg.length,
25
+ written: buf.length
26
+ };
27
+ });
28
+
29
+ function passStringToWasm0(arg, malloc, realloc) {
30
+
31
+ if (realloc === undefined) {
32
+ const buf = cachedTextEncoder.encode(arg);
33
+ const ptr = malloc(buf.length, 1) >>> 0;
34
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
35
+ WASM_VECTOR_LEN = buf.length;
36
+ return ptr;
37
+ }
38
+
39
+ let len = arg.length;
40
+ let ptr = malloc(len, 1) >>> 0;
41
+
42
+ const mem = getUint8ArrayMemory0();
43
+
44
+ let offset = 0;
45
+
46
+ for (; offset < len; offset++) {
47
+ const code = arg.charCodeAt(offset);
48
+ if (code > 0x7F) break;
49
+ mem[ptr + offset] = code;
50
+ }
51
+
52
+ if (offset !== len) {
53
+ if (offset !== 0) {
54
+ arg = arg.slice(offset);
55
+ }
56
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
57
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
58
+ const ret = encodeString(arg, view);
59
+
60
+ offset += ret.written;
61
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
62
+ }
63
+
64
+ WASM_VECTOR_LEN = offset;
65
+ return ptr;
66
+ }
67
+
68
+ let cachedDataViewMemory0 = null;
69
+
70
+ function getDataViewMemory0() {
71
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
72
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
73
+ }
74
+ return cachedDataViewMemory0;
75
+ }
76
+
77
+ function addToExternrefTable0(obj) {
78
+ const idx = wasm.__externref_table_alloc();
79
+ wasm.__wbindgen_export_4.set(idx, obj);
80
+ return idx;
81
+ }
82
+
83
+ function handleError(f, args) {
84
+ try {
85
+ return f.apply(this, args);
86
+ } catch (e) {
87
+ const idx = addToExternrefTable0(e);
88
+ wasm.__wbindgen_exn_store(idx);
89
+ }
90
+ }
91
+
92
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
93
+
94
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
95
+
96
+ function getStringFromWasm0(ptr, len) {
97
+ ptr = ptr >>> 0;
98
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
99
+ }
100
+
101
+ function isLikeNone(x) {
102
+ return x === undefined || x === null;
103
+ }
104
+
105
+ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
106
+ ? { register: () => {}, unregister: () => {} }
107
+ : new FinalizationRegistry(state => {
108
+ wasm.__wbindgen_export_6.get(state.dtor)(state.a, state.b)
109
+ });
110
+
111
+ function makeMutClosure(arg0, arg1, dtor, f) {
112
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
113
+ const real = (...args) => {
114
+ // First up with a closure we increment the internal reference
115
+ // count. This ensures that the Rust closure environment won't
116
+ // be deallocated while we're invoking it.
117
+ state.cnt++;
118
+ const a = state.a;
119
+ state.a = 0;
120
+ try {
121
+ return f(a, state.b, ...args);
122
+ } finally {
123
+ if (--state.cnt === 0) {
124
+ wasm.__wbindgen_export_6.get(state.dtor)(a, state.b);
125
+ CLOSURE_DTORS.unregister(state);
126
+ } else {
127
+ state.a = a;
128
+ }
129
+ }
130
+ };
131
+ real.original = state;
132
+ CLOSURE_DTORS.register(real, state, state);
133
+ return real;
134
+ }
135
+
136
+ function debugString(val) {
137
+ // primitive types
138
+ const type = typeof val;
139
+ if (type == 'number' || type == 'boolean' || val == null) {
140
+ return `${val}`;
141
+ }
142
+ if (type == 'string') {
143
+ return `"${val}"`;
144
+ }
145
+ if (type == 'symbol') {
146
+ const description = val.description;
147
+ if (description == null) {
148
+ return 'Symbol';
149
+ } else {
150
+ return `Symbol(${description})`;
151
+ }
152
+ }
153
+ if (type == 'function') {
154
+ const name = val.name;
155
+ if (typeof name == 'string' && name.length > 0) {
156
+ return `Function(${name})`;
157
+ } else {
158
+ return 'Function';
159
+ }
160
+ }
161
+ // objects
162
+ if (Array.isArray(val)) {
163
+ const length = val.length;
164
+ let debug = '[';
165
+ if (length > 0) {
166
+ debug += debugString(val[0]);
167
+ }
168
+ for(let i = 1; i < length; i++) {
169
+ debug += ', ' + debugString(val[i]);
170
+ }
171
+ debug += ']';
172
+ return debug;
173
+ }
174
+ // Test for built-in
175
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
176
+ let className;
177
+ if (builtInMatches && builtInMatches.length > 1) {
178
+ className = builtInMatches[1];
179
+ } else {
180
+ // Failed to match the standard '[object ClassName]'
181
+ return toString.call(val);
182
+ }
183
+ if (className == 'Object') {
184
+ // we're a user defined class or Object
185
+ // JSON.stringify avoids problems with cycles, and is generally much
186
+ // easier than looping through ownProperties of `val`.
187
+ try {
188
+ return 'Object(' + JSON.stringify(val) + ')';
189
+ } catch (_) {
190
+ return 'Object';
191
+ }
192
+ }
193
+ // errors
194
+ if (val instanceof Error) {
195
+ return `${val.name}: ${val.message}\n${val.stack}`;
196
+ }
197
+ // TODO we could test for more things here, like `Set`s and `Map`s.
198
+ return className;
199
+ }
200
+ /**
201
+ * Initializes the WASM module.
202
+ *
203
+ * This function is automatically called when the WASM module is loaded.
204
+ * It sets up the panic hook to route Rust panics to the JavaScript console.
205
+ */
206
+ export function start() {
207
+ wasm.start();
208
+ }
209
+
210
+ /**
211
+ * Drains the pending callback queue, invoking all enqueued callbacks.
212
+ *
213
+ * This function is exported to JavaScript and can be called manually,
214
+ * but is typically invoked automatically via microtasks.
215
+ *
216
+ * Callbacks are invoked sequentially. If any callback throws an error,
217
+ * the error is propagated to JavaScript after the current batch completes.
218
+ */
219
+ export function callPendingEvents() {
220
+ wasm.callPendingEvents();
221
+ }
222
+
223
+ function takeFromExternrefTable0(idx) {
224
+ const value = wasm.__wbindgen_export_4.get(idx);
225
+ wasm.__externref_table_dealloc(idx);
226
+ return value;
227
+ }
228
+
229
+ function getArrayU8FromWasm0(ptr, len) {
230
+ ptr = ptr >>> 0;
231
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
232
+ }
233
+
234
+ function _assertClass(instance, klass) {
235
+ if (!(instance instanceof klass)) {
236
+ throw new Error(`expected instance of ${klass.name}`);
237
+ }
238
+ }
239
+
240
+ function passArray8ToWasm0(arg, malloc) {
241
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
242
+ getUint8ArrayMemory0().set(arg, ptr / 1);
243
+ WASM_VECTOR_LEN = arg.length;
244
+ return ptr;
245
+ }
246
+ function __wbg_adapter_56(arg0, arg1, arg2) {
247
+ wasm.closure38_externref_shim(arg0, arg1, arg2);
248
+ }
249
+
250
+ const RawFlockFinalization = (typeof FinalizationRegistry === 'undefined')
251
+ ? { register: () => {}, unregister: () => {} }
252
+ : new FinalizationRegistry(ptr => wasm.__wbg_rawflock_free(ptr >>> 0, 1));
253
+ /**
254
+ * The main WASM-exposed flock instance.
255
+ *
256
+ * Wraps the underlying [`flock::Flock`] and provides JavaScript-compatible
257
+ * methods for all CRDT operations including put, get, delete, scan, merge,
258
+ * import/export, and event subscription.
259
+ */
260
+ export class RawFlock {
261
+
262
+ static __wrap(ptr) {
263
+ ptr = ptr >>> 0;
264
+ const obj = Object.create(RawFlock.prototype);
265
+ obj.__wbg_ptr = ptr;
266
+ RawFlockFinalization.register(obj, obj.__wbg_ptr, obj);
267
+ return obj;
268
+ }
269
+
270
+ __destroy_into_raw() {
271
+ const ptr = this.__wbg_ptr;
272
+ this.__wbg_ptr = 0;
273
+ RawFlockFinalization.unregister(this);
274
+ return ptr;
275
+ }
276
+
277
+ free() {
278
+ const ptr = this.__destroy_into_raw();
279
+ wasm.__wbg_rawflock_free(ptr, 0);
280
+ }
281
+ /**
282
+ * Commits the current transaction.
283
+ *
284
+ * Flushes all buffered operations and delivers batched events.
285
+ *
286
+ * # Errors
287
+ *
288
+ * Returns an error if no transaction is active or if commit fails.
289
+ */
290
+ txnCommit() {
291
+ const ret = wasm.rawflock_txnCommit(this.__wbg_ptr);
292
+ if (ret[1]) {
293
+ throw takeFromExternrefTable0(ret[0]);
294
+ }
295
+ }
296
+ /**
297
+ * @returns {Uint8Array}
298
+ */
299
+ exportFile() {
300
+ const ret = wasm.rawflock_exportFile(this.__wbg_ptr);
301
+ if (ret[3]) {
302
+ throw takeFromExternrefTable0(ret[2]);
303
+ }
304
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
305
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
306
+ return v1;
307
+ }
308
+ /**
309
+ * Exports the current state as a JSON bundle.
310
+ *
311
+ * # Arguments
312
+ *
313
+ * * `from` - Optional version vector for incremental export
314
+ * * `prune_tombstones_before` - Optional timestamp to prune tombstones older than this
315
+ * * `peer_id` - Optional peer ID filter to only export entries from this peer
316
+ *
317
+ * # Returns
318
+ *
319
+ * An export bundle containing entries and version information.
320
+ *
321
+ * # Errors
322
+ *
323
+ * Returns an error if arguments are invalid or serialization fails.
324
+ * @param {any} from
325
+ * @param {any} prune_tombstones_before
326
+ * @param {any} peer_id
327
+ * @returns {any}
328
+ */
329
+ exportJson(from, prune_tombstones_before, peer_id) {
330
+ const ret = wasm.rawflock_exportJson(this.__wbg_ptr, from, prune_tombstones_before, peer_id);
331
+ if (ret[2]) {
332
+ throw takeFromExternrefTable0(ret[1]);
333
+ }
334
+ return takeFromExternrefTable0(ret[0]);
335
+ }
336
+ /**
337
+ * Imports a JSON bundle into this flock instance.
338
+ *
339
+ * # Arguments
340
+ *
341
+ * * `bundle` - The export bundle to import
342
+ *
343
+ * # Returns
344
+ *
345
+ * An import report containing counts of accepted and skipped entries.
346
+ *
347
+ * # Errors
348
+ *
349
+ * Returns an error if the bundle is invalid or import fails.
350
+ * @param {any} bundle
351
+ * @returns {any}
352
+ */
353
+ importJson(bundle) {
354
+ const ret = wasm.rawflock_importJson(this.__wbg_ptr, bundle);
355
+ if (ret[2]) {
356
+ throw takeFromExternrefTable0(ret[1]);
357
+ }
358
+ return takeFromExternrefTable0(ret[0]);
359
+ }
360
+ /**
361
+ * Sets a new peer ID for this flock instance.
362
+ *
363
+ * # Arguments
364
+ *
365
+ * * `peer_id` - The new peer ID to set
366
+ *
367
+ * # Errors
368
+ *
369
+ * Returns an error if the peer ID is invalid.
370
+ * @param {string} peer_id
371
+ */
372
+ setPeerId(peer_id) {
373
+ const ptr0 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
374
+ const len0 = WASM_VECTOR_LEN;
375
+ const ret = wasm.rawflock_setPeerId(this.__wbg_ptr, ptr0, len0);
376
+ if (ret[1]) {
377
+ throw takeFromExternrefTable0(ret[0]);
378
+ }
379
+ }
380
+ /**
381
+ * Unsubscribes from change events.
382
+ *
383
+ * # Arguments
384
+ *
385
+ * * `id` - The subscription ID returned from `subscribe`
386
+ *
387
+ * # Returns
388
+ *
389
+ * `true` if a subscription was removed, `false` if the ID was not found.
390
+ * @param {number} id
391
+ * @returns {boolean}
392
+ */
393
+ unsubscribe(id) {
394
+ const ret = wasm.rawflock_unsubscribe(this.__wbg_ptr, id);
395
+ return ret !== 0;
396
+ }
397
+ /**
398
+ * Rolls back the current transaction.
399
+ *
400
+ * Discards all buffered operations since `txnBegin` was called.
401
+ * Note: Data changes are not rolled back, only event emission is affected.
402
+ */
403
+ txnRollback() {
404
+ wasm.rawflock_txnRollback(this.__wbg_ptr);
405
+ }
406
+ /**
407
+ * Stores a value with associated metadata at the specified key.
408
+ *
409
+ * # Arguments
410
+ *
411
+ * * `key` - The key as a JSON array
412
+ * * `value` - The value to store
413
+ * * `metadata` - Optional metadata object to associate with this entry
414
+ * * `now` - Optional timestamp in milliseconds
415
+ *
416
+ * # Errors
417
+ *
418
+ * Returns an error if any argument is invalid or the operation fails.
419
+ * @param {any} key
420
+ * @param {any} value
421
+ * @param {any} metadata
422
+ * @param {any} now
423
+ */
424
+ putWithMeta(key, value, metadata, now) {
425
+ const ret = wasm.rawflock_putWithMeta(this.__wbg_ptr, key, value, metadata, now);
426
+ if (ret[1]) {
427
+ throw takeFromExternrefTable0(ret[0]);
428
+ }
429
+ }
430
+ /**
431
+ * Returns the inclusive version vector for this flock.
432
+ *
433
+ * The inclusive version includes all peers ever seen, even if their
434
+ * entries have been overridden by other peers.
435
+ *
436
+ * # Errors
437
+ *
438
+ * Returns an error if serialization fails.
439
+ * @returns {any}
440
+ */
441
+ inclusiveVersion() {
442
+ const ret = wasm.rawflock_inclusiveVersion(this.__wbg_ptr);
443
+ if (ret[2]) {
444
+ throw takeFromExternrefTable0(ret[1]);
445
+ }
446
+ return takeFromExternrefTable0(ret[0]);
447
+ }
448
+ /**
449
+ * Returns the maximum physical time across all entries in this flock.
450
+ *
451
+ * This is useful for determining a safe timestamp for tombstone pruning.
452
+ * @returns {number}
453
+ */
454
+ getMaxPhysicalTime() {
455
+ const ret = wasm.rawflock_getMaxPhysicalTime(this.__wbg_ptr);
456
+ return ret;
457
+ }
458
+ /**
459
+ * Retrieves the value at the specified key.
460
+ *
461
+ * Returns `undefined` if the key doesn't exist or has been deleted.
462
+ *
463
+ * # Arguments
464
+ *
465
+ * * `key` - The key as a JSON array
466
+ *
467
+ * # Errors
468
+ *
469
+ * Returns an error if serialization of the result fails.
470
+ * @param {any} key
471
+ * @returns {any}
472
+ */
473
+ get(key) {
474
+ const ret = wasm.rawflock_get(this.__wbg_ptr, key);
475
+ if (ret[2]) {
476
+ throw takeFromExternrefTable0(ret[1]);
477
+ }
478
+ return takeFromExternrefTable0(ret[0]);
479
+ }
480
+ /**
481
+ * Creates a new WASM flock instance with the given peer ID.
482
+ *
483
+ * The instance is created in buffered mode with memtable enabled.
484
+ * Use transactions (`txnBegin` + `txnCommit`) to flush buffered writes explicitly.
485
+ *
486
+ * # Arguments
487
+ *
488
+ * * `peer_id` - The unique identifier for this peer
489
+ *
490
+ * # Errors
491
+ *
492
+ * Returns an error if the peer ID is invalid or if instance creation fails.
493
+ * @param {string} peer_id
494
+ */
495
+ constructor(peer_id) {
496
+ const ptr0 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
497
+ const len0 = WASM_VECTOR_LEN;
498
+ const ret = wasm.rawflock_new(ptr0, len0);
499
+ if (ret[2]) {
500
+ throw takeFromExternrefTable0(ret[1]);
501
+ }
502
+ this.__wbg_ptr = ret[0] >>> 0;
503
+ RawFlockFinalization.register(this, this.__wbg_ptr, this);
504
+ return this;
505
+ }
506
+ /**
507
+ * Stores a value at the specified key.
508
+ *
509
+ * # Arguments
510
+ *
511
+ * * `key` - The key as a JSON array
512
+ * * `value` - The value to store (any JSON-serializable value)
513
+ * * `now` - Optional timestamp in milliseconds (uses current time if undefined)
514
+ *
515
+ * # Errors
516
+ *
517
+ * Returns an error if the key or value is invalid, or if the operation fails.
518
+ * @param {any} key
519
+ * @param {any} value
520
+ * @param {any} now
521
+ */
522
+ put(key, value, now) {
523
+ const ret = wasm.rawflock_put(this.__wbg_ptr, key, value, now);
524
+ if (ret[1]) {
525
+ throw takeFromExternrefTable0(ret[0]);
526
+ }
527
+ }
528
+ /**
529
+ * Scans entries within the specified bounds and prefix.
530
+ *
531
+ * # Arguments
532
+ *
533
+ * * `start` - Optional start bound (inclusive/exclusive/unbounded)
534
+ * * `end` - Optional end bound
535
+ * * `prefix` - Optional key prefix to filter by
536
+ *
537
+ * # Returns
538
+ *
539
+ * An array of scan rows containing keys, values, and raw records.
540
+ *
541
+ * # Errors
542
+ *
543
+ * Returns an error if scan bounds are invalid or serialization fails.
544
+ * @param {any} start
545
+ * @param {any} end
546
+ * @param {any} prefix
547
+ * @returns {any}
548
+ */
549
+ scan(start, end, prefix) {
550
+ const ret = wasm.rawflock_scan(this.__wbg_ptr, start, end, prefix);
551
+ if (ret[2]) {
552
+ throw takeFromExternrefTable0(ret[1]);
553
+ }
554
+ return takeFromExternrefTable0(ret[0]);
555
+ }
556
+ /**
557
+ * Merges state from another flock instance into this one.
558
+ *
559
+ * # Arguments
560
+ *
561
+ * * `other` - The other flock instance to merge from
562
+ *
563
+ * # Returns
564
+ *
565
+ * An import report containing counts of accepted and skipped entries.
566
+ *
567
+ * # Errors
568
+ *
569
+ * Returns an error if the merge operation fails.
570
+ * @param {RawFlock} other
571
+ * @returns {any}
572
+ */
573
+ merge(other) {
574
+ _assertClass(other, RawFlock);
575
+ const ret = wasm.rawflock_merge(this.__wbg_ptr, other.__wbg_ptr);
576
+ if (ret[2]) {
577
+ throw takeFromExternrefTable0(ret[1]);
578
+ }
579
+ return takeFromExternrefTable0(ret[0]);
580
+ }
581
+ /**
582
+ * Deletes the value at the specified key (creates a tombstone).
583
+ *
584
+ * # Arguments
585
+ *
586
+ * * `key` - The key as a JSON array
587
+ * * `now` - Optional timestamp in milliseconds
588
+ *
589
+ * # Errors
590
+ *
591
+ * Returns an error if the key is invalid or the operation fails.
592
+ * @param {any} key
593
+ * @param {any} now
594
+ */
595
+ delete(key, now) {
596
+ const ret = wasm.rawflock_delete(this.__wbg_ptr, key, now);
597
+ if (ret[1]) {
598
+ throw takeFromExternrefTable0(ret[0]);
599
+ }
600
+ }
601
+ /**
602
+ * Returns the current peer ID of this flock instance.
603
+ * @returns {string}
604
+ */
605
+ peerId() {
606
+ let deferred1_0;
607
+ let deferred1_1;
608
+ try {
609
+ const ret = wasm.rawflock_peerId(this.__wbg_ptr);
610
+ deferred1_0 = ret[0];
611
+ deferred1_1 = ret[1];
612
+ return getStringFromWasm0(ret[0], ret[1]);
613
+ } finally {
614
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
615
+ }
616
+ }
617
+ /**
618
+ * Returns the exclusive version vector for this flock.
619
+ *
620
+ * The exclusive version only includes peers that have at least one entry
621
+ * in the current state (excluding tombstones and overridden entries).
622
+ *
623
+ * # Errors
624
+ *
625
+ * Returns an error if serialization fails.
626
+ * @returns {any}
627
+ */
628
+ version() {
629
+ const ret = wasm.rawflock_version(this.__wbg_ptr);
630
+ if (ret[2]) {
631
+ throw takeFromExternrefTable0(ret[1]);
632
+ }
633
+ return takeFromExternrefTable0(ret[0]);
634
+ }
635
+ /**
636
+ * Creates a new flock instance from a file bytes array.
637
+ *
638
+ * # Arguments
639
+ *
640
+ * * `peer_id` - The peer ID for the new instance
641
+ * * `bytes` - The file contents as a Uint8Array
642
+ *
643
+ * # Errors
644
+ *
645
+ * Returns an error if the file format is invalid or loading fails.
646
+ * @param {string} peer_id
647
+ * @param {Uint8Array} bytes
648
+ * @returns {RawFlock}
649
+ */
650
+ static fromFile(peer_id, bytes) {
651
+ const ptr0 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
652
+ const len0 = WASM_VECTOR_LEN;
653
+ const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
654
+ const len1 = WASM_VECTOR_LEN;
655
+ const ret = wasm.rawflock_fromFile(ptr0, len0, ptr1, len1);
656
+ if (ret[2]) {
657
+ throw takeFromExternrefTable0(ret[1]);
658
+ }
659
+ return RawFlock.__wrap(ret[0]);
660
+ }
661
+ /**
662
+ * Creates a new flock instance from a JSON export bundle.
663
+ *
664
+ * # Arguments
665
+ *
666
+ * * `bundle` - The export bundle as a JavaScript object
667
+ * * `peer_id` - The peer ID for the new instance
668
+ *
669
+ * # Errors
670
+ *
671
+ * Returns an error if the bundle is invalid or import fails.
672
+ * @param {any} bundle
673
+ * @param {string} peer_id
674
+ * @returns {RawFlock}
675
+ */
676
+ static fromJson(bundle, peer_id) {
677
+ const ptr0 = passStringToWasm0(peer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
678
+ const len0 = WASM_VECTOR_LEN;
679
+ const ret = wasm.rawflock_fromJson(bundle, ptr0, len0);
680
+ if (ret[2]) {
681
+ throw takeFromExternrefTable0(ret[1]);
682
+ }
683
+ return RawFlock.__wrap(ret[0]);
684
+ }
685
+ /**
686
+ * Retrieves complete entry information including data, metadata, and clock.
687
+ *
688
+ * Returns `undefined` if the key doesn't exist.
689
+ *
690
+ * # Arguments
691
+ *
692
+ * * `key` - The key as a JSON array
693
+ *
694
+ * # Errors
695
+ *
696
+ * Returns an error if serialization of the result fails.
697
+ * @param {any} key
698
+ * @returns {any}
699
+ */
700
+ getEntry(key) {
701
+ const ret = wasm.rawflock_getEntry(this.__wbg_ptr, key);
702
+ if (ret[2]) {
703
+ throw takeFromExternrefTable0(ret[1]);
704
+ }
705
+ return takeFromExternrefTable0(ret[0]);
706
+ }
707
+ /**
708
+ * Returns whether a transaction is currently active.
709
+ * @returns {boolean}
710
+ */
711
+ isInTxn() {
712
+ const ret = wasm.rawflock_isInTxn(this.__wbg_ptr);
713
+ return ret !== 0;
714
+ }
715
+ /**
716
+ * Subscribes to change events from this flock instance.
717
+ *
718
+ * # Arguments
719
+ *
720
+ * * `listener` - A JavaScript function that will be called with event batches
721
+ *
722
+ * # Returns
723
+ *
724
+ * A subscription ID that can be used to unsubscribe later.
725
+ *
726
+ * # Errors
727
+ *
728
+ * Returns an error if the subscription fails or the ID overflows.
729
+ * @param {Function} listener
730
+ * @returns {number}
731
+ */
732
+ subscribe(listener) {
733
+ const ret = wasm.rawflock_subscribe(this.__wbg_ptr, listener);
734
+ if (ret[2]) {
735
+ throw takeFromExternrefTable0(ret[1]);
736
+ }
737
+ return ret[0] >>> 0;
738
+ }
739
+ /**
740
+ * Begins a transaction.
741
+ *
742
+ * All subsequent put/delete operations will be buffered until `txnCommit`
743
+ * is called. Events will be batched and delivered as a single batch on commit.
744
+ *
745
+ * # Errors
746
+ *
747
+ * Returns an error if a transaction is already active or if begin fails.
748
+ */
749
+ txnBegin() {
750
+ const ret = wasm.rawflock_txnBegin(this.__wbg_ptr);
751
+ if (ret[1]) {
752
+ throw takeFromExternrefTable0(ret[0]);
753
+ }
754
+ }
755
+ }
756
+
757
+ async function __wbg_load(module, imports) {
758
+ if (typeof Response === 'function' && module instanceof Response) {
759
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
760
+ try {
761
+ return await WebAssembly.instantiateStreaming(module, imports);
762
+
763
+ } catch (e) {
764
+ if (module.headers.get('Content-Type') != 'application/wasm') {
765
+ 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);
766
+
767
+ } else {
768
+ throw e;
769
+ }
770
+ }
771
+ }
772
+
773
+ const bytes = await module.arrayBuffer();
774
+ return await WebAssembly.instantiate(bytes, imports);
775
+
776
+ } else {
777
+ const instance = await WebAssembly.instantiate(module, imports);
778
+
779
+ if (instance instanceof WebAssembly.Instance) {
780
+ return { instance, module };
781
+
782
+ } else {
783
+ return instance;
784
+ }
785
+ }
786
+ }
787
+
788
+ function __wbg_get_imports() {
789
+ const imports = {};
790
+ imports.wbg = {};
791
+ imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
792
+ const ret = String(arg1);
793
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
794
+ const len1 = WASM_VECTOR_LEN;
795
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
796
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
797
+ };
798
+ imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
799
+ const ret = arg0.buffer;
800
+ return ret;
801
+ };
802
+ imports.wbg.__wbg_call_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) {
803
+ const ret = arg0.call(arg1);
804
+ return ret;
805
+ }, arguments) };
806
+ imports.wbg.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) {
807
+ const ret = arg0.call(arg1, arg2);
808
+ return ret;
809
+ }, arguments) };
810
+ imports.wbg.__wbg_done_769e5ede4b31c67b = function(arg0) {
811
+ const ret = arg0.done;
812
+ return ret;
813
+ };
814
+ imports.wbg.__wbg_entries_3265d4158b33e5dc = function(arg0) {
815
+ const ret = Object.entries(arg0);
816
+ return ret;
817
+ };
818
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
819
+ let deferred0_0;
820
+ let deferred0_1;
821
+ try {
822
+ deferred0_0 = arg0;
823
+ deferred0_1 = arg1;
824
+ console.error(getStringFromWasm0(arg0, arg1));
825
+ } finally {
826
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
827
+ }
828
+ };
829
+ imports.wbg.__wbg_get_67b2ba62fc30de12 = function() { return handleError(function (arg0, arg1) {
830
+ const ret = Reflect.get(arg0, arg1);
831
+ return ret;
832
+ }, arguments) };
833
+ imports.wbg.__wbg_get_b9b93047fe3cf45b = function(arg0, arg1) {
834
+ const ret = arg0[arg1 >>> 0];
835
+ return ret;
836
+ };
837
+ imports.wbg.__wbg_getwithrefkey_1dc361bd10053bfe = function(arg0, arg1) {
838
+ const ret = arg0[arg1];
839
+ return ret;
840
+ };
841
+ imports.wbg.__wbg_instanceof_ArrayBuffer_e14585432e3737fc = function(arg0) {
842
+ let result;
843
+ try {
844
+ result = arg0 instanceof ArrayBuffer;
845
+ } catch (_) {
846
+ result = false;
847
+ }
848
+ const ret = result;
849
+ return ret;
850
+ };
851
+ imports.wbg.__wbg_instanceof_Map_f3469ce2244d2430 = function(arg0) {
852
+ let result;
853
+ try {
854
+ result = arg0 instanceof Map;
855
+ } catch (_) {
856
+ result = false;
857
+ }
858
+ const ret = result;
859
+ return ret;
860
+ };
861
+ imports.wbg.__wbg_instanceof_Uint8Array_17156bcf118086a9 = function(arg0) {
862
+ let result;
863
+ try {
864
+ result = arg0 instanceof Uint8Array;
865
+ } catch (_) {
866
+ result = false;
867
+ }
868
+ const ret = result;
869
+ return ret;
870
+ };
871
+ imports.wbg.__wbg_isArray_a1eab7e0d067391b = function(arg0) {
872
+ const ret = Array.isArray(arg0);
873
+ return ret;
874
+ };
875
+ imports.wbg.__wbg_isSafeInteger_343e2beeeece1bb0 = function(arg0) {
876
+ const ret = Number.isSafeInteger(arg0);
877
+ return ret;
878
+ };
879
+ imports.wbg.__wbg_iterator_9a24c88df860dc65 = function() {
880
+ const ret = Symbol.iterator;
881
+ return ret;
882
+ };
883
+ imports.wbg.__wbg_length_a446193dc22c12f8 = function(arg0) {
884
+ const ret = arg0.length;
885
+ return ret;
886
+ };
887
+ imports.wbg.__wbg_length_e2d2a49132c1b256 = function(arg0) {
888
+ const ret = arg0.length;
889
+ return ret;
890
+ };
891
+ imports.wbg.__wbg_new_405e22f390576ce2 = function() {
892
+ const ret = new Object();
893
+ return ret;
894
+ };
895
+ imports.wbg.__wbg_new_5e0be73521bc8c17 = function() {
896
+ const ret = new Map();
897
+ return ret;
898
+ };
899
+ imports.wbg.__wbg_new_78feb108b6472713 = function() {
900
+ const ret = new Array();
901
+ return ret;
902
+ };
903
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
904
+ const ret = new Error();
905
+ return ret;
906
+ };
907
+ imports.wbg.__wbg_new_a12002a7f91c75be = function(arg0) {
908
+ const ret = new Uint8Array(arg0);
909
+ return ret;
910
+ };
911
+ imports.wbg.__wbg_new_c68d7209be747379 = function(arg0, arg1) {
912
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
913
+ return ret;
914
+ };
915
+ imports.wbg.__wbg_next_25feadfc0913fea9 = function(arg0) {
916
+ const ret = arg0.next;
917
+ return ret;
918
+ };
919
+ imports.wbg.__wbg_next_6574e1a8a62d1055 = function() { return handleError(function (arg0) {
920
+ const ret = arg0.next();
921
+ return ret;
922
+ }, arguments) };
923
+ imports.wbg.__wbg_now_807e54c39636c349 = function() {
924
+ const ret = Date.now();
925
+ return ret;
926
+ };
927
+ imports.wbg.__wbg_resolve_4851785c9c5f573d = function(arg0) {
928
+ const ret = Promise.resolve(arg0);
929
+ return ret;
930
+ };
931
+ imports.wbg.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) {
932
+ arg0[arg1 >>> 0] = arg2;
933
+ };
934
+ imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
935
+ arg0[arg1] = arg2;
936
+ };
937
+ imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
938
+ arg0.set(arg1, arg2 >>> 0);
939
+ };
940
+ imports.wbg.__wbg_set_8fc6bf8a5b1071d1 = function(arg0, arg1, arg2) {
941
+ const ret = arg0.set(arg1, arg2);
942
+ return ret;
943
+ };
944
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
945
+ const ret = arg1.stack;
946
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
947
+ const len1 = WASM_VECTOR_LEN;
948
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
949
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
950
+ };
951
+ imports.wbg.__wbg_then_44b73946d2fb3e7d = function(arg0, arg1) {
952
+ const ret = arg0.then(arg1);
953
+ return ret;
954
+ };
955
+ imports.wbg.__wbg_value_cd1ffa7b1ab794f1 = function(arg0) {
956
+ const ret = arg0.value;
957
+ return ret;
958
+ };
959
+ imports.wbg.__wbindgen_as_number = function(arg0) {
960
+ const ret = +arg0;
961
+ return ret;
962
+ };
963
+ imports.wbg.__wbindgen_bigint_from_i64 = function(arg0) {
964
+ const ret = arg0;
965
+ return ret;
966
+ };
967
+ imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
968
+ const ret = BigInt.asUintN(64, arg0);
969
+ return ret;
970
+ };
971
+ imports.wbg.__wbindgen_bigint_get_as_i64 = function(arg0, arg1) {
972
+ const v = arg1;
973
+ const ret = typeof(v) === 'bigint' ? v : undefined;
974
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
975
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
976
+ };
977
+ imports.wbg.__wbindgen_boolean_get = function(arg0) {
978
+ const v = arg0;
979
+ const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
980
+ return ret;
981
+ };
982
+ imports.wbg.__wbindgen_cb_drop = function(arg0) {
983
+ const obj = arg0.original;
984
+ if (obj.cnt-- == 1) {
985
+ obj.a = 0;
986
+ return true;
987
+ }
988
+ const ret = false;
989
+ return ret;
990
+ };
991
+ imports.wbg.__wbindgen_closure_wrapper303 = function(arg0, arg1, arg2) {
992
+ const ret = makeMutClosure(arg0, arg1, 39, __wbg_adapter_56);
993
+ return ret;
994
+ };
995
+ imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
996
+ const ret = debugString(arg1);
997
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
998
+ const len1 = WASM_VECTOR_LEN;
999
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1000
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1001
+ };
1002
+ imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
1003
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
1004
+ return ret;
1005
+ };
1006
+ imports.wbg.__wbindgen_in = function(arg0, arg1) {
1007
+ const ret = arg0 in arg1;
1008
+ return ret;
1009
+ };
1010
+ imports.wbg.__wbindgen_init_externref_table = function() {
1011
+ const table = wasm.__wbindgen_export_4;
1012
+ const offset = table.grow(4);
1013
+ table.set(0, undefined);
1014
+ table.set(offset + 0, undefined);
1015
+ table.set(offset + 1, null);
1016
+ table.set(offset + 2, true);
1017
+ table.set(offset + 3, false);
1018
+ ;
1019
+ };
1020
+ imports.wbg.__wbindgen_is_bigint = function(arg0) {
1021
+ const ret = typeof(arg0) === 'bigint';
1022
+ return ret;
1023
+ };
1024
+ imports.wbg.__wbindgen_is_function = function(arg0) {
1025
+ const ret = typeof(arg0) === 'function';
1026
+ return ret;
1027
+ };
1028
+ imports.wbg.__wbindgen_is_null = function(arg0) {
1029
+ const ret = arg0 === null;
1030
+ return ret;
1031
+ };
1032
+ imports.wbg.__wbindgen_is_object = function(arg0) {
1033
+ const val = arg0;
1034
+ const ret = typeof(val) === 'object' && val !== null;
1035
+ return ret;
1036
+ };
1037
+ imports.wbg.__wbindgen_is_string = function(arg0) {
1038
+ const ret = typeof(arg0) === 'string';
1039
+ return ret;
1040
+ };
1041
+ imports.wbg.__wbindgen_is_undefined = function(arg0) {
1042
+ const ret = arg0 === undefined;
1043
+ return ret;
1044
+ };
1045
+ imports.wbg.__wbindgen_jsval_eq = function(arg0, arg1) {
1046
+ const ret = arg0 === arg1;
1047
+ return ret;
1048
+ };
1049
+ imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
1050
+ const ret = arg0 == arg1;
1051
+ return ret;
1052
+ };
1053
+ imports.wbg.__wbindgen_memory = function() {
1054
+ const ret = wasm.memory;
1055
+ return ret;
1056
+ };
1057
+ imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
1058
+ const obj = arg1;
1059
+ const ret = typeof(obj) === 'number' ? obj : undefined;
1060
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
1061
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1062
+ };
1063
+ imports.wbg.__wbindgen_number_new = function(arg0) {
1064
+ const ret = arg0;
1065
+ return ret;
1066
+ };
1067
+ imports.wbg.__wbindgen_rethrow = function(arg0) {
1068
+ throw arg0;
1069
+ };
1070
+ imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
1071
+ const obj = arg1;
1072
+ const ret = typeof(obj) === 'string' ? obj : undefined;
1073
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1074
+ var len1 = WASM_VECTOR_LEN;
1075
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1076
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1077
+ };
1078
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
1079
+ const ret = getStringFromWasm0(arg0, arg1);
1080
+ return ret;
1081
+ };
1082
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
1083
+ throw new Error(getStringFromWasm0(arg0, arg1));
1084
+ };
1085
+
1086
+ return imports;
1087
+ }
1088
+
1089
+ function __wbg_init_memory(imports, memory) {
1090
+
1091
+ }
1092
+
1093
+ function __wbg_finalize_init(instance, module) {
1094
+ wasm = instance.exports;
1095
+ __wbg_init.__wbindgen_wasm_module = module;
1096
+ cachedDataViewMemory0 = null;
1097
+ cachedUint8ArrayMemory0 = null;
1098
+
1099
+
1100
+ wasm.__wbindgen_start();
1101
+ return wasm;
1102
+ }
1103
+
1104
+ function initSync(module) {
1105
+ if (wasm !== undefined) return wasm;
1106
+
1107
+
1108
+ if (typeof module !== 'undefined') {
1109
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1110
+ ({module} = module)
1111
+ } else {
1112
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1113
+ }
1114
+ }
1115
+
1116
+ const imports = __wbg_get_imports();
1117
+
1118
+ __wbg_init_memory(imports);
1119
+
1120
+ if (!(module instanceof WebAssembly.Module)) {
1121
+ module = new WebAssembly.Module(module);
1122
+ }
1123
+
1124
+ const instance = new WebAssembly.Instance(module, imports);
1125
+
1126
+ return __wbg_finalize_init(instance, module);
1127
+ }
1128
+
1129
+ async function __wbg_init(module_or_path) {
1130
+ if (wasm !== undefined) return wasm;
1131
+
1132
+
1133
+ if (typeof module_or_path !== 'undefined') {
1134
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1135
+ ({module_or_path} = module_or_path)
1136
+ } else {
1137
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1138
+ }
1139
+ }
1140
+
1141
+ if (typeof module_or_path === 'undefined') {
1142
+ module_or_path = new URL('flock_wasm_bg.wasm', import.meta.url);
1143
+ }
1144
+ const imports = __wbg_get_imports();
1145
+
1146
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1147
+ module_or_path = fetch(module_or_path);
1148
+ }
1149
+
1150
+ __wbg_init_memory(imports);
1151
+
1152
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1153
+
1154
+ return __wbg_finalize_init(instance, module);
1155
+ }
1156
+
1157
+ export { initSync };
1158
+ export default __wbg_init;