@loro-dev/flock-wasm 0.1.5 → 0.2.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.
@@ -55,6 +55,7 @@ export class RawFlock {
55
55
  * Returns an error if arguments are invalid or serialization fails.
56
56
  */
57
57
  exportJson(from: any, prune_tombstones_before: any, peer_id: any): any;
58
+ importFile(bytes: Uint8Array): void;
58
59
  /**
59
60
  * Imports a JSON bundle into this flock instance.
60
61
  *
@@ -62,15 +63,11 @@ export class RawFlock {
62
63
  *
63
64
  * * `bundle` - The export bundle to import
64
65
  *
65
- * # Returns
66
- *
67
- * An import report containing counts of accepted and skipped entries.
68
- *
69
66
  * # Errors
70
67
  *
71
68
  * Returns an error if the bundle is invalid or import fails.
72
69
  */
73
- importJson(bundle: any): any;
70
+ importJson(bundle: any): void;
74
71
  /**
75
72
  * Sets a new peer ID for this flock instance.
76
73
  *
@@ -205,15 +202,11 @@ export class RawFlock {
205
202
  *
206
203
  * * `other` - The other flock instance to merge from
207
204
  *
208
- * # Returns
209
- *
210
- * An import report containing counts of accepted and skipped entries.
211
- *
212
205
  * # Errors
213
206
  *
214
207
  * Returns an error if the merge operation fails.
215
208
  */
216
- merge(other: RawFlock): any;
209
+ merge(other: RawFlock): void;
217
210
  /**
218
211
  * Deletes the value at the specified key (creates a tombstone).
219
212
  *
@@ -244,6 +237,7 @@ export class RawFlock {
244
237
  * Returns an error if serialization fails.
245
238
  */
246
239
  version(): any;
240
+ isEmpty(): boolean;
247
241
  /**
248
242
  * Creates a new flock instance from a file bytes array.
249
243
  *
@@ -239,20 +239,20 @@ function getArrayU8FromWasm0(ptr, len) {
239
239
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
240
240
  }
241
241
 
242
- function _assertClass(instance, klass) {
243
- if (!(instance instanceof klass)) {
244
- throw new Error(`expected instance of ${klass.name}`);
245
- }
246
- }
247
-
248
242
  function passArray8ToWasm0(arg, malloc) {
249
243
  const ptr = malloc(arg.length * 1, 1) >>> 0;
250
244
  getUint8ArrayMemory0().set(arg, ptr / 1);
251
245
  WASM_VECTOR_LEN = arg.length;
252
246
  return ptr;
253
247
  }
248
+
249
+ function _assertClass(instance, klass) {
250
+ if (!(instance instanceof klass)) {
251
+ throw new Error(`expected instance of ${klass.name}`);
252
+ }
253
+ }
254
254
  function __wbg_adapter_56(arg0, arg1, arg2) {
255
- wasm.closure43_externref_shim(arg0, arg1, arg2);
255
+ wasm.closure32_externref_shim(arg0, arg1, arg2);
256
256
  }
257
257
 
258
258
  const RawFlockFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -341,6 +341,17 @@ export class RawFlock {
341
341
  }
342
342
  return takeFromExternrefTable0(ret[0]);
343
343
  }
344
+ /**
345
+ * @param {Uint8Array} bytes
346
+ */
347
+ importFile(bytes) {
348
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
349
+ const len0 = WASM_VECTOR_LEN;
350
+ const ret = wasm.rawflock_importFile(this.__wbg_ptr, ptr0, len0);
351
+ if (ret[1]) {
352
+ throw takeFromExternrefTable0(ret[0]);
353
+ }
354
+ }
344
355
  /**
345
356
  * Imports a JSON bundle into this flock instance.
346
357
  *
@@ -348,22 +359,16 @@ export class RawFlock {
348
359
  *
349
360
  * * `bundle` - The export bundle to import
350
361
  *
351
- * # Returns
352
- *
353
- * An import report containing counts of accepted and skipped entries.
354
- *
355
362
  * # Errors
356
363
  *
357
364
  * Returns an error if the bundle is invalid or import fails.
358
365
  * @param {any} bundle
359
- * @returns {any}
360
366
  */
361
367
  importJson(bundle) {
362
368
  const ret = wasm.rawflock_importJson(this.__wbg_ptr, bundle);
363
- if (ret[2]) {
364
- throw takeFromExternrefTable0(ret[1]);
369
+ if (ret[1]) {
370
+ throw takeFromExternrefTable0(ret[0]);
365
371
  }
366
- return takeFromExternrefTable0(ret[0]);
367
372
  }
368
373
  /**
369
374
  * Sets a new peer ID for this flock instance.
@@ -571,23 +576,17 @@ export class RawFlock {
571
576
  *
572
577
  * * `other` - The other flock instance to merge from
573
578
  *
574
- * # Returns
575
- *
576
- * An import report containing counts of accepted and skipped entries.
577
- *
578
579
  * # Errors
579
580
  *
580
581
  * Returns an error if the merge operation fails.
581
582
  * @param {RawFlock} other
582
- * @returns {any}
583
583
  */
584
584
  merge(other) {
585
585
  _assertClass(other, RawFlock);
586
586
  const ret = wasm.rawflock_merge(this.__wbg_ptr, other.__wbg_ptr);
587
- if (ret[2]) {
588
- throw takeFromExternrefTable0(ret[1]);
587
+ if (ret[1]) {
588
+ throw takeFromExternrefTable0(ret[0]);
589
589
  }
590
- return takeFromExternrefTable0(ret[0]);
591
590
  }
592
591
  /**
593
592
  * Deletes the value at the specified key (creates a tombstone).
@@ -645,6 +644,13 @@ export class RawFlock {
645
644
  }
646
645
  return takeFromExternrefTable0(ret[0]);
647
646
  }
647
+ /**
648
+ * @returns {boolean}
649
+ */
650
+ isEmpty() {
651
+ const ret = wasm.rawflock_isEmpty(this.__wbg_ptr);
652
+ return ret !== 0;
653
+ }
648
654
  /**
649
655
  * Creates a new flock instance from a file bytes array.
650
656
  *
@@ -1008,8 +1014,8 @@ export function __wbindgen_cb_drop(arg0) {
1008
1014
  return ret;
1009
1015
  };
1010
1016
 
1011
- export function __wbindgen_closure_wrapper303(arg0, arg1, arg2) {
1012
- const ret = makeMutClosure(arg0, arg1, 44, __wbg_adapter_56);
1017
+ export function __wbindgen_closure_wrapper229(arg0, arg1, arg2) {
1018
+ const ret = makeMutClosure(arg0, arg1, 33, __wbg_adapter_56);
1013
1019
  return ret;
1014
1020
  };
1015
1021
 
Binary file
@@ -11,10 +11,12 @@ export const rawflock_fromJson: (a: any, b: number, c: number) => [number, numbe
11
11
  export const rawflock_get: (a: number, b: any) => [number, number, number];
12
12
  export const rawflock_getEntry: (a: number, b: any) => [number, number, number];
13
13
  export const rawflock_getMaxPhysicalTime: (a: number) => number;
14
- export const rawflock_importJson: (a: number, b: any) => [number, number, number];
14
+ export const rawflock_importFile: (a: number, b: number, c: number) => [number, number];
15
+ export const rawflock_importJson: (a: number, b: any) => [number, number];
15
16
  export const rawflock_inclusiveVersion: (a: number) => [number, number, number];
17
+ export const rawflock_isEmpty: (a: number) => number;
16
18
  export const rawflock_isInTxn: (a: number) => number;
17
- export const rawflock_merge: (a: number, b: number) => [number, number, number];
19
+ export const rawflock_merge: (a: number, b: number) => [number, number];
18
20
  export const rawflock_new: (a: number, b: number) => [number, number, number];
19
21
  export const rawflock_peerId: (a: number) => [number, number];
20
22
  export const rawflock_put: (a: number, b: any, c: any, d: any) => [number, number];
@@ -36,5 +38,5 @@ export const __wbindgen_export_4: WebAssembly.Table;
36
38
  export const __wbindgen_free: (a: number, b: number, c: number) => void;
37
39
  export const __wbindgen_export_6: WebAssembly.Table;
38
40
  export const __externref_table_dealloc: (a: number) => void;
39
- export const closure43_externref_shim: (a: number, b: number, c: any) => void;
41
+ export const closure32_externref_shim: (a: number, b: number, c: any) => void;
40
42
  export const __wbindgen_start: () => void;
@@ -67,13 +67,6 @@ export type ImportDecision = ImportAccept | ImportSkip | ImportPayload | void;
67
67
  export type ImportHooks = {
68
68
  preprocess?: (context: ImportHookContext, payload: ImportPayload) => MaybePromise<ImportDecision>;
69
69
  };
70
- export type ImportReport = {
71
- accepted: number;
72
- skipped: Array<{
73
- key: KeyPart[];
74
- reason: string;
75
- }>;
76
- };
77
70
  export type PutPayload = ExportPayload;
78
71
  export type PutHookContext = {
79
72
  key: KeyPart[];
@@ -126,6 +119,7 @@ export declare class Flock {
126
119
  private static fromInner;
127
120
  static fromJson(bundle: ExportBundle, peerId: string): Flock;
128
121
  static fromFile(bytes: Uint8Array, peerId?: string): Flock;
122
+ isEmpty(): boolean;
129
123
  checkInvariants(): void;
130
124
  setPeerId(peerId: string): void;
131
125
  private putWithMetaInternal;
@@ -183,9 +177,10 @@ export declare class Flock {
183
177
  exportJson(options: ExportOptions): Promise<ExportBundle>;
184
178
  private importJsonInternal;
185
179
  private importJsonWithHooks;
186
- importJson(bundle: ExportBundle): ImportReport;
187
- importJson(options: ImportOptions): Promise<ImportReport>;
188
- importJsonStr(bundle: string): ImportReport;
180
+ importJson(bundle: ExportBundle): void;
181
+ importJson(options: ImportOptions): Promise<void>;
182
+ importFile(bytes: Uint8Array): void;
183
+ importJsonStr(bundle: string): void;
189
184
  getMaxPhysicalTime(): number;
190
185
  peerId(): string;
191
186
  kvToJson(): ExportBundle;
package/bundler/index.js CHANGED
@@ -502,20 +502,6 @@ function normalizeImportDecision(decision) {
502
502
  }
503
503
  return { accept: true };
504
504
  }
505
- function decodeImportReport(raw) {
506
- if (!raw || typeof raw !== "object") {
507
- return { accepted: 0, skipped: [] };
508
- }
509
- const report = raw;
510
- const accepted = typeof report.accepted === "number" ? report.accepted : 0;
511
- const skippedRaw = Array.isArray(report.skipped) ? report.skipped : [];
512
- const skipped = skippedRaw.map((entry) => {
513
- const key = entry && Array.isArray(entry.key) ? entry.key : [];
514
- const reason = entry && typeof entry.reason === "string" ? entry.reason : "unknown";
515
- return { key, reason };
516
- });
517
- return { accepted, skipped };
518
- }
519
505
  function cloneBundle(bundle) {
520
506
  const next = { version: bundle.version, entries: {} };
521
507
  for (const [key, record] of Object.entries(bundle.entries)) {
@@ -576,6 +562,9 @@ export class Flock {
576
562
  const inner = RawFlock.fromFile(normalizePeerId(peerId), bytes);
577
563
  return Flock.fromInner(inner);
578
564
  }
565
+ isEmpty() {
566
+ return this.inner.isEmpty();
567
+ }
579
568
  checkInvariants() {
580
569
  void this.version();
581
570
  void this.inclusiveVersion();
@@ -647,7 +636,7 @@ export class Flock {
647
636
  }
648
637
  merge(other) {
649
638
  this.eventBatcher.beforeImport();
650
- void this.inner.merge(other.inner);
639
+ this.inner.merge(other.inner);
651
640
  }
652
641
  /**
653
642
  * Returns the exclusive/visible version vector.
@@ -706,13 +695,11 @@ export class Flock {
706
695
  }
707
696
  importJsonInternal(bundle) {
708
697
  this.eventBatcher.beforeImport();
709
- const report = this.inner.importJson(bundle);
710
- return decodeImportReport(report);
698
+ this.inner.importJson(bundle);
711
699
  }
712
700
  async importJsonWithHooks(options) {
713
701
  const preprocess = options.hooks?.preprocess;
714
702
  const working = preprocess ? cloneBundle(options.bundle) : options.bundle;
715
- const skippedByHooks = [];
716
703
  if (preprocess) {
717
704
  for (const key of Object.keys(working.entries)) {
718
705
  const record = working.entries[key];
@@ -724,18 +711,13 @@ export class Flock {
724
711
  const decision = await preprocess(context, clonePayload(basePayload));
725
712
  const normalized = normalizeImportDecision(decision);
726
713
  if (!normalized.accept) {
727
- skippedByHooks.push({ key: context.key, reason: normalized.reason });
728
714
  delete working.entries[key];
729
715
  continue;
730
716
  }
731
717
  working.entries[key] = buildRecord(record.c, basePayload);
732
718
  }
733
719
  }
734
- const coreReport = this.importJsonInternal(working);
735
- return {
736
- accepted: coreReport.accepted,
737
- skipped: skippedByHooks.concat(coreReport.skipped),
738
- };
720
+ this.importJsonInternal(working);
739
721
  }
740
722
  importJson(arg) {
741
723
  if (isImportOptions(arg)) {
@@ -743,9 +725,13 @@ export class Flock {
743
725
  }
744
726
  return this.importJsonInternal(arg);
745
727
  }
728
+ importFile(bytes) {
729
+ this.eventBatcher.beforeImport();
730
+ this.inner.importFile(bytes);
731
+ }
746
732
  importJsonStr(bundle) {
747
733
  const parsed = JSON.parse(bundle);
748
- return this.importJson(parsed);
734
+ this.importJson(parsed);
749
735
  }
750
736
  getMaxPhysicalTime() {
751
737
  return Number(this.inner.getMaxPhysicalTime());
package/bundler/wasm.d.ts CHANGED
@@ -2,6 +2,7 @@ export declare class RawFlock {
2
2
  constructor(peerId: string);
3
3
  static fromJson(bundle: unknown, peerId: string): RawFlock;
4
4
  static fromFile(peerId: string, bytes: Uint8Array): RawFlock;
5
+ isEmpty(): boolean;
5
6
  peerId(): string;
6
7
  setPeerId(peerId: string): void;
7
8
  getMaxPhysicalTime(): number;
@@ -21,8 +22,9 @@ export declare class RawFlock {
21
22
  pruneTombstonesBefore?: number,
22
23
  peerId?: string,
23
24
  ): unknown;
24
- importJson(bundle: unknown): unknown;
25
- merge(other: RawFlock): unknown;
25
+ importJson(bundle: unknown): void;
26
+ importFile(bytes: Uint8Array): void;
27
+ merge(other: RawFlock): void;
26
28
  version(): unknown;
27
29
  inclusiveVersion(): unknown;
28
30
  exportFile(): Uint8Array;
@@ -55,6 +55,7 @@ export class RawFlock {
55
55
  * Returns an error if arguments are invalid or serialization fails.
56
56
  */
57
57
  exportJson(from: any, prune_tombstones_before: any, peer_id: any): any;
58
+ importFile(bytes: Uint8Array): void;
58
59
  /**
59
60
  * Imports a JSON bundle into this flock instance.
60
61
  *
@@ -62,15 +63,11 @@ export class RawFlock {
62
63
  *
63
64
  * * `bundle` - The export bundle to import
64
65
  *
65
- * # Returns
66
- *
67
- * An import report containing counts of accepted and skipped entries.
68
- *
69
66
  * # Errors
70
67
  *
71
68
  * Returns an error if the bundle is invalid or import fails.
72
69
  */
73
- importJson(bundle: any): any;
70
+ importJson(bundle: any): void;
74
71
  /**
75
72
  * Sets a new peer ID for this flock instance.
76
73
  *
@@ -205,15 +202,11 @@ export class RawFlock {
205
202
  *
206
203
  * * `other` - The other flock instance to merge from
207
204
  *
208
- * # Returns
209
- *
210
- * An import report containing counts of accepted and skipped entries.
211
- *
212
205
  * # Errors
213
206
  *
214
207
  * Returns an error if the merge operation fails.
215
208
  */
216
- merge(other: RawFlock): any;
209
+ merge(other: RawFlock): void;
217
210
  /**
218
211
  * Deletes the value at the specified key (creates a tombstone).
219
212
  *
@@ -244,6 +237,7 @@ export class RawFlock {
244
237
  * Returns an error if serialization fails.
245
238
  */
246
239
  version(): any;
240
+ isEmpty(): boolean;
247
241
  /**
248
242
  * Creates a new flock instance from a file bytes array.
249
243
  *
@@ -235,20 +235,20 @@ function getArrayU8FromWasm0(ptr, len) {
235
235
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
236
236
  }
237
237
 
238
- function _assertClass(instance, klass) {
239
- if (!(instance instanceof klass)) {
240
- throw new Error(`expected instance of ${klass.name}`);
241
- }
242
- }
243
-
244
238
  function passArray8ToWasm0(arg, malloc) {
245
239
  const ptr = malloc(arg.length * 1, 1) >>> 0;
246
240
  getUint8ArrayMemory0().set(arg, ptr / 1);
247
241
  WASM_VECTOR_LEN = arg.length;
248
242
  return ptr;
249
243
  }
244
+
245
+ function _assertClass(instance, klass) {
246
+ if (!(instance instanceof klass)) {
247
+ throw new Error(`expected instance of ${klass.name}`);
248
+ }
249
+ }
250
250
  function __wbg_adapter_56(arg0, arg1, arg2) {
251
- wasm.closure43_externref_shim(arg0, arg1, arg2);
251
+ wasm.closure32_externref_shim(arg0, arg1, arg2);
252
252
  }
253
253
 
254
254
  const RawFlockFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -337,6 +337,17 @@ class RawFlock {
337
337
  }
338
338
  return takeFromExternrefTable0(ret[0]);
339
339
  }
340
+ /**
341
+ * @param {Uint8Array} bytes
342
+ */
343
+ importFile(bytes) {
344
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
345
+ const len0 = WASM_VECTOR_LEN;
346
+ const ret = wasm.rawflock_importFile(this.__wbg_ptr, ptr0, len0);
347
+ if (ret[1]) {
348
+ throw takeFromExternrefTable0(ret[0]);
349
+ }
350
+ }
340
351
  /**
341
352
  * Imports a JSON bundle into this flock instance.
342
353
  *
@@ -344,22 +355,16 @@ class RawFlock {
344
355
  *
345
356
  * * `bundle` - The export bundle to import
346
357
  *
347
- * # Returns
348
- *
349
- * An import report containing counts of accepted and skipped entries.
350
- *
351
358
  * # Errors
352
359
  *
353
360
  * Returns an error if the bundle is invalid or import fails.
354
361
  * @param {any} bundle
355
- * @returns {any}
356
362
  */
357
363
  importJson(bundle) {
358
364
  const ret = wasm.rawflock_importJson(this.__wbg_ptr, bundle);
359
- if (ret[2]) {
360
- throw takeFromExternrefTable0(ret[1]);
365
+ if (ret[1]) {
366
+ throw takeFromExternrefTable0(ret[0]);
361
367
  }
362
- return takeFromExternrefTable0(ret[0]);
363
368
  }
364
369
  /**
365
370
  * Sets a new peer ID for this flock instance.
@@ -567,23 +572,17 @@ class RawFlock {
567
572
  *
568
573
  * * `other` - The other flock instance to merge from
569
574
  *
570
- * # Returns
571
- *
572
- * An import report containing counts of accepted and skipped entries.
573
- *
574
575
  * # Errors
575
576
  *
576
577
  * Returns an error if the merge operation fails.
577
578
  * @param {RawFlock} other
578
- * @returns {any}
579
579
  */
580
580
  merge(other) {
581
581
  _assertClass(other, RawFlock);
582
582
  const ret = wasm.rawflock_merge(this.__wbg_ptr, other.__wbg_ptr);
583
- if (ret[2]) {
584
- throw takeFromExternrefTable0(ret[1]);
583
+ if (ret[1]) {
584
+ throw takeFromExternrefTable0(ret[0]);
585
585
  }
586
- return takeFromExternrefTable0(ret[0]);
587
586
  }
588
587
  /**
589
588
  * Deletes the value at the specified key (creates a tombstone).
@@ -641,6 +640,13 @@ class RawFlock {
641
640
  }
642
641
  return takeFromExternrefTable0(ret[0]);
643
642
  }
643
+ /**
644
+ * @returns {boolean}
645
+ */
646
+ isEmpty() {
647
+ const ret = wasm.rawflock_isEmpty(this.__wbg_ptr);
648
+ return ret !== 0;
649
+ }
644
650
  /**
645
651
  * Creates a new flock instance from a file bytes array.
646
652
  *
@@ -1005,8 +1011,8 @@ module.exports.__wbindgen_cb_drop = function(arg0) {
1005
1011
  return ret;
1006
1012
  };
1007
1013
 
1008
- module.exports.__wbindgen_closure_wrapper303 = function(arg0, arg1, arg2) {
1009
- const ret = makeMutClosure(arg0, arg1, 44, __wbg_adapter_56);
1014
+ module.exports.__wbindgen_closure_wrapper229 = function(arg0, arg1, arg2) {
1015
+ const ret = makeMutClosure(arg0, arg1, 33, __wbg_adapter_56);
1010
1016
  return ret;
1011
1017
  };
1012
1018
 
Binary file
@@ -11,10 +11,12 @@ export const rawflock_fromJson: (a: any, b: number, c: number) => [number, numbe
11
11
  export const rawflock_get: (a: number, b: any) => [number, number, number];
12
12
  export const rawflock_getEntry: (a: number, b: any) => [number, number, number];
13
13
  export const rawflock_getMaxPhysicalTime: (a: number) => number;
14
- export const rawflock_importJson: (a: number, b: any) => [number, number, number];
14
+ export const rawflock_importFile: (a: number, b: number, c: number) => [number, number];
15
+ export const rawflock_importJson: (a: number, b: any) => [number, number];
15
16
  export const rawflock_inclusiveVersion: (a: number) => [number, number, number];
17
+ export const rawflock_isEmpty: (a: number) => number;
16
18
  export const rawflock_isInTxn: (a: number) => number;
17
- export const rawflock_merge: (a: number, b: number) => [number, number, number];
19
+ export const rawflock_merge: (a: number, b: number) => [number, number];
18
20
  export const rawflock_new: (a: number, b: number) => [number, number, number];
19
21
  export const rawflock_peerId: (a: number) => [number, number];
20
22
  export const rawflock_put: (a: number, b: any, c: any, d: any) => [number, number];
@@ -36,5 +38,5 @@ export const __wbindgen_export_4: WebAssembly.Table;
36
38
  export const __wbindgen_free: (a: number, b: number, c: number) => void;
37
39
  export const __wbindgen_export_6: WebAssembly.Table;
38
40
  export const __externref_table_dealloc: (a: number) => void;
39
- export const closure43_externref_shim: (a: number, b: number, c: any) => void;
41
+ export const closure32_externref_shim: (a: number, b: number, c: any) => void;
40
42
  export const __wbindgen_start: () => void;
package/nodejs/index.d.ts CHANGED
@@ -67,13 +67,6 @@ export type ImportDecision = ImportAccept | ImportSkip | ImportPayload | void;
67
67
  export type ImportHooks = {
68
68
  preprocess?: (context: ImportHookContext, payload: ImportPayload) => MaybePromise<ImportDecision>;
69
69
  };
70
- export type ImportReport = {
71
- accepted: number;
72
- skipped: Array<{
73
- key: KeyPart[];
74
- reason: string;
75
- }>;
76
- };
77
70
  export type PutPayload = ExportPayload;
78
71
  export type PutHookContext = {
79
72
  key: KeyPart[];
@@ -126,6 +119,7 @@ export declare class Flock {
126
119
  private static fromInner;
127
120
  static fromJson(bundle: ExportBundle, peerId: string): Flock;
128
121
  static fromFile(bytes: Uint8Array, peerId?: string): Flock;
122
+ isEmpty(): boolean;
129
123
  checkInvariants(): void;
130
124
  setPeerId(peerId: string): void;
131
125
  private putWithMetaInternal;
@@ -183,9 +177,10 @@ export declare class Flock {
183
177
  exportJson(options: ExportOptions): Promise<ExportBundle>;
184
178
  private importJsonInternal;
185
179
  private importJsonWithHooks;
186
- importJson(bundle: ExportBundle): ImportReport;
187
- importJson(options: ImportOptions): Promise<ImportReport>;
188
- importJsonStr(bundle: string): ImportReport;
180
+ importJson(bundle: ExportBundle): void;
181
+ importJson(options: ImportOptions): Promise<void>;
182
+ importFile(bytes: Uint8Array): void;
183
+ importJsonStr(bundle: string): void;
189
184
  getMaxPhysicalTime(): number;
190
185
  peerId(): string;
191
186
  kvToJson(): ExportBundle;
package/nodejs/index.js CHANGED
@@ -507,20 +507,6 @@ function normalizeImportDecision(decision) {
507
507
  }
508
508
  return { accept: true };
509
509
  }
510
- function decodeImportReport(raw) {
511
- if (!raw || typeof raw !== "object") {
512
- return { accepted: 0, skipped: [] };
513
- }
514
- const report = raw;
515
- const accepted = typeof report.accepted === "number" ? report.accepted : 0;
516
- const skippedRaw = Array.isArray(report.skipped) ? report.skipped : [];
517
- const skipped = skippedRaw.map((entry) => {
518
- const key = entry && Array.isArray(entry.key) ? entry.key : [];
519
- const reason = entry && typeof entry.reason === "string" ? entry.reason : "unknown";
520
- return { key, reason };
521
- });
522
- return { accepted, skipped };
523
- }
524
510
  function cloneBundle(bundle) {
525
511
  const next = { version: bundle.version, entries: {} };
526
512
  for (const [key, record] of Object.entries(bundle.entries)) {
@@ -581,6 +567,9 @@ class Flock {
581
567
  const inner = wasm_js_1.RawFlock.fromFile(normalizePeerId(peerId), bytes);
582
568
  return Flock.fromInner(inner);
583
569
  }
570
+ isEmpty() {
571
+ return this.inner.isEmpty();
572
+ }
584
573
  checkInvariants() {
585
574
  void this.version();
586
575
  void this.inclusiveVersion();
@@ -652,7 +641,7 @@ class Flock {
652
641
  }
653
642
  merge(other) {
654
643
  this.eventBatcher.beforeImport();
655
- void this.inner.merge(other.inner);
644
+ this.inner.merge(other.inner);
656
645
  }
657
646
  /**
658
647
  * Returns the exclusive/visible version vector.
@@ -711,13 +700,11 @@ class Flock {
711
700
  }
712
701
  importJsonInternal(bundle) {
713
702
  this.eventBatcher.beforeImport();
714
- const report = this.inner.importJson(bundle);
715
- return decodeImportReport(report);
703
+ this.inner.importJson(bundle);
716
704
  }
717
705
  async importJsonWithHooks(options) {
718
706
  const preprocess = options.hooks?.preprocess;
719
707
  const working = preprocess ? cloneBundle(options.bundle) : options.bundle;
720
- const skippedByHooks = [];
721
708
  if (preprocess) {
722
709
  for (const key of Object.keys(working.entries)) {
723
710
  const record = working.entries[key];
@@ -729,18 +716,13 @@ class Flock {
729
716
  const decision = await preprocess(context, clonePayload(basePayload));
730
717
  const normalized = normalizeImportDecision(decision);
731
718
  if (!normalized.accept) {
732
- skippedByHooks.push({ key: context.key, reason: normalized.reason });
733
719
  delete working.entries[key];
734
720
  continue;
735
721
  }
736
722
  working.entries[key] = buildRecord(record.c, basePayload);
737
723
  }
738
724
  }
739
- const coreReport = this.importJsonInternal(working);
740
- return {
741
- accepted: coreReport.accepted,
742
- skipped: skippedByHooks.concat(coreReport.skipped),
743
- };
725
+ this.importJsonInternal(working);
744
726
  }
745
727
  importJson(arg) {
746
728
  if (isImportOptions(arg)) {
@@ -748,9 +730,13 @@ class Flock {
748
730
  }
749
731
  return this.importJsonInternal(arg);
750
732
  }
733
+ importFile(bytes) {
734
+ this.eventBatcher.beforeImport();
735
+ this.inner.importFile(bytes);
736
+ }
751
737
  importJsonStr(bundle) {
752
738
  const parsed = JSON.parse(bundle);
753
- return this.importJson(parsed);
739
+ this.importJson(parsed);
754
740
  }
755
741
  getMaxPhysicalTime() {
756
742
  return Number(this.inner.getMaxPhysicalTime());
package/nodejs/wasm.d.ts CHANGED
@@ -2,6 +2,7 @@ export declare class RawFlock {
2
2
  constructor(peerId: string);
3
3
  static fromJson(bundle: unknown, peerId: string): RawFlock;
4
4
  static fromFile(peerId: string, bytes: Uint8Array): RawFlock;
5
+ isEmpty(): boolean;
5
6
  peerId(): string;
6
7
  setPeerId(peerId: string): void;
7
8
  getMaxPhysicalTime(): number;
@@ -21,8 +22,9 @@ export declare class RawFlock {
21
22
  pruneTombstonesBefore?: number,
22
23
  peerId?: string,
23
24
  ): unknown;
24
- importJson(bundle: unknown): unknown;
25
- merge(other: RawFlock): unknown;
25
+ importJson(bundle: unknown): void;
26
+ importFile(bytes: Uint8Array): void;
27
+ merge(other: RawFlock): void;
26
28
  version(): unknown;
27
29
  inclusiveVersion(): unknown;
28
30
  exportFile(): Uint8Array;