@twin.org/synchronised-storage-service 0.0.1-next.4 → 0.0.1-next.6

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.
@@ -7,6 +7,10 @@ export declare class SyncSnapshotEntry<T extends ISynchronisedEntity = ISynchron
7
7
  * The id for the snapshot.
8
8
  */
9
9
  id: string;
10
+ /**
11
+ * The version for the snapshot.
12
+ */
13
+ version: string;
10
14
  /**
11
15
  * The storage key for the snapshot i.e. which entity is being synchronized.
12
16
  */
@@ -18,11 +22,19 @@ export declare class SyncSnapshotEntry<T extends ISynchronisedEntity = ISynchron
18
22
  /**
19
23
  * The date the snapshot was last modified.
20
24
  */
21
- dateModified?: string;
25
+ dateModified: string;
26
+ /**
27
+ * The flag to determine if this is the snapshot is the local one containing changes for this node.
28
+ */
29
+ isLocal: boolean;
30
+ /**
31
+ * The flag to determine if this is a consolidated snapshot.
32
+ */
33
+ isConsolidated: boolean;
22
34
  /**
23
- * The flag to determine if this is the current local snapshot containing changes for this node.
35
+ * The epoch for the changeset.
24
36
  */
25
- isLocalSnapshot?: boolean;
37
+ epoch: number;
26
38
  /**
27
39
  * The ids of the storage for the change sets in the snapshot, if this is not a local snapshot.
28
40
  */
@@ -23,11 +23,17 @@ export declare class BlobStorageHelper {
23
23
  * @param blobId The id of the blob to apply.
24
24
  * @returns The blob.
25
25
  */
26
- load<T>(blobId: string): Promise<T | undefined>;
26
+ loadBlob<T>(blobId: string): Promise<T | undefined>;
27
27
  /**
28
28
  * Save a blob.
29
29
  * @param blob The blob to save.
30
30
  * @returns The id of the blob.
31
31
  */
32
32
  saveBlob<T>(blob: T): Promise<string>;
33
+ /**
34
+ * Remove a blob from storage.
35
+ * @param blobId The id of the blob to remove.
36
+ * @returns Nothing.
37
+ */
38
+ removeBlob(blobId: string): Promise<void>;
33
39
  }
@@ -2,7 +2,7 @@ import type { IEventBusComponent } from "@twin.org/event-bus-models";
2
2
  import { type IIdentityConnector } from "@twin.org/identity-models";
3
3
  import type { ILoggingConnector } from "@twin.org/logging-models";
4
4
  import { type IProof } from "@twin.org/standards-w3c-did";
5
- import { type ISyncChangeSet, type ISynchronisedEntity } from "@twin.org/synchronised-storage-models";
5
+ import { type ISyncChangeSet, type ISynchronisedEntity, type SyncNodeIdentityMode } from "@twin.org/synchronised-storage-models";
6
6
  import type { BlobStorageHelper } from "./blobStorageHelper";
7
7
  /**
8
8
  * Class for performing change set operations.
@@ -71,4 +71,11 @@ export declare class ChangeSetHelper<T extends ISynchronisedEntity = ISynchronis
71
71
  syncChangeSet: ISyncChangeSet<T>;
72
72
  changeSetStorageId: string;
73
73
  } | undefined>;
74
+ /**
75
+ * Reset the storage for a given storage key.
76
+ * @param storageKey The key of the storage to reset.
77
+ * @param resetMode The reset mode, this will use the nodeIdentity in the entities to determine which are local/remote.
78
+ * @returns Nothing.
79
+ */
80
+ reset(storageKey: string, resetMode: SyncNodeIdentityMode): Promise<void>;
74
81
  }
@@ -1,6 +1,6 @@
1
1
  import type { IEntityStorageConnector } from "@twin.org/entity-storage-models";
2
2
  import type { ILoggingConnector } from "@twin.org/logging-models";
3
- import type { ISynchronisedEntity, SyncChangeOperation } from "@twin.org/synchronised-storage-models";
3
+ import { type ISynchronisedEntity, type SyncChangeOperation } from "@twin.org/synchronised-storage-models";
4
4
  import type { ChangeSetHelper } from "./changeSetHelper";
5
5
  import type { SyncSnapshotEntry } from "../entities/syncSnapshotEntry";
6
6
  import type { ISyncState } from "../models/ISyncState";
@@ -28,11 +28,12 @@ export declare class LocalSyncStateHelper<T extends ISynchronisedEntity = ISynch
28
28
  */
29
29
  addLocalChange(storageKey: string, operation: SyncChangeOperation, id: string): Promise<void>;
30
30
  /**
31
- * Get the current local snapshot which contains just the changes for this node.
31
+ * Get the snapshot which contains just the changes for this node.
32
32
  * @param storageKey The storage key of the snapshot to get.
33
+ * @param isLocal Whether to get the local snapshot or not.
33
34
  * @returns The local snapshot entry.
34
35
  */
35
- getLocalChangeSnapshot(storageKey: string): Promise<SyncSnapshotEntry<T>>;
36
+ getSnapshots(storageKey: string, isLocal: boolean): Promise<SyncSnapshotEntry<T>[]>;
36
37
  /**
37
38
  * Set the current local snapshot with changes for this node.
38
39
  * @param localChangeSnapshot The local change snapshot to set.
@@ -22,8 +22,9 @@ export declare class RemoteSyncStateHelper<T extends ISynchronisedEntity = ISync
22
22
  * @param blobStorageHelper The blob storage helper to use for remote sync states.
23
23
  * @param changeSetHelper The change set helper to use for managing changesets.
24
24
  * @param isTrustedNode Whether the node is trusted or not.
25
+ * @param maxConsolidations The maximum number of consolidations to keep in storage.
25
26
  */
26
- constructor(logging: ILoggingConnector | undefined, eventBusComponent: IEventBusComponent, verifiableSyncPointerStorageConnector: IVerifiableStorageConnector, blobStorageHelper: BlobStorageHelper, changeSetHelper: ChangeSetHelper<T>, isTrustedNode: boolean);
27
+ constructor(logging: ILoggingConnector | undefined, eventBusComponent: IEventBusComponent, verifiableSyncPointerStorageConnector: IVerifiableStorageConnector, blobStorageHelper: BlobStorageHelper, changeSetHelper: ChangeSetHelper<T>, isTrustedNode: boolean, maxConsolidations: number);
27
28
  /**
28
29
  * Set the node identity to use for signing changesets.
29
30
  * @param nodeIdentity The identity of the node that is performing the update.
@@ -85,7 +86,7 @@ export declare class RemoteSyncStateHelper<T extends ISynchronisedEntity = ISync
85
86
  * @param syncPointerId The id of the sync pointer to retrieve the state for.
86
87
  * @returns The remote sync state.
87
88
  */
88
- getRemoteSyncState(syncPointerId: string): Promise<ISyncState | undefined>;
89
+ getSyncState(syncPointerId: string): Promise<ISyncState | undefined>;
89
90
  /**
90
91
  * Handle the batch response which is triggered from a consolidation request.
91
92
  * @param response The batch response to handle.
@@ -18,6 +18,14 @@ export interface ISyncSnapshot {
18
18
  * The date the snapshot was last modified.
19
19
  */
20
20
  dateModified: string;
21
+ /**
22
+ * Is this a consolidated snapshot?
23
+ */
24
+ isConsolidated: boolean;
25
+ /**
26
+ * The epoch of the snapshot.
27
+ */
28
+ epoch: number;
21
29
  /**
22
30
  * The ids of the storage for the change sets in the snapshot.
23
31
  */
@@ -7,6 +7,10 @@ export interface ISyncState {
7
7
  * The version of the sync state.
8
8
  */
9
9
  version: string;
10
+ /**
11
+ * The storage type contained in the sync state.
12
+ */
13
+ storageKey: string;
10
14
  /**
11
15
  * The snapshots.
12
16
  */
@@ -27,6 +27,11 @@ export interface ISynchronisedStorageServiceConfig {
27
27
  * @default 1000
28
28
  */
29
29
  consolidationBatchSize?: number;
30
+ /**
31
+ * The maximum number of consolidations to keep in storage.
32
+ * @default 5
33
+ */
34
+ maxConsolidations?: number;
30
35
  /**
31
36
  * The encryption key id from the vault to use for blob storage, only required for trusted nodes, untrusted nodes will request the key.
32
37
  * @default synchronised-storage-blob-encryption-key
@@ -122,4 +122,7 @@ AnyNode → [Poll] → VerifiableStorage → [Fetch] → DecentralisedStorage
122
122
 
123
123
  ## Data Structures
124
124
 
125
- - ChangeSet - contains a set of changes that a regular node will send to a trusted node - will contain a proof generated by the identity of the regular node
125
+ - Sync Pointer Store - stored in verifiable storage, for each storage type contains a storage id of the location for sync states
126
+ - Sync State - stored in decentralised storage, contains all of the snapshots for a specific storage key
127
+ - Sync Snapshot - contains a list of all the decentralised storage ids for the change sets which make up the snapshot
128
+ - Change Set - contains a set of changes to be made to the entity storage
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.1-next.6](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-service-v0.0.1-next.5...synchronised-storage-service-v0.0.1-next.6) (2025-08-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * improve consolidation logic ([698232f](https://github.com/twinfoundation/synchronised-storage/commit/698232f57640f87642ecd323cb1e4670eda33343))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/synchronised-storage-models bumped from 0.0.1-next.5 to 0.0.1-next.6
16
+
17
+ ## [0.0.1-next.5](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-service-v0.0.1-next.4...synchronised-storage-service-v0.0.1-next.5) (2025-08-11)
18
+
19
+
20
+ ### Features
21
+
22
+ * additional node identity checks ([76257c4](https://github.com/twinfoundation/synchronised-storage/commit/76257c4173303d484391f71f581fd0e214204029))
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/synchronised-storage-models bumped from 0.0.1-next.4 to 0.0.1-next.5
30
+
3
31
  ## [0.0.1-next.4](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-service-v0.0.1-next.3...synchronised-storage-service-v0.0.1-next.4) (2025-08-08)
4
32
 
5
33
 
@@ -41,6 +41,7 @@
41
41
  "value": {
42
42
  "id": "0909090909090909090909090909090909090909090909090909090909090909",
43
43
  "dateCreated": "2025-05-29T01:00:00.000Z",
44
+ "dateModified": "2025-05-29T01:00:00.000Z",
44
45
  "nodeIdentity": "did:entity-storage:0xd2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2",
45
46
  "changes": [
46
47
  {
@@ -340,6 +341,7 @@
340
341
  "id",
341
342
  "dateCreated",
342
343
  "storageKey",
344
+ "dateModified",
343
345
  "changes",
344
346
  "nodeIdentity"
345
347
  ],
@@ -28,6 +28,14 @@ The id for the snapshot.
28
28
 
29
29
  ***
30
30
 
31
+ ### version
32
+
33
+ > **version**: `string`
34
+
35
+ The version for the snapshot.
36
+
37
+ ***
38
+
31
39
  ### storageKey
32
40
 
33
41
  > **storageKey**: `string`
@@ -44,19 +52,35 @@ The date the snapshot was created.
44
52
 
45
53
  ***
46
54
 
47
- ### dateModified?
55
+ ### dateModified
48
56
 
49
- > `optional` **dateModified**: `string`
57
+ > **dateModified**: `string`
50
58
 
51
59
  The date the snapshot was last modified.
52
60
 
53
61
  ***
54
62
 
55
- ### isLocalSnapshot?
63
+ ### isLocal
64
+
65
+ > **isLocal**: `boolean`
66
+
67
+ The flag to determine if this is the snapshot is the local one containing changes for this node.
68
+
69
+ ***
70
+
71
+ ### isConsolidated
72
+
73
+ > **isConsolidated**: `boolean`
74
+
75
+ The flag to determine if this is a consolidated snapshot.
76
+
77
+ ***
78
+
79
+ ### epoch
56
80
 
57
- > `optional` **isLocalSnapshot**: `boolean`
81
+ > **epoch**: `number`
58
82
 
59
- The flag to determine if this is the current local snapshot containing changes for this node.
83
+ The epoch for the changeset.
60
84
 
61
85
  ***
62
86
 
@@ -36,6 +36,22 @@ The date the snapshot was last modified.
36
36
 
37
37
  ***
38
38
 
39
+ ### isConsolidated
40
+
41
+ > **isConsolidated**: `boolean`
42
+
43
+ Is this a consolidated snapshot?
44
+
45
+ ***
46
+
47
+ ### epoch
48
+
49
+ > **epoch**: `number`
50
+
51
+ The epoch of the snapshot.
52
+
53
+ ***
54
+
39
55
  ### changeSetStorageIds
40
56
 
41
57
  > **changeSetStorageIds**: `string`[]
@@ -12,6 +12,14 @@ The version of the sync state.
12
12
 
13
13
  ***
14
14
 
15
+ ### storageKey
16
+
17
+ > **storageKey**: `string`
18
+
19
+ The storage type contained in the sync state.
20
+
21
+ ***
22
+
15
23
  ### snapshots
16
24
 
17
25
  > **snapshots**: [`ISyncSnapshot`](ISyncSnapshot.md)[]
@@ -74,6 +74,20 @@ The number of entities to process in a single consolidation batch.
74
74
 
75
75
  ***
76
76
 
77
+ ### maxConsolidations?
78
+
79
+ > `optional` **maxConsolidations**: `number`
80
+
81
+ The maximum number of consolidations to keep in storage.
82
+
83
+ #### Default
84
+
85
+ ```ts
86
+ 5
87
+ ```
88
+
89
+ ***
90
+
77
91
  ### blobStorageEncryptionKeyId?
78
92
 
79
93
  > `optional` **blobStorageEncryptionKeyId**: `string`
package/locales/en.json CHANGED
@@ -10,14 +10,18 @@
10
10
  "createdChangeSetProof": "Created change proof for change set with id \"{id}\", proof value is \"{proofValue}\"",
11
11
  "getChangeSet": "Retrieving change set with id \"{changeSetStorageId}\"",
12
12
  "getChangeSetEmpty": "No change set found with id \"{changeSetStorageId}\"",
13
- "copyChangeSet": "Copying change set with id \"{changeSetStorageId}\""
13
+ "copyChangeSet": "Copying change set with id \"{changeSetStorageId}\"",
14
+ "storageReset": "Resetting storage for storage key \"{storageKey}\""
14
15
  },
15
16
  "localSyncStateHelper": {
16
- "getLocalChangeSnapshot": "Retrieving local change snapshot for storage key \"{storageKey}\"",
17
- "localChangeSnapshotExists": "Found existing local change snapshot for storage key \"{storageKey}\"",
18
- "localChangeSnapshotDoesNotExist": "No local change snapshot found for storage key \"{storageKey}\", creating new one",
17
+ "getSnapshots": "Retrieving snapshot for storage key \"{storageKey}\"",
18
+ "getSnapshotsExists": "Found existing snapshot for storage key \"{storageKey}\"",
19
+ "getSnapshotsDoesNotExist": "No local change snapshot found for storage key \"{storageKey}\", creating new one",
19
20
  "applySyncState": "Syncing from remote state with \"{snapshotCount}\" snapshots",
20
21
  "applySnapshot": "Processing sync snapshot with id \"{snapshotId}\" created on \"{dateCreated}\"",
22
+ "applySnapshotNoExisting": "There are no existing snapshots, find a consolidated snapshot for storage key \"{storageKey}\"",
23
+ "applySnapshotFoundConsolidated": "Found consolidated snapshot with id \"{snapshotId}\" for storage key \"{storageKey}\"",
24
+ "applySnapshotNoConsolidated": "No consolidated snapshot found, cannot apply sync state for storage key \"{storageKey}\"",
21
25
  "processModifiedSnapshot": "Processing modified sync snapshot with id \"{snapshotId}\", remote modified on \"{remoteModified}\", local modified on \"{localModified}\"",
22
26
  "processNewSnapshot": "Processing new sync snapshot with id \"{snapshotId}\", created on \"{dateCreated}\"",
23
27
  "removeLocalChangeSnapshot": "Removing local change snapshot with id \"{snapshotId}\"",
@@ -29,10 +33,10 @@
29
33
  "verifiableSyncPointerStoreNotFound": "No verifiable sync pointer store found for key \"{key}\"",
30
34
  "verifiableSyncPointerStoreRetrieved": "Retrieved verifiable sync pointer for key \"{key}\"",
31
35
  "verifiableSyncPointerStoreStoring": "Storing verifiable sync pointer store for key \"{key}\"",
32
- "remoteSyncStateStoring": "Storing remote sync state entry with \"{snapshotCount}\" snapshots",
33
- "remoteSyncStateRetrieving": "Retrieving remote sync state entry for syncPointerId \"{syncPointerId}\"",
34
- "remoteSyncStateRetrieved": "Retrieving remote sync state entry for syncPointerId \"{syncPointerId}\" with \"{snapshotCount}\" snapshots",
35
- "remoteSyncStateNotFound": "No remote sync state entry found for syncPointerId \"{syncPointerId}\"",
36
+ "syncStateStoring": "Storing sync state entry with \"{snapshotCount}\" snapshots",
37
+ "syncStateRetrieving": "Retrieving sync state entry for syncPointerId \"{syncPointerId}\"",
38
+ "syncStateRetrieved": "Retrieving sync state entry for syncPointerId \"{syncPointerId}\" with \"{snapshotCount}\" snapshots",
39
+ "syncStateNotFound": "No sync state entry found for syncPointerId \"{syncPointerId}\"",
36
40
  "consolidationStarting": "Starting consolidation of remote sync state",
37
41
  "consolidationCompleted": "Consolidation of remote sync state completed",
38
42
  "addChangeSetToSyncState": "Adding change set with id \"{changeSetStorageId}\" to remote sync state for storage key \"{storageKey}\"",
@@ -58,7 +62,10 @@
58
62
  "loadedBlob": "Loaded blob with id \"{blobId}\"",
59
63
  "loadBlobEmpty": "No blob found with id \"{blobId}\"",
60
64
  "saveBlob": "Saving blob",
61
- "savedBlob": "Saved blob with id \"{blobId}\""
65
+ "savedBlob": "Saved blob with id \"{blobId}\"",
66
+ "removeBlob": "Removing blob with id \"{blobId}\"",
67
+ "removedBlob": "Removed blob with id \"{blobId}\"",
68
+ "removeBlobEmpty": "No blob found to remove with id \"{blobId}\""
62
69
  }
63
70
  },
64
71
  "error": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/synchronised-storage-service",
3
- "version": "0.0.1-next.4",
3
+ "version": "0.0.1-next.6",
4
4
  "description": "Synchronised storage contract implementation and REST endpoint definitions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  "@twin.org/logging-models": "next",
27
27
  "@twin.org/nameof": "next",
28
28
  "@twin.org/standards-w3c-did": "next",
29
- "@twin.org/synchronised-storage-models": "0.0.1-next.4",
29
+ "@twin.org/synchronised-storage-models": "0.0.1-next.6",
30
30
  "@twin.org/verifiable-storage-models": "next",
31
31
  "@twin.org/web": "next"
32
32
  },