@1sat/wallet-browser 0.0.19 → 0.0.20
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/package.json +1 -1
- package/dist/fullSync.d.ts +0 -58
- package/dist/fullSync.d.ts.map +0 -1
- package/dist/fullSync.js +0 -92
- package/dist/fullSync.js.map +0 -1
package/package.json
CHANGED
package/dist/fullSync.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Full wallet synchronization with remote backup server.
|
|
3
|
-
*
|
|
4
|
-
* Performs a complete resync: push local → reset sync state → full pull from server.
|
|
5
|
-
* This is a deliberate user action (not automatic) for recovering from sync issues.
|
|
6
|
-
*/
|
|
7
|
-
import type { WalletStorageManager } from '@bsv/wallet-toolbox/out/src/index.client.js';
|
|
8
|
-
import type { sdk as mobileToolboxSdk } from '@bsv/wallet-toolbox/out/src/index.client.js';
|
|
9
|
-
type WalletStorageProvider = mobileToolboxSdk.WalletStorageProvider;
|
|
10
|
-
export type FullSyncStage = 'pushing' | 'resetting' | 'pulling' | 'complete';
|
|
11
|
-
export interface FullSyncOptions {
|
|
12
|
-
/** Local storage manager */
|
|
13
|
-
storage: WalletStorageManager;
|
|
14
|
-
/** Remote backup storage provider (StorageClient) */
|
|
15
|
-
remoteStorage: WalletStorageProvider;
|
|
16
|
-
/** Identity key for the wallet */
|
|
17
|
-
identityKey: string;
|
|
18
|
-
/** Optional progress callback */
|
|
19
|
-
onProgress?: (stage: FullSyncStage, message: string) => void;
|
|
20
|
-
/** Max rough size per chunk in bytes (default: 1MB) */
|
|
21
|
-
maxRoughSize?: number;
|
|
22
|
-
/** Max items per chunk (default: 100) */
|
|
23
|
-
maxItems?: number;
|
|
24
|
-
}
|
|
25
|
-
export interface FullSyncResult {
|
|
26
|
-
pushed: {
|
|
27
|
-
inserts: number;
|
|
28
|
-
updates: number;
|
|
29
|
-
};
|
|
30
|
-
pulled: {
|
|
31
|
-
inserts: number;
|
|
32
|
-
updates: number;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Perform a full sync with the remote backup server.
|
|
37
|
-
*
|
|
38
|
-
* Steps:
|
|
39
|
-
* 1. Push all local data to remote backup
|
|
40
|
-
* 2. Clear local syncMap / reset sync state
|
|
41
|
-
* 3. Pull ALL data from server (not incremental)
|
|
42
|
-
* 4. Rebuild complete server→client ID mappings
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* const result = await fullSync({
|
|
47
|
-
* storage,
|
|
48
|
-
* remoteStorage: remoteClient,
|
|
49
|
-
* identityKey: pubKey,
|
|
50
|
-
* onProgress: (stage, msg) => console.log(`[${stage}] ${msg}`)
|
|
51
|
-
* });
|
|
52
|
-
* console.log(`Pushed: ${result.pushed.inserts}/${result.pushed.updates}`);
|
|
53
|
-
* console.log(`Pulled: ${result.pulled.inserts}/${result.pulled.updates}`);
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export declare function fullSync(options: FullSyncOptions): Promise<FullSyncResult>;
|
|
57
|
-
export {};
|
|
58
|
-
//# sourceMappingURL=fullSync.d.ts.map
|
package/dist/fullSync.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fullSync.d.ts","sourceRoot":"","sources":["../src/fullSync.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAA;AACvF,OAAO,KAAK,EAAE,GAAG,IAAI,gBAAgB,EAAE,MAAM,6CAA6C,CAAA;AAI1F,KAAK,qBAAqB,GAAG,gBAAgB,CAAC,qBAAqB,CAAA;AAEnE,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAA;AAE5E,MAAM,WAAW,eAAe;IAC/B,4BAA4B;IAC5B,OAAO,EAAE,oBAAoB,CAAA;IAC7B,qDAAqD;IACrD,aAAa,EAAE,qBAAqB,CAAA;IACpC,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB,iCAAiC;IACjC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5D,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,cAAc;IAC9B,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5C,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,QAAQ,CAC7B,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,cAAc,CAAC,CAwGzB"}
|
package/dist/fullSync.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Full wallet synchronization with remote backup server.
|
|
3
|
-
*
|
|
4
|
-
* Performs a complete resync: push local → reset sync state → full pull from server.
|
|
5
|
-
* This is a deliberate user action (not automatic) for recovering from sync issues.
|
|
6
|
-
*/
|
|
7
|
-
import { createSyncMap } from '@bsv/wallet-toolbox/out/src/storage/schema/entities/EntityBase.js';
|
|
8
|
-
import { EntitySyncState } from '@bsv/wallet-toolbox/out/src/storage/schema/entities/EntitySyncState.js';
|
|
9
|
-
/**
|
|
10
|
-
* Perform a full sync with the remote backup server.
|
|
11
|
-
*
|
|
12
|
-
* Steps:
|
|
13
|
-
* 1. Push all local data to remote backup
|
|
14
|
-
* 2. Clear local syncMap / reset sync state
|
|
15
|
-
* 3. Pull ALL data from server (not incremental)
|
|
16
|
-
* 4. Rebuild complete server→client ID mappings
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* const result = await fullSync({
|
|
21
|
-
* storage,
|
|
22
|
-
* remoteStorage: remoteClient,
|
|
23
|
-
* identityKey: pubKey,
|
|
24
|
-
* onProgress: (stage, msg) => console.log(`[${stage}] ${msg}`)
|
|
25
|
-
* });
|
|
26
|
-
* console.log(`Pushed: ${result.pushed.inserts}/${result.pushed.updates}`);
|
|
27
|
-
* console.log(`Pulled: ${result.pulled.inserts}/${result.pulled.updates}`);
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export async function fullSync(options) {
|
|
31
|
-
const { storage, remoteStorage, identityKey, onProgress, maxRoughSize = 1000000, // 1 MB default
|
|
32
|
-
maxItems = 100, } = options;
|
|
33
|
-
// Step 1: Push ALL local data to remote (bypassing timestamp filter)
|
|
34
|
-
onProgress?.('pushing', 'Pushing local data to remote...');
|
|
35
|
-
const localSettings = storage.getSettings();
|
|
36
|
-
const remoteSettings = await remoteStorage.makeAvailable();
|
|
37
|
-
let pushInserts = 0;
|
|
38
|
-
let pushUpdates = 0;
|
|
39
|
-
let chunkCount = 0;
|
|
40
|
-
for (;;) {
|
|
41
|
-
// Get sync state from remote for proper offsets
|
|
42
|
-
const ss = await EntitySyncState.fromStorage(remoteStorage, identityKey, localSettings);
|
|
43
|
-
const args = ss.makeRequestSyncChunkArgs(identityKey, remoteSettings.storageIdentityKey, maxRoughSize, maxItems);
|
|
44
|
-
// KEY: Override since to undefined - includes ALL data regardless of timestamp
|
|
45
|
-
args.since = undefined;
|
|
46
|
-
// Get chunk from local storage
|
|
47
|
-
const chunk = await storage.runAsSync(async (sync) => sync.getSyncChunk(args));
|
|
48
|
-
// Send chunk to remote
|
|
49
|
-
const result = await remoteStorage.processSyncChunk(args, chunk);
|
|
50
|
-
pushInserts += result.inserts;
|
|
51
|
-
pushUpdates += result.updates;
|
|
52
|
-
chunkCount++;
|
|
53
|
-
onProgress?.('pushing', `Chunk ${chunkCount}: ${result.inserts} inserts, ${result.updates} updates`);
|
|
54
|
-
if (result.done)
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
onProgress?.('pushing', `Pushed ${pushInserts} inserts, ${pushUpdates} updates`);
|
|
58
|
-
// Step 2: Reset sync state to force full pull
|
|
59
|
-
onProgress?.('resetting', 'Resetting sync state...');
|
|
60
|
-
const auth = await storage.getAuth();
|
|
61
|
-
await storage.runAsStorageProvider(async (active) => {
|
|
62
|
-
const syncStates = await active.findSyncStates({
|
|
63
|
-
partial: {
|
|
64
|
-
userId: auth.userId,
|
|
65
|
-
storageIdentityKey: remoteSettings.storageIdentityKey,
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
if (syncStates.length > 0) {
|
|
69
|
-
const syncState = syncStates[0];
|
|
70
|
-
await active.updateSyncState(syncState.syncStateId, {
|
|
71
|
-
syncMap: JSON.stringify(createSyncMap()),
|
|
72
|
-
when: undefined,
|
|
73
|
-
status: 'unknown',
|
|
74
|
-
});
|
|
75
|
-
onProgress?.('resetting', 'Sync state reset complete');
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
onProgress?.('resetting', 'No existing sync state found');
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
// Step 3: Pull from remote (full pull due to reset state)
|
|
82
|
-
onProgress?.('pulling', 'Pulling all data from remote...');
|
|
83
|
-
const pullResult = await storage.syncFromReader(identityKey, remoteStorage);
|
|
84
|
-
onProgress?.('pulling', `Pulled ${pullResult.inserts} inserts, ${pullResult.updates} updates`);
|
|
85
|
-
// Step 4: Complete
|
|
86
|
-
onProgress?.('complete', 'Full sync complete');
|
|
87
|
-
return {
|
|
88
|
-
pushed: { inserts: pushInserts, updates: pushUpdates },
|
|
89
|
-
pulled: { inserts: pullResult.inserts, updates: pullResult.updates },
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=fullSync.js.map
|
package/dist/fullSync.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1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