@twin.org/entity-storage-connector-synchronised 0.0.1-next.29 → 0.0.2-next.3

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.
@@ -26,10 +26,10 @@ class SynchronisedEntityStorageConnector {
26
26
  */
27
27
  _primaryKey;
28
28
  /**
29
- * The entity schema type.
29
+ * The storage key for the entity.
30
30
  * @internal
31
31
  */
32
- _entitySchemaType;
32
+ _storageKey;
33
33
  /**
34
34
  * The entity storage connector to use for actual data.
35
35
  * @internal
@@ -49,7 +49,7 @@ class SynchronisedEntityStorageConnector {
49
49
  core.Guards.stringValue(this.CLASS_NAME, "options.entitySchema", options.entitySchema);
50
50
  core.Guards.stringValue(this.CLASS_NAME, "options.entityStorageConnectorType", options.entityStorageConnectorType);
51
51
  this._entitySchema = entity.EntitySchemaFactory.get(options.entitySchema);
52
- this._entitySchemaType = core.StringHelper.kebabCase(options.entitySchema);
52
+ this._storageKey = options?.config?.storageKey ?? core.StringHelper.kebabCase(options.entitySchema);
53
53
  this._primaryKey = entity.EntitySchemaHelper.getPrimaryKey(this._entitySchema);
54
54
  const requiredProperties = ["nodeIdentity", "dateModified"];
55
55
  for (const requiredProperty of requiredProperties) {
@@ -81,9 +81,9 @@ class SynchronisedEntityStorageConnector {
81
81
  * @returns Nothing.
82
82
  */
83
83
  async start(nodeIdentity, nodeLoggingConnectorType, componentState) {
84
- // Tell the synchronised storage about this schema type
85
- await this._eventBusComponent.publish(synchronisedStorageModels.SynchronisedStorageTopics.RegisterSchemaType, {
86
- schemaType: this._entitySchemaType
84
+ // Tell the synchronised storage about this storage key
85
+ await this._eventBusComponent.publish(synchronisedStorageModels.SynchronisedStorageTopics.RegisterStorageKey, {
86
+ storageKey: this._storageKey
87
87
  });
88
88
  this.handleEventBusMessages();
89
89
  }
@@ -111,7 +111,7 @@ class SynchronisedEntityStorageConnector {
111
111
  await this._entityStorageConnector.set(entity, conditions);
112
112
  // Tell the synchronised storage about the entity changes
113
113
  await this._eventBusComponent.publish(synchronisedStorageModels.SynchronisedStorageTopics.LocalItemChange, {
114
- schemaType: this._entitySchemaType,
114
+ storageKey: this._storageKey,
115
115
  operation: synchronisedStorageModels.SyncChangeOperation.Set,
116
116
  id: entity[this._primaryKey.property]
117
117
  });
@@ -127,7 +127,7 @@ class SynchronisedEntityStorageConnector {
127
127
  await this._entityStorageConnector.remove(id, conditions);
128
128
  // Tell the synchronised storage about the entity removal
129
129
  await this._eventBusComponent.publish(synchronisedStorageModels.SynchronisedStorageTopics.LocalItemChange, {
130
- schemaType: this._entitySchemaType,
130
+ storageKey: this._storageKey,
131
131
  operation: synchronisedStorageModels.SyncChangeOperation.Delete,
132
132
  id
133
133
  });
@@ -152,8 +152,8 @@ class SynchronisedEntityStorageConnector {
152
152
  handleEventBusMessages() {
153
153
  // When the synchronised storage requests an item, we need to provide it
154
154
  this._eventBusComponent.subscribe(synchronisedStorageModels.SynchronisedStorageTopics.LocalItemRequest, async (params) => {
155
- // Only handle the request if it matches the schema type
156
- if (params.data.schemaType === this._entitySchemaType) {
155
+ // Only handle the request if it matches the storage key
156
+ if (params.data.storageKey === this._storageKey) {
157
157
  let entity;
158
158
  try {
159
159
  entity = await this._entityStorageConnector.get(params.data.id);
@@ -161,7 +161,7 @@ class SynchronisedEntityStorageConnector {
161
161
  catch { }
162
162
  // Publish the item response with the entity
163
163
  this._eventBusComponent.publish(synchronisedStorageModels.SynchronisedStorageTopics.LocalItemResponse, {
164
- schemaType: this._entitySchemaType,
164
+ storageKey: this._storageKey,
165
165
  id: params.data.id,
166
166
  entity
167
167
  });
@@ -169,15 +169,15 @@ class SynchronisedEntityStorageConnector {
169
169
  });
170
170
  // When the synchronised storage requests a batch, we need to provide it
171
171
  this._eventBusComponent.subscribe(synchronisedStorageModels.SynchronisedStorageTopics.BatchRequest, async (params) => {
172
- // Only handle the request if it matches the schema type
173
- if (params.data.schemaType === this._entitySchemaType) {
172
+ // Only handle the request if it matches the storage key
173
+ if (params.data.storageKey === this._storageKey) {
174
174
  let cursor;
175
175
  do {
176
176
  const result = await this._entityStorageConnector.query(undefined, [{ property: "dateModified", sortDirection: entity.SortDirection.Ascending }], undefined, cursor, params.data.batchSize);
177
177
  cursor = result.cursor;
178
178
  // Publish the batch response with the entities
179
179
  this._eventBusComponent.publish(synchronisedStorageModels.SynchronisedStorageTopics.BatchResponse, {
180
- schemaType: this._entitySchemaType,
180
+ storageKey: this._storageKey,
181
181
  primaryKey: this._primaryKey.property,
182
182
  entities: result.entities,
183
183
  lastEntry: !core.Is.stringValue(cursor)
@@ -187,15 +187,15 @@ class SynchronisedEntityStorageConnector {
187
187
  });
188
188
  // Subscribe to remote item set events from the synchronised storage and update the local storage
189
189
  this._eventBusComponent.subscribe(synchronisedStorageModels.SynchronisedStorageTopics.RemoteItemSet, async (params) => {
190
- // Only remove the item if it matches the schema type
191
- if (params.data.schemaType === this._entitySchemaType) {
190
+ // Only remove the item if it matches the storage key
191
+ if (params.data.storageKey === this._storageKey) {
192
192
  await this.set(params.data.entity);
193
193
  }
194
194
  });
195
195
  // Subscribe to remote item remove events from the synchronised storage and update the local storage
196
196
  this._eventBusComponent.subscribe(synchronisedStorageModels.SynchronisedStorageTopics.RemoteItemRemove, async (params) => {
197
- // Only remove the item if it matches the schema type
198
- if (params.data.schemaType === this._entitySchemaType) {
197
+ // Only remove the item if it matches the storage key
198
+ if (params.data.storageKey === this._storageKey) {
199
199
  await this.remove(params.data.id);
200
200
  }
201
201
  });
@@ -24,10 +24,10 @@ class SynchronisedEntityStorageConnector {
24
24
  */
25
25
  _primaryKey;
26
26
  /**
27
- * The entity schema type.
27
+ * The storage key for the entity.
28
28
  * @internal
29
29
  */
30
- _entitySchemaType;
30
+ _storageKey;
31
31
  /**
32
32
  * The entity storage connector to use for actual data.
33
33
  * @internal
@@ -47,7 +47,7 @@ class SynchronisedEntityStorageConnector {
47
47
  Guards.stringValue(this.CLASS_NAME, "options.entitySchema", options.entitySchema);
48
48
  Guards.stringValue(this.CLASS_NAME, "options.entityStorageConnectorType", options.entityStorageConnectorType);
49
49
  this._entitySchema = EntitySchemaFactory.get(options.entitySchema);
50
- this._entitySchemaType = StringHelper.kebabCase(options.entitySchema);
50
+ this._storageKey = options?.config?.storageKey ?? StringHelper.kebabCase(options.entitySchema);
51
51
  this._primaryKey = EntitySchemaHelper.getPrimaryKey(this._entitySchema);
52
52
  const requiredProperties = ["nodeIdentity", "dateModified"];
53
53
  for (const requiredProperty of requiredProperties) {
@@ -79,9 +79,9 @@ class SynchronisedEntityStorageConnector {
79
79
  * @returns Nothing.
80
80
  */
81
81
  async start(nodeIdentity, nodeLoggingConnectorType, componentState) {
82
- // Tell the synchronised storage about this schema type
83
- await this._eventBusComponent.publish(SynchronisedStorageTopics.RegisterSchemaType, {
84
- schemaType: this._entitySchemaType
82
+ // Tell the synchronised storage about this storage key
83
+ await this._eventBusComponent.publish(SynchronisedStorageTopics.RegisterStorageKey, {
84
+ storageKey: this._storageKey
85
85
  });
86
86
  this.handleEventBusMessages();
87
87
  }
@@ -109,7 +109,7 @@ class SynchronisedEntityStorageConnector {
109
109
  await this._entityStorageConnector.set(entity, conditions);
110
110
  // Tell the synchronised storage about the entity changes
111
111
  await this._eventBusComponent.publish(SynchronisedStorageTopics.LocalItemChange, {
112
- schemaType: this._entitySchemaType,
112
+ storageKey: this._storageKey,
113
113
  operation: SyncChangeOperation.Set,
114
114
  id: entity[this._primaryKey.property]
115
115
  });
@@ -125,7 +125,7 @@ class SynchronisedEntityStorageConnector {
125
125
  await this._entityStorageConnector.remove(id, conditions);
126
126
  // Tell the synchronised storage about the entity removal
127
127
  await this._eventBusComponent.publish(SynchronisedStorageTopics.LocalItemChange, {
128
- schemaType: this._entitySchemaType,
128
+ storageKey: this._storageKey,
129
129
  operation: SyncChangeOperation.Delete,
130
130
  id
131
131
  });
@@ -150,8 +150,8 @@ class SynchronisedEntityStorageConnector {
150
150
  handleEventBusMessages() {
151
151
  // When the synchronised storage requests an item, we need to provide it
152
152
  this._eventBusComponent.subscribe(SynchronisedStorageTopics.LocalItemRequest, async (params) => {
153
- // Only handle the request if it matches the schema type
154
- if (params.data.schemaType === this._entitySchemaType) {
153
+ // Only handle the request if it matches the storage key
154
+ if (params.data.storageKey === this._storageKey) {
155
155
  let entity;
156
156
  try {
157
157
  entity = await this._entityStorageConnector.get(params.data.id);
@@ -159,7 +159,7 @@ class SynchronisedEntityStorageConnector {
159
159
  catch { }
160
160
  // Publish the item response with the entity
161
161
  this._eventBusComponent.publish(SynchronisedStorageTopics.LocalItemResponse, {
162
- schemaType: this._entitySchemaType,
162
+ storageKey: this._storageKey,
163
163
  id: params.data.id,
164
164
  entity
165
165
  });
@@ -167,15 +167,15 @@ class SynchronisedEntityStorageConnector {
167
167
  });
168
168
  // When the synchronised storage requests a batch, we need to provide it
169
169
  this._eventBusComponent.subscribe(SynchronisedStorageTopics.BatchRequest, async (params) => {
170
- // Only handle the request if it matches the schema type
171
- if (params.data.schemaType === this._entitySchemaType) {
170
+ // Only handle the request if it matches the storage key
171
+ if (params.data.storageKey === this._storageKey) {
172
172
  let cursor;
173
173
  do {
174
174
  const result = await this._entityStorageConnector.query(undefined, [{ property: "dateModified", sortDirection: SortDirection.Ascending }], undefined, cursor, params.data.batchSize);
175
175
  cursor = result.cursor;
176
176
  // Publish the batch response with the entities
177
177
  this._eventBusComponent.publish(SynchronisedStorageTopics.BatchResponse, {
178
- schemaType: this._entitySchemaType,
178
+ storageKey: this._storageKey,
179
179
  primaryKey: this._primaryKey.property,
180
180
  entities: result.entities,
181
181
  lastEntry: !Is.stringValue(cursor)
@@ -185,15 +185,15 @@ class SynchronisedEntityStorageConnector {
185
185
  });
186
186
  // Subscribe to remote item set events from the synchronised storage and update the local storage
187
187
  this._eventBusComponent.subscribe(SynchronisedStorageTopics.RemoteItemSet, async (params) => {
188
- // Only remove the item if it matches the schema type
189
- if (params.data.schemaType === this._entitySchemaType) {
188
+ // Only remove the item if it matches the storage key
189
+ if (params.data.storageKey === this._storageKey) {
190
190
  await this.set(params.data.entity);
191
191
  }
192
192
  });
193
193
  // Subscribe to remote item remove events from the synchronised storage and update the local storage
194
194
  this._eventBusComponent.subscribe(SynchronisedStorageTopics.RemoteItemRemove, async (params) => {
195
- // Only remove the item if it matches the schema type
196
- if (params.data.schemaType === this._entitySchemaType) {
195
+ // Only remove the item if it matches the storage key
196
+ if (params.data.storageKey === this._storageKey) {
197
197
  await this.remove(params.data.id);
198
198
  }
199
199
  });
@@ -2,4 +2,9 @@
2
2
  * Configuration for the Synchronised Entity Storage Connector.
3
3
  */
4
4
  export interface ISynchronisedEntityStorageConnectorConfig {
5
+ /**
6
+ * The storage key for the synchronised entity storage connector.
7
+ * Will default to kebab cased entity schema name.
8
+ */
9
+ storageKey?: string;
5
10
  }
package/docs/changelog.md CHANGED
@@ -1 +1,28 @@
1
- # @twin.org/entity-storage-connector-synchronised - Changelog
1
+ # Changelog
2
+
3
+ ## [0.0.2-next.3](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-synchronised-v0.0.2-next.2...entity-storage-connector-synchronised-v0.0.2-next.3) (2025-07-25)
4
+
5
+
6
+ ### Features
7
+
8
+ * add synchronised to release configs ([e1e749c](https://github.com/twinfoundation/entity-storage/commit/e1e749cf261b58c8c36729686861e29c7d5e068e))
9
+ * add tests for synchronised storage connector ([1e10623](https://github.com/twinfoundation/entity-storage/commit/1e106231747c8351f3cf5ecb9a33145e3ea56475))
10
+ * synchronised storage ([#44](https://github.com/twinfoundation/entity-storage/issues/44)) ([94e10e2](https://github.com/twinfoundation/entity-storage/commit/94e10e26d1feec801449dc04af7a9757ac7495ff))
11
+ * test with custom key ([264f372](https://github.com/twinfoundation/entity-storage/commit/264f372a38c0ab66b16300542ae2530bd808b6cb))
12
+ * update schema type to storage key for synchronised storage ([a21b206](https://github.com/twinfoundation/entity-storage/commit/a21b2060d0a6d7ec43b189f5fa58b4ada1fde8cb))
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * linting ([ba1c21b](https://github.com/twinfoundation/entity-storage/commit/ba1c21b6261de437d68f53f243b297f6d41a49b7))
18
+
19
+
20
+ ### Dependencies
21
+
22
+ * The following workspace dependencies were updated
23
+ * dependencies
24
+ * @twin.org/entity-storage-models bumped from 0.0.1-next.29 to 0.0.2-next.3
25
+ * devDependencies
26
+ * @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.29 to 0.0.2-next.3
27
+
28
+ ## @twin.org/entity-storage-connector-synchronised - Changelog
@@ -1,3 +1,12 @@
1
1
  # Interface: ISynchronisedEntityStorageConnectorConfig
2
2
 
3
3
  Configuration for the Synchronised Entity Storage Connector.
4
+
5
+ ## Properties
6
+
7
+ ### storageKey?
8
+
9
+ > `optional` **storageKey**: `string`
10
+
11
+ The storage key for the synchronised entity storage connector.
12
+ Will default to kebab cased entity schema name.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-connector-synchronised",
3
- "version": "0.0.1-next.29",
3
+ "version": "0.0.2-next.3",
4
4
  "description": "Entity Storage connector implementation using synchronised storage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
18
  "@twin.org/entity": "next",
19
- "@twin.org/entity-storage-models": "0.0.1-next.29",
19
+ "@twin.org/entity-storage-models": "0.0.2-next.3",
20
20
  "@twin.org/event-bus-models": "next",
21
21
  "@twin.org/logging-models": "next",
22
22
  "@twin.org/nameof": "next",