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