@twin.org/synchronised-storage-service 0.0.1-next.6 → 0.0.1-next.7
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/dist/cjs/index.cjs +93 -94
- package/dist/esm/index.mjs +93 -94
- package/dist/types/helpers/blobStorageHelper.d.ts +3 -3
- package/dist/types/helpers/changeSetHelper.d.ts +3 -3
- package/dist/types/helpers/localSyncStateHelper.d.ts +3 -3
- package/dist/types/helpers/remoteSyncStateHelper.d.ts +3 -3
- package/dist/types/models/ISynchronisedStorageServiceConstructorOptions.d.ts +2 -2
- package/docs/changelog.md +14 -0
- package/docs/reference/interfaces/ISynchronisedStorageServiceConstructorOptions.md +3 -3
- package/package.json +2 -2
package/dist/esm/index.mjs
CHANGED
|
@@ -4,7 +4,6 @@ import { HttpStatusCode } from '@twin.org/web';
|
|
|
4
4
|
import { BlobStorageConnectorFactory } from '@twin.org/blob-storage-models';
|
|
5
5
|
import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
|
|
6
6
|
import { DocumentHelper, IdentityConnectorFactory } from '@twin.org/identity-models';
|
|
7
|
-
import { LoggingConnectorFactory } from '@twin.org/logging-models';
|
|
8
7
|
import { ProofTypes } from '@twin.org/standards-w3c-did';
|
|
9
8
|
import { SyncChangeOperation, SynchronisedStorageTopics, SyncNodeIdentityMode } from '@twin.org/synchronised-storage-models';
|
|
10
9
|
import { VaultEncryptionType, VaultConnectorFactory } from '@twin.org/vault-models';
|
|
@@ -295,10 +294,10 @@ class BlobStorageHelper {
|
|
|
295
294
|
*/
|
|
296
295
|
CLASS_NAME = "BlobStorageHelper";
|
|
297
296
|
/**
|
|
298
|
-
* The logging
|
|
297
|
+
* The logging component to use for logging.
|
|
299
298
|
* @internal
|
|
300
299
|
*/
|
|
301
|
-
|
|
300
|
+
_loggingComponent;
|
|
302
301
|
/**
|
|
303
302
|
* The vault connector.
|
|
304
303
|
* @internal
|
|
@@ -321,14 +320,14 @@ class BlobStorageHelper {
|
|
|
321
320
|
_isTrustedNode;
|
|
322
321
|
/**
|
|
323
322
|
* Create a new instance of BlobStorageHelper.
|
|
324
|
-
* @param
|
|
323
|
+
* @param loggingComponent The logging connector to use for logging.
|
|
325
324
|
* @param vaultConnector The vault connector to use for for the encryption key.
|
|
326
325
|
* @param blobStorageConnector The blob storage component to use.
|
|
327
326
|
* @param blobStorageEncryptionKeyId The id of the vault key to use for encrypting/decrypting blobs.
|
|
328
327
|
* @param isTrustedNode Is this a trusted node.
|
|
329
328
|
*/
|
|
330
|
-
constructor(
|
|
331
|
-
this.
|
|
329
|
+
constructor(loggingComponent, vaultConnector, blobStorageConnector, blobStorageEncryptionKeyId, isTrustedNode) {
|
|
330
|
+
this._loggingComponent = loggingComponent;
|
|
332
331
|
this._vaultConnector = vaultConnector;
|
|
333
332
|
this._blobStorageConnector = blobStorageConnector;
|
|
334
333
|
this._blobStorageEncryptionKeyId = blobStorageEncryptionKeyId;
|
|
@@ -340,7 +339,7 @@ class BlobStorageHelper {
|
|
|
340
339
|
* @returns The blob.
|
|
341
340
|
*/
|
|
342
341
|
async loadBlob(blobId) {
|
|
343
|
-
await this.
|
|
342
|
+
await this._loggingComponent?.log({
|
|
344
343
|
level: "info",
|
|
345
344
|
source: this.CLASS_NAME,
|
|
346
345
|
message: "loadBlob",
|
|
@@ -363,7 +362,7 @@ class BlobStorageHelper {
|
|
|
363
362
|
compressedBlob = rsa.decrypt(encryptedBlob);
|
|
364
363
|
}
|
|
365
364
|
const decompressedBlob = await Compression.decompress(compressedBlob, CompressionType.Gzip);
|
|
366
|
-
await this.
|
|
365
|
+
await this._loggingComponent?.log({
|
|
367
366
|
level: "info",
|
|
368
367
|
source: this.CLASS_NAME,
|
|
369
368
|
message: "loadedBlob",
|
|
@@ -375,7 +374,7 @@ class BlobStorageHelper {
|
|
|
375
374
|
}
|
|
376
375
|
}
|
|
377
376
|
catch (error) {
|
|
378
|
-
await this.
|
|
377
|
+
await this._loggingComponent?.log({
|
|
379
378
|
level: "error",
|
|
380
379
|
source: this.CLASS_NAME,
|
|
381
380
|
message: "loadBlobFailed",
|
|
@@ -385,7 +384,7 @@ class BlobStorageHelper {
|
|
|
385
384
|
error: BaseError.fromError(error)
|
|
386
385
|
});
|
|
387
386
|
}
|
|
388
|
-
await this.
|
|
387
|
+
await this._loggingComponent?.log({
|
|
389
388
|
level: "info",
|
|
390
389
|
source: this.CLASS_NAME,
|
|
391
390
|
message: "loadBlobEmpty",
|
|
@@ -400,7 +399,7 @@ class BlobStorageHelper {
|
|
|
400
399
|
* @returns The id of the blob.
|
|
401
400
|
*/
|
|
402
401
|
async saveBlob(blob) {
|
|
403
|
-
await this.
|
|
402
|
+
await this._loggingComponent?.log({
|
|
404
403
|
level: "info",
|
|
405
404
|
source: this.CLASS_NAME,
|
|
406
405
|
message: "saveBlob"
|
|
@@ -412,7 +411,7 @@ class BlobStorageHelper {
|
|
|
412
411
|
const encryptedBlob = await this._vaultConnector.encrypt(this._blobStorageEncryptionKeyId, VaultEncryptionType.Rsa2048, compressedBlob);
|
|
413
412
|
try {
|
|
414
413
|
const blobId = await this._blobStorageConnector.set(encryptedBlob);
|
|
415
|
-
await this.
|
|
414
|
+
await this._loggingComponent?.log({
|
|
416
415
|
level: "info",
|
|
417
416
|
source: this.CLASS_NAME,
|
|
418
417
|
message: "savedBlob",
|
|
@@ -423,7 +422,7 @@ class BlobStorageHelper {
|
|
|
423
422
|
return blobId;
|
|
424
423
|
}
|
|
425
424
|
catch (error) {
|
|
426
|
-
await this.
|
|
425
|
+
await this._loggingComponent?.log({
|
|
427
426
|
level: "error",
|
|
428
427
|
source: this.CLASS_NAME,
|
|
429
428
|
message: "saveBlobFailed",
|
|
@@ -438,7 +437,7 @@ class BlobStorageHelper {
|
|
|
438
437
|
* @returns Nothing.
|
|
439
438
|
*/
|
|
440
439
|
async removeBlob(blobId) {
|
|
441
|
-
await this.
|
|
440
|
+
await this._loggingComponent?.log({
|
|
442
441
|
level: "info",
|
|
443
442
|
source: this.CLASS_NAME,
|
|
444
443
|
message: "removeBlob",
|
|
@@ -448,7 +447,7 @@ class BlobStorageHelper {
|
|
|
448
447
|
});
|
|
449
448
|
try {
|
|
450
449
|
await this._blobStorageConnector.remove(blobId);
|
|
451
|
-
await this.
|
|
450
|
+
await this._loggingComponent?.log({
|
|
452
451
|
level: "info",
|
|
453
452
|
source: this.CLASS_NAME,
|
|
454
453
|
message: "removedBlob",
|
|
@@ -458,7 +457,7 @@ class BlobStorageHelper {
|
|
|
458
457
|
});
|
|
459
458
|
}
|
|
460
459
|
catch (error) {
|
|
461
|
-
await this.
|
|
460
|
+
await this._loggingComponent?.log({
|
|
462
461
|
level: "error",
|
|
463
462
|
source: this.CLASS_NAME,
|
|
464
463
|
message: "removeBlobFailed",
|
|
@@ -468,7 +467,7 @@ class BlobStorageHelper {
|
|
|
468
467
|
error: BaseError.fromError(error)
|
|
469
468
|
});
|
|
470
469
|
}
|
|
471
|
-
await this.
|
|
470
|
+
await this._loggingComponent?.log({
|
|
472
471
|
level: "info",
|
|
473
472
|
source: this.CLASS_NAME,
|
|
474
473
|
message: "removeBlobEmpty",
|
|
@@ -490,10 +489,10 @@ class ChangeSetHelper {
|
|
|
490
489
|
*/
|
|
491
490
|
CLASS_NAME = "ChangeSetHelper";
|
|
492
491
|
/**
|
|
493
|
-
* The logging
|
|
492
|
+
* The logging component to use for logging.
|
|
494
493
|
* @internal
|
|
495
494
|
*/
|
|
496
|
-
|
|
495
|
+
_loggingComponent;
|
|
497
496
|
/**
|
|
498
497
|
* The event bus component.
|
|
499
498
|
* @internal
|
|
@@ -521,14 +520,14 @@ class ChangeSetHelper {
|
|
|
521
520
|
_nodeIdentity;
|
|
522
521
|
/**
|
|
523
522
|
* Create a new instance of ChangeSetHelper.
|
|
524
|
-
* @param
|
|
523
|
+
* @param loggingComponent The logging connector to use for logging.
|
|
525
524
|
* @param eventBusComponent The event bus component to use for events.
|
|
526
525
|
* @param identityConnector The identity connector to use for signing/verifying changesets.
|
|
527
526
|
* @param blobStorageHelper The blob storage component to use for remote sync states.
|
|
528
527
|
* @param decentralisedStorageMethodId The id of the identity method to use when signing/verifying changesets.
|
|
529
528
|
*/
|
|
530
|
-
constructor(
|
|
531
|
-
this.
|
|
529
|
+
constructor(loggingComponent, eventBusComponent, identityConnector, blobStorageHelper, decentralisedStorageMethodId) {
|
|
530
|
+
this._loggingComponent = loggingComponent;
|
|
532
531
|
this._eventBusComponent = eventBusComponent;
|
|
533
532
|
this._decentralisedStorageMethodId = decentralisedStorageMethodId;
|
|
534
533
|
this._blobStorageHelper = blobStorageHelper;
|
|
@@ -547,7 +546,7 @@ class ChangeSetHelper {
|
|
|
547
546
|
* @returns The changeset if it was verified.
|
|
548
547
|
*/
|
|
549
548
|
async getAndVerifyChangeset(changeSetStorageId) {
|
|
550
|
-
await this.
|
|
549
|
+
await this._loggingComponent?.log({
|
|
551
550
|
level: "info",
|
|
552
551
|
source: this.CLASS_NAME,
|
|
553
552
|
message: "getChangeSet",
|
|
@@ -563,7 +562,7 @@ class ChangeSetHelper {
|
|
|
563
562
|
}
|
|
564
563
|
}
|
|
565
564
|
catch (error) {
|
|
566
|
-
await this.
|
|
565
|
+
await this._loggingComponent?.log({
|
|
567
566
|
level: "warn",
|
|
568
567
|
source: this.CLASS_NAME,
|
|
569
568
|
message: "getChangeSetError",
|
|
@@ -573,7 +572,7 @@ class ChangeSetHelper {
|
|
|
573
572
|
error: BaseError.fromError(error)
|
|
574
573
|
});
|
|
575
574
|
}
|
|
576
|
-
await this.
|
|
575
|
+
await this._loggingComponent?.log({
|
|
577
576
|
level: "info",
|
|
578
577
|
source: this.CLASS_NAME,
|
|
579
578
|
message: "getChangeSetEmpty",
|
|
@@ -604,7 +603,7 @@ class ChangeSetHelper {
|
|
|
604
603
|
async applyChangeset(syncChangeset) {
|
|
605
604
|
if (Is.arrayValue(syncChangeset.changes)) {
|
|
606
605
|
for (const change of syncChangeset.changes) {
|
|
607
|
-
await this.
|
|
606
|
+
await this._loggingComponent?.log({
|
|
608
607
|
level: "info",
|
|
609
608
|
source: this.CLASS_NAME,
|
|
610
609
|
message: "changeSetApplyingChange",
|
|
@@ -650,7 +649,7 @@ class ChangeSetHelper {
|
|
|
650
649
|
* @returns The id of the change set.
|
|
651
650
|
*/
|
|
652
651
|
async storeChangeSet(syncChangeSet) {
|
|
653
|
-
await this.
|
|
652
|
+
await this._loggingComponent?.log({
|
|
654
653
|
level: "info",
|
|
655
654
|
source: this.CLASS_NAME,
|
|
656
655
|
message: "changeSetStoring",
|
|
@@ -667,7 +666,7 @@ class ChangeSetHelper {
|
|
|
667
666
|
*/
|
|
668
667
|
async verifyChangesetProof(syncChangeset) {
|
|
669
668
|
if (Is.empty(syncChangeset.proof)) {
|
|
670
|
-
await this.
|
|
669
|
+
await this._loggingComponent?.log({
|
|
671
670
|
level: "info",
|
|
672
671
|
source: this.CLASS_NAME,
|
|
673
672
|
message: "verifyChangeSetProofMissing",
|
|
@@ -680,7 +679,7 @@ class ChangeSetHelper {
|
|
|
680
679
|
// If the proof or verification method is missing, the proof is invalid
|
|
681
680
|
const verificationMethod = syncChangeset.proof?.verificationMethod;
|
|
682
681
|
if (!Is.stringValue(verificationMethod)) {
|
|
683
|
-
await this.
|
|
682
|
+
await this._loggingComponent?.log({
|
|
684
683
|
level: "error",
|
|
685
684
|
source: this.CLASS_NAME,
|
|
686
685
|
message: "verifyChangeSetProofMissing",
|
|
@@ -694,7 +693,7 @@ class ChangeSetHelper {
|
|
|
694
693
|
// otherwise you could sign a changeset for another node
|
|
695
694
|
const changeSetNodeIdentity = DocumentHelper.parseId(verificationMethod ?? "");
|
|
696
695
|
if (changeSetNodeIdentity.id !== syncChangeset.nodeIdentity) {
|
|
697
|
-
await this.
|
|
696
|
+
await this._loggingComponent?.log({
|
|
698
697
|
level: "error",
|
|
699
698
|
source: this.CLASS_NAME,
|
|
700
699
|
message: "verifyChangeSetProofNodeIdentityMismatch",
|
|
@@ -707,7 +706,7 @@ class ChangeSetHelper {
|
|
|
707
706
|
delete changeSetWithoutProof.proof;
|
|
708
707
|
const isValid = await this._identityConnector.verifyProof(changeSetWithoutProof, syncChangeset.proof);
|
|
709
708
|
if (!isValid) {
|
|
710
|
-
await this.
|
|
709
|
+
await this._loggingComponent?.log({
|
|
711
710
|
level: "error",
|
|
712
711
|
source: this.CLASS_NAME,
|
|
713
712
|
message: "verifyChangeSetProofInvalid",
|
|
@@ -717,7 +716,7 @@ class ChangeSetHelper {
|
|
|
717
716
|
});
|
|
718
717
|
}
|
|
719
718
|
else {
|
|
720
|
-
await this.
|
|
719
|
+
await this._loggingComponent?.log({
|
|
721
720
|
level: "error",
|
|
722
721
|
source: this.CLASS_NAME,
|
|
723
722
|
message: "verifyChangeSetProofValid",
|
|
@@ -738,7 +737,7 @@ class ChangeSetHelper {
|
|
|
738
737
|
const changeSetWithoutProof = ObjectHelper.clone(syncChangeset);
|
|
739
738
|
delete changeSetWithoutProof.proof;
|
|
740
739
|
const proof = await this._identityConnector.createProof(this._nodeIdentity, DocumentHelper.joinId(this._nodeIdentity, this._decentralisedStorageMethodId), ProofTypes.DataIntegrityProof, changeSetWithoutProof);
|
|
741
|
-
await this.
|
|
740
|
+
await this._loggingComponent?.log({
|
|
742
741
|
level: "info",
|
|
743
742
|
source: this.CLASS_NAME,
|
|
744
743
|
message: "createdChangeSetProof",
|
|
@@ -758,7 +757,7 @@ class ChangeSetHelper {
|
|
|
758
757
|
if (Is.stringValue(this._nodeIdentity)) {
|
|
759
758
|
const verified = await this.verifyChangesetProof(syncChangeSet);
|
|
760
759
|
if (verified) {
|
|
761
|
-
await this.
|
|
760
|
+
await this._loggingComponent?.log({
|
|
762
761
|
level: "info",
|
|
763
762
|
source: this.CLASS_NAME,
|
|
764
763
|
message: "copyChangeSet",
|
|
@@ -787,7 +786,7 @@ class ChangeSetHelper {
|
|
|
787
786
|
async reset(storageKey, resetMode) {
|
|
788
787
|
// If we are applying a consolidation we need to reset the local db
|
|
789
788
|
// but keep any entries from the local node, as they might have been updated
|
|
790
|
-
await this.
|
|
789
|
+
await this._loggingComponent?.log({
|
|
791
790
|
level: "info",
|
|
792
791
|
source: this.CLASS_NAME,
|
|
793
792
|
message: "storageReset",
|
|
@@ -819,10 +818,10 @@ class LocalSyncStateHelper {
|
|
|
819
818
|
*/
|
|
820
819
|
CLASS_NAME = "LocalSyncStateHelper";
|
|
821
820
|
/**
|
|
822
|
-
* The logging
|
|
821
|
+
* The logging component to use for logging.
|
|
823
822
|
* @internal
|
|
824
823
|
*/
|
|
825
|
-
|
|
824
|
+
_loggingComponent;
|
|
826
825
|
/**
|
|
827
826
|
* The storage connector for the sync snapshot entries.
|
|
828
827
|
* @internal
|
|
@@ -835,12 +834,12 @@ class LocalSyncStateHelper {
|
|
|
835
834
|
_changeSetHelper;
|
|
836
835
|
/**
|
|
837
836
|
* Create a new instance of LocalSyncStateHelper.
|
|
838
|
-
* @param
|
|
837
|
+
* @param loggingComponent The logging connector to use for logging.
|
|
839
838
|
* @param snapshotEntryEntityStorage The storage connector for the sync snapshot entries.
|
|
840
839
|
* @param changeSetHelper The change set helper to use for applying changesets.
|
|
841
840
|
*/
|
|
842
|
-
constructor(
|
|
843
|
-
this.
|
|
841
|
+
constructor(loggingComponent, snapshotEntryEntityStorage, changeSetHelper) {
|
|
842
|
+
this._loggingComponent = loggingComponent;
|
|
844
843
|
this._snapshotEntryEntityStorage = snapshotEntryEntityStorage;
|
|
845
844
|
this._changeSetHelper = changeSetHelper;
|
|
846
845
|
}
|
|
@@ -852,7 +851,7 @@ class LocalSyncStateHelper {
|
|
|
852
851
|
* @returns Nothing.
|
|
853
852
|
*/
|
|
854
853
|
async addLocalChange(storageKey, operation, id) {
|
|
855
|
-
await this.
|
|
854
|
+
await this._loggingComponent?.log({
|
|
856
855
|
level: "info",
|
|
857
856
|
source: this.CLASS_NAME,
|
|
858
857
|
message: "addLocalChange",
|
|
@@ -890,7 +889,7 @@ class LocalSyncStateHelper {
|
|
|
890
889
|
* @returns The local snapshot entry.
|
|
891
890
|
*/
|
|
892
891
|
async getSnapshots(storageKey, isLocal) {
|
|
893
|
-
await this.
|
|
892
|
+
await this._loggingComponent?.log({
|
|
894
893
|
level: "info",
|
|
895
894
|
source: this.CLASS_NAME,
|
|
896
895
|
message: "getSnapshots",
|
|
@@ -913,7 +912,7 @@ class LocalSyncStateHelper {
|
|
|
913
912
|
]
|
|
914
913
|
});
|
|
915
914
|
if (queryResult.entities.length > 0) {
|
|
916
|
-
await this.
|
|
915
|
+
await this._loggingComponent?.log({
|
|
917
916
|
level: "info",
|
|
918
917
|
source: this.CLASS_NAME,
|
|
919
918
|
message: "getSnapshotsExists",
|
|
@@ -923,7 +922,7 @@ class LocalSyncStateHelper {
|
|
|
923
922
|
});
|
|
924
923
|
return queryResult.entities;
|
|
925
924
|
}
|
|
926
|
-
await this.
|
|
925
|
+
await this._loggingComponent?.log({
|
|
927
926
|
level: "info",
|
|
928
927
|
source: this.CLASS_NAME,
|
|
929
928
|
message: "getSnapshotsDoesNotExist",
|
|
@@ -952,7 +951,7 @@ class LocalSyncStateHelper {
|
|
|
952
951
|
* @returns Nothing.
|
|
953
952
|
*/
|
|
954
953
|
async setLocalChangeSnapshot(localChangeSnapshot) {
|
|
955
|
-
await this.
|
|
954
|
+
await this._loggingComponent?.log({
|
|
956
955
|
level: "info",
|
|
957
956
|
source: this.CLASS_NAME,
|
|
958
957
|
message: "setLocalChangeSnapshot",
|
|
@@ -968,7 +967,7 @@ class LocalSyncStateHelper {
|
|
|
968
967
|
* @returns Nothing.
|
|
969
968
|
*/
|
|
970
969
|
async removeLocalChangeSnapshot(localChangeSnapshot) {
|
|
971
|
-
await this.
|
|
970
|
+
await this._loggingComponent?.log({
|
|
972
971
|
level: "info",
|
|
973
972
|
source: this.CLASS_NAME,
|
|
974
973
|
message: "removeLocalChangeSnapshot",
|
|
@@ -985,7 +984,7 @@ class LocalSyncStateHelper {
|
|
|
985
984
|
* @returns Nothing.
|
|
986
985
|
*/
|
|
987
986
|
async applySyncState(storageKey, syncState) {
|
|
988
|
-
await this.
|
|
987
|
+
await this._loggingComponent?.log({
|
|
989
988
|
level: "info",
|
|
990
989
|
source: this.CLASS_NAME,
|
|
991
990
|
message: "applySyncState",
|
|
@@ -1010,7 +1009,7 @@ class LocalSyncStateHelper {
|
|
|
1010
1009
|
// If we have an epoch gap or no existing snapshots then we need to apply
|
|
1011
1010
|
// a full sync from a consolidation
|
|
1012
1011
|
if (!existingSnapshots.some(s => s.isConsolidated) || hasEpochGap) {
|
|
1013
|
-
await this.
|
|
1012
|
+
await this._loggingComponent?.log({
|
|
1014
1013
|
level: "info",
|
|
1015
1014
|
source: this.CLASS_NAME,
|
|
1016
1015
|
message: "applySnapshotNoExisting",
|
|
@@ -1021,7 +1020,7 @@ class LocalSyncStateHelper {
|
|
|
1021
1020
|
const mostRecentConsolidation = syncStateSnapshots.findIndex(snapshot => snapshot.isConsolidated);
|
|
1022
1021
|
if (mostRecentConsolidation !== -1) {
|
|
1023
1022
|
// We found the most recent consolidated snapshot, we can use it
|
|
1024
|
-
await this.
|
|
1023
|
+
await this._loggingComponent?.log({
|
|
1025
1024
|
level: "info",
|
|
1026
1025
|
source: this.CLASS_NAME,
|
|
1027
1026
|
message: "applySnapshotFoundConsolidated",
|
|
@@ -1049,7 +1048,7 @@ class LocalSyncStateHelper {
|
|
|
1049
1048
|
}
|
|
1050
1049
|
}
|
|
1051
1050
|
else {
|
|
1052
|
-
await this.
|
|
1051
|
+
await this._loggingComponent?.log({
|
|
1053
1052
|
level: "info",
|
|
1054
1053
|
source: this.CLASS_NAME,
|
|
1055
1054
|
message: "applySnapshotNoConsolidated",
|
|
@@ -1074,7 +1073,7 @@ class LocalSyncStateHelper {
|
|
|
1074
1073
|
const referencedExistingSnapshots = Object.keys(existingSnapshotsMap);
|
|
1075
1074
|
let completedProcessing = false;
|
|
1076
1075
|
for (const snapshot of syncStateSnapshots) {
|
|
1077
|
-
await this.
|
|
1076
|
+
await this._loggingComponent?.log({
|
|
1078
1077
|
level: "info",
|
|
1079
1078
|
source: this.CLASS_NAME,
|
|
1080
1079
|
message: "applySnapshot",
|
|
@@ -1135,7 +1134,7 @@ class LocalSyncStateHelper {
|
|
|
1135
1134
|
*/
|
|
1136
1135
|
async processModifiedSnapshots(modifiedSnapshots) {
|
|
1137
1136
|
for (const modifiedSnapshot of modifiedSnapshots) {
|
|
1138
|
-
await this.
|
|
1137
|
+
await this._loggingComponent?.log({
|
|
1139
1138
|
level: "info",
|
|
1140
1139
|
source: this.CLASS_NAME,
|
|
1141
1140
|
message: "processModifiedSnapshot",
|
|
@@ -1168,7 +1167,7 @@ class LocalSyncStateHelper {
|
|
|
1168
1167
|
*/
|
|
1169
1168
|
async processNewSnapshots(newSnapshots) {
|
|
1170
1169
|
for (const newSnapshot of newSnapshots) {
|
|
1171
|
-
await this.
|
|
1170
|
+
await this._loggingComponent?.log({
|
|
1172
1171
|
level: "info",
|
|
1173
1172
|
source: this.CLASS_NAME,
|
|
1174
1173
|
message: "processNewSnapshot",
|
|
@@ -1199,10 +1198,10 @@ class RemoteSyncStateHelper {
|
|
|
1199
1198
|
*/
|
|
1200
1199
|
CLASS_NAME = "RemoteSyncStateHelper";
|
|
1201
1200
|
/**
|
|
1202
|
-
* The logging
|
|
1201
|
+
* The logging component to use for logging.
|
|
1203
1202
|
* @internal
|
|
1204
1203
|
*/
|
|
1205
|
-
|
|
1204
|
+
_loggingComponent;
|
|
1206
1205
|
/**
|
|
1207
1206
|
* The event bus component.
|
|
1208
1207
|
* @internal
|
|
@@ -1255,7 +1254,7 @@ class RemoteSyncStateHelper {
|
|
|
1255
1254
|
_maxConsolidations;
|
|
1256
1255
|
/**
|
|
1257
1256
|
* Create a new instance of DecentralisedEntityStorageConnector.
|
|
1258
|
-
* @param
|
|
1257
|
+
* @param loggingComponent The logging component to use for logging.
|
|
1259
1258
|
* @param eventBusComponent The event bus component to use for events.
|
|
1260
1259
|
* @param verifiableSyncPointerStorageConnector The verifiable storage connector to use for storing sync pointers.
|
|
1261
1260
|
* @param blobStorageHelper The blob storage helper to use for remote sync states.
|
|
@@ -1263,8 +1262,8 @@ class RemoteSyncStateHelper {
|
|
|
1263
1262
|
* @param isTrustedNode Whether the node is trusted or not.
|
|
1264
1263
|
* @param maxConsolidations The maximum number of consolidations to keep in storage.
|
|
1265
1264
|
*/
|
|
1266
|
-
constructor(
|
|
1267
|
-
this.
|
|
1265
|
+
constructor(loggingComponent, eventBusComponent, verifiableSyncPointerStorageConnector, blobStorageHelper, changeSetHelper, isTrustedNode, maxConsolidations) {
|
|
1266
|
+
this._loggingComponent = loggingComponent;
|
|
1268
1267
|
this._eventBusComponent = eventBusComponent;
|
|
1269
1268
|
this._verifiableSyncPointerStorageConnector = verifiableSyncPointerStorageConnector;
|
|
1270
1269
|
this._changeSetHelper = changeSetHelper;
|
|
@@ -1302,7 +1301,7 @@ class RemoteSyncStateHelper {
|
|
|
1302
1301
|
* @returns The storage id of the change set if created.
|
|
1303
1302
|
*/
|
|
1304
1303
|
async buildChangeSet(storageKey, changes, completeCallback) {
|
|
1305
|
-
await this.
|
|
1304
|
+
await this._loggingComponent?.log({
|
|
1306
1305
|
level: "info",
|
|
1307
1306
|
source: this.CLASS_NAME,
|
|
1308
1307
|
message: "buildingChangeSet",
|
|
@@ -1328,7 +1327,7 @@ class RemoteSyncStateHelper {
|
|
|
1328
1327
|
// Once all the requests are handled the callback will be called
|
|
1329
1328
|
for (const change of setChanges) {
|
|
1330
1329
|
// Create a request for each change to populate the full details
|
|
1331
|
-
await this.
|
|
1330
|
+
await this._loggingComponent?.log({
|
|
1332
1331
|
level: "info",
|
|
1333
1332
|
source: this.CLASS_NAME,
|
|
1334
1333
|
message: "createChangeSetRequestingItem",
|
|
@@ -1351,7 +1350,7 @@ class RemoteSyncStateHelper {
|
|
|
1351
1350
|
* @returns Nothing.
|
|
1352
1351
|
*/
|
|
1353
1352
|
async finaliseFullChanges(storageKey, completeCallback) {
|
|
1354
|
-
await this.
|
|
1353
|
+
await this._loggingComponent?.log({
|
|
1355
1354
|
level: "info",
|
|
1356
1355
|
source: this.CLASS_NAME,
|
|
1357
1356
|
message: "finalisingSyncChanges",
|
|
@@ -1392,7 +1391,7 @@ class RemoteSyncStateHelper {
|
|
|
1392
1391
|
await completeCallback(syncChangeSet, changeSetStorageId);
|
|
1393
1392
|
}
|
|
1394
1393
|
catch (err) {
|
|
1395
|
-
await this.
|
|
1394
|
+
await this._loggingComponent?.log({
|
|
1396
1395
|
level: "error",
|
|
1397
1396
|
source: this.CLASS_NAME,
|
|
1398
1397
|
message: "finalisingSyncChangesFailed",
|
|
@@ -1415,7 +1414,7 @@ class RemoteSyncStateHelper {
|
|
|
1415
1414
|
* @returns Nothing.
|
|
1416
1415
|
*/
|
|
1417
1416
|
async addChangeSetToSyncState(storageKey, changeSetStorageId) {
|
|
1418
|
-
await this.
|
|
1417
|
+
await this._loggingComponent?.log({
|
|
1419
1418
|
level: "info",
|
|
1420
1419
|
source: this.CLASS_NAME,
|
|
1421
1420
|
message: "addChangeSetToSyncState",
|
|
@@ -1472,7 +1471,7 @@ class RemoteSyncStateHelper {
|
|
|
1472
1471
|
* @returns Nothing.
|
|
1473
1472
|
*/
|
|
1474
1473
|
async consolidationStart(storageKey, batchSize) {
|
|
1475
|
-
await this.
|
|
1474
|
+
await this._loggingComponent?.log({
|
|
1476
1475
|
level: "info",
|
|
1477
1476
|
source: this.CLASS_NAME,
|
|
1478
1477
|
message: "consolidationStarting"
|
|
@@ -1487,7 +1486,7 @@ class RemoteSyncStateHelper {
|
|
|
1487
1486
|
async getVerifiableSyncPointerStore() {
|
|
1488
1487
|
if (Is.stringValue(this._synchronisedStorageKey)) {
|
|
1489
1488
|
try {
|
|
1490
|
-
await this.
|
|
1489
|
+
await this._loggingComponent?.log({
|
|
1491
1490
|
level: "info",
|
|
1492
1491
|
source: this.CLASS_NAME,
|
|
1493
1492
|
message: "verifiableSyncPointerStoreRetrieving",
|
|
@@ -1498,7 +1497,7 @@ class RemoteSyncStateHelper {
|
|
|
1498
1497
|
const syncPointerStore = await this._verifiableSyncPointerStorageConnector.get(this._synchronisedStorageKey, { includeData: true });
|
|
1499
1498
|
if (Is.uint8Array(syncPointerStore.data)) {
|
|
1500
1499
|
const syncPointer = ObjectHelper.fromBytes(syncPointerStore.data);
|
|
1501
|
-
await this.
|
|
1500
|
+
await this._loggingComponent?.log({
|
|
1502
1501
|
level: "info",
|
|
1503
1502
|
source: this.CLASS_NAME,
|
|
1504
1503
|
message: "verifiableSyncPointerStoreRetrieved",
|
|
@@ -1514,7 +1513,7 @@ class RemoteSyncStateHelper {
|
|
|
1514
1513
|
throw err;
|
|
1515
1514
|
}
|
|
1516
1515
|
}
|
|
1517
|
-
await this.
|
|
1516
|
+
await this._loggingComponent?.log({
|
|
1518
1517
|
level: "info",
|
|
1519
1518
|
source: this.CLASS_NAME,
|
|
1520
1519
|
message: "verifiableSyncPointerStoreNotFound",
|
|
@@ -1536,7 +1535,7 @@ class RemoteSyncStateHelper {
|
|
|
1536
1535
|
*/
|
|
1537
1536
|
async storeVerifiableSyncPointerStore(syncPointerStore) {
|
|
1538
1537
|
if (Is.stringValue(this._nodeIdentity) && Is.stringValue(this._synchronisedStorageKey)) {
|
|
1539
|
-
await this.
|
|
1538
|
+
await this._loggingComponent?.log({
|
|
1540
1539
|
level: "info",
|
|
1541
1540
|
source: this.CLASS_NAME,
|
|
1542
1541
|
message: "verifiableSyncPointerStoreStoring",
|
|
@@ -1554,7 +1553,7 @@ class RemoteSyncStateHelper {
|
|
|
1554
1553
|
* @returns The id of the sync state.
|
|
1555
1554
|
*/
|
|
1556
1555
|
async storeRemoteSyncState(syncState) {
|
|
1557
|
-
await this.
|
|
1556
|
+
await this._loggingComponent?.log({
|
|
1558
1557
|
level: "info",
|
|
1559
1558
|
source: this.CLASS_NAME,
|
|
1560
1559
|
message: "syncStateStoring",
|
|
@@ -1597,7 +1596,7 @@ class RemoteSyncStateHelper {
|
|
|
1597
1596
|
*/
|
|
1598
1597
|
async getSyncState(syncPointerId) {
|
|
1599
1598
|
try {
|
|
1600
|
-
await this.
|
|
1599
|
+
await this._loggingComponent?.log({
|
|
1601
1600
|
level: "info",
|
|
1602
1601
|
source: this.CLASS_NAME,
|
|
1603
1602
|
message: "syncStateRetrieving",
|
|
@@ -1607,7 +1606,7 @@ class RemoteSyncStateHelper {
|
|
|
1607
1606
|
});
|
|
1608
1607
|
const syncState = await this._blobStorageHelper.loadBlob(syncPointerId);
|
|
1609
1608
|
if (Is.object(syncState)) {
|
|
1610
|
-
await this.
|
|
1609
|
+
await this._loggingComponent?.log({
|
|
1611
1610
|
level: "info",
|
|
1612
1611
|
source: this.CLASS_NAME,
|
|
1613
1612
|
message: "syncStateRetrieved",
|
|
@@ -1620,7 +1619,7 @@ class RemoteSyncStateHelper {
|
|
|
1620
1619
|
}
|
|
1621
1620
|
}
|
|
1622
1621
|
catch (error) {
|
|
1623
|
-
await this.
|
|
1622
|
+
await this._loggingComponent?.log({
|
|
1624
1623
|
level: "warn",
|
|
1625
1624
|
source: this.CLASS_NAME,
|
|
1626
1625
|
message: "getSyncStateError",
|
|
@@ -1630,7 +1629,7 @@ class RemoteSyncStateHelper {
|
|
|
1630
1629
|
error: BaseError.fromError(error)
|
|
1631
1630
|
});
|
|
1632
1631
|
}
|
|
1633
|
-
await this.
|
|
1632
|
+
await this._loggingComponent?.log({
|
|
1634
1633
|
level: "info",
|
|
1635
1634
|
source: this.CLASS_NAME,
|
|
1636
1635
|
message: "syncStateNotFound",
|
|
@@ -1702,7 +1701,7 @@ class RemoteSyncStateHelper {
|
|
|
1702
1701
|
// Remove the batch response storage ids for the storage key
|
|
1703
1702
|
// as we have consolidated the changes
|
|
1704
1703
|
delete this._batchResponseStorageIds[response.storageKey];
|
|
1705
|
-
await this.
|
|
1704
|
+
await this._loggingComponent?.log({
|
|
1706
1705
|
level: "info",
|
|
1707
1706
|
source: this.CLASS_NAME,
|
|
1708
1707
|
message: "consolidationCompleted"
|
|
@@ -1715,7 +1714,7 @@ class RemoteSyncStateHelper {
|
|
|
1715
1714
|
* @param response The item response to handle.
|
|
1716
1715
|
*/
|
|
1717
1716
|
async handleLocalItemResponse(response) {
|
|
1718
|
-
await this.
|
|
1717
|
+
await this._loggingComponent?.log({
|
|
1719
1718
|
level: "info",
|
|
1720
1719
|
source: this.CLASS_NAME,
|
|
1721
1720
|
message: "createChangeSetRespondingItem",
|
|
@@ -1769,10 +1768,10 @@ class SynchronisedStorageService {
|
|
|
1769
1768
|
*/
|
|
1770
1769
|
CLASS_NAME = "SynchronisedStorageService";
|
|
1771
1770
|
/**
|
|
1772
|
-
* The logging
|
|
1771
|
+
* The logging component to use for logging.
|
|
1773
1772
|
* @internal
|
|
1774
1773
|
*/
|
|
1775
|
-
|
|
1774
|
+
_loggingComponent;
|
|
1776
1775
|
/**
|
|
1777
1776
|
* The event bus component.
|
|
1778
1777
|
* @internal
|
|
@@ -1866,7 +1865,7 @@ class SynchronisedStorageService {
|
|
|
1866
1865
|
Guards.object(this.CLASS_NAME, "options", options);
|
|
1867
1866
|
Guards.object(this.CLASS_NAME, "options.config", options.config);
|
|
1868
1867
|
this._eventBusComponent = ComponentFactory.get(options.eventBusComponentType ?? "event-bus");
|
|
1869
|
-
this.
|
|
1868
|
+
this._loggingComponent = ComponentFactory.getIfExists(options.loggingComponentType ?? "logging");
|
|
1870
1869
|
this._vaultConnector = VaultConnectorFactory.get(options.vaultConnectorType ?? "vault");
|
|
1871
1870
|
this._localSyncSnapshotEntryEntityStorage = EntityStorageConnectorFactory.get(options.syncSnapshotStorageConnectorType ?? "sync-snapshot-entry");
|
|
1872
1871
|
this._verifiableSyncPointerStorageConnector = VerifiableStorageConnectorFactory.get(options.verifiableStorageConnectorType ?? "verifiable-storage");
|
|
@@ -1895,10 +1894,10 @@ class SynchronisedStorageService {
|
|
|
1895
1894
|
this._trustedSynchronisedStorageComponent =
|
|
1896
1895
|
ComponentFactory.get(options.trustedSynchronisedStorageComponentType);
|
|
1897
1896
|
}
|
|
1898
|
-
this._blobStorageHelper = new BlobStorageHelper(this.
|
|
1899
|
-
this._changeSetHelper = new ChangeSetHelper(this.
|
|
1900
|
-
this._localSyncStateHelper = new LocalSyncStateHelper(this.
|
|
1901
|
-
this._remoteSyncStateHelper = new RemoteSyncStateHelper(this.
|
|
1897
|
+
this._blobStorageHelper = new BlobStorageHelper(this._loggingComponent, this._vaultConnector, this._blobStorageConnector, this._config.blobStorageEncryptionKeyId, this._config.isTrustedNode);
|
|
1898
|
+
this._changeSetHelper = new ChangeSetHelper(this._loggingComponent, this._eventBusComponent, this._identityConnector, this._blobStorageHelper, this._config.synchronisedStorageMethodId);
|
|
1899
|
+
this._localSyncStateHelper = new LocalSyncStateHelper(this._loggingComponent, this._localSyncSnapshotEntryEntityStorage, this._changeSetHelper);
|
|
1900
|
+
this._remoteSyncStateHelper = new RemoteSyncStateHelper(this._loggingComponent, this._eventBusComponent, this._verifiableSyncPointerStorageConnector, this._blobStorageHelper, this._changeSetHelper, this._config.isTrustedNode, this._config.maxConsolidations);
|
|
1902
1901
|
this._serviceStarted = false;
|
|
1903
1902
|
this._activeStorageKeys = {};
|
|
1904
1903
|
this._eventBusComponent.subscribe(SynchronisedStorageTopics.RegisterStorageKey, async (event) => this.registerStorageKey(event.data));
|
|
@@ -1983,7 +1982,7 @@ class SynchronisedStorageService {
|
|
|
1983
1982
|
throw new GeneralError(this.CLASS_NAME, "notTrustedNode");
|
|
1984
1983
|
}
|
|
1985
1984
|
Guards.object(this.CLASS_NAME, "syncChangeSet", syncChangeSet);
|
|
1986
|
-
await this.
|
|
1985
|
+
await this._loggingComponent?.log({
|
|
1987
1986
|
level: "info",
|
|
1988
1987
|
source: this.CLASS_NAME,
|
|
1989
1988
|
message: "syncChangeSetForRemoteNode",
|
|
@@ -2012,7 +2011,7 @@ class SynchronisedStorageService {
|
|
|
2012
2011
|
*/
|
|
2013
2012
|
async startEntitySync(storageKey) {
|
|
2014
2013
|
try {
|
|
2015
|
-
await this.
|
|
2014
|
+
await this._loggingComponent?.log({
|
|
2016
2015
|
level: "info",
|
|
2017
2016
|
source: this.CLASS_NAME,
|
|
2018
2017
|
message: "startEntitySync",
|
|
@@ -2026,7 +2025,7 @@ class SynchronisedStorageService {
|
|
|
2026
2025
|
await this.updateFromLocalSyncState(storageKey);
|
|
2027
2026
|
}
|
|
2028
2027
|
catch (error) {
|
|
2029
|
-
await this.
|
|
2028
|
+
await this._loggingComponent?.log({
|
|
2030
2029
|
level: "error",
|
|
2031
2030
|
source: this.CLASS_NAME,
|
|
2032
2031
|
message: "entitySyncFailed",
|
|
@@ -2041,7 +2040,7 @@ class SynchronisedStorageService {
|
|
|
2041
2040
|
* @internal
|
|
2042
2041
|
*/
|
|
2043
2042
|
async updateFromRemoteSyncState(storageKey) {
|
|
2044
|
-
await this.
|
|
2043
|
+
await this._loggingComponent?.log({
|
|
2045
2044
|
level: "info",
|
|
2046
2045
|
source: this.CLASS_NAME,
|
|
2047
2046
|
message: "updateFromRemoteSyncState",
|
|
@@ -2067,7 +2066,7 @@ class SynchronisedStorageService {
|
|
|
2067
2066
|
* @internal
|
|
2068
2067
|
*/
|
|
2069
2068
|
async updateFromLocalSyncState(storageKey) {
|
|
2070
|
-
await this.
|
|
2069
|
+
await this._loggingComponent?.log({
|
|
2071
2070
|
level: "info",
|
|
2072
2071
|
source: this.CLASS_NAME,
|
|
2073
2072
|
message: "updateFromLocalSyncState",
|
|
@@ -2081,7 +2080,7 @@ class SynchronisedStorageService {
|
|
|
2081
2080
|
if (Is.arrayValue(localChangeSnapshot.changes)) {
|
|
2082
2081
|
await this._remoteSyncStateHelper.buildChangeSet(storageKey, localChangeSnapshot.changes, async (syncChangeSet, changeSetStorageId) => {
|
|
2083
2082
|
if (Is.empty(syncChangeSet) && Is.empty(changeSetStorageId)) {
|
|
2084
|
-
await this.
|
|
2083
|
+
await this._loggingComponent?.log({
|
|
2085
2084
|
level: "info",
|
|
2086
2085
|
source: this.CLASS_NAME,
|
|
2087
2086
|
message: "builtStorageChangeSetNone",
|
|
@@ -2091,7 +2090,7 @@ class SynchronisedStorageService {
|
|
|
2091
2090
|
});
|
|
2092
2091
|
}
|
|
2093
2092
|
else {
|
|
2094
|
-
await this.
|
|
2093
|
+
await this._loggingComponent?.log({
|
|
2095
2094
|
level: "info",
|
|
2096
2095
|
source: this.CLASS_NAME,
|
|
2097
2096
|
message: "builtStorageChangeSet",
|
|
@@ -2111,7 +2110,7 @@ class SynchronisedStorageService {
|
|
|
2111
2110
|
Is.object(syncChangeSet)) {
|
|
2112
2111
|
// If we are not a trusted node, we need to send the changes to the trusted node
|
|
2113
2112
|
// and then remove the local change snapshot
|
|
2114
|
-
await this.
|
|
2113
|
+
await this._loggingComponent?.log({
|
|
2115
2114
|
level: "info",
|
|
2116
2115
|
source: this.CLASS_NAME,
|
|
2117
2116
|
message: "sendingChangeSetToTrustedNode",
|
|
@@ -2127,7 +2126,7 @@ class SynchronisedStorageService {
|
|
|
2127
2126
|
});
|
|
2128
2127
|
}
|
|
2129
2128
|
else {
|
|
2130
|
-
await this.
|
|
2129
|
+
await this._loggingComponent?.log({
|
|
2131
2130
|
level: "info",
|
|
2132
2131
|
source: this.CLASS_NAME,
|
|
2133
2132
|
message: "updateFromLocalSyncStateNoChanges",
|
|
@@ -2156,7 +2155,7 @@ class SynchronisedStorageService {
|
|
|
2156
2155
|
SynchronisedStorageService._DEFAULT_CONSOLIDATION_BATCH_SIZE);
|
|
2157
2156
|
}
|
|
2158
2157
|
catch (error) {
|
|
2159
|
-
await this.
|
|
2158
|
+
await this._loggingComponent?.log({
|
|
2160
2159
|
level: "error",
|
|
2161
2160
|
source: this.CLASS_NAME,
|
|
2162
2161
|
message: "consolidationSyncFailed",
|
|
@@ -2170,7 +2169,7 @@ class SynchronisedStorageService {
|
|
|
2170
2169
|
* @internal
|
|
2171
2170
|
*/
|
|
2172
2171
|
async registerStorageKey(syncRegisterStorageKey) {
|
|
2173
|
-
await this.
|
|
2172
|
+
await this._loggingComponent?.log({
|
|
2174
2173
|
level: "info",
|
|
2175
2174
|
source: this.CLASS_NAME,
|
|
2176
2175
|
message: "registerStorageKey",
|
|
@@ -2192,7 +2191,7 @@ class SynchronisedStorageService {
|
|
|
2192
2191
|
*/
|
|
2193
2192
|
async activateStorageKey(storageKey) {
|
|
2194
2193
|
if (!Is.empty(this._activeStorageKeys[storageKey]) && !this._activeStorageKeys[storageKey]) {
|
|
2195
|
-
await this.
|
|
2194
|
+
await this._loggingComponent?.log({
|
|
2196
2195
|
level: "info",
|
|
2197
2196
|
source: this.CLASS_NAME,
|
|
2198
2197
|
message: "activateStorageKey",
|