@twin.org/engine-core 0.0.1-next.3 → 0.0.1-next.30
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 +225 -1306
- package/dist/esm/index.mjs +229 -1309
- package/dist/types/engineCore.d.ts +24 -8
- package/dist/types/index.d.ts +0 -1
- package/dist/types/models/IEngineCoreOptions.d.ts +14 -5
- package/dist/types/storage/memoryStateStorage.d.ts +2 -1
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/EngineCore.md +71 -17
- package/docs/reference/classes/FileStateStorage.md +2 -2
- package/docs/reference/classes/MemoryStateStorage.md +7 -3
- package/docs/reference/index.md +0 -4
- package/docs/reference/interfaces/IEngineCoreOptions.md +43 -5
- package/package.json +5 -61
- package/dist/types/components/attestation.d.ts +0 -21
- package/dist/types/components/auditableItemGraph.d.ts +0 -11
- package/dist/types/components/auditableItemStream.d.ts +0 -11
- package/dist/types/components/backgroundTask.d.ts +0 -11
- package/dist/types/components/blobStorage.d.ts +0 -21
- package/dist/types/components/entityStorage.d.ts +0 -20
- package/dist/types/components/faucet.d.ts +0 -11
- package/dist/types/components/identity.d.ts +0 -21
- package/dist/types/components/identityProfile.d.ts +0 -21
- package/dist/types/components/immutableProof.d.ts +0 -11
- package/dist/types/components/immutableStorage.d.ts +0 -11
- package/dist/types/components/logging.d.ts +0 -21
- package/dist/types/components/nft.d.ts +0 -21
- package/dist/types/components/telemetry.d.ts +0 -21
- package/dist/types/components/vault.d.ts +0 -11
- package/dist/types/components/wallet.d.ts +0 -21
- package/docs/reference/functions/initialiseEntityStorageConnector.md +0 -31
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,1180 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var core = require('@twin.org/core');
|
|
4
|
-
var
|
|
5
|
-
var entityStorageConnectorCosmosdb = require('@twin.org/entity-storage-connector-cosmosdb');
|
|
6
|
-
var entityStorageConnectorDynamodb = require('@twin.org/entity-storage-connector-dynamodb');
|
|
7
|
-
var entityStorageConnectorFile = require('@twin.org/entity-storage-connector-file');
|
|
8
|
-
var entityStorageConnectorGcpFirestore = require('@twin.org/entity-storage-connector-gcp-firestore');
|
|
9
|
-
var entityStorageConnectorMemory = require('@twin.org/entity-storage-connector-memory');
|
|
10
|
-
var entityStorageConnectorScylladb = require('@twin.org/entity-storage-connector-scylladb');
|
|
11
|
-
var entityStorageModels = require('@twin.org/entity-storage-models');
|
|
12
|
-
var entityStorageService = require('@twin.org/entity-storage-service');
|
|
4
|
+
var entity = require('@twin.org/entity');
|
|
13
5
|
var loggingConnectorConsole = require('@twin.org/logging-connector-console');
|
|
14
6
|
var loggingModels = require('@twin.org/logging-models');
|
|
15
|
-
var
|
|
16
|
-
var attestationConnectorIota = require('@twin.org/attestation-connector-iota');
|
|
17
|
-
var attestationModels = require('@twin.org/attestation-models');
|
|
18
|
-
var attestationService = require('@twin.org/attestation-service');
|
|
19
|
-
var auditableItemGraphService = require('@twin.org/auditable-item-graph-service');
|
|
20
|
-
var auditableItemStreamService = require('@twin.org/auditable-item-stream-service');
|
|
21
|
-
var backgroundTaskConnectorEntityStorage = require('@twin.org/background-task-connector-entity-storage');
|
|
22
|
-
var backgroundTaskModels = require('@twin.org/background-task-models');
|
|
23
|
-
var blobStorageConnectorAwsS3 = require('@twin.org/blob-storage-connector-aws-s3');
|
|
24
|
-
var blobStorageConnectorAzure = require('@twin.org/blob-storage-connector-azure');
|
|
25
|
-
var blobStorageConnectorFile = require('@twin.org/blob-storage-connector-file');
|
|
26
|
-
var blobStorageConnectorGcp = require('@twin.org/blob-storage-connector-gcp');
|
|
27
|
-
var blobStorageConnectorIpfs = require('@twin.org/blob-storage-connector-ipfs');
|
|
28
|
-
var blobStorageConnectorMemory = require('@twin.org/blob-storage-connector-memory');
|
|
29
|
-
var blobStorageModels = require('@twin.org/blob-storage-models');
|
|
30
|
-
var blobStorageService = require('@twin.org/blob-storage-service');
|
|
31
|
-
var walletConnectorEntityStorage = require('@twin.org/wallet-connector-entity-storage');
|
|
32
|
-
var walletConnectorIota = require('@twin.org/wallet-connector-iota');
|
|
33
|
-
var walletModels = require('@twin.org/wallet-models');
|
|
34
|
-
var identityConnectorEntityStorage = require('@twin.org/identity-connector-entity-storage');
|
|
35
|
-
var identityConnectorIota = require('@twin.org/identity-connector-iota');
|
|
36
|
-
var identityModels = require('@twin.org/identity-models');
|
|
37
|
-
var identityService = require('@twin.org/identity-service');
|
|
38
|
-
var immutableProofService = require('@twin.org/immutable-proof-service');
|
|
39
|
-
var immutableStorageConnectorEntityStorage = require('@twin.org/immutable-storage-connector-entity-storage');
|
|
40
|
-
var immutableStorageConnectorIota = require('@twin.org/immutable-storage-connector-iota');
|
|
41
|
-
var immutableStorageModels = require('@twin.org/immutable-storage-models');
|
|
42
|
-
var loggingConnectorEntityStorage = require('@twin.org/logging-connector-entity-storage');
|
|
43
|
-
var loggingService = require('@twin.org/logging-service');
|
|
44
|
-
var nftConnectorEntityStorage = require('@twin.org/nft-connector-entity-storage');
|
|
45
|
-
var nftConnectorIota = require('@twin.org/nft-connector-iota');
|
|
46
|
-
var nftModels = require('@twin.org/nft-models');
|
|
47
|
-
var nftService = require('@twin.org/nft-service');
|
|
48
|
-
var telemetryConnectorEntityStorage = require('@twin.org/telemetry-connector-entity-storage');
|
|
49
|
-
var telemetryModels = require('@twin.org/telemetry-models');
|
|
50
|
-
var telemetryService = require('@twin.org/telemetry-service');
|
|
51
|
-
var vaultConnectorEntityStorage = require('@twin.org/vault-connector-entity-storage');
|
|
52
|
-
var vaultConnectorHashicorp = require('@twin.org/vault-connector-hashicorp');
|
|
53
|
-
var vaultModels = require('@twin.org/vault-models');
|
|
7
|
+
var modules = require('@twin.org/modules');
|
|
54
8
|
var promises = require('node:fs/promises');
|
|
9
|
+
var path = require('node:path');
|
|
55
10
|
|
|
56
11
|
// Copyright 2024 IOTA Stiftung.
|
|
57
12
|
// SPDX-License-Identifier: Apache-2.0.
|
|
58
13
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @param engineCore The engine core.
|
|
61
|
-
* @param context The context for the engine.
|
|
62
|
-
* @param typeCustom Override the type of connector to use instead of default configuration.
|
|
63
|
-
* @param schema The schema for the entity storage.
|
|
64
|
-
* @throws GeneralError if the connector type is unknown.
|
|
65
|
-
*/
|
|
66
|
-
function initialiseEntityStorageConnector(engineCore, context, typeCustom, schema) {
|
|
67
|
-
const instanceName = core.StringHelper.kebabCase(schema);
|
|
68
|
-
let entityStorageConfig;
|
|
69
|
-
if (core.Is.stringValue(typeCustom)) {
|
|
70
|
-
// A custom type has been specified, so look it up
|
|
71
|
-
entityStorageConfig = context.config.entityStorageConnector?.find(c => c.type === typeCustom || c.overrideInstanceType === typeCustom);
|
|
72
|
-
if (core.Is.empty(entityStorageConfig)) {
|
|
73
|
-
throw new core.GeneralError("engineCore", "entityStorageCustomMissing", {
|
|
74
|
-
typeCustom,
|
|
75
|
-
storageName: instanceName
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
// The default entity storage method is either the one with the isDefault flag set
|
|
81
|
-
// or pick the first one if no default is set.
|
|
82
|
-
entityStorageConfig =
|
|
83
|
-
context.config.entityStorageConnector?.find(c => c.isDefault ?? false) ??
|
|
84
|
-
context.config.entityStorageConnector?.[0];
|
|
85
|
-
if (core.Is.empty(entityStorageConfig)) {
|
|
86
|
-
throw new core.GeneralError("engineCore", "entityStorageMissing", {
|
|
87
|
-
storageName: instanceName
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const type = entityStorageConfig.type;
|
|
92
|
-
let entityStorageConnector;
|
|
93
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuringEntityStorage", {
|
|
94
|
-
element: "Entity Storage",
|
|
95
|
-
storageName: instanceName,
|
|
96
|
-
storageType: type
|
|
97
|
-
}));
|
|
98
|
-
if (type === engineModels.EntityStorageConnectorType.Memory) {
|
|
99
|
-
entityStorageConnector = new entityStorageConnectorMemory.MemoryEntityStorageConnector({
|
|
100
|
-
entitySchema: schema
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else if (type === engineModels.EntityStorageConnectorType.File) {
|
|
104
|
-
entityStorageConnector = new entityStorageConnectorFile.FileEntityStorageConnector({
|
|
105
|
-
entitySchema: schema,
|
|
106
|
-
...entityStorageConfig.options
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
else if (type === engineModels.EntityStorageConnectorType.AwsDynamoDb) {
|
|
110
|
-
entityStorageConnector = new entityStorageConnectorDynamodb.DynamoDbEntityStorageConnector({
|
|
111
|
-
entitySchema: schema,
|
|
112
|
-
...entityStorageConfig.options,
|
|
113
|
-
config: {
|
|
114
|
-
...entityStorageConfig.options.config,
|
|
115
|
-
tableName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
else if (type === engineModels.EntityStorageConnectorType.AzureCosmosDb) {
|
|
120
|
-
entityStorageConnector = new entityStorageConnectorCosmosdb.CosmosDbEntityStorageConnector({
|
|
121
|
-
entitySchema: schema,
|
|
122
|
-
...entityStorageConfig.options,
|
|
123
|
-
config: {
|
|
124
|
-
...entityStorageConfig.options.config,
|
|
125
|
-
containerId: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
else if (type === engineModels.EntityStorageConnectorType.GcpFirestoreDb) {
|
|
130
|
-
entityStorageConnector = new entityStorageConnectorGcpFirestore.FirestoreEntityStorageConnector({
|
|
131
|
-
entitySchema: schema,
|
|
132
|
-
...entityStorageConfig.options,
|
|
133
|
-
config: {
|
|
134
|
-
...entityStorageConfig.options.config,
|
|
135
|
-
collectionName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
else if (type === engineModels.EntityStorageConnectorType.ScyllaDb) {
|
|
140
|
-
entityStorageConnector = new entityStorageConnectorScylladb.ScyllaDBTableConnector({
|
|
141
|
-
entitySchema: schema,
|
|
142
|
-
...entityStorageConfig.options,
|
|
143
|
-
config: {
|
|
144
|
-
...entityStorageConfig.options.config,
|
|
145
|
-
tableName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
151
|
-
type,
|
|
152
|
-
connectorType: "entityStorageConnector"
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
context.componentInstances.push({
|
|
156
|
-
instanceType: instanceName,
|
|
157
|
-
component: entityStorageConnector
|
|
158
|
-
});
|
|
159
|
-
entityStorageModels.EntityStorageConnectorFactory.register(instanceName, () => entityStorageConnector);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Initialise the entity storage connector.
|
|
163
|
-
* @param engineCore The engine core.
|
|
164
|
-
* @param context The context for the engine.
|
|
165
|
-
* @param instanceConfig The instance config.
|
|
166
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
167
|
-
* @returns The name of the instance created.
|
|
168
|
-
* @throws GeneralError if the connector type is unknown.
|
|
169
|
-
*/
|
|
170
|
-
function initialiseEntityStorageComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
171
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
172
|
-
element: `Entity Storage Component: ${instanceConfig.type}`
|
|
173
|
-
}));
|
|
174
|
-
const type = instanceConfig.type;
|
|
175
|
-
let connector;
|
|
176
|
-
let instanceType;
|
|
177
|
-
if (type === engineModels.EntityStorageComponentType.Service) {
|
|
178
|
-
const kebabName = core.StringHelper.kebabCase(instanceConfig.options.entityStorageType);
|
|
179
|
-
// See if there is a custom entity storage for this type, otherwise just use the default one.
|
|
180
|
-
const hasCustom = context.config.entityStorageConnector?.some(c => c.type === kebabName || c.overrideInstanceType === kebabName);
|
|
181
|
-
initialiseEntityStorageConnector(engineCore, context, hasCustom ? kebabName : undefined, instanceConfig.options.entityStorageType);
|
|
182
|
-
connector = new entityStorageService.EntityStorageService({
|
|
183
|
-
entityStorageType: kebabName,
|
|
184
|
-
config: {
|
|
185
|
-
...instanceConfig.options.config
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
instanceType = core.StringHelper.kebabCase(instanceConfig.options.entityStorageType);
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
192
|
-
type,
|
|
193
|
-
serviceType: "entityStorageComponent"
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
197
|
-
context.componentInstances.push({
|
|
198
|
-
instanceType: finalInstanceType,
|
|
199
|
-
component: connector
|
|
200
|
-
});
|
|
201
|
-
core.ComponentFactory.register(finalInstanceType, () => connector);
|
|
202
|
-
return finalInstanceType;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Copyright 2024 IOTA Stiftung.
|
|
206
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
207
|
-
/**
|
|
208
|
-
* Initialise the attestation connector.
|
|
209
|
-
* @param engineCore The engine core.
|
|
210
|
-
* @param context The context for the engine.
|
|
211
|
-
* @param instanceConfig The instance config.
|
|
212
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
213
|
-
* @returns The name of the instance created.
|
|
214
|
-
* @throws GeneralError if the connector type is unknown.
|
|
215
|
-
*/
|
|
216
|
-
function initialiseAttestationConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
217
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
218
|
-
element: `Attestation Connector: ${instanceConfig.type}`
|
|
219
|
-
}));
|
|
220
|
-
const type = instanceConfig.type;
|
|
221
|
-
let connector;
|
|
222
|
-
let instanceType;
|
|
223
|
-
if (type === engineModels.AttestationConnectorType.Iota) {
|
|
224
|
-
connector = new attestationConnectorIota.IotaAttestationConnector({
|
|
225
|
-
identityConnectorType: context.defaultTypes.identityConnector,
|
|
226
|
-
nftConnectorType: context.defaultTypes.nftConnector,
|
|
227
|
-
...instanceConfig.options
|
|
228
|
-
});
|
|
229
|
-
instanceType = attestationConnectorIota.IotaAttestationConnector.NAMESPACE;
|
|
230
|
-
}
|
|
231
|
-
else if (type === engineModels.AttestationConnectorType.EntityStorage) {
|
|
232
|
-
connector = new attestationConnectorEntityStorage.EntityStorageAttestationConnector({
|
|
233
|
-
identityConnectorType: context.defaultTypes.identityConnector,
|
|
234
|
-
nftConnectorType: context.defaultTypes.nftConnector,
|
|
235
|
-
...instanceConfig.options
|
|
236
|
-
});
|
|
237
|
-
instanceType = attestationConnectorEntityStorage.EntityStorageAttestationConnector.NAMESPACE;
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
241
|
-
type,
|
|
242
|
-
connectorType: "attestationConnector"
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
246
|
-
context.componentInstances.push({
|
|
247
|
-
instanceType: finalInstanceType,
|
|
248
|
-
component: connector
|
|
249
|
-
});
|
|
250
|
-
attestationModels.AttestationConnectorFactory.register(finalInstanceType, () => connector);
|
|
251
|
-
return finalInstanceType;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Initialise the attestation component.
|
|
255
|
-
* @param engineCore The engine core.
|
|
256
|
-
* @param context The context for the engine.
|
|
257
|
-
* @param instanceConfig The instance config.
|
|
258
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
259
|
-
* @returns The name of the instance created.
|
|
260
|
-
* @throws GeneralError if the component type is unknown.
|
|
261
|
-
*/
|
|
262
|
-
function initialiseAttestationComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
263
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
264
|
-
element: `Attestation Component: ${instanceConfig.type}`
|
|
265
|
-
}));
|
|
266
|
-
const type = instanceConfig.type;
|
|
267
|
-
let component;
|
|
268
|
-
let instanceType;
|
|
269
|
-
if (type === engineModels.AttestationComponentType.Service) {
|
|
270
|
-
component = new attestationService.AttestationService({
|
|
271
|
-
walletConnectorType: context.defaultTypes.walletConnector,
|
|
272
|
-
...instanceConfig.options
|
|
273
|
-
});
|
|
274
|
-
instanceType = attestationService.AttestationService.NAMESPACE;
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
278
|
-
type,
|
|
279
|
-
componentType: "attestationComponent"
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
283
|
-
context.componentInstances.push({
|
|
284
|
-
instanceType: finalInstanceType,
|
|
285
|
-
component
|
|
286
|
-
});
|
|
287
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
288
|
-
return finalInstanceType;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Initialise the auditable item graph component.
|
|
293
|
-
* @param engineCore The engine core.
|
|
294
|
-
* @param context The context for the engine.
|
|
295
|
-
* @param instanceConfig The instance config.
|
|
296
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
297
|
-
* @returns The name of the instance created.
|
|
298
|
-
* @throws GeneralError if the component type is unknown.
|
|
299
|
-
*/
|
|
300
|
-
function initialiseAuditableItemGraphComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
301
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
302
|
-
element: `Auditable Item Graph Component: ${instanceConfig.type}`
|
|
303
|
-
}));
|
|
304
|
-
const type = instanceConfig.type;
|
|
305
|
-
let component;
|
|
306
|
-
let instanceType;
|
|
307
|
-
if (type === engineModels.AuditableItemGraphComponentType.Service) {
|
|
308
|
-
auditableItemGraphService.initSchema();
|
|
309
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.vertexEntityStorageType, "AuditableItemGraphVertex");
|
|
310
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.changesetEntityStorageType, "AuditableItemGraphChangeset");
|
|
311
|
-
component = new auditableItemGraphService.AuditableItemGraphService({
|
|
312
|
-
immutableProofComponentType: context.defaultTypes.immutableProofComponent,
|
|
313
|
-
...instanceConfig.options
|
|
314
|
-
});
|
|
315
|
-
instanceType = auditableItemGraphService.AuditableItemGraphService.NAMESPACE;
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
319
|
-
type,
|
|
320
|
-
componentType: "auditableItemGraphComponent"
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
324
|
-
context.componentInstances.push({
|
|
325
|
-
instanceType: finalInstanceType,
|
|
326
|
-
component
|
|
327
|
-
});
|
|
328
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
329
|
-
return finalInstanceType;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Initialise the auditable item stream component.
|
|
334
|
-
* @param engineCore The engine core.
|
|
335
|
-
* @param context The context for the engine.
|
|
336
|
-
* @param instanceConfig The instance config.
|
|
337
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
338
|
-
* @returns The name of the instance created.
|
|
339
|
-
* @throws GeneralError if the component type is unknown.
|
|
340
|
-
*/
|
|
341
|
-
function initialiseAuditableItemStreamComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
342
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
343
|
-
element: `Auditable Item Stream Component: ${instanceConfig.type}`
|
|
344
|
-
}));
|
|
345
|
-
const type = instanceConfig.type;
|
|
346
|
-
let component;
|
|
347
|
-
let instanceType;
|
|
348
|
-
if (type === engineModels.AuditableItemStreamComponentType.Service) {
|
|
349
|
-
auditableItemStreamService.initSchema();
|
|
350
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.streamEntityStorageType, "AuditableItemStream");
|
|
351
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.streamEntryEntityStorageType, "AuditableItemStreamEntry");
|
|
352
|
-
component = new auditableItemStreamService.AuditableItemStreamService({
|
|
353
|
-
immutableProofComponentType: context.defaultTypes.immutableProofComponent,
|
|
354
|
-
...instanceConfig.options
|
|
355
|
-
});
|
|
356
|
-
instanceType = auditableItemStreamService.AuditableItemStreamService.NAMESPACE;
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
360
|
-
type,
|
|
361
|
-
componentType: "auditableItemStreamComponent"
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
365
|
-
context.componentInstances.push({
|
|
366
|
-
instanceType: finalInstanceType,
|
|
367
|
-
component
|
|
368
|
-
});
|
|
369
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
370
|
-
return finalInstanceType;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Copyright 2024 IOTA Stiftung.
|
|
374
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
375
|
-
/**
|
|
376
|
-
* Initialise a background task connector.
|
|
377
|
-
* @param engineCore The engine core.
|
|
378
|
-
* @param context The context for the engine.
|
|
379
|
-
* @param instanceConfig The instance config.
|
|
380
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
381
|
-
* @returns The name of the instance created.
|
|
382
|
-
* @throws GeneralError if the connector type is unknown.
|
|
383
|
-
*/
|
|
384
|
-
function initialiseBackgroundTaskConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
385
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
386
|
-
element: `Background Task Connector: ${instanceConfig.type}`
|
|
387
|
-
}));
|
|
388
|
-
const type = instanceConfig.type;
|
|
389
|
-
let connector;
|
|
390
|
-
let instanceType;
|
|
391
|
-
if (type === engineModels.BackgroundTaskConnectorType.EntityStorage) {
|
|
392
|
-
backgroundTaskConnectorEntityStorage.initSchema();
|
|
393
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.backgroundTaskEntityStorageType, "BackgroundTask");
|
|
394
|
-
connector = new backgroundTaskConnectorEntityStorage.EntityStorageBackgroundTaskConnector({
|
|
395
|
-
loggingConnectorType: context.defaultTypes.loggingConnector,
|
|
396
|
-
...instanceConfig.options
|
|
397
|
-
});
|
|
398
|
-
instanceType = backgroundTaskConnectorEntityStorage.EntityStorageBackgroundTaskConnector.NAMESPACE;
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
402
|
-
type,
|
|
403
|
-
connectorType: "backgroundTaskConnector"
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
407
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component: connector });
|
|
408
|
-
backgroundTaskModels.BackgroundTaskConnectorFactory.register(finalInstanceType, () => connector);
|
|
409
|
-
return finalInstanceType;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// Copyright 2024 IOTA Stiftung.
|
|
413
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
414
|
-
/**
|
|
415
|
-
* Initialise the blob storage connector.
|
|
416
|
-
* @param engineCore The engine core.
|
|
417
|
-
* @param context The context for the engine.
|
|
418
|
-
* @param instanceConfig The instance config.
|
|
419
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
420
|
-
* @returns The name of the instance created.
|
|
421
|
-
* @throws GeneralError if the connector type is unknown.
|
|
422
|
-
*/
|
|
423
|
-
function initialiseBlobStorageConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
424
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
425
|
-
element: `Blob Storage Connector: ${instanceConfig.type}`
|
|
426
|
-
}));
|
|
427
|
-
const type = instanceConfig.type;
|
|
428
|
-
let connector;
|
|
429
|
-
let instanceType;
|
|
430
|
-
if (type === engineModels.BlobStorageConnectorType.Ipfs) {
|
|
431
|
-
connector = new blobStorageConnectorIpfs.IpfsBlobStorageConnector(instanceConfig.options);
|
|
432
|
-
instanceType = blobStorageConnectorIpfs.IpfsBlobStorageConnector.NAMESPACE;
|
|
433
|
-
}
|
|
434
|
-
else if (type === engineModels.BlobStorageConnectorType.File) {
|
|
435
|
-
connector = new blobStorageConnectorFile.FileBlobStorageConnector({
|
|
436
|
-
...instanceConfig.options,
|
|
437
|
-
config: {
|
|
438
|
-
...instanceConfig.options.config,
|
|
439
|
-
directory: `${instanceConfig.options.storagePrefix ?? ""}${instanceConfig.options.config.directory}`
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
instanceType = blobStorageConnectorFile.FileBlobStorageConnector.NAMESPACE;
|
|
443
|
-
}
|
|
444
|
-
else if (type === engineModels.BlobStorageConnectorType.Memory) {
|
|
445
|
-
connector = new blobStorageConnectorMemory.MemoryBlobStorageConnector();
|
|
446
|
-
instanceType = blobStorageConnectorMemory.MemoryBlobStorageConnector.NAMESPACE;
|
|
447
|
-
}
|
|
448
|
-
else if (type === engineModels.BlobStorageConnectorType.AwsS3) {
|
|
449
|
-
connector = new blobStorageConnectorAwsS3.S3BlobStorageConnector({
|
|
450
|
-
...instanceConfig.options,
|
|
451
|
-
config: {
|
|
452
|
-
...instanceConfig.options.config,
|
|
453
|
-
bucketName: `${instanceConfig.options.storagePrefix ?? ""}${instanceConfig.options.config.bucketName}`
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
instanceType = blobStorageConnectorAwsS3.S3BlobStorageConnector.NAMESPACE;
|
|
457
|
-
}
|
|
458
|
-
else if (type === engineModels.BlobStorageConnectorType.GcpStorage) {
|
|
459
|
-
connector = new blobStorageConnectorGcp.GcpBlobStorageConnector({
|
|
460
|
-
...instanceConfig.options,
|
|
461
|
-
config: {
|
|
462
|
-
...instanceConfig.options.config,
|
|
463
|
-
bucketName: `${instanceConfig.options.storagePrefix ?? ""}${instanceConfig.options.config.bucketName}`
|
|
464
|
-
}
|
|
465
|
-
});
|
|
466
|
-
instanceType = blobStorageConnectorGcp.GcpBlobStorageConnector.NAMESPACE;
|
|
467
|
-
}
|
|
468
|
-
else if (type === engineModels.BlobStorageConnectorType.AzureStorage) {
|
|
469
|
-
connector = new blobStorageConnectorAzure.AzureBlobStorageConnector({
|
|
470
|
-
...instanceConfig.options,
|
|
471
|
-
config: {
|
|
472
|
-
...instanceConfig.options.config,
|
|
473
|
-
containerName: `${instanceConfig.options.storagePrefix ?? ""}${instanceConfig.options.config.containerName}`
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
instanceType = blobStorageConnectorAzure.AzureBlobStorageConnector.NAMESPACE;
|
|
477
|
-
}
|
|
478
|
-
else {
|
|
479
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
480
|
-
type,
|
|
481
|
-
connectorType: "blobStorageConnector"
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
485
|
-
context.componentInstances.push({
|
|
486
|
-
instanceType: finalInstanceType,
|
|
487
|
-
component: connector
|
|
488
|
-
});
|
|
489
|
-
blobStorageModels.BlobStorageConnectorFactory.register(finalInstanceType, () => connector);
|
|
490
|
-
return finalInstanceType;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Initialise the blob storage component.
|
|
494
|
-
* @param engineCore The engine core.
|
|
495
|
-
* @param context The context for the engine.
|
|
496
|
-
* @param instanceConfig The instance config.
|
|
497
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
498
|
-
* @returns The name of the instance created.
|
|
499
|
-
* @throws GeneralError if the component type is unknown.
|
|
500
|
-
*/
|
|
501
|
-
function initialiseBlobStorageComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
502
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
503
|
-
element: `Blob Storage Component: ${instanceConfig.type}`
|
|
504
|
-
}));
|
|
505
|
-
const type = instanceConfig.type;
|
|
506
|
-
let component;
|
|
507
|
-
let instanceType;
|
|
508
|
-
if (type === engineModels.BlobStorageComponentType.Service) {
|
|
509
|
-
blobStorageService.initSchema();
|
|
510
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.entryEntityStorageType, "BlobStorageEntry");
|
|
511
|
-
component = new blobStorageService.BlobStorageService({
|
|
512
|
-
vaultConnectorType: context.defaultTypes.vaultConnector,
|
|
513
|
-
...instanceConfig.options
|
|
514
|
-
});
|
|
515
|
-
instanceType = blobStorageService.BlobStorageService.NAMESPACE;
|
|
516
|
-
}
|
|
517
|
-
else {
|
|
518
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
519
|
-
type,
|
|
520
|
-
componentType: "blobStorageComponent"
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
524
|
-
context.componentInstances.push({
|
|
525
|
-
instanceType: finalInstanceType,
|
|
526
|
-
component
|
|
527
|
-
});
|
|
528
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
529
|
-
return finalInstanceType;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
// Copyright 2024 IOTA Stiftung.
|
|
533
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
534
|
-
/**
|
|
535
|
-
* Initialise a faucet connector.
|
|
536
|
-
* @param engineCore The engine core.
|
|
537
|
-
* @param context The context for the engine.
|
|
538
|
-
* @param instanceConfig The instance config.
|
|
539
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
540
|
-
* @returns The name of the instance created.
|
|
541
|
-
* @throws GeneralError if the connector type is unknown.
|
|
542
|
-
*/
|
|
543
|
-
function initialiseFaucetConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
544
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
545
|
-
element: `Faucet Connector: ${instanceConfig.type}`
|
|
546
|
-
}));
|
|
547
|
-
const type = instanceConfig.type;
|
|
548
|
-
let connector;
|
|
549
|
-
let instanceType;
|
|
550
|
-
if (type === engineModels.FaucetConnectorType.Iota) {
|
|
551
|
-
const dltConfig = context.config.dltConfig?.find(dlt => dlt.type === context.defaultTypes.dltConfig);
|
|
552
|
-
connector = new walletConnectorIota.IotaFaucetConnector({
|
|
553
|
-
...instanceConfig.options,
|
|
554
|
-
config: {
|
|
555
|
-
...dltConfig?.options?.config,
|
|
556
|
-
...instanceConfig.options.config
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
instanceType = walletConnectorIota.IotaFaucetConnector.NAMESPACE;
|
|
560
|
-
}
|
|
561
|
-
else if (type === engineModels.FaucetConnectorType.EntityStorage) {
|
|
562
|
-
connector = new walletConnectorEntityStorage.EntityStorageFaucetConnector(instanceConfig.options);
|
|
563
|
-
instanceType = walletConnectorEntityStorage.EntityStorageFaucetConnector.NAMESPACE;
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
567
|
-
type,
|
|
568
|
-
connectorType: "faucetConnector"
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
572
|
-
context.componentInstances.push({
|
|
573
|
-
instanceType: finalInstanceType,
|
|
574
|
-
component: connector
|
|
575
|
-
});
|
|
576
|
-
walletModels.FaucetConnectorFactory.register(finalInstanceType, () => connector);
|
|
577
|
-
return finalInstanceType;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// Copyright 2024 IOTA Stiftung.
|
|
581
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
582
|
-
/**
|
|
583
|
-
* Initialise the identity connector.
|
|
584
|
-
* @param engineCore The engine core.
|
|
585
|
-
* @param context The context for the engine.
|
|
586
|
-
* @param instanceConfig The instance config.
|
|
587
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
588
|
-
* @returns The name of the instance created.
|
|
589
|
-
* @throws GeneralError if the connector type is unknown.
|
|
590
|
-
*/
|
|
591
|
-
function initialiseIdentityConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
592
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
593
|
-
element: `Identity Connector: ${instanceConfig.type}`
|
|
594
|
-
}));
|
|
595
|
-
const type = instanceConfig.type;
|
|
596
|
-
let connector;
|
|
597
|
-
let instanceType;
|
|
598
|
-
if (type === engineModels.IdentityConnectorType.Iota) {
|
|
599
|
-
const dltConfig = context.config.dltConfig?.find(dlt => dlt.type === context.defaultTypes.dltConfig);
|
|
600
|
-
connector = new identityConnectorIota.IotaIdentityConnector({
|
|
601
|
-
...instanceConfig.options,
|
|
602
|
-
config: {
|
|
603
|
-
...dltConfig?.options?.config,
|
|
604
|
-
...instanceConfig.options.config
|
|
605
|
-
}
|
|
606
|
-
});
|
|
607
|
-
instanceType = identityConnectorIota.IotaIdentityConnector.NAMESPACE;
|
|
608
|
-
}
|
|
609
|
-
else if (type === engineModels.IdentityConnectorType.EntityStorage) {
|
|
610
|
-
identityConnectorEntityStorage.initSchema({ includeProfile: false });
|
|
611
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.didDocumentEntityStorageType, "IdentityDocument");
|
|
612
|
-
connector = new identityConnectorEntityStorage.EntityStorageIdentityConnector({
|
|
613
|
-
vaultConnectorType: context.defaultTypes.vaultConnector,
|
|
614
|
-
...instanceConfig.options
|
|
615
|
-
});
|
|
616
|
-
instanceType = identityConnectorEntityStorage.EntityStorageIdentityConnector.NAMESPACE;
|
|
617
|
-
}
|
|
618
|
-
else {
|
|
619
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
620
|
-
type,
|
|
621
|
-
connectorType: "identityConnector"
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
625
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component: connector });
|
|
626
|
-
identityModels.IdentityConnectorFactory.register(finalInstanceType, () => connector);
|
|
627
|
-
return finalInstanceType;
|
|
628
|
-
}
|
|
629
|
-
/**
|
|
630
|
-
* Initialise the identity component.
|
|
631
|
-
* @param engineCore The engine core.
|
|
632
|
-
* @param context The context for the engine.
|
|
633
|
-
* @param instanceConfig The instance config.
|
|
634
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
635
|
-
* @returns The name of the instance created.
|
|
636
|
-
* @throws GeneralError if the component type is unknown.
|
|
637
|
-
*/
|
|
638
|
-
function initialiseIdentityComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
639
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
640
|
-
element: `Identity Component: ${instanceConfig.type}`
|
|
641
|
-
}));
|
|
642
|
-
const type = instanceConfig.type;
|
|
643
|
-
let component;
|
|
644
|
-
let instanceType;
|
|
645
|
-
if (type === engineModels.IdentityComponentType.Service) {
|
|
646
|
-
component = new identityService.IdentityService(instanceConfig.options);
|
|
647
|
-
instanceType = identityService.IdentityService.NAMESPACE;
|
|
648
|
-
}
|
|
649
|
-
else {
|
|
650
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
651
|
-
type,
|
|
652
|
-
componentType: "identityComponent"
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
656
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component });
|
|
657
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
658
|
-
return finalInstanceType;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
// Copyright 2024 IOTA Stiftung.
|
|
662
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
663
|
-
/**
|
|
664
|
-
* Initialise the identity profile connector.
|
|
665
|
-
* @param engineCore The engine core.
|
|
666
|
-
* @param context The context for the engine.
|
|
667
|
-
* @param instanceConfig The instance config.
|
|
668
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
669
|
-
* @returns The name of the instance created.
|
|
670
|
-
* @throws GeneralError if the connector type is unknown.
|
|
671
|
-
*/
|
|
672
|
-
function initialiseIdentityProfileConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
673
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
674
|
-
element: `Identity Profile Connector: ${instanceConfig.type}`
|
|
675
|
-
}));
|
|
676
|
-
const type = instanceConfig.type;
|
|
677
|
-
let connector;
|
|
678
|
-
let instanceType;
|
|
679
|
-
if (type === engineModels.IdentityProfileConnectorType.EntityStorage) {
|
|
680
|
-
identityConnectorEntityStorage.initSchema({ includeDocument: false });
|
|
681
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.profileEntityStorageType, "IdentityProfile");
|
|
682
|
-
connector = new identityConnectorEntityStorage.EntityStorageIdentityProfileConnector(instanceConfig.options);
|
|
683
|
-
instanceType = identityConnectorEntityStorage.EntityStorageIdentityProfileConnector.NAMESPACE;
|
|
684
|
-
}
|
|
685
|
-
else {
|
|
686
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
687
|
-
type,
|
|
688
|
-
serviceType: "identityProfile"
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
692
|
-
context.componentInstances.push({
|
|
693
|
-
instanceType: finalInstanceType,
|
|
694
|
-
component: connector
|
|
695
|
-
});
|
|
696
|
-
identityModels.IdentityProfileConnectorFactory.register(finalInstanceType, () => connector);
|
|
697
|
-
return finalInstanceType;
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* Initialise the identity profile component.
|
|
701
|
-
* @param engineCore The engine core.
|
|
702
|
-
* @param context The context for the engine.
|
|
703
|
-
* @param instanceConfig The instance config.
|
|
704
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
705
|
-
* @returns The name of the instance created.
|
|
706
|
-
* @throws GeneralError if the component type is unknown.
|
|
707
|
-
*/
|
|
708
|
-
function initialiseIdentityProfileComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
709
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
710
|
-
element: `Identity Profile Component: ${instanceConfig.type}`
|
|
711
|
-
}));
|
|
712
|
-
const type = instanceConfig.type;
|
|
713
|
-
let component;
|
|
714
|
-
let instanceType;
|
|
715
|
-
if (type === engineModels.IdentityProfileComponentType.Service) {
|
|
716
|
-
component = new identityService.IdentityProfileService({
|
|
717
|
-
profileEntityConnectorType: context.defaultTypes.identityProfileConnector,
|
|
718
|
-
...instanceConfig.options
|
|
719
|
-
});
|
|
720
|
-
instanceType = identityService.IdentityProfileService.NAMESPACE;
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
724
|
-
type,
|
|
725
|
-
componentType: "identityProfileComponent"
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
729
|
-
context.componentInstances.push({
|
|
730
|
-
instanceType: finalInstanceType,
|
|
731
|
-
component
|
|
732
|
-
});
|
|
733
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
734
|
-
return finalInstanceType;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
// Copyright 2024 IOTA Stiftung.
|
|
738
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
739
|
-
/**
|
|
740
|
-
* Initialise the immutable proof component.
|
|
741
|
-
* @param engineCore The engine core.
|
|
742
|
-
* @param context The context for the engine.
|
|
743
|
-
* @param instanceConfig The instance config.
|
|
744
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
745
|
-
* @returns The name of the instance created.
|
|
746
|
-
* @throws GeneralError if the component type is unknown.
|
|
747
|
-
*/
|
|
748
|
-
function initialiseImmutableProofComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
749
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
750
|
-
element: `Immutable Proof Component: ${instanceConfig.type}`
|
|
751
|
-
}));
|
|
752
|
-
const type = instanceConfig.type;
|
|
753
|
-
let component;
|
|
754
|
-
let instanceType;
|
|
755
|
-
if (type === engineModels.ImmutableProofComponentType.Service) {
|
|
756
|
-
immutableProofService.initSchema();
|
|
757
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.immutableProofEntityStorageType, "ImmutableProof");
|
|
758
|
-
component = new immutableProofService.ImmutableProofService({
|
|
759
|
-
vaultConnectorType: context.defaultTypes.vaultConnector,
|
|
760
|
-
immutableStorageType: context.defaultTypes.immutableStorageConnector,
|
|
761
|
-
identityConnectorType: context.defaultTypes.identityConnector,
|
|
762
|
-
backgroundTaskConnectorType: context.defaultTypes.backgroundTaskConnector,
|
|
763
|
-
...instanceConfig.options
|
|
764
|
-
});
|
|
765
|
-
instanceType = immutableProofService.ImmutableProofService.NAMESPACE;
|
|
766
|
-
}
|
|
767
|
-
else {
|
|
768
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
769
|
-
type,
|
|
770
|
-
componentType: "immutableProofComponent"
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
774
|
-
context.componentInstances.push({
|
|
775
|
-
instanceType: finalInstanceType,
|
|
776
|
-
component
|
|
777
|
-
});
|
|
778
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
779
|
-
return finalInstanceType;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
// Copyright 2024 IOTA Stiftung.
|
|
783
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
784
|
-
/**
|
|
785
|
-
* Initialise the immutable storage connector.
|
|
786
|
-
* @param engineCore The engine core.
|
|
787
|
-
* @param context The context for the engine.
|
|
788
|
-
* @param instanceConfig The instance config.
|
|
789
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
790
|
-
* @returns The name of the instance created.
|
|
791
|
-
* @throws GeneralError if the connector type is unknown.
|
|
792
|
-
*/
|
|
793
|
-
function initialiseImmutableStorageConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
794
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
795
|
-
element: `Immutable Storage Connector: ${instanceConfig.type}`
|
|
796
|
-
}));
|
|
797
|
-
const type = instanceConfig.type;
|
|
798
|
-
let connector;
|
|
799
|
-
let instanceType;
|
|
800
|
-
if (type === engineModels.ImmutableStorageConnectorType.Iota) {
|
|
801
|
-
const dltConfig = context.config.dltConfig?.find(dlt => dlt.type === context.defaultTypes.dltConfig);
|
|
802
|
-
connector = new immutableStorageConnectorIota.IotaImmutableStorageConnector({
|
|
803
|
-
...instanceConfig.options,
|
|
804
|
-
config: {
|
|
805
|
-
...dltConfig?.options?.config,
|
|
806
|
-
...instanceConfig.options.config
|
|
807
|
-
}
|
|
808
|
-
});
|
|
809
|
-
instanceType = immutableStorageConnectorIota.IotaImmutableStorageConnector.NAMESPACE;
|
|
810
|
-
}
|
|
811
|
-
else if (type === engineModels.ImmutableStorageConnectorType.EntityStorage) {
|
|
812
|
-
immutableStorageConnectorEntityStorage.initSchema();
|
|
813
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.immutableStorageEntityStorageType, "ImmutableItem");
|
|
814
|
-
connector = new immutableStorageConnectorEntityStorage.EntityStorageImmutableStorageConnector(instanceConfig.options);
|
|
815
|
-
instanceType = immutableStorageConnectorEntityStorage.EntityStorageImmutableStorageConnector.NAMESPACE;
|
|
816
|
-
}
|
|
817
|
-
else {
|
|
818
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
819
|
-
type,
|
|
820
|
-
connectorType: "immutableStorageConnector"
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
824
|
-
context.componentInstances.push({
|
|
825
|
-
instanceType: finalInstanceType,
|
|
826
|
-
component: connector
|
|
827
|
-
});
|
|
828
|
-
immutableStorageModels.ImmutableStorageConnectorFactory.register(finalInstanceType, () => connector);
|
|
829
|
-
return finalInstanceType;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
// Copyright 2024 IOTA Stiftung.
|
|
833
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
834
|
-
/**
|
|
835
|
-
* Initialise the logging connector.
|
|
836
|
-
* @param engineCore The engine core.
|
|
837
|
-
* @param context The engine core context.
|
|
838
|
-
* @param instanceConfig The instance config.
|
|
839
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
840
|
-
* @returns The name of the instance created.
|
|
841
|
-
* @throws GeneralError if the connector type is unknown.
|
|
842
|
-
*/
|
|
843
|
-
function initialiseLoggingConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
844
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
845
|
-
element: `Logging Connector: ${instanceConfig.type}`
|
|
846
|
-
}));
|
|
847
|
-
const type = instanceConfig.type;
|
|
848
|
-
let connector;
|
|
849
|
-
let instanceType;
|
|
850
|
-
if (type === engineModels.LoggingConnectorType.Console) {
|
|
851
|
-
connector = new loggingConnectorConsole.ConsoleLoggingConnector(instanceConfig.options);
|
|
852
|
-
instanceType = loggingConnectorConsole.ConsoleLoggingConnector.NAMESPACE;
|
|
853
|
-
}
|
|
854
|
-
else if (type === engineModels.LoggingConnectorType.EntityStorage) {
|
|
855
|
-
loggingConnectorEntityStorage.initSchema();
|
|
856
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.logEntryStorageConnectorType, "LogEntry");
|
|
857
|
-
connector = new loggingConnectorEntityStorage.EntityStorageLoggingConnector(instanceConfig.options);
|
|
858
|
-
instanceType = loggingConnectorEntityStorage.EntityStorageLoggingConnector.NAMESPACE;
|
|
859
|
-
}
|
|
860
|
-
else if (type === engineModels.LoggingConnectorType.Multi) {
|
|
861
|
-
connector = new loggingModels.MultiLoggingConnector(instanceConfig.options);
|
|
862
|
-
instanceType = loggingModels.MultiLoggingConnector.NAMESPACE;
|
|
863
|
-
}
|
|
864
|
-
else {
|
|
865
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
866
|
-
type,
|
|
867
|
-
connectorType: "loggingConnector"
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
871
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component: connector });
|
|
872
|
-
loggingModels.LoggingConnectorFactory.register(finalInstanceType, () => connector);
|
|
873
|
-
return finalInstanceType;
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* Initialise the logging component.
|
|
877
|
-
* @param engineCore The engine core.
|
|
878
|
-
* @param context The context for the engine.
|
|
879
|
-
* @param instanceConfig The instance config.
|
|
880
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
881
|
-
* @returns The name of the instance created.
|
|
882
|
-
* @throws GeneralError if the component type is unknown.
|
|
883
|
-
*/
|
|
884
|
-
function initialiseLoggingComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
885
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
886
|
-
element: `Logging Component: ${instanceConfig.type}`
|
|
887
|
-
}));
|
|
888
|
-
const type = instanceConfig.type;
|
|
889
|
-
let component;
|
|
890
|
-
let instanceType;
|
|
891
|
-
if (type === engineModels.LoggingComponentType.Service) {
|
|
892
|
-
component = new loggingService.LoggingService({
|
|
893
|
-
loggingConnectorType: context.defaultTypes.loggingConnector,
|
|
894
|
-
...instanceConfig.options
|
|
895
|
-
});
|
|
896
|
-
instanceType = loggingService.LoggingService.NAMESPACE;
|
|
897
|
-
}
|
|
898
|
-
else {
|
|
899
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
900
|
-
type,
|
|
901
|
-
componentType: "loggingComponent"
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
905
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component });
|
|
906
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
907
|
-
return finalInstanceType;
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
// Copyright 2024 IOTA Stiftung.
|
|
911
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
912
|
-
/**
|
|
913
|
-
* Initialise the NFT connector.
|
|
914
|
-
* @param engineCore The engine core.
|
|
915
|
-
* @param context The context for the engine.
|
|
916
|
-
* @param instanceConfig The instance config.
|
|
917
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
918
|
-
* @returns The name of the instance created.
|
|
919
|
-
* @throws GeneralError if the connector type is unknown.
|
|
920
|
-
*/
|
|
921
|
-
function initialiseNftConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
922
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
923
|
-
element: `NFT Connector: ${instanceConfig.type}`
|
|
924
|
-
}));
|
|
925
|
-
const type = instanceConfig.type;
|
|
926
|
-
let connector;
|
|
927
|
-
let instanceType;
|
|
928
|
-
if (type === engineModels.NftConnectorType.EntityStorage) {
|
|
929
|
-
nftConnectorEntityStorage.initSchema();
|
|
930
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.nftEntityStorageType, "Nft");
|
|
931
|
-
connector = new nftConnectorEntityStorage.EntityStorageNftConnector(instanceConfig.options);
|
|
932
|
-
instanceType = nftConnectorEntityStorage.EntityStorageNftConnector.NAMESPACE;
|
|
933
|
-
}
|
|
934
|
-
else if (type === engineModels.NftConnectorType.Iota) {
|
|
935
|
-
connector = new nftConnectorIota.IotaNftConnector({
|
|
936
|
-
...instanceConfig.options
|
|
937
|
-
});
|
|
938
|
-
instanceType = nftConnectorIota.IotaNftConnector.NAMESPACE;
|
|
939
|
-
}
|
|
940
|
-
else {
|
|
941
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
942
|
-
type,
|
|
943
|
-
connectorType: "nftConnector"
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
947
|
-
context.componentInstances.push({
|
|
948
|
-
instanceType: finalInstanceType,
|
|
949
|
-
component: connector
|
|
950
|
-
});
|
|
951
|
-
nftModels.NftConnectorFactory.register(finalInstanceType, () => connector);
|
|
952
|
-
return finalInstanceType;
|
|
953
|
-
}
|
|
954
|
-
/**
|
|
955
|
-
* Initialise the NFT component.
|
|
956
|
-
* @param engineCore The engine core.
|
|
957
|
-
* @param context The context for the engine.
|
|
958
|
-
* @param instanceConfig The instance config.
|
|
959
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
960
|
-
* @returns The name of the instance created.
|
|
961
|
-
* @throws GeneralError if the component type is unknown.
|
|
962
|
-
*/
|
|
963
|
-
function initialiseNftComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
964
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
965
|
-
element: `Nft Storage Component: ${instanceConfig.type}`
|
|
966
|
-
}));
|
|
967
|
-
const type = instanceConfig.type;
|
|
968
|
-
let component;
|
|
969
|
-
let instanceType;
|
|
970
|
-
if (type === engineModels.NftComponentType.Service) {
|
|
971
|
-
component = new nftService.NftService(instanceConfig.options);
|
|
972
|
-
instanceType = nftService.NftService.NAMESPACE;
|
|
973
|
-
}
|
|
974
|
-
else {
|
|
975
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
976
|
-
type,
|
|
977
|
-
componentType: "nftComponent"
|
|
978
|
-
});
|
|
979
|
-
}
|
|
980
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
981
|
-
context.componentInstances.push({
|
|
982
|
-
instanceType: finalInstanceType,
|
|
983
|
-
component
|
|
984
|
-
});
|
|
985
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
986
|
-
return finalInstanceType;
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
// Copyright 2024 IOTA Stiftung.
|
|
990
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
991
|
-
/**
|
|
992
|
-
* Initialise a telemetry connector.
|
|
993
|
-
* @param engineCore The engine core.
|
|
994
|
-
* @param context The context for the engine.
|
|
995
|
-
* @param instanceConfig The instance config.
|
|
996
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
997
|
-
* @returns The name of the instance created.
|
|
998
|
-
* @throws GeneralError if the connector type is unknown.
|
|
999
|
-
*/
|
|
1000
|
-
function initialiseTelemetryConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
1001
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
1002
|
-
element: `Telemetry Connector: ${instanceConfig.type}`
|
|
1003
|
-
}));
|
|
1004
|
-
const type = instanceConfig.type;
|
|
1005
|
-
let connector;
|
|
1006
|
-
let instanceType;
|
|
1007
|
-
if (type === engineModels.TelemetryConnectorType.EntityStorage) {
|
|
1008
|
-
telemetryConnectorEntityStorage.initSchema();
|
|
1009
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.telemetryMetricStorageConnectorType, "TelemetryMetric");
|
|
1010
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.telemetryMetricValueStorageConnectorType, "TelemetryMetricValue");
|
|
1011
|
-
connector = new telemetryConnectorEntityStorage.EntityStorageTelemetryConnector({
|
|
1012
|
-
loggingConnectorType: context.defaultTypes.loggingConnector,
|
|
1013
|
-
...instanceConfig.options
|
|
1014
|
-
});
|
|
1015
|
-
instanceType = telemetryConnectorEntityStorage.EntityStorageTelemetryConnector.NAMESPACE;
|
|
1016
|
-
}
|
|
1017
|
-
else {
|
|
1018
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
1019
|
-
type,
|
|
1020
|
-
connectorType: "telemetryConnector"
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
1024
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component: connector });
|
|
1025
|
-
telemetryModels.TelemetryConnectorFactory.register(finalInstanceType, () => connector);
|
|
1026
|
-
return finalInstanceType;
|
|
1027
|
-
}
|
|
1028
|
-
/**
|
|
1029
|
-
* Initialise the telemetry component.
|
|
1030
|
-
* @param engineCore The engine core.
|
|
1031
|
-
* @param context The context for the engine.
|
|
1032
|
-
* @param instanceConfig The instance config.
|
|
1033
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
1034
|
-
* @returns The name of the instance created.
|
|
1035
|
-
* @throws GeneralError if the component type is unknown.
|
|
1036
|
-
*/
|
|
1037
|
-
function initialiseTelemetryComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
1038
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
1039
|
-
element: `Telemetry Component: ${instanceConfig.type}`
|
|
1040
|
-
}));
|
|
1041
|
-
const type = instanceConfig.type;
|
|
1042
|
-
let component;
|
|
1043
|
-
let instanceType;
|
|
1044
|
-
if (type === engineModels.TelemetryComponentType.Service) {
|
|
1045
|
-
component = new telemetryService.TelemetryService({
|
|
1046
|
-
telemetryConnectorType: context.defaultTypes.telemetryConnector,
|
|
1047
|
-
...instanceConfig.options
|
|
1048
|
-
});
|
|
1049
|
-
instanceType = telemetryService.TelemetryService.NAMESPACE;
|
|
1050
|
-
}
|
|
1051
|
-
else {
|
|
1052
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
1053
|
-
type,
|
|
1054
|
-
componentType: "telemetryComponent"
|
|
1055
|
-
});
|
|
1056
|
-
}
|
|
1057
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
1058
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component });
|
|
1059
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
1060
|
-
return finalInstanceType;
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
// Copyright 2024 IOTA Stiftung.
|
|
1064
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
1065
|
-
/**
|
|
1066
|
-
* Initialise the vault connector.
|
|
1067
|
-
* @param engineCore The engine core.
|
|
1068
|
-
* @param context The context for the engine.
|
|
1069
|
-
* @param instanceConfig The instance config.
|
|
1070
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
1071
|
-
* @returns The name of the instance created.
|
|
1072
|
-
* @throws GeneralError if the connector type is unknown.
|
|
1073
|
-
*/
|
|
1074
|
-
function initialiseVaultConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
1075
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
1076
|
-
element: `Vault Connector: ${instanceConfig.type}`
|
|
1077
|
-
}));
|
|
1078
|
-
const type = instanceConfig.type;
|
|
1079
|
-
let connector;
|
|
1080
|
-
let instanceType;
|
|
1081
|
-
if (type === engineModels.VaultConnectorType.EntityStorage) {
|
|
1082
|
-
vaultConnectorEntityStorage.initSchema();
|
|
1083
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.vaultKeyEntityStorageType, "VaultKey");
|
|
1084
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.vaultSecretEntityStorageType, "VaultSecret");
|
|
1085
|
-
connector = new vaultConnectorEntityStorage.EntityStorageVaultConnector(instanceConfig.options);
|
|
1086
|
-
instanceType = vaultConnectorEntityStorage.EntityStorageVaultConnector.NAMESPACE;
|
|
1087
|
-
}
|
|
1088
|
-
else if (type === engineModels.VaultConnectorType.Hashicorp) {
|
|
1089
|
-
connector = new vaultConnectorHashicorp.HashicorpVaultConnector(instanceConfig.options);
|
|
1090
|
-
instanceType = vaultConnectorHashicorp.HashicorpVaultConnector.NAMESPACE;
|
|
1091
|
-
}
|
|
1092
|
-
else {
|
|
1093
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
1094
|
-
type,
|
|
1095
|
-
connectorType: "vaultConnector"
|
|
1096
|
-
});
|
|
1097
|
-
}
|
|
1098
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
1099
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component: connector });
|
|
1100
|
-
vaultModels.VaultConnectorFactory.register(finalInstanceType, () => connector);
|
|
1101
|
-
return finalInstanceType;
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
// Copyright 2024 IOTA Stiftung.
|
|
1105
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
1106
|
-
/**
|
|
1107
|
-
* Initialise a wallet connector.
|
|
1108
|
-
* @param engineCore The engine core.
|
|
1109
|
-
* @param context The context for the node.
|
|
1110
|
-
* @param instanceConfig The instance config.
|
|
1111
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
1112
|
-
* @returns The name of the instance created.
|
|
1113
|
-
* @throws GeneralError if the connector type is unknown.
|
|
14
|
+
* Store state in memory.
|
|
1114
15
|
*/
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
});
|
|
1139
|
-
instanceType = walletConnectorEntityStorage.EntityStorageWalletConnector.NAMESPACE;
|
|
1140
|
-
}
|
|
1141
|
-
else {
|
|
1142
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
1143
|
-
type,
|
|
1144
|
-
connectorType: "walletConnector"
|
|
1145
|
-
});
|
|
16
|
+
class MemoryStateStorage {
|
|
17
|
+
/**
|
|
18
|
+
* Runtime name for the class.
|
|
19
|
+
*/
|
|
20
|
+
CLASS_NAME = "MemoryStateStorage";
|
|
21
|
+
/**
|
|
22
|
+
* Readonly mode state file is not updated.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
_readonlyMode;
|
|
26
|
+
/**
|
|
27
|
+
* The state object.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
_engineState;
|
|
31
|
+
/**
|
|
32
|
+
* Create a new instance of MemoryStateStorage.
|
|
33
|
+
* @param readonlyMode Whether the file is in read-only mode.
|
|
34
|
+
* @param state The initial state.
|
|
35
|
+
*/
|
|
36
|
+
constructor(readonlyMode = false, state) {
|
|
37
|
+
this._readonlyMode = readonlyMode;
|
|
38
|
+
this._engineState = state;
|
|
1146
39
|
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
* @param engineCore The engine core.
|
|
1158
|
-
* @param context The context for the engine.
|
|
1159
|
-
* @param instanceConfig The instance config.
|
|
1160
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
1161
|
-
* @returns Nothing.
|
|
1162
|
-
* @throws GeneralError if the connector type is unknown.
|
|
1163
|
-
*/
|
|
1164
|
-
function initialiseWalletStorage(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
1165
|
-
const type = instanceConfig.type;
|
|
1166
|
-
if (type === engineModels.WalletConnectorType.Iota) ;
|
|
1167
|
-
else if (type === engineModels.WalletConnectorType.EntityStorage) {
|
|
1168
|
-
walletConnectorEntityStorage.initSchema();
|
|
1169
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.walletAddressEntityStorageType, "WalletAddress");
|
|
40
|
+
/**
|
|
41
|
+
* Method for loading the state.
|
|
42
|
+
* @param engineCore The engine core to load the state for.
|
|
43
|
+
* @returns The state of the engine or undefined if it doesn't exist.
|
|
44
|
+
*/
|
|
45
|
+
async load(engineCore) {
|
|
46
|
+
engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.loading`, {
|
|
47
|
+
filename: this._engineState
|
|
48
|
+
}));
|
|
49
|
+
return this._engineState;
|
|
1170
50
|
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Method for saving the state.
|
|
53
|
+
* @param engineCore The engine core to save the state for.
|
|
54
|
+
* @param state The state of the engine to save.
|
|
55
|
+
* @returns Nothing.
|
|
56
|
+
*/
|
|
57
|
+
async save(engineCore, state) {
|
|
58
|
+
if (!this._readonlyMode) {
|
|
59
|
+
engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.saving`));
|
|
60
|
+
this._engineState = state;
|
|
61
|
+
}
|
|
1176
62
|
}
|
|
1177
|
-
return undefined;
|
|
1178
63
|
}
|
|
1179
64
|
|
|
1180
65
|
// Copyright 2024 IOTA Stiftung.
|
|
@@ -1193,7 +78,6 @@ class EngineCore {
|
|
|
1193
78
|
CLASS_NAME = "EngineCore";
|
|
1194
79
|
/**
|
|
1195
80
|
* The core context.
|
|
1196
|
-
* @internal
|
|
1197
81
|
*/
|
|
1198
82
|
_context;
|
|
1199
83
|
/**
|
|
@@ -1211,11 +95,26 @@ class EngineCore {
|
|
|
1211
95
|
* @internal
|
|
1212
96
|
*/
|
|
1213
97
|
_skipBootstrap;
|
|
98
|
+
/**
|
|
99
|
+
* The logger type name to use.
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
_loggerTypeName;
|
|
1214
103
|
/**
|
|
1215
104
|
* The type initialisers.
|
|
1216
105
|
* @internal
|
|
1217
106
|
*/
|
|
1218
107
|
_typeInitialisers;
|
|
108
|
+
/**
|
|
109
|
+
* Is the engine started.
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
_isStarted;
|
|
113
|
+
/**
|
|
114
|
+
* Add type initialisers to the engine.
|
|
115
|
+
* @internal
|
|
116
|
+
*/
|
|
117
|
+
_populateTypeInitialisers;
|
|
1219
118
|
/**
|
|
1220
119
|
* Method for bootstrapping any data for the engine.
|
|
1221
120
|
* @internal
|
|
@@ -1230,61 +129,94 @@ class EngineCore {
|
|
|
1230
129
|
options.config = options.config ?? {};
|
|
1231
130
|
options.config.debug = options.config.debug ?? false;
|
|
1232
131
|
options.config.silent = options.config.silent ?? false;
|
|
132
|
+
options.config.types ??= {};
|
|
1233
133
|
this._skipBootstrap = options.skipBootstrap ?? false;
|
|
134
|
+
this._populateTypeInitialisers = options.populateTypeInitialisers;
|
|
1234
135
|
this._customBootstrap = options.customBootstrap;
|
|
136
|
+
this._loggerTypeName = options.loggerTypeName ?? EngineCore.LOGGER_TYPE_NAME;
|
|
1235
137
|
this._typeInitialisers = [];
|
|
1236
138
|
this._context = {
|
|
1237
139
|
config: options.config,
|
|
1238
140
|
defaultTypes: {},
|
|
1239
141
|
componentInstances: [],
|
|
1240
|
-
state: { bootstrappedComponents: [] },
|
|
142
|
+
state: { bootstrappedComponents: [], componentStates: {} },
|
|
1241
143
|
stateDirty: false
|
|
1242
144
|
};
|
|
1243
145
|
this._stateStorage = options.stateStorage;
|
|
1244
|
-
this.
|
|
146
|
+
this._isStarted = false;
|
|
147
|
+
if (core.Is.function(this._populateTypeInitialisers)) {
|
|
148
|
+
this._populateTypeInitialisers(this, this._context);
|
|
149
|
+
}
|
|
1245
150
|
}
|
|
1246
151
|
/**
|
|
1247
152
|
* Add a type initialiser.
|
|
1248
153
|
* @param type The type to add the initialiser for.
|
|
1249
154
|
* @param typeConfig The type config.
|
|
1250
|
-
* @param
|
|
155
|
+
* @param module The name of the module which contains the initialiser method.
|
|
156
|
+
* @param method The name of the method to call.
|
|
1251
157
|
*/
|
|
1252
|
-
addTypeInitialiser(type, typeConfig,
|
|
158
|
+
addTypeInitialiser(type, typeConfig, module, method) {
|
|
1253
159
|
if (!core.Is.empty(typeConfig)) {
|
|
1254
160
|
this._typeInitialisers.push({
|
|
1255
161
|
type,
|
|
1256
162
|
typeConfig,
|
|
1257
|
-
|
|
163
|
+
module,
|
|
164
|
+
method
|
|
1258
165
|
});
|
|
1259
166
|
}
|
|
1260
167
|
}
|
|
1261
168
|
/**
|
|
1262
169
|
* Start the engine core.
|
|
1263
|
-
* @returns
|
|
170
|
+
* @returns True if the start was successful.
|
|
1264
171
|
*/
|
|
1265
172
|
async start() {
|
|
173
|
+
if (this._isStarted) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
1266
176
|
this.setupEngineLogger();
|
|
1267
177
|
this.logInfo(core.I18n.formatMessage("engineCore.starting"));
|
|
1268
178
|
if (this._context.config.debug) {
|
|
1269
179
|
this.logInfo(core.I18n.formatMessage("engineCore.debuggingEnabled"));
|
|
1270
180
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
}
|
|
1275
|
-
const canContinue = await this.bootstrap();
|
|
181
|
+
let canContinue;
|
|
182
|
+
try {
|
|
183
|
+
canContinue = await this.stateLoad();
|
|
1276
184
|
if (canContinue) {
|
|
185
|
+
for (const { type, typeConfig, module, method } of this._typeInitialisers) {
|
|
186
|
+
await this.initialiseTypeConfig(type, typeConfig, module, method);
|
|
187
|
+
}
|
|
188
|
+
await this.bootstrap();
|
|
1277
189
|
this.logInfo(core.I18n.formatMessage("engineCore.componentsStarting"));
|
|
1278
190
|
for (const instance of this._context.componentInstances) {
|
|
1279
191
|
if (core.Is.function(instance.component.start)) {
|
|
1280
|
-
this.
|
|
1281
|
-
|
|
192
|
+
const instanceName = this.getInstanceName(instance);
|
|
193
|
+
this.logInfo(core.I18n.formatMessage("engineCore.componentStarting", {
|
|
194
|
+
element: instance.instanceType
|
|
195
|
+
}));
|
|
196
|
+
const componentState = this._context.state.componentStates[instanceName] ?? {};
|
|
197
|
+
const lastState = core.ObjectHelper.clone(componentState);
|
|
198
|
+
await instance.component.start(this._context.state.nodeIdentity, this._loggerTypeName, componentState);
|
|
199
|
+
if (!core.ObjectHelper.equal(lastState, componentState)) {
|
|
200
|
+
this._context.state.componentStates[instanceName] = componentState;
|
|
201
|
+
this._context.stateDirty = true;
|
|
202
|
+
}
|
|
1282
203
|
}
|
|
1283
204
|
}
|
|
1284
205
|
this.logInfo(core.I18n.formatMessage("engineCore.componentsComplete"));
|
|
1285
206
|
}
|
|
207
|
+
this.logInfo(core.I18n.formatMessage("engineCore.started"));
|
|
208
|
+
this._isStarted = true;
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
canContinue = false;
|
|
212
|
+
this.logError(core.BaseError.fromError(err));
|
|
1286
213
|
}
|
|
1287
|
-
|
|
214
|
+
finally {
|
|
215
|
+
if (!(await this.stateSave())) {
|
|
216
|
+
canContinue = false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return canContinue;
|
|
1288
220
|
}
|
|
1289
221
|
/**
|
|
1290
222
|
* Stop the engine core.
|
|
@@ -1295,9 +227,16 @@ class EngineCore {
|
|
|
1295
227
|
this.logInfo(core.I18n.formatMessage("engineCore.componentsStopping"));
|
|
1296
228
|
for (const instance of this._context.componentInstances) {
|
|
1297
229
|
if (core.Is.function(instance.component.stop)) {
|
|
230
|
+
const instanceName = this.getInstanceName(instance);
|
|
231
|
+
const componentState = this._context.state.componentStates[instanceName] ?? {};
|
|
232
|
+
const lastState = core.ObjectHelper.clone(componentState);
|
|
1298
233
|
this.logInfo(core.I18n.formatMessage("engineCore.componentStopping", { element: instance.instanceType }));
|
|
1299
234
|
try {
|
|
1300
|
-
await instance.component.stop(this._context.state.nodeIdentity,
|
|
235
|
+
await instance.component.stop(this._context.state.nodeIdentity, this._loggerTypeName, componentState);
|
|
236
|
+
if (!core.ObjectHelper.equal(lastState, componentState)) {
|
|
237
|
+
this._context.state.componentStates[instanceName] = componentState;
|
|
238
|
+
this._context.stateDirty = true;
|
|
239
|
+
}
|
|
1301
240
|
}
|
|
1302
241
|
catch (err) {
|
|
1303
242
|
this.logError(new core.GeneralError(this.CLASS_NAME, "componentStopFailed", {
|
|
@@ -1306,6 +245,7 @@ class EngineCore {
|
|
|
1306
245
|
}
|
|
1307
246
|
}
|
|
1308
247
|
}
|
|
248
|
+
await this.stateSave();
|
|
1309
249
|
this.logInfo(core.I18n.formatMessage("engineCore.componentsStopped"));
|
|
1310
250
|
this.logInfo(core.I18n.formatMessage("engineCore.stopped"));
|
|
1311
251
|
}
|
|
@@ -1361,14 +301,63 @@ class EngineCore {
|
|
|
1361
301
|
getDefaultTypes() {
|
|
1362
302
|
return this._context.defaultTypes;
|
|
1363
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Get the data required to create a clone of the engine.
|
|
306
|
+
* @returns The clone data.
|
|
307
|
+
*/
|
|
308
|
+
getCloneData() {
|
|
309
|
+
const entitySchemas = {};
|
|
310
|
+
const entitySchemaNames = entity.EntitySchemaFactory.names();
|
|
311
|
+
for (const schemaName of entitySchemaNames) {
|
|
312
|
+
entitySchemas[schemaName] = entity.EntitySchemaFactory.get(schemaName);
|
|
313
|
+
}
|
|
314
|
+
const cloneData = {
|
|
315
|
+
config: this._context.config,
|
|
316
|
+
state: this._context.state,
|
|
317
|
+
typeInitialisers: this._typeInitialisers,
|
|
318
|
+
entitySchemas,
|
|
319
|
+
loggerTypeName: this._loggerTypeName
|
|
320
|
+
};
|
|
321
|
+
return cloneData;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Populate the engine from the clone data.
|
|
325
|
+
* @param cloneData The clone data to populate from.
|
|
326
|
+
* @param silent Should the clone be silent.
|
|
327
|
+
*/
|
|
328
|
+
populateClone(cloneData, silent) {
|
|
329
|
+
core.Guards.object(this.CLASS_NAME, "cloneData", cloneData);
|
|
330
|
+
core.Guards.object(this.CLASS_NAME, "cloneData.config", cloneData.config);
|
|
331
|
+
core.Guards.object(this.CLASS_NAME, "cloneData.state", cloneData.state);
|
|
332
|
+
core.Guards.array(this.CLASS_NAME, "cloneData.typeInitialisers", cloneData.typeInitialisers);
|
|
333
|
+
this._loggerTypeName = cloneData.loggerTypeName;
|
|
334
|
+
this._skipBootstrap = true;
|
|
335
|
+
if (silent ?? false) {
|
|
336
|
+
cloneData.config.silent = true;
|
|
337
|
+
}
|
|
338
|
+
this._context = {
|
|
339
|
+
config: cloneData.config,
|
|
340
|
+
defaultTypes: {},
|
|
341
|
+
componentInstances: [],
|
|
342
|
+
state: { bootstrappedComponents: [], componentStates: {} },
|
|
343
|
+
stateDirty: false
|
|
344
|
+
};
|
|
345
|
+
this._typeInitialisers = cloneData.typeInitialisers;
|
|
346
|
+
for (const schemaName of Object.keys(cloneData.entitySchemas)) {
|
|
347
|
+
entity.EntitySchemaFactory.register(schemaName, () => cloneData.entitySchemas[schemaName]);
|
|
348
|
+
}
|
|
349
|
+
this._stateStorage = new MemoryStateStorage(true, cloneData.state);
|
|
350
|
+
this._isStarted = false;
|
|
351
|
+
}
|
|
1364
352
|
/**
|
|
1365
353
|
* Initialise the types from connector.
|
|
1366
354
|
* @param typeKey The key for the default types.
|
|
1367
355
|
* @param instanceMethod The function to initialise the instance.
|
|
1368
356
|
* @internal
|
|
1369
357
|
*/
|
|
1370
|
-
initialiseTypeConfig(typeKey, typeConfig,
|
|
358
|
+
async initialiseTypeConfig(typeKey, typeConfig, module, method) {
|
|
1371
359
|
if (core.Is.arrayValue(typeConfig)) {
|
|
360
|
+
const instanceMethod = await modules.ModuleHelper.getModuleEntry(module, method);
|
|
1372
361
|
for (let i = 0; i < typeConfig.length; i++) {
|
|
1373
362
|
const instanceType = instanceMethod(this, this._context, typeConfig[i], typeConfig[i].overrideInstanceType);
|
|
1374
363
|
if (core.Is.stringValue(instanceType) &&
|
|
@@ -1383,21 +372,22 @@ class EngineCore {
|
|
|
1383
372
|
* @internal
|
|
1384
373
|
*/
|
|
1385
374
|
setupEngineLogger() {
|
|
1386
|
-
|
|
1387
|
-
|
|
375
|
+
const silent = this._context.config.silent ?? false;
|
|
376
|
+
const engineLogger = silent
|
|
377
|
+
? new loggingModels.SilentLoggingConnector()
|
|
378
|
+
: new loggingConnectorConsole.ConsoleLoggingConnector({
|
|
1388
379
|
config: {
|
|
1389
380
|
translateMessages: true,
|
|
1390
381
|
hideGroups: true
|
|
1391
382
|
}
|
|
1392
383
|
});
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
}
|
|
384
|
+
this._context.componentInstances.push({
|
|
385
|
+
instanceType: this._loggerTypeName,
|
|
386
|
+
component: engineLogger
|
|
387
|
+
});
|
|
388
|
+
loggingModels.LoggingConnectorFactory.register(this._loggerTypeName, () => engineLogger);
|
|
389
|
+
this._engineLoggingConnector = engineLogger;
|
|
390
|
+
this._context.defaultTypes.loggingConnector = this._loggerTypeName;
|
|
1401
391
|
}
|
|
1402
392
|
/**
|
|
1403
393
|
* Load the state.
|
|
@@ -1408,9 +398,11 @@ class EngineCore {
|
|
|
1408
398
|
if (this._stateStorage) {
|
|
1409
399
|
try {
|
|
1410
400
|
this._context.state = ((await this._stateStorage.load(this)) ?? {
|
|
1411
|
-
bootstrappedComponents: []
|
|
401
|
+
bootstrappedComponents: [],
|
|
402
|
+
componentStates: {}
|
|
1412
403
|
});
|
|
1413
404
|
this._context.state.bootstrappedComponents ??= [];
|
|
405
|
+
this._context.state.componentStates ??= {};
|
|
1414
406
|
this._context.stateDirty = false;
|
|
1415
407
|
return true;
|
|
1416
408
|
}
|
|
@@ -1423,6 +415,7 @@ class EngineCore {
|
|
|
1423
415
|
}
|
|
1424
416
|
/**
|
|
1425
417
|
* Save the state.
|
|
418
|
+
* @returns True if the state was saved.
|
|
1426
419
|
* @internal
|
|
1427
420
|
*/
|
|
1428
421
|
async stateSave() {
|
|
@@ -1430,90 +423,65 @@ class EngineCore {
|
|
|
1430
423
|
try {
|
|
1431
424
|
await this._stateStorage.save(this, this._context.state);
|
|
1432
425
|
this._context.stateDirty = false;
|
|
426
|
+
return true;
|
|
1433
427
|
}
|
|
1434
428
|
catch (err) {
|
|
1435
429
|
this.logError(core.BaseError.fromError(err));
|
|
1436
430
|
}
|
|
431
|
+
return false;
|
|
1437
432
|
}
|
|
433
|
+
return true;
|
|
1438
434
|
}
|
|
1439
435
|
/**
|
|
1440
436
|
* Bootstrap the engine.
|
|
1441
|
-
* @returns True if the engine can continue.
|
|
1442
437
|
* @internal
|
|
1443
438
|
*/
|
|
1444
439
|
async bootstrap() {
|
|
1445
|
-
let canContinue = true;
|
|
1446
440
|
if (!this._skipBootstrap) {
|
|
1447
441
|
this.logInfo(core.I18n.formatMessage("engineCore.bootstrapStarted"));
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
442
|
+
// First bootstrap the components.
|
|
443
|
+
for (const instance of this._context.componentInstances) {
|
|
444
|
+
if (core.Is.function(instance.component.bootstrap)) {
|
|
445
|
+
const instanceName = this.getInstanceName(instance);
|
|
446
|
+
if (!this._context.state.bootstrappedComponents.includes(instanceName)) {
|
|
447
|
+
this.logInfo(core.I18n.formatMessage("engineCore.bootstrapping", {
|
|
448
|
+
element: instanceName
|
|
449
|
+
}));
|
|
450
|
+
const componentState = this._context.state.componentStates[instanceName] ?? {};
|
|
451
|
+
const lastState = core.ObjectHelper.clone(componentState);
|
|
452
|
+
const bootstrapSuccess = await instance.component.bootstrap(this._loggerTypeName, componentState);
|
|
453
|
+
// If the bootstrap method failed then throw an error
|
|
454
|
+
if (!bootstrapSuccess) {
|
|
455
|
+
throw new core.GeneralError(this.CLASS_NAME, "bootstrapFailed", {
|
|
456
|
+
component: `${instance.component.CLASS_NAME}:${instance.instanceType}`
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
// Otherwise add the component to the bootstrapped list and set the state as dirty
|
|
460
|
+
this._context.state.bootstrappedComponents.push(instanceName);
|
|
461
|
+
if (!core.ObjectHelper.equal(lastState, componentState)) {
|
|
462
|
+
this._context.state.componentStates[instanceName] = componentState;
|
|
1467
463
|
}
|
|
464
|
+
this._context.stateDirty = true;
|
|
1468
465
|
}
|
|
1469
466
|
}
|
|
1470
|
-
// Now perform any custom bootstrap operations
|
|
1471
|
-
if (canContinue && core.Is.function(this._customBootstrap)) {
|
|
1472
|
-
await this._customBootstrap(this, this._context);
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
catch (err) {
|
|
1476
|
-
canContinue = false;
|
|
1477
|
-
this.logError(core.BaseError.fromError(err));
|
|
1478
467
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
this.logInfo(core.I18n.formatMessage("engineCore.bootstrapComplete"));
|
|
1483
|
-
}
|
|
468
|
+
// Now perform any custom bootstrap operations
|
|
469
|
+
if (core.Is.function(this._customBootstrap)) {
|
|
470
|
+
await this._customBootstrap(this, this._context);
|
|
1484
471
|
}
|
|
472
|
+
this.logInfo(core.I18n.formatMessage("engineCore.bootstrapComplete"));
|
|
1485
473
|
}
|
|
1486
|
-
return canContinue;
|
|
1487
474
|
}
|
|
1488
475
|
/**
|
|
1489
|
-
*
|
|
476
|
+
* Get the instance name.
|
|
477
|
+
* @param instance The instance to get the name for.
|
|
478
|
+
* @param instance.instanceType The instance type.
|
|
479
|
+
* @param instance.component The component.
|
|
480
|
+
* @returns The instance name.
|
|
1490
481
|
* @internal
|
|
1491
482
|
*/
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
this.addTypeInitialiser("loggingComponent", this._context.config.loggingComponent, initialiseLoggingComponent);
|
|
1495
|
-
this.addTypeInitialiser("backgroundTaskConnector", this._context.config.backgroundTaskConnector, initialiseBackgroundTaskConnector);
|
|
1496
|
-
this.addTypeInitialiser("telemetryConnector", this._context.config.telemetryConnector, initialiseTelemetryConnector);
|
|
1497
|
-
this.addTypeInitialiser("telemetryComponent", this._context.config.telemetryComponent, initialiseTelemetryComponent);
|
|
1498
|
-
this.addTypeInitialiser("entityStorageComponent", this._context.config.entityStorageComponent, initialiseEntityStorageComponent);
|
|
1499
|
-
this.addTypeInitialiser("vaultConnector", this._context.config.vaultConnector, initialiseVaultConnector);
|
|
1500
|
-
this.addTypeInitialiser("blobStorageConnector", this._context.config.blobStorageConnector, initialiseBlobStorageConnector);
|
|
1501
|
-
this.addTypeInitialiser("blobStorageComponent", this._context.config.blobStorageComponent, initialiseBlobStorageComponent);
|
|
1502
|
-
this.addTypeInitialiser("immutableStorageConnector", this._context.config.immutableStorageConnector, initialiseImmutableStorageConnector);
|
|
1503
|
-
this.addTypeInitialiser("walletConnector", this._context.config.walletConnector, initialiseWalletStorage);
|
|
1504
|
-
this.addTypeInitialiser("faucetConnector", this._context.config.faucetConnector, initialiseFaucetConnector);
|
|
1505
|
-
this.addTypeInitialiser("walletConnector", this._context.config.walletConnector, initialiseWalletConnector);
|
|
1506
|
-
this.addTypeInitialiser("identityConnector", this._context.config.identityConnector, initialiseIdentityConnector);
|
|
1507
|
-
this.addTypeInitialiser("identityComponent", this._context.config.identityComponent, initialiseIdentityComponent);
|
|
1508
|
-
this.addTypeInitialiser("identityProfileConnector", this._context.config.identityProfileConnector, initialiseIdentityProfileConnector);
|
|
1509
|
-
this.addTypeInitialiser("identityProfileComponent", this._context.config.identityProfileComponent, initialiseIdentityProfileComponent);
|
|
1510
|
-
this.addTypeInitialiser("nftConnector", this._context.config.nftConnector, initialiseNftConnector);
|
|
1511
|
-
this.addTypeInitialiser("nftComponent", this._context.config.nftComponent, initialiseNftComponent);
|
|
1512
|
-
this.addTypeInitialiser("immutableProofComponent", this._context.config.immutableProofComponent, initialiseImmutableProofComponent);
|
|
1513
|
-
this.addTypeInitialiser("attestationConnector", this._context.config.attestationConnector, initialiseAttestationConnector);
|
|
1514
|
-
this.addTypeInitialiser("attestationComponent", this._context.config.attestationComponent, initialiseAttestationComponent);
|
|
1515
|
-
this.addTypeInitialiser("auditableItemGraphComponent", this._context.config.auditableItemGraphComponent, initialiseAuditableItemGraphComponent);
|
|
1516
|
-
this.addTypeInitialiser("auditableItemStreamComponent", this._context.config.auditableItemStreamComponent, initialiseAuditableItemStreamComponent);
|
|
483
|
+
getInstanceName(instance) {
|
|
484
|
+
return `${instance.component.CLASS_NAME}-${instance.instanceType}`;
|
|
1517
485
|
}
|
|
1518
486
|
}
|
|
1519
487
|
|
|
@@ -1578,7 +546,11 @@ class FileStateStorage {
|
|
|
1578
546
|
engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.saving`, {
|
|
1579
547
|
filename: this._filename
|
|
1580
548
|
}));
|
|
1581
|
-
|
|
549
|
+
try {
|
|
550
|
+
await promises.mkdir(path.dirname(this._filename), { recursive: true });
|
|
551
|
+
}
|
|
552
|
+
catch { }
|
|
553
|
+
await promises.writeFile(this._filename, JSON.stringify(state, undefined, "\t"), "utf8");
|
|
1582
554
|
}
|
|
1583
555
|
catch (err) {
|
|
1584
556
|
throw new core.GeneralError(this.CLASS_NAME, "savingError", { filename: this._filename }, core.BaseError.fromError(err));
|
|
@@ -1602,59 +574,6 @@ class FileStateStorage {
|
|
|
1602
574
|
}
|
|
1603
575
|
}
|
|
1604
576
|
|
|
1605
|
-
// Copyright 2024 IOTA Stiftung.
|
|
1606
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
1607
|
-
/**
|
|
1608
|
-
* Store state in memory.
|
|
1609
|
-
*/
|
|
1610
|
-
class MemoryStateStorage {
|
|
1611
|
-
/**
|
|
1612
|
-
* Runtime name for the class.
|
|
1613
|
-
*/
|
|
1614
|
-
CLASS_NAME = "MemoryStateStorage";
|
|
1615
|
-
/**
|
|
1616
|
-
* Readonly mode state file is not updated.
|
|
1617
|
-
* @internal
|
|
1618
|
-
*/
|
|
1619
|
-
_readonlyMode;
|
|
1620
|
-
/**
|
|
1621
|
-
* The state object.
|
|
1622
|
-
* @internal
|
|
1623
|
-
*/
|
|
1624
|
-
_engineState;
|
|
1625
|
-
/**
|
|
1626
|
-
* Create a new instance of MemoryStateStorage.
|
|
1627
|
-
* @param readonlyMode Whether the file is in read-only mode.
|
|
1628
|
-
*/
|
|
1629
|
-
constructor(readonlyMode = false) {
|
|
1630
|
-
this._readonlyMode = readonlyMode;
|
|
1631
|
-
}
|
|
1632
|
-
/**
|
|
1633
|
-
* Method for loading the state.
|
|
1634
|
-
* @param engineCore The engine core to load the state for.
|
|
1635
|
-
* @returns The state of the engine or undefined if it doesn't exist.
|
|
1636
|
-
*/
|
|
1637
|
-
async load(engineCore) {
|
|
1638
|
-
engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.loading`, {
|
|
1639
|
-
filename: this._engineState
|
|
1640
|
-
}));
|
|
1641
|
-
return this._engineState;
|
|
1642
|
-
}
|
|
1643
|
-
/**
|
|
1644
|
-
* Method for saving the state.
|
|
1645
|
-
* @param engineCore The engine core to save the state for.
|
|
1646
|
-
* @param state The state of the engine to save.
|
|
1647
|
-
* @returns Nothing.
|
|
1648
|
-
*/
|
|
1649
|
-
async save(engineCore, state) {
|
|
1650
|
-
if (!this._readonlyMode) {
|
|
1651
|
-
engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.saving`));
|
|
1652
|
-
this._engineState = state;
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
577
|
exports.EngineCore = EngineCore;
|
|
1658
578
|
exports.FileStateStorage = FileStateStorage;
|
|
1659
579
|
exports.MemoryStateStorage = MemoryStateStorage;
|
|
1660
|
-
exports.initialiseEntityStorageConnector = initialiseEntityStorageConnector;
|