@loro-dev/flock-wasm 0.1.4 → 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.
- package/README.md +10 -19
- package/base64/flock_wasm.js +41 -35
- package/base64/index.d.ts +5 -10
- package/base64/index.js +12 -26
- package/base64/wasm.d.ts +4 -2
- package/base64/wasm.js +1 -1
- package/bundler/flock_wasm.d.ts +11 -17
- package/bundler/flock_wasm_bg.js +41 -35
- package/bundler/flock_wasm_bg.wasm +0 -0
- package/bundler/flock_wasm_bg.wasm.d.ts +5 -3
- package/bundler/index.d.ts +5 -10
- package/bundler/index.js +12 -26
- package/bundler/wasm.d.ts +4 -2
- package/nodejs/flock_wasm.d.ts +11 -17
- package/nodejs/flock_wasm.js +41 -35
- package/nodejs/flock_wasm_bg.wasm +0 -0
- package/nodejs/flock_wasm_bg.wasm.d.ts +5 -3
- package/nodejs/index.d.ts +5 -10
- package/nodejs/index.js +12 -26
- package/nodejs/wasm.d.ts +4 -2
- package/package.json +1 -1
- package/web/flock_wasm.d.ts +16 -20
- package/web/flock_wasm.js +41 -35
- package/web/flock_wasm_bg.wasm +0 -0
- package/web/flock_wasm_bg.wasm.d.ts +5 -3
- package/web/index.d.ts +5 -10
- package/web/index.js +12 -26
- package/web/wasm.d.ts +4 -2
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):
|
|
187
|
-
importJson(options: ImportOptions): Promise<
|
|
188
|
-
|
|
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
|
@@ -246,7 +246,7 @@ function decodeVersionVectorBinary(bytes) {
|
|
|
246
246
|
return decodeLegacyVersionVector(bytes);
|
|
247
247
|
}
|
|
248
248
|
function encodeVersionVectorForFfi(vv) {
|
|
249
|
-
if (!vv) {
|
|
249
|
+
if (!vv || Object.keys(vv).length === 0) {
|
|
250
250
|
return undefined;
|
|
251
251
|
}
|
|
252
252
|
const raw = {};
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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):
|
|
25
|
-
|
|
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;
|
package/package.json
CHANGED
package/web/flock_wasm.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
/**
|
|
4
|
-
* Initializes the WASM module.
|
|
5
|
-
*
|
|
6
|
-
* This function is automatically called when the WASM module is loaded.
|
|
7
|
-
* It sets up the panic hook to route Rust panics to the JavaScript console.
|
|
8
|
-
*/
|
|
9
|
-
export function start(): void;
|
|
10
3
|
/**
|
|
11
4
|
* Drains the pending callback queue, invoking all enqueued callbacks.
|
|
12
5
|
*
|
|
@@ -17,6 +10,13 @@ export function start(): void;
|
|
|
17
10
|
* the error is propagated to JavaScript after the current batch completes.
|
|
18
11
|
*/
|
|
19
12
|
export function callPendingEvents(): void;
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the WASM module.
|
|
15
|
+
*
|
|
16
|
+
* This function is automatically called when the WASM module is loaded.
|
|
17
|
+
* It sets up the panic hook to route Rust panics to the JavaScript console.
|
|
18
|
+
*/
|
|
19
|
+
export function start(): void;
|
|
20
20
|
/**
|
|
21
21
|
* The main WASM-exposed flock instance.
|
|
22
22
|
*
|
|
@@ -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):
|
|
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):
|
|
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
|
*
|
|
@@ -331,10 +325,12 @@ export interface InitOutput {
|
|
|
331
325
|
readonly rawflock_get: (a: number, b: any) => [number, number, number];
|
|
332
326
|
readonly rawflock_getEntry: (a: number, b: any) => [number, number, number];
|
|
333
327
|
readonly rawflock_getMaxPhysicalTime: (a: number) => number;
|
|
334
|
-
readonly
|
|
328
|
+
readonly rawflock_importFile: (a: number, b: number, c: number) => [number, number];
|
|
329
|
+
readonly rawflock_importJson: (a: number, b: any) => [number, number];
|
|
335
330
|
readonly rawflock_inclusiveVersion: (a: number) => [number, number, number];
|
|
331
|
+
readonly rawflock_isEmpty: (a: number) => number;
|
|
336
332
|
readonly rawflock_isInTxn: (a: number) => number;
|
|
337
|
-
readonly rawflock_merge: (a: number, b: number) => [number, number
|
|
333
|
+
readonly rawflock_merge: (a: number, b: number) => [number, number];
|
|
338
334
|
readonly rawflock_new: (a: number, b: number) => [number, number, number];
|
|
339
335
|
readonly rawflock_peerId: (a: number) => [number, number];
|
|
340
336
|
readonly rawflock_put: (a: number, b: any, c: any, d: any) => [number, number];
|
|
@@ -356,7 +352,7 @@ export interface InitOutput {
|
|
|
356
352
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
357
353
|
readonly __wbindgen_export_6: WebAssembly.Table;
|
|
358
354
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
359
|
-
readonly
|
|
355
|
+
readonly closure32_externref_shim: (a: number, b: number, c: any) => void;
|
|
360
356
|
readonly __wbindgen_start: () => void;
|
|
361
357
|
}
|
|
362
358
|
|
package/web/flock_wasm.js
CHANGED
|
@@ -197,16 +197,6 @@ function debugString(val) {
|
|
|
197
197
|
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
198
198
|
return className;
|
|
199
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
200
|
/**
|
|
211
201
|
* Drains the pending callback queue, invoking all enqueued callbacks.
|
|
212
202
|
*
|
|
@@ -220,6 +210,16 @@ export function callPendingEvents() {
|
|
|
220
210
|
wasm.callPendingEvents();
|
|
221
211
|
}
|
|
222
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Initializes the WASM module.
|
|
215
|
+
*
|
|
216
|
+
* This function is automatically called when the WASM module is loaded.
|
|
217
|
+
* It sets up the panic hook to route Rust panics to the JavaScript console.
|
|
218
|
+
*/
|
|
219
|
+
export function start() {
|
|
220
|
+
wasm.start();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
223
|
function takeFromExternrefTable0(idx) {
|
|
224
224
|
const value = wasm.__wbindgen_export_4.get(idx);
|
|
225
225
|
wasm.__externref_table_dealloc(idx);
|
|
@@ -231,20 +231,20 @@ function getArrayU8FromWasm0(ptr, len) {
|
|
|
231
231
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
function _assertClass(instance, klass) {
|
|
235
|
-
if (!(instance instanceof klass)) {
|
|
236
|
-
throw new Error(`expected instance of ${klass.name}`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
234
|
function passArray8ToWasm0(arg, malloc) {
|
|
241
235
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
242
236
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
243
237
|
WASM_VECTOR_LEN = arg.length;
|
|
244
238
|
return ptr;
|
|
245
239
|
}
|
|
240
|
+
|
|
241
|
+
function _assertClass(instance, klass) {
|
|
242
|
+
if (!(instance instanceof klass)) {
|
|
243
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
246
|
function __wbg_adapter_56(arg0, arg1, arg2) {
|
|
247
|
-
wasm.
|
|
247
|
+
wasm.closure32_externref_shim(arg0, arg1, arg2);
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
const RawFlockFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
@@ -333,6 +333,17 @@ export class RawFlock {
|
|
|
333
333
|
}
|
|
334
334
|
return takeFromExternrefTable0(ret[0]);
|
|
335
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* @param {Uint8Array} bytes
|
|
338
|
+
*/
|
|
339
|
+
importFile(bytes) {
|
|
340
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
341
|
+
const len0 = WASM_VECTOR_LEN;
|
|
342
|
+
const ret = wasm.rawflock_importFile(this.__wbg_ptr, ptr0, len0);
|
|
343
|
+
if (ret[1]) {
|
|
344
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
336
347
|
/**
|
|
337
348
|
* Imports a JSON bundle into this flock instance.
|
|
338
349
|
*
|
|
@@ -340,22 +351,16 @@ export class RawFlock {
|
|
|
340
351
|
*
|
|
341
352
|
* * `bundle` - The export bundle to import
|
|
342
353
|
*
|
|
343
|
-
* # Returns
|
|
344
|
-
*
|
|
345
|
-
* An import report containing counts of accepted and skipped entries.
|
|
346
|
-
*
|
|
347
354
|
* # Errors
|
|
348
355
|
*
|
|
349
356
|
* Returns an error if the bundle is invalid or import fails.
|
|
350
357
|
* @param {any} bundle
|
|
351
|
-
* @returns {any}
|
|
352
358
|
*/
|
|
353
359
|
importJson(bundle) {
|
|
354
360
|
const ret = wasm.rawflock_importJson(this.__wbg_ptr, bundle);
|
|
355
|
-
if (ret[
|
|
356
|
-
throw takeFromExternrefTable0(ret[
|
|
361
|
+
if (ret[1]) {
|
|
362
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
357
363
|
}
|
|
358
|
-
return takeFromExternrefTable0(ret[0]);
|
|
359
364
|
}
|
|
360
365
|
/**
|
|
361
366
|
* Sets a new peer ID for this flock instance.
|
|
@@ -563,23 +568,17 @@ export class RawFlock {
|
|
|
563
568
|
*
|
|
564
569
|
* * `other` - The other flock instance to merge from
|
|
565
570
|
*
|
|
566
|
-
* # Returns
|
|
567
|
-
*
|
|
568
|
-
* An import report containing counts of accepted and skipped entries.
|
|
569
|
-
*
|
|
570
571
|
* # Errors
|
|
571
572
|
*
|
|
572
573
|
* Returns an error if the merge operation fails.
|
|
573
574
|
* @param {RawFlock} other
|
|
574
|
-
* @returns {any}
|
|
575
575
|
*/
|
|
576
576
|
merge(other) {
|
|
577
577
|
_assertClass(other, RawFlock);
|
|
578
578
|
const ret = wasm.rawflock_merge(this.__wbg_ptr, other.__wbg_ptr);
|
|
579
|
-
if (ret[
|
|
580
|
-
throw takeFromExternrefTable0(ret[
|
|
579
|
+
if (ret[1]) {
|
|
580
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
581
581
|
}
|
|
582
|
-
return takeFromExternrefTable0(ret[0]);
|
|
583
582
|
}
|
|
584
583
|
/**
|
|
585
584
|
* Deletes the value at the specified key (creates a tombstone).
|
|
@@ -637,6 +636,13 @@ export class RawFlock {
|
|
|
637
636
|
}
|
|
638
637
|
return takeFromExternrefTable0(ret[0]);
|
|
639
638
|
}
|
|
639
|
+
/**
|
|
640
|
+
* @returns {boolean}
|
|
641
|
+
*/
|
|
642
|
+
isEmpty() {
|
|
643
|
+
const ret = wasm.rawflock_isEmpty(this.__wbg_ptr);
|
|
644
|
+
return ret !== 0;
|
|
645
|
+
}
|
|
640
646
|
/**
|
|
641
647
|
* Creates a new flock instance from a file bytes array.
|
|
642
648
|
*
|
|
@@ -993,8 +999,8 @@ function __wbg_get_imports() {
|
|
|
993
999
|
const ret = false;
|
|
994
1000
|
return ret;
|
|
995
1001
|
};
|
|
996
|
-
imports.wbg.
|
|
997
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
1002
|
+
imports.wbg.__wbindgen_closure_wrapper229 = function(arg0, arg1, arg2) {
|
|
1003
|
+
const ret = makeMutClosure(arg0, arg1, 33, __wbg_adapter_56);
|
|
998
1004
|
return ret;
|
|
999
1005
|
};
|
|
1000
1006
|
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
|
package/web/flock_wasm_bg.wasm
CHANGED
|
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
|
|
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
|
|
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
|
|
41
|
+
export const closure32_externref_shim: (a: number, b: number, c: any) => void;
|
|
40
42
|
export const __wbindgen_start: () => void;
|
package/web/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):
|
|
187
|
-
importJson(options: ImportOptions): Promise<
|
|
188
|
-
|
|
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/web/index.js
CHANGED
|
@@ -241,7 +241,7 @@ function decodeVersionVectorBinary(bytes) {
|
|
|
241
241
|
return decodeLegacyVersionVector(bytes);
|
|
242
242
|
}
|
|
243
243
|
function encodeVersionVectorForFfi(vv) {
|
|
244
|
-
if (!vv) {
|
|
244
|
+
if (!vv || Object.keys(vv).length === 0) {
|
|
245
245
|
return undefined;
|
|
246
246
|
}
|
|
247
247
|
const raw = {};
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
734
|
+
this.importJson(parsed);
|
|
749
735
|
}
|
|
750
736
|
getMaxPhysicalTime() {
|
|
751
737
|
return Number(this.inner.getMaxPhysicalTime());
|
package/web/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):
|
|
25
|
-
|
|
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;
|