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

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,15 +49,21 @@ 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
- const requiredProperties = ["nodeIdentity", "dateModified"];
54
+ const requiredProperties = [
55
+ "id",
56
+ "nodeIdentity",
57
+ "dateModified"
58
+ ];
55
59
  for (const requiredProperty of requiredProperties) {
56
60
  const foundProperty = this._entitySchema.properties?.find(prop => prop.property === requiredProperty);
57
61
  if (core.Is.empty(foundProperty)) {
58
62
  throw new core.GeneralError(this.CLASS_NAME, "missingRequiredProperty", { requiredProperty });
59
63
  }
60
- else if (core.Is.empty(foundProperty.isSecondary) && core.Is.empty(foundProperty.sortDirection)) {
64
+ else if (core.Is.empty(foundProperty.isPrimary) &&
65
+ core.Is.empty(foundProperty.isSecondary) &&
66
+ core.Is.empty(foundProperty.sortDirection)) {
61
67
  throw new core.GeneralError(this.CLASS_NAME, "missingRequiredPropertySort", {
62
68
  requiredProperty
63
69
  });
@@ -81,9 +87,9 @@ class SynchronisedEntityStorageConnector {
81
87
  * @returns Nothing.
82
88
  */
83
89
  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
90
+ // Tell the synchronised storage about this storage key
91
+ await this._eventBusComponent.publish(synchronisedStorageModels.SynchronisedStorageTopics.RegisterStorageKey, {
92
+ storageKey: this._storageKey
87
93
  });
88
94
  this.handleEventBusMessages();
89
95
  }
@@ -111,7 +117,7 @@ class SynchronisedEntityStorageConnector {
111
117
  await this._entityStorageConnector.set(entity, conditions);
112
118
  // Tell the synchronised storage about the entity changes
113
119
  await this._eventBusComponent.publish(synchronisedStorageModels.SynchronisedStorageTopics.LocalItemChange, {
114
- schemaType: this._entitySchemaType,
120
+ storageKey: this._storageKey,
115
121
  operation: synchronisedStorageModels.SyncChangeOperation.Set,
116
122
  id: entity[this._primaryKey.property]
117
123
  });
@@ -127,7 +133,7 @@ class SynchronisedEntityStorageConnector {
127
133
  await this._entityStorageConnector.remove(id, conditions);
128
134
  // Tell the synchronised storage about the entity removal
129
135
  await this._eventBusComponent.publish(synchronisedStorageModels.SynchronisedStorageTopics.LocalItemChange, {
130
- schemaType: this._entitySchemaType,
136
+ storageKey: this._storageKey,
131
137
  operation: synchronisedStorageModels.SyncChangeOperation.Delete,
132
138
  id
133
139
  });
@@ -152,8 +158,8 @@ class SynchronisedEntityStorageConnector {
152
158
  handleEventBusMessages() {
153
159
  // When the synchronised storage requests an item, we need to provide it
154
160
  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) {
161
+ // Only handle the request if it matches the storage key
162
+ if (params.data.storageKey === this._storageKey) {
157
163
  let entity;
158
164
  try {
159
165
  entity = await this._entityStorageConnector.get(params.data.id);
@@ -161,7 +167,7 @@ class SynchronisedEntityStorageConnector {
161
167
  catch { }
162
168
  // Publish the item response with the entity
163
169
  this._eventBusComponent.publish(synchronisedStorageModels.SynchronisedStorageTopics.LocalItemResponse, {
164
- schemaType: this._entitySchemaType,
170
+ storageKey: this._storageKey,
165
171
  id: params.data.id,
166
172
  entity
167
173
  });
@@ -169,16 +175,15 @@ class SynchronisedEntityStorageConnector {
169
175
  });
170
176
  // When the synchronised storage requests a batch, we need to provide it
171
177
  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) {
178
+ // Only handle the request if it matches the storage key
179
+ if (params.data.storageKey === this._storageKey) {
174
180
  let cursor;
175
181
  do {
176
182
  const result = await this._entityStorageConnector.query(undefined, [{ property: "dateModified", sortDirection: entity.SortDirection.Ascending }], undefined, cursor, params.data.batchSize);
177
183
  cursor = result.cursor;
178
184
  // Publish the batch response with the entities
179
185
  this._eventBusComponent.publish(synchronisedStorageModels.SynchronisedStorageTopics.BatchResponse, {
180
- schemaType: this._entitySchemaType,
181
- primaryKey: this._primaryKey.property,
186
+ storageKey: this._storageKey,
182
187
  entities: result.entities,
183
188
  lastEntry: !core.Is.stringValue(cursor)
184
189
  });
@@ -187,15 +192,15 @@ class SynchronisedEntityStorageConnector {
187
192
  });
188
193
  // Subscribe to remote item set events from the synchronised storage and update the local storage
189
194
  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) {
195
+ // Only remove the item if it matches the storage key
196
+ if (params.data.storageKey === this._storageKey) {
192
197
  await this.set(params.data.entity);
193
198
  }
194
199
  });
195
200
  // Subscribe to remote item remove events from the synchronised storage and update the local storage
196
201
  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) {
202
+ // Only remove the item if it matches the storage key
203
+ if (params.data.storageKey === this._storageKey) {
199
204
  await this.remove(params.data.id);
200
205
  }
201
206
  });
@@ -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,15 +47,21 @@ 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
- const requiredProperties = ["nodeIdentity", "dateModified"];
52
+ const requiredProperties = [
53
+ "id",
54
+ "nodeIdentity",
55
+ "dateModified"
56
+ ];
53
57
  for (const requiredProperty of requiredProperties) {
54
58
  const foundProperty = this._entitySchema.properties?.find(prop => prop.property === requiredProperty);
55
59
  if (Is.empty(foundProperty)) {
56
60
  throw new GeneralError(this.CLASS_NAME, "missingRequiredProperty", { requiredProperty });
57
61
  }
58
- else if (Is.empty(foundProperty.isSecondary) && Is.empty(foundProperty.sortDirection)) {
62
+ else if (Is.empty(foundProperty.isPrimary) &&
63
+ Is.empty(foundProperty.isSecondary) &&
64
+ Is.empty(foundProperty.sortDirection)) {
59
65
  throw new GeneralError(this.CLASS_NAME, "missingRequiredPropertySort", {
60
66
  requiredProperty
61
67
  });
@@ -79,9 +85,9 @@ class SynchronisedEntityStorageConnector {
79
85
  * @returns Nothing.
80
86
  */
81
87
  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
88
+ // Tell the synchronised storage about this storage key
89
+ await this._eventBusComponent.publish(SynchronisedStorageTopics.RegisterStorageKey, {
90
+ storageKey: this._storageKey
85
91
  });
86
92
  this.handleEventBusMessages();
87
93
  }
@@ -109,7 +115,7 @@ class SynchronisedEntityStorageConnector {
109
115
  await this._entityStorageConnector.set(entity, conditions);
110
116
  // Tell the synchronised storage about the entity changes
111
117
  await this._eventBusComponent.publish(SynchronisedStorageTopics.LocalItemChange, {
112
- schemaType: this._entitySchemaType,
118
+ storageKey: this._storageKey,
113
119
  operation: SyncChangeOperation.Set,
114
120
  id: entity[this._primaryKey.property]
115
121
  });
@@ -125,7 +131,7 @@ class SynchronisedEntityStorageConnector {
125
131
  await this._entityStorageConnector.remove(id, conditions);
126
132
  // Tell the synchronised storage about the entity removal
127
133
  await this._eventBusComponent.publish(SynchronisedStorageTopics.LocalItemChange, {
128
- schemaType: this._entitySchemaType,
134
+ storageKey: this._storageKey,
129
135
  operation: SyncChangeOperation.Delete,
130
136
  id
131
137
  });
@@ -150,8 +156,8 @@ class SynchronisedEntityStorageConnector {
150
156
  handleEventBusMessages() {
151
157
  // When the synchronised storage requests an item, we need to provide it
152
158
  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) {
159
+ // Only handle the request if it matches the storage key
160
+ if (params.data.storageKey === this._storageKey) {
155
161
  let entity;
156
162
  try {
157
163
  entity = await this._entityStorageConnector.get(params.data.id);
@@ -159,7 +165,7 @@ class SynchronisedEntityStorageConnector {
159
165
  catch { }
160
166
  // Publish the item response with the entity
161
167
  this._eventBusComponent.publish(SynchronisedStorageTopics.LocalItemResponse, {
162
- schemaType: this._entitySchemaType,
168
+ storageKey: this._storageKey,
163
169
  id: params.data.id,
164
170
  entity
165
171
  });
@@ -167,16 +173,15 @@ class SynchronisedEntityStorageConnector {
167
173
  });
168
174
  // When the synchronised storage requests a batch, we need to provide it
169
175
  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) {
176
+ // Only handle the request if it matches the storage key
177
+ if (params.data.storageKey === this._storageKey) {
172
178
  let cursor;
173
179
  do {
174
180
  const result = await this._entityStorageConnector.query(undefined, [{ property: "dateModified", sortDirection: SortDirection.Ascending }], undefined, cursor, params.data.batchSize);
175
181
  cursor = result.cursor;
176
182
  // Publish the batch response with the entities
177
183
  this._eventBusComponent.publish(SynchronisedStorageTopics.BatchResponse, {
178
- schemaType: this._entitySchemaType,
179
- primaryKey: this._primaryKey.property,
184
+ storageKey: this._storageKey,
180
185
  entities: result.entities,
181
186
  lastEntry: !Is.stringValue(cursor)
182
187
  });
@@ -185,15 +190,15 @@ class SynchronisedEntityStorageConnector {
185
190
  });
186
191
  // Subscribe to remote item set events from the synchronised storage and update the local storage
187
192
  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) {
193
+ // Only remove the item if it matches the storage key
194
+ if (params.data.storageKey === this._storageKey) {
190
195
  await this.set(params.data.entity);
191
196
  }
192
197
  });
193
198
  // Subscribe to remote item remove events from the synchronised storage and update the local storage
194
199
  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) {
200
+ // Only remove the item if it matches the storage key
201
+ if (params.data.storageKey === this._storageKey) {
197
202
  await this.remove(params.data.id);
198
203
  }
199
204
  });
@@ -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,44 @@
1
- # @twin.org/entity-storage-connector-synchronised - Changelog
1
+ # Changelog
2
+
3
+ ## [0.0.2-next.4](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-synchronised-v0.0.2-next.3...entity-storage-connector-synchronised-v0.0.2-next.4) (2025-08-08)
4
+
5
+
6
+ ### Features
7
+
8
+ * support new synchronised storage features ([a43ee88](https://github.com/twinfoundation/entity-storage/commit/a43ee88431ee3eb8e59e4aeb176009d63ea09d05))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/entity-storage-models bumped from 0.0.2-next.3 to 0.0.2-next.4
16
+ * devDependencies
17
+ * @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.3 to 0.0.2-next.4
18
+
19
+ ## [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)
20
+
21
+
22
+ ### Features
23
+
24
+ * add synchronised to release configs ([e1e749c](https://github.com/twinfoundation/entity-storage/commit/e1e749cf261b58c8c36729686861e29c7d5e068e))
25
+ * add tests for synchronised storage connector ([1e10623](https://github.com/twinfoundation/entity-storage/commit/1e106231747c8351f3cf5ecb9a33145e3ea56475))
26
+ * synchronised storage ([#44](https://github.com/twinfoundation/entity-storage/issues/44)) ([94e10e2](https://github.com/twinfoundation/entity-storage/commit/94e10e26d1feec801449dc04af7a9757ac7495ff))
27
+ * test with custom key ([264f372](https://github.com/twinfoundation/entity-storage/commit/264f372a38c0ab66b16300542ae2530bd808b6cb))
28
+ * update schema type to storage key for synchronised storage ([a21b206](https://github.com/twinfoundation/entity-storage/commit/a21b2060d0a6d7ec43b189f5fa58b4ada1fde8cb))
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * linting ([ba1c21b](https://github.com/twinfoundation/entity-storage/commit/ba1c21b6261de437d68f53f243b297f6d41a49b7))
34
+
35
+
36
+ ### Dependencies
37
+
38
+ * The following workspace dependencies were updated
39
+ * dependencies
40
+ * @twin.org/entity-storage-models bumped from 0.0.1-next.29 to 0.0.2-next.3
41
+ * devDependencies
42
+ * @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.29 to 0.0.2-next.3
43
+
44
+ ## @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.4",
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.4",
20
20
  "@twin.org/event-bus-models": "next",
21
21
  "@twin.org/logging-models": "next",
22
22
  "@twin.org/nameof": "next",