@twin.org/engine-core 0.0.1-next.11 → 0.0.1-next.13

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.
@@ -107,7 +107,7 @@ function initialiseEntityStorageConnector(engineCore, context, typeCustom, schem
107
107
  ...entityStorageConfig.options,
108
108
  config: {
109
109
  ...entityStorageConfig.options.config,
110
- directory: path.join(entityStorageConfig.options.config.directory, instanceName)
110
+ directory: path.join(entityStorageConfig.options.config.directory, `${entityStorageConfig.options.folderPrefix ?? ""}${instanceName}`)
111
111
  }
112
112
  });
113
113
  }
@@ -1189,6 +1189,60 @@ function initialiseWalletStorage(engineCore, context, instanceConfig, overrideIn
1189
1189
  return undefined;
1190
1190
  }
1191
1191
 
1192
+ // Copyright 2024 IOTA Stiftung.
1193
+ // SPDX-License-Identifier: Apache-2.0.
1194
+ /**
1195
+ * Store state in memory.
1196
+ */
1197
+ class MemoryStateStorage {
1198
+ /**
1199
+ * Runtime name for the class.
1200
+ */
1201
+ CLASS_NAME = "MemoryStateStorage";
1202
+ /**
1203
+ * Readonly mode state file is not updated.
1204
+ * @internal
1205
+ */
1206
+ _readonlyMode;
1207
+ /**
1208
+ * The state object.
1209
+ * @internal
1210
+ */
1211
+ _engineState;
1212
+ /**
1213
+ * Create a new instance of MemoryStateStorage.
1214
+ * @param readonlyMode Whether the file is in read-only mode.
1215
+ * @param state The initial state.
1216
+ */
1217
+ constructor(readonlyMode = false, state) {
1218
+ this._readonlyMode = readonlyMode;
1219
+ this._engineState = state;
1220
+ }
1221
+ /**
1222
+ * Method for loading the state.
1223
+ * @param engineCore The engine core to load the state for.
1224
+ * @returns The state of the engine or undefined if it doesn't exist.
1225
+ */
1226
+ async load(engineCore) {
1227
+ engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.loading`, {
1228
+ filename: this._engineState
1229
+ }));
1230
+ return this._engineState;
1231
+ }
1232
+ /**
1233
+ * Method for saving the state.
1234
+ * @param engineCore The engine core to save the state for.
1235
+ * @param state The state of the engine to save.
1236
+ * @returns Nothing.
1237
+ */
1238
+ async save(engineCore, state) {
1239
+ if (!this._readonlyMode) {
1240
+ engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.saving`));
1241
+ this._engineState = state;
1242
+ }
1243
+ }
1244
+ }
1245
+
1192
1246
  // Copyright 2024 IOTA Stiftung.
1193
1247
  // SPDX-License-Identifier: Apache-2.0.
1194
1248
  /**
@@ -1387,6 +1441,36 @@ class EngineCore {
1387
1441
  getDefaultTypes() {
1388
1442
  return this._context.defaultTypes;
1389
1443
  }
1444
+ /**
1445
+ * Get the data required to create a clone of the engine.
1446
+ * @returns The clone data.
1447
+ */
1448
+ getCloneData() {
1449
+ const cloneData = {
1450
+ config: this._context.config,
1451
+ state: this._context.state
1452
+ };
1453
+ return cloneData;
1454
+ }
1455
+ /**
1456
+ * Populate the engine from the clone data.
1457
+ * @param cloneData The clone data to populate from.
1458
+ */
1459
+ populateClone(cloneData) {
1460
+ core.Guards.object(this.CLASS_NAME, "cloneData", cloneData);
1461
+ core.Guards.object(this.CLASS_NAME, "cloneData.config", cloneData.config);
1462
+ core.Guards.object(this.CLASS_NAME, "cloneData.state", cloneData.state);
1463
+ this._context = {
1464
+ config: cloneData.config,
1465
+ defaultTypes: {},
1466
+ componentInstances: [],
1467
+ state: { bootstrappedComponents: [] },
1468
+ stateDirty: false
1469
+ };
1470
+ this.addCoreTypeInitialisers();
1471
+ this._stateStorage = new MemoryStateStorage(true, cloneData.state);
1472
+ this._isStarted = false;
1473
+ }
1390
1474
  /**
1391
1475
  * Initialise the types from connector.
1392
1476
  * @param typeKey The key for the default types.
@@ -1636,58 +1720,6 @@ class FileStateStorage {
1636
1720
  }
1637
1721
  }
1638
1722
 
1639
- // Copyright 2024 IOTA Stiftung.
1640
- // SPDX-License-Identifier: Apache-2.0.
1641
- /**
1642
- * Store state in memory.
1643
- */
1644
- class MemoryStateStorage {
1645
- /**
1646
- * Runtime name for the class.
1647
- */
1648
- CLASS_NAME = "MemoryStateStorage";
1649
- /**
1650
- * Readonly mode state file is not updated.
1651
- * @internal
1652
- */
1653
- _readonlyMode;
1654
- /**
1655
- * The state object.
1656
- * @internal
1657
- */
1658
- _engineState;
1659
- /**
1660
- * Create a new instance of MemoryStateStorage.
1661
- * @param readonlyMode Whether the file is in read-only mode.
1662
- */
1663
- constructor(readonlyMode = false) {
1664
- this._readonlyMode = readonlyMode;
1665
- }
1666
- /**
1667
- * Method for loading the state.
1668
- * @param engineCore The engine core to load the state for.
1669
- * @returns The state of the engine or undefined if it doesn't exist.
1670
- */
1671
- async load(engineCore) {
1672
- engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.loading`, {
1673
- filename: this._engineState
1674
- }));
1675
- return this._engineState;
1676
- }
1677
- /**
1678
- * Method for saving the state.
1679
- * @param engineCore The engine core to save the state for.
1680
- * @param state The state of the engine to save.
1681
- * @returns Nothing.
1682
- */
1683
- async save(engineCore, state) {
1684
- if (!this._readonlyMode) {
1685
- engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.saving`));
1686
- this._engineState = state;
1687
- }
1688
- }
1689
- }
1690
-
1691
1723
  // Copyright 2024 IOTA Stiftung.
1692
1724
  // SPDX-License-Identifier: Apache-2.0.
1693
1725
  /**
@@ -1785,7 +1817,10 @@ function configureEntityStorageConnectors(coreConfig, envVars) {
1785
1817
  envVars.entityStorageConnectorType === engineModels.EntityStorageConnectorType.File) {
1786
1818
  coreConfig.entityStorageConnector.push({
1787
1819
  type: engineModels.EntityStorageConnectorType.File,
1788
- options: { config: { directory: envVars.storageFileRoot } }
1820
+ options: {
1821
+ config: { directory: envVars.storageFileRoot },
1822
+ folderPrefix: envVars.entityStorageTablePrefix
1823
+ }
1789
1824
  });
1790
1825
  }
1791
1826
  if (core.Is.stringValue(envVars.awsDynamodbAccessKeyId)) {
@@ -105,7 +105,7 @@ function initialiseEntityStorageConnector(engineCore, context, typeCustom, schem
105
105
  ...entityStorageConfig.options,
106
106
  config: {
107
107
  ...entityStorageConfig.options.config,
108
- directory: path.join(entityStorageConfig.options.config.directory, instanceName)
108
+ directory: path.join(entityStorageConfig.options.config.directory, `${entityStorageConfig.options.folderPrefix ?? ""}${instanceName}`)
109
109
  }
110
110
  });
111
111
  }
@@ -1187,6 +1187,60 @@ function initialiseWalletStorage(engineCore, context, instanceConfig, overrideIn
1187
1187
  return undefined;
1188
1188
  }
1189
1189
 
1190
+ // Copyright 2024 IOTA Stiftung.
1191
+ // SPDX-License-Identifier: Apache-2.0.
1192
+ /**
1193
+ * Store state in memory.
1194
+ */
1195
+ class MemoryStateStorage {
1196
+ /**
1197
+ * Runtime name for the class.
1198
+ */
1199
+ CLASS_NAME = "MemoryStateStorage";
1200
+ /**
1201
+ * Readonly mode state file is not updated.
1202
+ * @internal
1203
+ */
1204
+ _readonlyMode;
1205
+ /**
1206
+ * The state object.
1207
+ * @internal
1208
+ */
1209
+ _engineState;
1210
+ /**
1211
+ * Create a new instance of MemoryStateStorage.
1212
+ * @param readonlyMode Whether the file is in read-only mode.
1213
+ * @param state The initial state.
1214
+ */
1215
+ constructor(readonlyMode = false, state) {
1216
+ this._readonlyMode = readonlyMode;
1217
+ this._engineState = state;
1218
+ }
1219
+ /**
1220
+ * Method for loading the state.
1221
+ * @param engineCore The engine core to load the state for.
1222
+ * @returns The state of the engine or undefined if it doesn't exist.
1223
+ */
1224
+ async load(engineCore) {
1225
+ engineCore.logInfo(I18n.formatMessage(`${StringHelper.camelCase(this.CLASS_NAME)}.loading`, {
1226
+ filename: this._engineState
1227
+ }));
1228
+ return this._engineState;
1229
+ }
1230
+ /**
1231
+ * Method for saving the state.
1232
+ * @param engineCore The engine core to save the state for.
1233
+ * @param state The state of the engine to save.
1234
+ * @returns Nothing.
1235
+ */
1236
+ async save(engineCore, state) {
1237
+ if (!this._readonlyMode) {
1238
+ engineCore.logInfo(I18n.formatMessage(`${StringHelper.camelCase(this.CLASS_NAME)}.saving`));
1239
+ this._engineState = state;
1240
+ }
1241
+ }
1242
+ }
1243
+
1190
1244
  // Copyright 2024 IOTA Stiftung.
1191
1245
  // SPDX-License-Identifier: Apache-2.0.
1192
1246
  /**
@@ -1385,6 +1439,36 @@ class EngineCore {
1385
1439
  getDefaultTypes() {
1386
1440
  return this._context.defaultTypes;
1387
1441
  }
1442
+ /**
1443
+ * Get the data required to create a clone of the engine.
1444
+ * @returns The clone data.
1445
+ */
1446
+ getCloneData() {
1447
+ const cloneData = {
1448
+ config: this._context.config,
1449
+ state: this._context.state
1450
+ };
1451
+ return cloneData;
1452
+ }
1453
+ /**
1454
+ * Populate the engine from the clone data.
1455
+ * @param cloneData The clone data to populate from.
1456
+ */
1457
+ populateClone(cloneData) {
1458
+ Guards.object(this.CLASS_NAME, "cloneData", cloneData);
1459
+ Guards.object(this.CLASS_NAME, "cloneData.config", cloneData.config);
1460
+ Guards.object(this.CLASS_NAME, "cloneData.state", cloneData.state);
1461
+ this._context = {
1462
+ config: cloneData.config,
1463
+ defaultTypes: {},
1464
+ componentInstances: [],
1465
+ state: { bootstrappedComponents: [] },
1466
+ stateDirty: false
1467
+ };
1468
+ this.addCoreTypeInitialisers();
1469
+ this._stateStorage = new MemoryStateStorage(true, cloneData.state);
1470
+ this._isStarted = false;
1471
+ }
1388
1472
  /**
1389
1473
  * Initialise the types from connector.
1390
1474
  * @param typeKey The key for the default types.
@@ -1634,58 +1718,6 @@ class FileStateStorage {
1634
1718
  }
1635
1719
  }
1636
1720
 
1637
- // Copyright 2024 IOTA Stiftung.
1638
- // SPDX-License-Identifier: Apache-2.0.
1639
- /**
1640
- * Store state in memory.
1641
- */
1642
- class MemoryStateStorage {
1643
- /**
1644
- * Runtime name for the class.
1645
- */
1646
- CLASS_NAME = "MemoryStateStorage";
1647
- /**
1648
- * Readonly mode state file is not updated.
1649
- * @internal
1650
- */
1651
- _readonlyMode;
1652
- /**
1653
- * The state object.
1654
- * @internal
1655
- */
1656
- _engineState;
1657
- /**
1658
- * Create a new instance of MemoryStateStorage.
1659
- * @param readonlyMode Whether the file is in read-only mode.
1660
- */
1661
- constructor(readonlyMode = false) {
1662
- this._readonlyMode = readonlyMode;
1663
- }
1664
- /**
1665
- * Method for loading the state.
1666
- * @param engineCore The engine core to load the state for.
1667
- * @returns The state of the engine or undefined if it doesn't exist.
1668
- */
1669
- async load(engineCore) {
1670
- engineCore.logInfo(I18n.formatMessage(`${StringHelper.camelCase(this.CLASS_NAME)}.loading`, {
1671
- filename: this._engineState
1672
- }));
1673
- return this._engineState;
1674
- }
1675
- /**
1676
- * Method for saving the state.
1677
- * @param engineCore The engine core to save the state for.
1678
- * @param state The state of the engine to save.
1679
- * @returns Nothing.
1680
- */
1681
- async save(engineCore, state) {
1682
- if (!this._readonlyMode) {
1683
- engineCore.logInfo(I18n.formatMessage(`${StringHelper.camelCase(this.CLASS_NAME)}.saving`));
1684
- this._engineState = state;
1685
- }
1686
- }
1687
- }
1688
-
1689
1721
  // Copyright 2024 IOTA Stiftung.
1690
1722
  // SPDX-License-Identifier: Apache-2.0.
1691
1723
  /**
@@ -1783,7 +1815,10 @@ function configureEntityStorageConnectors(coreConfig, envVars) {
1783
1815
  envVars.entityStorageConnectorType === EntityStorageConnectorType.File) {
1784
1816
  coreConfig.entityStorageConnector.push({
1785
1817
  type: EntityStorageConnectorType.File,
1786
- options: { config: { directory: envVars.storageFileRoot } }
1818
+ options: {
1819
+ config: { directory: envVars.storageFileRoot },
1820
+ folderPrefix: envVars.entityStorageTablePrefix
1821
+ }
1787
1822
  });
1788
1823
  }
1789
1824
  if (Is.stringValue(envVars.awsDynamodbAccessKeyId)) {
@@ -1,5 +1,5 @@
1
1
  import { type IError } from "@twin.org/core";
2
- import type { EngineTypeInitialiser, IEngineCore, IEngineCoreConfig, IEngineCoreTypeBaseConfig, IEngineCoreTypeConfig, IEngineState } from "@twin.org/engine-models";
2
+ import type { EngineTypeInitialiser, IEngineCore, IEngineCoreClone, IEngineCoreConfig, IEngineCoreTypeBaseConfig, IEngineCoreTypeConfig, IEngineState } from "@twin.org/engine-models";
3
3
  import type { IEngineCoreOptions } from "./models/IEngineCoreOptions";
4
4
  /**
5
5
  * Core for the engine.
@@ -62,4 +62,14 @@ export declare class EngineCore<S extends IEngineState = IEngineState> implement
62
62
  getDefaultTypes(): {
63
63
  [type: string]: string;
64
64
  };
65
+ /**
66
+ * Get the data required to create a clone of the engine.
67
+ * @returns The clone data.
68
+ */
69
+ getCloneData(): IEngineCoreClone;
70
+ /**
71
+ * Populate the engine from the clone data.
72
+ * @param cloneData The clone data to populate from.
73
+ */
74
+ populateClone(cloneData: IEngineCoreClone): void;
65
75
  }
@@ -10,8 +10,9 @@ export declare class MemoryStateStorage<S extends IEngineState = IEngineState> i
10
10
  /**
11
11
  * Create a new instance of MemoryStateStorage.
12
12
  * @param readonlyMode Whether the file is in read-only mode.
13
+ * @param state The initial state.
13
14
  */
14
- constructor(readonlyMode?: boolean);
15
+ constructor(readonlyMode?: boolean, state?: S);
15
16
  /**
16
17
  * Method for loading the state.
17
18
  * @param engineCore The engine core to load the state for.
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/engine-core - Changelog
2
2
 
3
- ## v0.0.1-next.11
3
+ ## v0.0.1-next.13
4
4
 
5
5
  - Initial Release
@@ -211,3 +211,43 @@ The default types.
211
211
  #### Implementation of
212
212
 
213
213
  `IEngineCore.getDefaultTypes`
214
+
215
+ ***
216
+
217
+ ### getCloneData()
218
+
219
+ > **getCloneData**(): `IEngineCoreClone`\<`IEngineState`\>
220
+
221
+ Get the data required to create a clone of the engine.
222
+
223
+ #### Returns
224
+
225
+ `IEngineCoreClone`\<`IEngineState`\>
226
+
227
+ The clone data.
228
+
229
+ #### Implementation of
230
+
231
+ `IEngineCore.getCloneData`
232
+
233
+ ***
234
+
235
+ ### populateClone()
236
+
237
+ > **populateClone**(`cloneData`): `void`
238
+
239
+ Populate the engine from the clone data.
240
+
241
+ #### Parameters
242
+
243
+ • **cloneData**: `IEngineCoreClone`\<`IEngineState`\>
244
+
245
+ The clone data to populate from.
246
+
247
+ #### Returns
248
+
249
+ `void`
250
+
251
+ #### Implementation of
252
+
253
+ `IEngineCore.populateClone`
@@ -14,7 +14,7 @@ Store state in memory.
14
14
 
15
15
  ### new MemoryStateStorage()
16
16
 
17
- > **new MemoryStateStorage**\<`S`\>(`readonlyMode`): [`MemoryStateStorage`](MemoryStateStorage.md)\<`S`\>
17
+ > **new MemoryStateStorage**\<`S`\>(`readonlyMode`, `state`?): [`MemoryStateStorage`](MemoryStateStorage.md)\<`S`\>
18
18
 
19
19
  Create a new instance of MemoryStateStorage.
20
20
 
@@ -24,6 +24,10 @@ Create a new instance of MemoryStateStorage.
24
24
 
25
25
  Whether the file is in read-only mode.
26
26
 
27
+ • **state?**: `S`
28
+
29
+ The initial state.
30
+
27
31
  #### Returns
28
32
 
29
33
  [`MemoryStateStorage`](MemoryStateStorage.md)\<`S`\>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/engine-core",
3
- "version": "0.0.1-next.11",
3
+ "version": "0.0.1-next.13",
4
4
  "description": "Engine implementation for a core.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,7 +43,7 @@
43
43
  "@twin.org/crypto": "next",
44
44
  "@twin.org/data-core": "next",
45
45
  "@twin.org/data-schema-org": "next",
46
- "@twin.org/engine-models": "0.0.1-next.11",
46
+ "@twin.org/engine-models": "0.0.1-next.13",
47
47
  "@twin.org/entity": "next",
48
48
  "@twin.org/entity-storage-connector-cosmosdb": "next",
49
49
  "@twin.org/entity-storage-connector-dynamodb": "next",