@twin.org/engine-core 0.0.1-next.9 → 0.0.1
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 +220 -1839
- package/dist/esm/index.mjs +224 -1840
- package/dist/types/engineCore.d.ts +24 -8
- package/dist/types/index.d.ts +0 -4
- package/dist/types/models/IEngineCoreOptions.d.ts +14 -5
- package/dist/types/storage/memoryStateStorage.d.ts +2 -1
- package/docs/changelog.md +262 -1
- package/docs/reference/classes/EngineCore.md +99 -23
- package/docs/reference/classes/FileStateStorage.md +21 -9
- package/docs/reference/classes/MemoryStateStorage.md +24 -8
- package/docs/reference/index.md +0 -7
- package/docs/reference/interfaces/IEngineCoreOptions.md +55 -5
- package/package.json +7 -64
- 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/dist/types/models/IEngineCoreEnvironmentVariables.d.ts +0 -265
- package/dist/types/utils/engineCoreEnvBuilder.d.ts +0 -8
- package/dist/types/utils/envHelper.d.ts +0 -15
- package/docs/reference/classes/EnvHelper.md +0 -41
- package/docs/reference/functions/buildEngineCoreConfiguration.md +0 -17
- package/docs/reference/functions/initialiseEntityStorageConnector.md +0 -31
- package/docs/reference/interfaces/IEngineCoreEnvironmentVariables.md +0 -523
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,1185 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var path = require('node:path');
|
|
4
3
|
var core = require('@twin.org/core');
|
|
5
|
-
var
|
|
6
|
-
var entityStorageConnectorCosmosdb = require('@twin.org/entity-storage-connector-cosmosdb');
|
|
7
|
-
var entityStorageConnectorDynamodb = require('@twin.org/entity-storage-connector-dynamodb');
|
|
8
|
-
var entityStorageConnectorFile = require('@twin.org/entity-storage-connector-file');
|
|
9
|
-
var entityStorageConnectorGcpFirestore = require('@twin.org/entity-storage-connector-gcp-firestore');
|
|
10
|
-
var entityStorageConnectorMemory = require('@twin.org/entity-storage-connector-memory');
|
|
11
|
-
var entityStorageConnectorScylladb = require('@twin.org/entity-storage-connector-scylladb');
|
|
12
|
-
var entityStorageModels = require('@twin.org/entity-storage-models');
|
|
13
|
-
var entityStorageService = require('@twin.org/entity-storage-service');
|
|
4
|
+
var entity = require('@twin.org/entity');
|
|
14
5
|
var loggingConnectorConsole = require('@twin.org/logging-connector-console');
|
|
15
6
|
var loggingModels = require('@twin.org/logging-models');
|
|
16
|
-
var
|
|
17
|
-
var attestationConnectorIota = require('@twin.org/attestation-connector-iota');
|
|
18
|
-
var attestationModels = require('@twin.org/attestation-models');
|
|
19
|
-
var attestationService = require('@twin.org/attestation-service');
|
|
20
|
-
var auditableItemGraphService = require('@twin.org/auditable-item-graph-service');
|
|
21
|
-
var auditableItemStreamService = require('@twin.org/auditable-item-stream-service');
|
|
22
|
-
var backgroundTaskConnectorEntityStorage = require('@twin.org/background-task-connector-entity-storage');
|
|
23
|
-
var backgroundTaskModels = require('@twin.org/background-task-models');
|
|
24
|
-
var blobStorageConnectorAwsS3 = require('@twin.org/blob-storage-connector-aws-s3');
|
|
25
|
-
var blobStorageConnectorAzure = require('@twin.org/blob-storage-connector-azure');
|
|
26
|
-
var blobStorageConnectorFile = require('@twin.org/blob-storage-connector-file');
|
|
27
|
-
var blobStorageConnectorGcp = require('@twin.org/blob-storage-connector-gcp');
|
|
28
|
-
var blobStorageConnectorIpfs = require('@twin.org/blob-storage-connector-ipfs');
|
|
29
|
-
var blobStorageConnectorMemory = require('@twin.org/blob-storage-connector-memory');
|
|
30
|
-
var blobStorageModels = require('@twin.org/blob-storage-models');
|
|
31
|
-
var blobStorageService = require('@twin.org/blob-storage-service');
|
|
32
|
-
var walletConnectorEntityStorage = require('@twin.org/wallet-connector-entity-storage');
|
|
33
|
-
var walletConnectorIota = require('@twin.org/wallet-connector-iota');
|
|
34
|
-
var walletModels = require('@twin.org/wallet-models');
|
|
35
|
-
var identityConnectorEntityStorage = require('@twin.org/identity-connector-entity-storage');
|
|
36
|
-
var identityConnectorIota = require('@twin.org/identity-connector-iota');
|
|
37
|
-
var identityModels = require('@twin.org/identity-models');
|
|
38
|
-
var identityService = require('@twin.org/identity-service');
|
|
39
|
-
var immutableProofService = require('@twin.org/immutable-proof-service');
|
|
40
|
-
var immutableStorageConnectorEntityStorage = require('@twin.org/immutable-storage-connector-entity-storage');
|
|
41
|
-
var immutableStorageConnectorIota = require('@twin.org/immutable-storage-connector-iota');
|
|
42
|
-
var immutableStorageModels = require('@twin.org/immutable-storage-models');
|
|
43
|
-
var loggingConnectorEntityStorage = require('@twin.org/logging-connector-entity-storage');
|
|
44
|
-
var loggingService = require('@twin.org/logging-service');
|
|
45
|
-
var nftConnectorEntityStorage = require('@twin.org/nft-connector-entity-storage');
|
|
46
|
-
var nftConnectorIota = require('@twin.org/nft-connector-iota');
|
|
47
|
-
var nftModels = require('@twin.org/nft-models');
|
|
48
|
-
var nftService = require('@twin.org/nft-service');
|
|
49
|
-
var telemetryConnectorEntityStorage = require('@twin.org/telemetry-connector-entity-storage');
|
|
50
|
-
var telemetryModels = require('@twin.org/telemetry-models');
|
|
51
|
-
var telemetryService = require('@twin.org/telemetry-service');
|
|
52
|
-
var vaultConnectorEntityStorage = require('@twin.org/vault-connector-entity-storage');
|
|
53
|
-
var vaultConnectorHashicorp = require('@twin.org/vault-connector-hashicorp');
|
|
54
|
-
var vaultModels = require('@twin.org/vault-models');
|
|
7
|
+
var modules = require('@twin.org/modules');
|
|
55
8
|
var promises = require('node:fs/promises');
|
|
9
|
+
var path = require('node:path');
|
|
56
10
|
|
|
57
11
|
// Copyright 2024 IOTA Stiftung.
|
|
58
12
|
// SPDX-License-Identifier: Apache-2.0.
|
|
59
13
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @param engineCore The engine core.
|
|
62
|
-
* @param context The context for the engine.
|
|
63
|
-
* @param typeCustom Override the type of connector to use instead of default configuration.
|
|
64
|
-
* @param schema The schema for the entity storage.
|
|
65
|
-
* @throws GeneralError if the connector type is unknown.
|
|
66
|
-
*/
|
|
67
|
-
function initialiseEntityStorageConnector(engineCore, context, typeCustom, schema) {
|
|
68
|
-
const instanceName = core.StringHelper.kebabCase(schema);
|
|
69
|
-
let entityStorageConfig;
|
|
70
|
-
if (core.Is.stringValue(typeCustom)) {
|
|
71
|
-
// A custom type has been specified, so look it up
|
|
72
|
-
entityStorageConfig = context.config.entityStorageConnector?.find(c => c.type === typeCustom || c.overrideInstanceType === typeCustom);
|
|
73
|
-
if (core.Is.empty(entityStorageConfig)) {
|
|
74
|
-
throw new core.GeneralError("engineCore", "entityStorageCustomMissing", {
|
|
75
|
-
typeCustom,
|
|
76
|
-
storageName: instanceName
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
// The default entity storage method is either the one with the isDefault flag set
|
|
82
|
-
// or pick the first one if no default is set.
|
|
83
|
-
entityStorageConfig =
|
|
84
|
-
context.config.entityStorageConnector?.find(c => c.isDefault ?? false) ??
|
|
85
|
-
context.config.entityStorageConnector?.[0];
|
|
86
|
-
if (core.Is.empty(entityStorageConfig)) {
|
|
87
|
-
throw new core.GeneralError("engineCore", "entityStorageMissing", {
|
|
88
|
-
storageName: instanceName
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const type = entityStorageConfig.type;
|
|
93
|
-
let entityStorageConnector;
|
|
94
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuringEntityStorage", {
|
|
95
|
-
element: "Entity Storage",
|
|
96
|
-
storageName: instanceName,
|
|
97
|
-
storageType: type
|
|
98
|
-
}));
|
|
99
|
-
if (type === engineModels.EntityStorageConnectorType.Memory) {
|
|
100
|
-
entityStorageConnector = new entityStorageConnectorMemory.MemoryEntityStorageConnector({
|
|
101
|
-
entitySchema: schema
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
else if (type === engineModels.EntityStorageConnectorType.File) {
|
|
105
|
-
entityStorageConnector = new entityStorageConnectorFile.FileEntityStorageConnector({
|
|
106
|
-
entitySchema: schema,
|
|
107
|
-
...entityStorageConfig.options,
|
|
108
|
-
config: {
|
|
109
|
-
...entityStorageConfig.options.config,
|
|
110
|
-
directory: path.join(entityStorageConfig.options.config.directory, instanceName)
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
else if (type === engineModels.EntityStorageConnectorType.AwsDynamoDb) {
|
|
115
|
-
entityStorageConnector = new entityStorageConnectorDynamodb.DynamoDbEntityStorageConnector({
|
|
116
|
-
entitySchema: schema,
|
|
117
|
-
...entityStorageConfig.options,
|
|
118
|
-
config: {
|
|
119
|
-
...entityStorageConfig.options.config,
|
|
120
|
-
tableName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
else if (type === engineModels.EntityStorageConnectorType.AzureCosmosDb) {
|
|
125
|
-
entityStorageConnector = new entityStorageConnectorCosmosdb.CosmosDbEntityStorageConnector({
|
|
126
|
-
entitySchema: schema,
|
|
127
|
-
...entityStorageConfig.options,
|
|
128
|
-
config: {
|
|
129
|
-
...entityStorageConfig.options.config,
|
|
130
|
-
containerId: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
else if (type === engineModels.EntityStorageConnectorType.GcpFirestoreDb) {
|
|
135
|
-
entityStorageConnector = new entityStorageConnectorGcpFirestore.FirestoreEntityStorageConnector({
|
|
136
|
-
entitySchema: schema,
|
|
137
|
-
...entityStorageConfig.options,
|
|
138
|
-
config: {
|
|
139
|
-
...entityStorageConfig.options.config,
|
|
140
|
-
collectionName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
else if (type === engineModels.EntityStorageConnectorType.ScyllaDb) {
|
|
145
|
-
entityStorageConnector = new entityStorageConnectorScylladb.ScyllaDBTableConnector({
|
|
146
|
-
entitySchema: schema,
|
|
147
|
-
...entityStorageConfig.options,
|
|
148
|
-
config: {
|
|
149
|
-
...entityStorageConfig.options.config,
|
|
150
|
-
tableName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
156
|
-
type,
|
|
157
|
-
connectorType: "entityStorageConnector"
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
context.componentInstances.push({
|
|
161
|
-
instanceType: instanceName,
|
|
162
|
-
component: entityStorageConnector
|
|
163
|
-
});
|
|
164
|
-
entityStorageModels.EntityStorageConnectorFactory.register(instanceName, () => entityStorageConnector);
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Initialise the entity storage connector.
|
|
168
|
-
* @param engineCore The engine core.
|
|
169
|
-
* @param context The context for the engine.
|
|
170
|
-
* @param instanceConfig The instance config.
|
|
171
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
172
|
-
* @returns The name of the instance created.
|
|
173
|
-
* @throws GeneralError if the connector type is unknown.
|
|
174
|
-
*/
|
|
175
|
-
function initialiseEntityStorageComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
176
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
177
|
-
element: `Entity Storage Component: ${instanceConfig.type}`
|
|
178
|
-
}));
|
|
179
|
-
const type = instanceConfig.type;
|
|
180
|
-
let connector;
|
|
181
|
-
let instanceType;
|
|
182
|
-
if (type === engineModels.EntityStorageComponentType.Service) {
|
|
183
|
-
const kebabName = core.StringHelper.kebabCase(instanceConfig.options.entityStorageType);
|
|
184
|
-
// See if there is a custom entity storage for this type, otherwise just use the default one.
|
|
185
|
-
const hasCustom = context.config.entityStorageConnector?.some(c => c.type === kebabName || c.overrideInstanceType === kebabName);
|
|
186
|
-
initialiseEntityStorageConnector(engineCore, context, hasCustom ? kebabName : undefined, instanceConfig.options.entityStorageType);
|
|
187
|
-
connector = new entityStorageService.EntityStorageService({
|
|
188
|
-
entityStorageType: kebabName,
|
|
189
|
-
config: {
|
|
190
|
-
...instanceConfig.options.config
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
instanceType = core.StringHelper.kebabCase(instanceConfig.options.entityStorageType);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
197
|
-
type,
|
|
198
|
-
serviceType: "entityStorageComponent"
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
202
|
-
context.componentInstances.push({
|
|
203
|
-
instanceType: finalInstanceType,
|
|
204
|
-
component: connector
|
|
205
|
-
});
|
|
206
|
-
core.ComponentFactory.register(finalInstanceType, () => connector);
|
|
207
|
-
return finalInstanceType;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Copyright 2024 IOTA Stiftung.
|
|
211
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
212
|
-
/**
|
|
213
|
-
* Initialise the attestation connector.
|
|
214
|
-
* @param engineCore The engine core.
|
|
215
|
-
* @param context The context for the engine.
|
|
216
|
-
* @param instanceConfig The instance config.
|
|
217
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
218
|
-
* @returns The name of the instance created.
|
|
219
|
-
* @throws GeneralError if the connector type is unknown.
|
|
220
|
-
*/
|
|
221
|
-
function initialiseAttestationConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
222
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
223
|
-
element: `Attestation Connector: ${instanceConfig.type}`
|
|
224
|
-
}));
|
|
225
|
-
const type = instanceConfig.type;
|
|
226
|
-
let connector;
|
|
227
|
-
let instanceType;
|
|
228
|
-
if (type === engineModels.AttestationConnectorType.Iota) {
|
|
229
|
-
connector = new attestationConnectorIota.IotaAttestationConnector({
|
|
230
|
-
identityConnectorType: context.defaultTypes.identityConnector,
|
|
231
|
-
nftConnectorType: context.defaultTypes.nftConnector,
|
|
232
|
-
...instanceConfig.options
|
|
233
|
-
});
|
|
234
|
-
instanceType = attestationConnectorIota.IotaAttestationConnector.NAMESPACE;
|
|
235
|
-
}
|
|
236
|
-
else if (type === engineModels.AttestationConnectorType.EntityStorage) {
|
|
237
|
-
connector = new attestationConnectorEntityStorage.EntityStorageAttestationConnector({
|
|
238
|
-
identityConnectorType: context.defaultTypes.identityConnector,
|
|
239
|
-
nftConnectorType: context.defaultTypes.nftConnector,
|
|
240
|
-
...instanceConfig.options
|
|
241
|
-
});
|
|
242
|
-
instanceType = attestationConnectorEntityStorage.EntityStorageAttestationConnector.NAMESPACE;
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
246
|
-
type,
|
|
247
|
-
connectorType: "attestationConnector"
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
251
|
-
context.componentInstances.push({
|
|
252
|
-
instanceType: finalInstanceType,
|
|
253
|
-
component: connector
|
|
254
|
-
});
|
|
255
|
-
attestationModels.AttestationConnectorFactory.register(finalInstanceType, () => connector);
|
|
256
|
-
return finalInstanceType;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Initialise the attestation component.
|
|
260
|
-
* @param engineCore The engine core.
|
|
261
|
-
* @param context The context for the engine.
|
|
262
|
-
* @param instanceConfig The instance config.
|
|
263
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
264
|
-
* @returns The name of the instance created.
|
|
265
|
-
* @throws GeneralError if the component type is unknown.
|
|
266
|
-
*/
|
|
267
|
-
function initialiseAttestationComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
268
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
269
|
-
element: `Attestation Component: ${instanceConfig.type}`
|
|
270
|
-
}));
|
|
271
|
-
const type = instanceConfig.type;
|
|
272
|
-
let component;
|
|
273
|
-
let instanceType;
|
|
274
|
-
if (type === engineModels.AttestationComponentType.Service) {
|
|
275
|
-
component = new attestationService.AttestationService({
|
|
276
|
-
walletConnectorType: context.defaultTypes.walletConnector,
|
|
277
|
-
...instanceConfig.options
|
|
278
|
-
});
|
|
279
|
-
instanceType = attestationService.AttestationService.NAMESPACE;
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
283
|
-
type,
|
|
284
|
-
componentType: "attestationComponent"
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
288
|
-
context.componentInstances.push({
|
|
289
|
-
instanceType: finalInstanceType,
|
|
290
|
-
component
|
|
291
|
-
});
|
|
292
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
293
|
-
return finalInstanceType;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Initialise the auditable item graph component.
|
|
298
|
-
* @param engineCore The engine core.
|
|
299
|
-
* @param context The context for the engine.
|
|
300
|
-
* @param instanceConfig The instance config.
|
|
301
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
302
|
-
* @returns The name of the instance created.
|
|
303
|
-
* @throws GeneralError if the component type is unknown.
|
|
304
|
-
*/
|
|
305
|
-
function initialiseAuditableItemGraphComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
306
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
307
|
-
element: `Auditable Item Graph Component: ${instanceConfig.type}`
|
|
308
|
-
}));
|
|
309
|
-
const type = instanceConfig.type;
|
|
310
|
-
let component;
|
|
311
|
-
let instanceType;
|
|
312
|
-
if (type === engineModels.AuditableItemGraphComponentType.Service) {
|
|
313
|
-
auditableItemGraphService.initSchema();
|
|
314
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.vertexEntityStorageType, "AuditableItemGraphVertex");
|
|
315
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.changesetEntityStorageType, "AuditableItemGraphChangeset");
|
|
316
|
-
component = new auditableItemGraphService.AuditableItemGraphService({
|
|
317
|
-
immutableProofComponentType: context.defaultTypes.immutableProofComponent,
|
|
318
|
-
...instanceConfig.options
|
|
319
|
-
});
|
|
320
|
-
instanceType = auditableItemGraphService.AuditableItemGraphService.NAMESPACE;
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
324
|
-
type,
|
|
325
|
-
componentType: "auditableItemGraphComponent"
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
329
|
-
context.componentInstances.push({
|
|
330
|
-
instanceType: finalInstanceType,
|
|
331
|
-
component
|
|
332
|
-
});
|
|
333
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
334
|
-
return finalInstanceType;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Initialise the auditable item stream component.
|
|
339
|
-
* @param engineCore The engine core.
|
|
340
|
-
* @param context The context for the engine.
|
|
341
|
-
* @param instanceConfig The instance config.
|
|
342
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
343
|
-
* @returns The name of the instance created.
|
|
344
|
-
* @throws GeneralError if the component type is unknown.
|
|
345
|
-
*/
|
|
346
|
-
function initialiseAuditableItemStreamComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
347
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
348
|
-
element: `Auditable Item Stream Component: ${instanceConfig.type}`
|
|
349
|
-
}));
|
|
350
|
-
const type = instanceConfig.type;
|
|
351
|
-
let component;
|
|
352
|
-
let instanceType;
|
|
353
|
-
if (type === engineModels.AuditableItemStreamComponentType.Service) {
|
|
354
|
-
auditableItemStreamService.initSchema();
|
|
355
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.streamEntityStorageType, "AuditableItemStream");
|
|
356
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.streamEntryEntityStorageType, "AuditableItemStreamEntry");
|
|
357
|
-
component = new auditableItemStreamService.AuditableItemStreamService({
|
|
358
|
-
immutableProofComponentType: context.defaultTypes.immutableProofComponent,
|
|
359
|
-
...instanceConfig.options
|
|
360
|
-
});
|
|
361
|
-
instanceType = auditableItemStreamService.AuditableItemStreamService.NAMESPACE;
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
365
|
-
type,
|
|
366
|
-
componentType: "auditableItemStreamComponent"
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
370
|
-
context.componentInstances.push({
|
|
371
|
-
instanceType: finalInstanceType,
|
|
372
|
-
component
|
|
373
|
-
});
|
|
374
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
375
|
-
return finalInstanceType;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// Copyright 2024 IOTA Stiftung.
|
|
379
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
380
|
-
/**
|
|
381
|
-
* Initialise a background task connector.
|
|
382
|
-
* @param engineCore The engine core.
|
|
383
|
-
* @param context The context for the engine.
|
|
384
|
-
* @param instanceConfig The instance config.
|
|
385
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
386
|
-
* @returns The name of the instance created.
|
|
387
|
-
* @throws GeneralError if the connector type is unknown.
|
|
388
|
-
*/
|
|
389
|
-
function initialiseBackgroundTaskConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
390
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
391
|
-
element: `Background Task Connector: ${instanceConfig.type}`
|
|
392
|
-
}));
|
|
393
|
-
const type = instanceConfig.type;
|
|
394
|
-
let connector;
|
|
395
|
-
let instanceType;
|
|
396
|
-
if (type === engineModels.BackgroundTaskConnectorType.EntityStorage) {
|
|
397
|
-
backgroundTaskConnectorEntityStorage.initSchema();
|
|
398
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.backgroundTaskEntityStorageType, "BackgroundTask");
|
|
399
|
-
connector = new backgroundTaskConnectorEntityStorage.EntityStorageBackgroundTaskConnector({
|
|
400
|
-
loggingConnectorType: context.defaultTypes.loggingConnector,
|
|
401
|
-
...instanceConfig.options
|
|
402
|
-
});
|
|
403
|
-
instanceType = backgroundTaskConnectorEntityStorage.EntityStorageBackgroundTaskConnector.NAMESPACE;
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
407
|
-
type,
|
|
408
|
-
connectorType: "backgroundTaskConnector"
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
412
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component: connector });
|
|
413
|
-
backgroundTaskModels.BackgroundTaskConnectorFactory.register(finalInstanceType, () => connector);
|
|
414
|
-
return finalInstanceType;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// Copyright 2024 IOTA Stiftung.
|
|
418
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
419
|
-
/**
|
|
420
|
-
* Initialise the blob storage connector.
|
|
421
|
-
* @param engineCore The engine core.
|
|
422
|
-
* @param context The context for the engine.
|
|
423
|
-
* @param instanceConfig The instance config.
|
|
424
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
425
|
-
* @returns The name of the instance created.
|
|
426
|
-
* @throws GeneralError if the connector type is unknown.
|
|
427
|
-
*/
|
|
428
|
-
function initialiseBlobStorageConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
429
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
430
|
-
element: `Blob Storage Connector: ${instanceConfig.type}`
|
|
431
|
-
}));
|
|
432
|
-
const type = instanceConfig.type;
|
|
433
|
-
let connector;
|
|
434
|
-
let instanceType;
|
|
435
|
-
if (type === engineModels.BlobStorageConnectorType.Ipfs) {
|
|
436
|
-
connector = new blobStorageConnectorIpfs.IpfsBlobStorageConnector(instanceConfig.options);
|
|
437
|
-
instanceType = blobStorageConnectorIpfs.IpfsBlobStorageConnector.NAMESPACE;
|
|
438
|
-
}
|
|
439
|
-
else if (type === engineModels.BlobStorageConnectorType.File) {
|
|
440
|
-
connector = new blobStorageConnectorFile.FileBlobStorageConnector({
|
|
441
|
-
...instanceConfig.options,
|
|
442
|
-
config: {
|
|
443
|
-
...instanceConfig.options.config,
|
|
444
|
-
directory: `${instanceConfig.options.storagePrefix ?? ""}${instanceConfig.options.config.directory}`
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
instanceType = blobStorageConnectorFile.FileBlobStorageConnector.NAMESPACE;
|
|
448
|
-
}
|
|
449
|
-
else if (type === engineModels.BlobStorageConnectorType.Memory) {
|
|
450
|
-
connector = new blobStorageConnectorMemory.MemoryBlobStorageConnector();
|
|
451
|
-
instanceType = blobStorageConnectorMemory.MemoryBlobStorageConnector.NAMESPACE;
|
|
452
|
-
}
|
|
453
|
-
else if (type === engineModels.BlobStorageConnectorType.AwsS3) {
|
|
454
|
-
connector = new blobStorageConnectorAwsS3.S3BlobStorageConnector({
|
|
455
|
-
...instanceConfig.options,
|
|
456
|
-
config: {
|
|
457
|
-
...instanceConfig.options.config,
|
|
458
|
-
bucketName: `${instanceConfig.options.storagePrefix ?? ""}${instanceConfig.options.config.bucketName}`
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
instanceType = blobStorageConnectorAwsS3.S3BlobStorageConnector.NAMESPACE;
|
|
462
|
-
}
|
|
463
|
-
else if (type === engineModels.BlobStorageConnectorType.GcpStorage) {
|
|
464
|
-
connector = new blobStorageConnectorGcp.GcpBlobStorageConnector({
|
|
465
|
-
...instanceConfig.options,
|
|
466
|
-
config: {
|
|
467
|
-
...instanceConfig.options.config,
|
|
468
|
-
bucketName: `${instanceConfig.options.storagePrefix ?? ""}${instanceConfig.options.config.bucketName}`
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
instanceType = blobStorageConnectorGcp.GcpBlobStorageConnector.NAMESPACE;
|
|
472
|
-
}
|
|
473
|
-
else if (type === engineModels.BlobStorageConnectorType.AzureStorage) {
|
|
474
|
-
connector = new blobStorageConnectorAzure.AzureBlobStorageConnector({
|
|
475
|
-
...instanceConfig.options,
|
|
476
|
-
config: {
|
|
477
|
-
...instanceConfig.options.config,
|
|
478
|
-
containerName: `${instanceConfig.options.storagePrefix ?? ""}${instanceConfig.options.config.containerName}`
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
instanceType = blobStorageConnectorAzure.AzureBlobStorageConnector.NAMESPACE;
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
485
|
-
type,
|
|
486
|
-
connectorType: "blobStorageConnector"
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
490
|
-
context.componentInstances.push({
|
|
491
|
-
instanceType: finalInstanceType,
|
|
492
|
-
component: connector
|
|
493
|
-
});
|
|
494
|
-
blobStorageModels.BlobStorageConnectorFactory.register(finalInstanceType, () => connector);
|
|
495
|
-
return finalInstanceType;
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Initialise the blob storage component.
|
|
499
|
-
* @param engineCore The engine core.
|
|
500
|
-
* @param context The context for the engine.
|
|
501
|
-
* @param instanceConfig The instance config.
|
|
502
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
503
|
-
* @returns The name of the instance created.
|
|
504
|
-
* @throws GeneralError if the component type is unknown.
|
|
505
|
-
*/
|
|
506
|
-
function initialiseBlobStorageComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
507
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
508
|
-
element: `Blob Storage Component: ${instanceConfig.type}`
|
|
509
|
-
}));
|
|
510
|
-
const type = instanceConfig.type;
|
|
511
|
-
let component;
|
|
512
|
-
let instanceType;
|
|
513
|
-
if (type === engineModels.BlobStorageComponentType.Service) {
|
|
514
|
-
blobStorageService.initSchema();
|
|
515
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.entryEntityStorageType, "BlobStorageEntry");
|
|
516
|
-
component = new blobStorageService.BlobStorageService({
|
|
517
|
-
vaultConnectorType: context.defaultTypes.vaultConnector,
|
|
518
|
-
...instanceConfig.options
|
|
519
|
-
});
|
|
520
|
-
instanceType = blobStorageService.BlobStorageService.NAMESPACE;
|
|
521
|
-
}
|
|
522
|
-
else {
|
|
523
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
524
|
-
type,
|
|
525
|
-
componentType: "blobStorageComponent"
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
529
|
-
context.componentInstances.push({
|
|
530
|
-
instanceType: finalInstanceType,
|
|
531
|
-
component
|
|
532
|
-
});
|
|
533
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
534
|
-
return finalInstanceType;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// Copyright 2024 IOTA Stiftung.
|
|
538
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
539
|
-
/**
|
|
540
|
-
* Initialise a faucet connector.
|
|
541
|
-
* @param engineCore The engine core.
|
|
542
|
-
* @param context The context for the engine.
|
|
543
|
-
* @param instanceConfig The instance config.
|
|
544
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
545
|
-
* @returns The name of the instance created.
|
|
546
|
-
* @throws GeneralError if the connector type is unknown.
|
|
547
|
-
*/
|
|
548
|
-
function initialiseFaucetConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
549
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
550
|
-
element: `Faucet Connector: ${instanceConfig.type}`
|
|
551
|
-
}));
|
|
552
|
-
const type = instanceConfig.type;
|
|
553
|
-
let connector;
|
|
554
|
-
let instanceType;
|
|
555
|
-
if (type === engineModels.FaucetConnectorType.Iota) {
|
|
556
|
-
const dltConfig = context.config.dltConfig?.find(dlt => dlt.type === context.defaultTypes.dltConfig);
|
|
557
|
-
connector = new walletConnectorIota.IotaFaucetConnector({
|
|
558
|
-
...instanceConfig.options,
|
|
559
|
-
config: {
|
|
560
|
-
...dltConfig?.options?.config,
|
|
561
|
-
...instanceConfig.options.config
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
instanceType = walletConnectorIota.IotaFaucetConnector.NAMESPACE;
|
|
565
|
-
}
|
|
566
|
-
else if (type === engineModels.FaucetConnectorType.EntityStorage) {
|
|
567
|
-
connector = new walletConnectorEntityStorage.EntityStorageFaucetConnector(instanceConfig.options);
|
|
568
|
-
instanceType = walletConnectorEntityStorage.EntityStorageFaucetConnector.NAMESPACE;
|
|
569
|
-
}
|
|
570
|
-
else {
|
|
571
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
572
|
-
type,
|
|
573
|
-
connectorType: "faucetConnector"
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
577
|
-
context.componentInstances.push({
|
|
578
|
-
instanceType: finalInstanceType,
|
|
579
|
-
component: connector
|
|
580
|
-
});
|
|
581
|
-
walletModels.FaucetConnectorFactory.register(finalInstanceType, () => connector);
|
|
582
|
-
return finalInstanceType;
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
// Copyright 2024 IOTA Stiftung.
|
|
586
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
587
|
-
/**
|
|
588
|
-
* Initialise the identity connector.
|
|
589
|
-
* @param engineCore The engine core.
|
|
590
|
-
* @param context The context for the engine.
|
|
591
|
-
* @param instanceConfig The instance config.
|
|
592
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
593
|
-
* @returns The name of the instance created.
|
|
594
|
-
* @throws GeneralError if the connector type is unknown.
|
|
595
|
-
*/
|
|
596
|
-
function initialiseIdentityConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
597
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
598
|
-
element: `Identity Connector: ${instanceConfig.type}`
|
|
599
|
-
}));
|
|
600
|
-
const type = instanceConfig.type;
|
|
601
|
-
let connector;
|
|
602
|
-
let instanceType;
|
|
603
|
-
if (type === engineModels.IdentityConnectorType.Iota) {
|
|
604
|
-
const dltConfig = context.config.dltConfig?.find(dlt => dlt.type === context.defaultTypes.dltConfig);
|
|
605
|
-
connector = new identityConnectorIota.IotaIdentityConnector({
|
|
606
|
-
...instanceConfig.options,
|
|
607
|
-
config: {
|
|
608
|
-
...dltConfig?.options?.config,
|
|
609
|
-
...instanceConfig.options.config
|
|
610
|
-
}
|
|
611
|
-
});
|
|
612
|
-
instanceType = identityConnectorIota.IotaIdentityConnector.NAMESPACE;
|
|
613
|
-
}
|
|
614
|
-
else if (type === engineModels.IdentityConnectorType.EntityStorage) {
|
|
615
|
-
identityConnectorEntityStorage.initSchema({ includeProfile: false });
|
|
616
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.didDocumentEntityStorageType, "IdentityDocument");
|
|
617
|
-
connector = new identityConnectorEntityStorage.EntityStorageIdentityConnector({
|
|
618
|
-
vaultConnectorType: context.defaultTypes.vaultConnector,
|
|
619
|
-
...instanceConfig.options
|
|
620
|
-
});
|
|
621
|
-
instanceType = identityConnectorEntityStorage.EntityStorageIdentityConnector.NAMESPACE;
|
|
622
|
-
}
|
|
623
|
-
else {
|
|
624
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
625
|
-
type,
|
|
626
|
-
connectorType: "identityConnector"
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
630
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component: connector });
|
|
631
|
-
identityModels.IdentityConnectorFactory.register(finalInstanceType, () => connector);
|
|
632
|
-
return finalInstanceType;
|
|
633
|
-
}
|
|
634
|
-
/**
|
|
635
|
-
* Initialise the identity component.
|
|
636
|
-
* @param engineCore The engine core.
|
|
637
|
-
* @param context The context for the engine.
|
|
638
|
-
* @param instanceConfig The instance config.
|
|
639
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
640
|
-
* @returns The name of the instance created.
|
|
641
|
-
* @throws GeneralError if the component type is unknown.
|
|
642
|
-
*/
|
|
643
|
-
function initialiseIdentityComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
644
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
645
|
-
element: `Identity Component: ${instanceConfig.type}`
|
|
646
|
-
}));
|
|
647
|
-
const type = instanceConfig.type;
|
|
648
|
-
let component;
|
|
649
|
-
let instanceType;
|
|
650
|
-
if (type === engineModels.IdentityComponentType.Service) {
|
|
651
|
-
component = new identityService.IdentityService(instanceConfig.options);
|
|
652
|
-
instanceType = identityService.IdentityService.NAMESPACE;
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
656
|
-
type,
|
|
657
|
-
componentType: "identityComponent"
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
661
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component });
|
|
662
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
663
|
-
return finalInstanceType;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
// Copyright 2024 IOTA Stiftung.
|
|
667
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
668
|
-
/**
|
|
669
|
-
* Initialise the identity profile connector.
|
|
670
|
-
* @param engineCore The engine core.
|
|
671
|
-
* @param context The context for the engine.
|
|
672
|
-
* @param instanceConfig The instance config.
|
|
673
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
674
|
-
* @returns The name of the instance created.
|
|
675
|
-
* @throws GeneralError if the connector type is unknown.
|
|
676
|
-
*/
|
|
677
|
-
function initialiseIdentityProfileConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
678
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
679
|
-
element: `Identity Profile Connector: ${instanceConfig.type}`
|
|
680
|
-
}));
|
|
681
|
-
const type = instanceConfig.type;
|
|
682
|
-
let connector;
|
|
683
|
-
let instanceType;
|
|
684
|
-
if (type === engineModels.IdentityProfileConnectorType.EntityStorage) {
|
|
685
|
-
identityConnectorEntityStorage.initSchema({ includeDocument: false });
|
|
686
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.profileEntityStorageType, "IdentityProfile");
|
|
687
|
-
connector = new identityConnectorEntityStorage.EntityStorageIdentityProfileConnector(instanceConfig.options);
|
|
688
|
-
instanceType = identityConnectorEntityStorage.EntityStorageIdentityProfileConnector.NAMESPACE;
|
|
689
|
-
}
|
|
690
|
-
else {
|
|
691
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
692
|
-
type,
|
|
693
|
-
serviceType: "identityProfile"
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
697
|
-
context.componentInstances.push({
|
|
698
|
-
instanceType: finalInstanceType,
|
|
699
|
-
component: connector
|
|
700
|
-
});
|
|
701
|
-
identityModels.IdentityProfileConnectorFactory.register(finalInstanceType, () => connector);
|
|
702
|
-
return finalInstanceType;
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* Initialise the identity profile component.
|
|
706
|
-
* @param engineCore The engine core.
|
|
707
|
-
* @param context The context for the engine.
|
|
708
|
-
* @param instanceConfig The instance config.
|
|
709
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
710
|
-
* @returns The name of the instance created.
|
|
711
|
-
* @throws GeneralError if the component type is unknown.
|
|
712
|
-
*/
|
|
713
|
-
function initialiseIdentityProfileComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
714
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
715
|
-
element: `Identity Profile Component: ${instanceConfig.type}`
|
|
716
|
-
}));
|
|
717
|
-
const type = instanceConfig.type;
|
|
718
|
-
let component;
|
|
719
|
-
let instanceType;
|
|
720
|
-
if (type === engineModels.IdentityProfileComponentType.Service) {
|
|
721
|
-
component = new identityService.IdentityProfileService({
|
|
722
|
-
profileEntityConnectorType: context.defaultTypes.identityProfileConnector,
|
|
723
|
-
...instanceConfig.options
|
|
724
|
-
});
|
|
725
|
-
instanceType = identityService.IdentityProfileService.NAMESPACE;
|
|
726
|
-
}
|
|
727
|
-
else {
|
|
728
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
729
|
-
type,
|
|
730
|
-
componentType: "identityProfileComponent"
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
734
|
-
context.componentInstances.push({
|
|
735
|
-
instanceType: finalInstanceType,
|
|
736
|
-
component
|
|
737
|
-
});
|
|
738
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
739
|
-
return finalInstanceType;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
// Copyright 2024 IOTA Stiftung.
|
|
743
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
744
|
-
/**
|
|
745
|
-
* Initialise the immutable proof component.
|
|
746
|
-
* @param engineCore The engine core.
|
|
747
|
-
* @param context The context for the engine.
|
|
748
|
-
* @param instanceConfig The instance config.
|
|
749
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
750
|
-
* @returns The name of the instance created.
|
|
751
|
-
* @throws GeneralError if the component type is unknown.
|
|
752
|
-
*/
|
|
753
|
-
function initialiseImmutableProofComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
754
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
755
|
-
element: `Immutable Proof Component: ${instanceConfig.type}`
|
|
756
|
-
}));
|
|
757
|
-
const type = instanceConfig.type;
|
|
758
|
-
let component;
|
|
759
|
-
let instanceType;
|
|
760
|
-
if (type === engineModels.ImmutableProofComponentType.Service) {
|
|
761
|
-
immutableProofService.initSchema();
|
|
762
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.immutableProofEntityStorageType, "ImmutableProof");
|
|
763
|
-
component = new immutableProofService.ImmutableProofService({
|
|
764
|
-
vaultConnectorType: context.defaultTypes.vaultConnector,
|
|
765
|
-
immutableStorageType: context.defaultTypes.immutableStorageConnector,
|
|
766
|
-
identityConnectorType: context.defaultTypes.identityConnector,
|
|
767
|
-
backgroundTaskConnectorType: context.defaultTypes.backgroundTaskConnector,
|
|
768
|
-
...instanceConfig.options
|
|
769
|
-
});
|
|
770
|
-
instanceType = immutableProofService.ImmutableProofService.NAMESPACE;
|
|
771
|
-
}
|
|
772
|
-
else {
|
|
773
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
774
|
-
type,
|
|
775
|
-
componentType: "immutableProofComponent"
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
779
|
-
context.componentInstances.push({
|
|
780
|
-
instanceType: finalInstanceType,
|
|
781
|
-
component
|
|
782
|
-
});
|
|
783
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
784
|
-
return finalInstanceType;
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
// Copyright 2024 IOTA Stiftung.
|
|
788
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
789
|
-
/**
|
|
790
|
-
* Initialise the immutable storage connector.
|
|
791
|
-
* @param engineCore The engine core.
|
|
792
|
-
* @param context The context for the engine.
|
|
793
|
-
* @param instanceConfig The instance config.
|
|
794
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
795
|
-
* @returns The name of the instance created.
|
|
796
|
-
* @throws GeneralError if the connector type is unknown.
|
|
797
|
-
*/
|
|
798
|
-
function initialiseImmutableStorageConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
799
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
800
|
-
element: `Immutable Storage Connector: ${instanceConfig.type}`
|
|
801
|
-
}));
|
|
802
|
-
const type = instanceConfig.type;
|
|
803
|
-
let connector;
|
|
804
|
-
let instanceType;
|
|
805
|
-
if (type === engineModels.ImmutableStorageConnectorType.Iota) {
|
|
806
|
-
const dltConfig = context.config.dltConfig?.find(dlt => dlt.type === context.defaultTypes.dltConfig);
|
|
807
|
-
connector = new immutableStorageConnectorIota.IotaImmutableStorageConnector({
|
|
808
|
-
...instanceConfig.options,
|
|
809
|
-
config: {
|
|
810
|
-
...dltConfig?.options?.config,
|
|
811
|
-
...instanceConfig.options.config
|
|
812
|
-
}
|
|
813
|
-
});
|
|
814
|
-
instanceType = immutableStorageConnectorIota.IotaImmutableStorageConnector.NAMESPACE;
|
|
815
|
-
}
|
|
816
|
-
else if (type === engineModels.ImmutableStorageConnectorType.EntityStorage) {
|
|
817
|
-
immutableStorageConnectorEntityStorage.initSchema();
|
|
818
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.immutableStorageEntityStorageType, "ImmutableItem");
|
|
819
|
-
connector = new immutableStorageConnectorEntityStorage.EntityStorageImmutableStorageConnector(instanceConfig.options);
|
|
820
|
-
instanceType = immutableStorageConnectorEntityStorage.EntityStorageImmutableStorageConnector.NAMESPACE;
|
|
821
|
-
}
|
|
822
|
-
else {
|
|
823
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
824
|
-
type,
|
|
825
|
-
connectorType: "immutableStorageConnector"
|
|
826
|
-
});
|
|
827
|
-
}
|
|
828
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
829
|
-
context.componentInstances.push({
|
|
830
|
-
instanceType: finalInstanceType,
|
|
831
|
-
component: connector
|
|
832
|
-
});
|
|
833
|
-
immutableStorageModels.ImmutableStorageConnectorFactory.register(finalInstanceType, () => connector);
|
|
834
|
-
return finalInstanceType;
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
// Copyright 2024 IOTA Stiftung.
|
|
838
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
839
|
-
/**
|
|
840
|
-
* Initialise the logging connector.
|
|
841
|
-
* @param engineCore The engine core.
|
|
842
|
-
* @param context The engine core context.
|
|
843
|
-
* @param instanceConfig The instance config.
|
|
844
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
845
|
-
* @returns The name of the instance created.
|
|
846
|
-
* @throws GeneralError if the connector type is unknown.
|
|
847
|
-
*/
|
|
848
|
-
function initialiseLoggingConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
849
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
850
|
-
element: `Logging Connector: ${instanceConfig.type}`
|
|
851
|
-
}));
|
|
852
|
-
const type = instanceConfig.type;
|
|
853
|
-
let connector;
|
|
854
|
-
let instanceType;
|
|
855
|
-
if (type === engineModels.LoggingConnectorType.Console) {
|
|
856
|
-
connector = new loggingConnectorConsole.ConsoleLoggingConnector(instanceConfig.options);
|
|
857
|
-
instanceType = loggingConnectorConsole.ConsoleLoggingConnector.NAMESPACE;
|
|
858
|
-
}
|
|
859
|
-
else if (type === engineModels.LoggingConnectorType.EntityStorage) {
|
|
860
|
-
loggingConnectorEntityStorage.initSchema();
|
|
861
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.logEntryStorageConnectorType, "LogEntry");
|
|
862
|
-
connector = new loggingConnectorEntityStorage.EntityStorageLoggingConnector(instanceConfig.options);
|
|
863
|
-
instanceType = loggingConnectorEntityStorage.EntityStorageLoggingConnector.NAMESPACE;
|
|
864
|
-
}
|
|
865
|
-
else if (type === engineModels.LoggingConnectorType.Multi) {
|
|
866
|
-
connector = new loggingModels.MultiLoggingConnector(instanceConfig.options);
|
|
867
|
-
instanceType = loggingModels.MultiLoggingConnector.NAMESPACE;
|
|
868
|
-
}
|
|
869
|
-
else {
|
|
870
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
871
|
-
type,
|
|
872
|
-
connectorType: "loggingConnector"
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
876
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component: connector });
|
|
877
|
-
loggingModels.LoggingConnectorFactory.register(finalInstanceType, () => connector);
|
|
878
|
-
return finalInstanceType;
|
|
879
|
-
}
|
|
880
|
-
/**
|
|
881
|
-
* Initialise the logging component.
|
|
882
|
-
* @param engineCore The engine core.
|
|
883
|
-
* @param context The context for the engine.
|
|
884
|
-
* @param instanceConfig The instance config.
|
|
885
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
886
|
-
* @returns The name of the instance created.
|
|
887
|
-
* @throws GeneralError if the component type is unknown.
|
|
888
|
-
*/
|
|
889
|
-
function initialiseLoggingComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
890
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
891
|
-
element: `Logging Component: ${instanceConfig.type}`
|
|
892
|
-
}));
|
|
893
|
-
const type = instanceConfig.type;
|
|
894
|
-
let component;
|
|
895
|
-
let instanceType;
|
|
896
|
-
if (type === engineModels.LoggingComponentType.Service) {
|
|
897
|
-
component = new loggingService.LoggingService({
|
|
898
|
-
loggingConnectorType: context.defaultTypes.loggingConnector,
|
|
899
|
-
...instanceConfig.options
|
|
900
|
-
});
|
|
901
|
-
instanceType = loggingService.LoggingService.NAMESPACE;
|
|
902
|
-
}
|
|
903
|
-
else {
|
|
904
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
905
|
-
type,
|
|
906
|
-
componentType: "loggingComponent"
|
|
907
|
-
});
|
|
908
|
-
}
|
|
909
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
910
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component });
|
|
911
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
912
|
-
return finalInstanceType;
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
// Copyright 2024 IOTA Stiftung.
|
|
916
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
917
|
-
/**
|
|
918
|
-
* Initialise the NFT connector.
|
|
919
|
-
* @param engineCore The engine core.
|
|
920
|
-
* @param context The context for the engine.
|
|
921
|
-
* @param instanceConfig The instance config.
|
|
922
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
923
|
-
* @returns The name of the instance created.
|
|
924
|
-
* @throws GeneralError if the connector type is unknown.
|
|
925
|
-
*/
|
|
926
|
-
function initialiseNftConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
927
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
928
|
-
element: `NFT Connector: ${instanceConfig.type}`
|
|
929
|
-
}));
|
|
930
|
-
const type = instanceConfig.type;
|
|
931
|
-
let connector;
|
|
932
|
-
let instanceType;
|
|
933
|
-
if (type === engineModels.NftConnectorType.EntityStorage) {
|
|
934
|
-
nftConnectorEntityStorage.initSchema();
|
|
935
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.nftEntityStorageType, "Nft");
|
|
936
|
-
connector = new nftConnectorEntityStorage.EntityStorageNftConnector(instanceConfig.options);
|
|
937
|
-
instanceType = nftConnectorEntityStorage.EntityStorageNftConnector.NAMESPACE;
|
|
938
|
-
}
|
|
939
|
-
else if (type === engineModels.NftConnectorType.Iota) {
|
|
940
|
-
connector = new nftConnectorIota.IotaNftConnector({
|
|
941
|
-
...instanceConfig.options
|
|
942
|
-
});
|
|
943
|
-
instanceType = nftConnectorIota.IotaNftConnector.NAMESPACE;
|
|
944
|
-
}
|
|
945
|
-
else {
|
|
946
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
947
|
-
type,
|
|
948
|
-
connectorType: "nftConnector"
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
952
|
-
context.componentInstances.push({
|
|
953
|
-
instanceType: finalInstanceType,
|
|
954
|
-
component: connector
|
|
955
|
-
});
|
|
956
|
-
nftModels.NftConnectorFactory.register(finalInstanceType, () => connector);
|
|
957
|
-
return finalInstanceType;
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* Initialise the NFT component.
|
|
961
|
-
* @param engineCore The engine core.
|
|
962
|
-
* @param context The context for the engine.
|
|
963
|
-
* @param instanceConfig The instance config.
|
|
964
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
965
|
-
* @returns The name of the instance created.
|
|
966
|
-
* @throws GeneralError if the component type is unknown.
|
|
967
|
-
*/
|
|
968
|
-
function initialiseNftComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
969
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
970
|
-
element: `Nft Storage Component: ${instanceConfig.type}`
|
|
971
|
-
}));
|
|
972
|
-
const type = instanceConfig.type;
|
|
973
|
-
let component;
|
|
974
|
-
let instanceType;
|
|
975
|
-
if (type === engineModels.NftComponentType.Service) {
|
|
976
|
-
component = new nftService.NftService(instanceConfig.options);
|
|
977
|
-
instanceType = nftService.NftService.NAMESPACE;
|
|
978
|
-
}
|
|
979
|
-
else {
|
|
980
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
981
|
-
type,
|
|
982
|
-
componentType: "nftComponent"
|
|
983
|
-
});
|
|
984
|
-
}
|
|
985
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
986
|
-
context.componentInstances.push({
|
|
987
|
-
instanceType: finalInstanceType,
|
|
988
|
-
component
|
|
989
|
-
});
|
|
990
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
991
|
-
return finalInstanceType;
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
// Copyright 2024 IOTA Stiftung.
|
|
995
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
996
|
-
/**
|
|
997
|
-
* Initialise a telemetry connector.
|
|
998
|
-
* @param engineCore The engine core.
|
|
999
|
-
* @param context The context for the engine.
|
|
1000
|
-
* @param instanceConfig The instance config.
|
|
1001
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
1002
|
-
* @returns The name of the instance created.
|
|
1003
|
-
* @throws GeneralError if the connector type is unknown.
|
|
1004
|
-
*/
|
|
1005
|
-
function initialiseTelemetryConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
1006
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
1007
|
-
element: `Telemetry Connector: ${instanceConfig.type}`
|
|
1008
|
-
}));
|
|
1009
|
-
const type = instanceConfig.type;
|
|
1010
|
-
let connector;
|
|
1011
|
-
let instanceType;
|
|
1012
|
-
if (type === engineModels.TelemetryConnectorType.EntityStorage) {
|
|
1013
|
-
telemetryConnectorEntityStorage.initSchema();
|
|
1014
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.telemetryMetricStorageConnectorType, "TelemetryMetric");
|
|
1015
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.telemetryMetricValueStorageConnectorType, "TelemetryMetricValue");
|
|
1016
|
-
connector = new telemetryConnectorEntityStorage.EntityStorageTelemetryConnector({
|
|
1017
|
-
loggingConnectorType: context.defaultTypes.loggingConnector,
|
|
1018
|
-
...instanceConfig.options
|
|
1019
|
-
});
|
|
1020
|
-
instanceType = telemetryConnectorEntityStorage.EntityStorageTelemetryConnector.NAMESPACE;
|
|
1021
|
-
}
|
|
1022
|
-
else {
|
|
1023
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
1024
|
-
type,
|
|
1025
|
-
connectorType: "telemetryConnector"
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
1029
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component: connector });
|
|
1030
|
-
telemetryModels.TelemetryConnectorFactory.register(finalInstanceType, () => connector);
|
|
1031
|
-
return finalInstanceType;
|
|
1032
|
-
}
|
|
1033
|
-
/**
|
|
1034
|
-
* Initialise the telemetry component.
|
|
1035
|
-
* @param engineCore The engine core.
|
|
1036
|
-
* @param context The context for the engine.
|
|
1037
|
-
* @param instanceConfig The instance config.
|
|
1038
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
1039
|
-
* @returns The name of the instance created.
|
|
1040
|
-
* @throws GeneralError if the component type is unknown.
|
|
1041
|
-
*/
|
|
1042
|
-
function initialiseTelemetryComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
1043
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
1044
|
-
element: `Telemetry Component: ${instanceConfig.type}`
|
|
1045
|
-
}));
|
|
1046
|
-
const type = instanceConfig.type;
|
|
1047
|
-
let component;
|
|
1048
|
-
let instanceType;
|
|
1049
|
-
if (type === engineModels.TelemetryComponentType.Service) {
|
|
1050
|
-
component = new telemetryService.TelemetryService({
|
|
1051
|
-
telemetryConnectorType: context.defaultTypes.telemetryConnector,
|
|
1052
|
-
...instanceConfig.options
|
|
1053
|
-
});
|
|
1054
|
-
instanceType = telemetryService.TelemetryService.NAMESPACE;
|
|
1055
|
-
}
|
|
1056
|
-
else {
|
|
1057
|
-
throw new core.GeneralError("engineCore", "componentUnknownType", {
|
|
1058
|
-
type,
|
|
1059
|
-
componentType: "telemetryComponent"
|
|
1060
|
-
});
|
|
1061
|
-
}
|
|
1062
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
1063
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component });
|
|
1064
|
-
core.ComponentFactory.register(finalInstanceType, () => component);
|
|
1065
|
-
return finalInstanceType;
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
// Copyright 2024 IOTA Stiftung.
|
|
1069
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
1070
|
-
/**
|
|
1071
|
-
* Initialise the vault connector.
|
|
1072
|
-
* @param engineCore The engine core.
|
|
1073
|
-
* @param context The context for the engine.
|
|
1074
|
-
* @param instanceConfig The instance config.
|
|
1075
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
1076
|
-
* @returns The name of the instance created.
|
|
1077
|
-
* @throws GeneralError if the connector type is unknown.
|
|
1078
|
-
*/
|
|
1079
|
-
function initialiseVaultConnector(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
1080
|
-
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuring", {
|
|
1081
|
-
element: `Vault Connector: ${instanceConfig.type}`
|
|
1082
|
-
}));
|
|
1083
|
-
const type = instanceConfig.type;
|
|
1084
|
-
let connector;
|
|
1085
|
-
let instanceType;
|
|
1086
|
-
if (type === engineModels.VaultConnectorType.EntityStorage) {
|
|
1087
|
-
vaultConnectorEntityStorage.initSchema();
|
|
1088
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.vaultKeyEntityStorageType, "VaultKey");
|
|
1089
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.vaultSecretEntityStorageType, "VaultSecret");
|
|
1090
|
-
connector = new vaultConnectorEntityStorage.EntityStorageVaultConnector(instanceConfig.options);
|
|
1091
|
-
instanceType = vaultConnectorEntityStorage.EntityStorageVaultConnector.NAMESPACE;
|
|
1092
|
-
}
|
|
1093
|
-
else if (type === engineModels.VaultConnectorType.Hashicorp) {
|
|
1094
|
-
connector = new vaultConnectorHashicorp.HashicorpVaultConnector(instanceConfig.options);
|
|
1095
|
-
instanceType = vaultConnectorHashicorp.HashicorpVaultConnector.NAMESPACE;
|
|
1096
|
-
}
|
|
1097
|
-
else {
|
|
1098
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
1099
|
-
type,
|
|
1100
|
-
connectorType: "vaultConnector"
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
1104
|
-
context.componentInstances.push({ instanceType: finalInstanceType, component: connector });
|
|
1105
|
-
vaultModels.VaultConnectorFactory.register(finalInstanceType, () => connector);
|
|
1106
|
-
return finalInstanceType;
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
// Copyright 2024 IOTA Stiftung.
|
|
1110
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
1111
|
-
/**
|
|
1112
|
-
* Initialise a wallet connector.
|
|
1113
|
-
* @param engineCore The engine core.
|
|
1114
|
-
* @param context The context for the node.
|
|
1115
|
-
* @param instanceConfig The instance config.
|
|
1116
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
1117
|
-
* @returns The name of the instance created.
|
|
1118
|
-
* @throws GeneralError if the connector type is unknown.
|
|
14
|
+
* Store state in memory.
|
|
1119
15
|
*/
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
});
|
|
1144
|
-
instanceType = walletConnectorEntityStorage.EntityStorageWalletConnector.NAMESPACE;
|
|
1145
|
-
}
|
|
1146
|
-
else {
|
|
1147
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
1148
|
-
type,
|
|
1149
|
-
connectorType: "walletConnector"
|
|
1150
|
-
});
|
|
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;
|
|
1151
39
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
* @param engineCore The engine core.
|
|
1163
|
-
* @param context The context for the engine.
|
|
1164
|
-
* @param instanceConfig The instance config.
|
|
1165
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
1166
|
-
* @returns Nothing.
|
|
1167
|
-
* @throws GeneralError if the connector type is unknown.
|
|
1168
|
-
*/
|
|
1169
|
-
function initialiseWalletStorage(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
1170
|
-
const type = instanceConfig.type;
|
|
1171
|
-
if (type === engineModels.WalletConnectorType.Iota) ;
|
|
1172
|
-
else if (type === engineModels.WalletConnectorType.EntityStorage) {
|
|
1173
|
-
walletConnectorEntityStorage.initSchema();
|
|
1174
|
-
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;
|
|
1175
50
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
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
|
+
}
|
|
1181
62
|
}
|
|
1182
|
-
return undefined;
|
|
1183
63
|
}
|
|
1184
64
|
|
|
1185
65
|
// Copyright 2024 IOTA Stiftung.
|
|
@@ -1198,7 +78,6 @@ class EngineCore {
|
|
|
1198
78
|
CLASS_NAME = "EngineCore";
|
|
1199
79
|
/**
|
|
1200
80
|
* The core context.
|
|
1201
|
-
* @internal
|
|
1202
81
|
*/
|
|
1203
82
|
_context;
|
|
1204
83
|
/**
|
|
@@ -1216,11 +95,26 @@ class EngineCore {
|
|
|
1216
95
|
* @internal
|
|
1217
96
|
*/
|
|
1218
97
|
_skipBootstrap;
|
|
98
|
+
/**
|
|
99
|
+
* The logger type name to use.
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
_loggerTypeName;
|
|
1219
103
|
/**
|
|
1220
104
|
* The type initialisers.
|
|
1221
105
|
* @internal
|
|
1222
106
|
*/
|
|
1223
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;
|
|
1224
118
|
/**
|
|
1225
119
|
* Method for bootstrapping any data for the engine.
|
|
1226
120
|
* @internal
|
|
@@ -1235,61 +129,94 @@ class EngineCore {
|
|
|
1235
129
|
options.config = options.config ?? {};
|
|
1236
130
|
options.config.debug = options.config.debug ?? false;
|
|
1237
131
|
options.config.silent = options.config.silent ?? false;
|
|
132
|
+
options.config.types ??= {};
|
|
1238
133
|
this._skipBootstrap = options.skipBootstrap ?? false;
|
|
134
|
+
this._populateTypeInitialisers = options.populateTypeInitialisers;
|
|
1239
135
|
this._customBootstrap = options.customBootstrap;
|
|
136
|
+
this._loggerTypeName = options.loggerTypeName ?? EngineCore.LOGGER_TYPE_NAME;
|
|
1240
137
|
this._typeInitialisers = [];
|
|
1241
138
|
this._context = {
|
|
1242
139
|
config: options.config,
|
|
1243
140
|
defaultTypes: {},
|
|
1244
141
|
componentInstances: [],
|
|
1245
|
-
state: {
|
|
142
|
+
state: { componentStates: {} },
|
|
1246
143
|
stateDirty: false
|
|
1247
144
|
};
|
|
1248
145
|
this._stateStorage = options.stateStorage;
|
|
1249
|
-
this.
|
|
146
|
+
this._isStarted = false;
|
|
147
|
+
if (core.Is.function(this._populateTypeInitialisers)) {
|
|
148
|
+
this._populateTypeInitialisers(this, this._context);
|
|
149
|
+
}
|
|
1250
150
|
}
|
|
1251
151
|
/**
|
|
1252
152
|
* Add a type initialiser.
|
|
1253
153
|
* @param type The type to add the initialiser for.
|
|
1254
154
|
* @param typeConfig The type config.
|
|
1255
|
-
* @param
|
|
155
|
+
* @param module The name of the module which contains the initialiser method.
|
|
156
|
+
* @param method The name of the method to call.
|
|
1256
157
|
*/
|
|
1257
|
-
addTypeInitialiser(type, typeConfig,
|
|
158
|
+
addTypeInitialiser(type, typeConfig, module, method) {
|
|
1258
159
|
if (!core.Is.empty(typeConfig)) {
|
|
1259
160
|
this._typeInitialisers.push({
|
|
1260
161
|
type,
|
|
1261
162
|
typeConfig,
|
|
1262
|
-
|
|
163
|
+
module,
|
|
164
|
+
method
|
|
1263
165
|
});
|
|
1264
166
|
}
|
|
1265
167
|
}
|
|
1266
168
|
/**
|
|
1267
169
|
* Start the engine core.
|
|
1268
|
-
* @returns
|
|
170
|
+
* @returns True if the start was successful.
|
|
1269
171
|
*/
|
|
1270
172
|
async start() {
|
|
173
|
+
if (this._isStarted) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
1271
176
|
this.setupEngineLogger();
|
|
1272
177
|
this.logInfo(core.I18n.formatMessage("engineCore.starting"));
|
|
1273
178
|
if (this._context.config.debug) {
|
|
1274
179
|
this.logInfo(core.I18n.formatMessage("engineCore.debuggingEnabled"));
|
|
1275
180
|
}
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
}
|
|
1280
|
-
const canContinue = await this.bootstrap();
|
|
181
|
+
let canContinue;
|
|
182
|
+
try {
|
|
183
|
+
canContinue = await this.stateLoad();
|
|
1281
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();
|
|
1282
189
|
this.logInfo(core.I18n.formatMessage("engineCore.componentsStarting"));
|
|
1283
190
|
for (const instance of this._context.componentInstances) {
|
|
1284
191
|
if (core.Is.function(instance.component.start)) {
|
|
1285
|
-
this.
|
|
1286
|
-
|
|
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
|
+
}
|
|
1287
203
|
}
|
|
1288
204
|
}
|
|
1289
205
|
this.logInfo(core.I18n.formatMessage("engineCore.componentsComplete"));
|
|
1290
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));
|
|
213
|
+
}
|
|
214
|
+
finally {
|
|
215
|
+
if (!(await this.stateSave())) {
|
|
216
|
+
canContinue = false;
|
|
217
|
+
}
|
|
1291
218
|
}
|
|
1292
|
-
|
|
219
|
+
return canContinue;
|
|
1293
220
|
}
|
|
1294
221
|
/**
|
|
1295
222
|
* Stop the engine core.
|
|
@@ -1300,9 +227,16 @@ class EngineCore {
|
|
|
1300
227
|
this.logInfo(core.I18n.formatMessage("engineCore.componentsStopping"));
|
|
1301
228
|
for (const instance of this._context.componentInstances) {
|
|
1302
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);
|
|
1303
233
|
this.logInfo(core.I18n.formatMessage("engineCore.componentStopping", { element: instance.instanceType }));
|
|
1304
234
|
try {
|
|
1305
|
-
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
|
+
}
|
|
1306
240
|
}
|
|
1307
241
|
catch (err) {
|
|
1308
242
|
this.logError(new core.GeneralError(this.CLASS_NAME, "componentStopFailed", {
|
|
@@ -1311,6 +245,7 @@ class EngineCore {
|
|
|
1311
245
|
}
|
|
1312
246
|
}
|
|
1313
247
|
}
|
|
248
|
+
await this.stateSave();
|
|
1314
249
|
this.logInfo(core.I18n.formatMessage("engineCore.componentsStopped"));
|
|
1315
250
|
this.logInfo(core.I18n.formatMessage("engineCore.stopped"));
|
|
1316
251
|
}
|
|
@@ -1366,14 +301,63 @@ class EngineCore {
|
|
|
1366
301
|
getDefaultTypes() {
|
|
1367
302
|
return this._context.defaultTypes;
|
|
1368
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: { 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
|
+
}
|
|
1369
352
|
/**
|
|
1370
353
|
* Initialise the types from connector.
|
|
1371
354
|
* @param typeKey The key for the default types.
|
|
1372
355
|
* @param instanceMethod The function to initialise the instance.
|
|
1373
356
|
* @internal
|
|
1374
357
|
*/
|
|
1375
|
-
initialiseTypeConfig(typeKey, typeConfig,
|
|
358
|
+
async initialiseTypeConfig(typeKey, typeConfig, module, method) {
|
|
1376
359
|
if (core.Is.arrayValue(typeConfig)) {
|
|
360
|
+
const instanceMethod = await modules.ModuleHelper.getModuleEntry(module, method);
|
|
1377
361
|
for (let i = 0; i < typeConfig.length; i++) {
|
|
1378
362
|
const instanceType = instanceMethod(this, this._context, typeConfig[i], typeConfig[i].overrideInstanceType);
|
|
1379
363
|
if (core.Is.stringValue(instanceType) &&
|
|
@@ -1388,21 +372,22 @@ class EngineCore {
|
|
|
1388
372
|
* @internal
|
|
1389
373
|
*/
|
|
1390
374
|
setupEngineLogger() {
|
|
1391
|
-
|
|
1392
|
-
|
|
375
|
+
const silent = this._context.config.silent ?? false;
|
|
376
|
+
const engineLogger = silent
|
|
377
|
+
? new loggingModels.SilentLoggingConnector()
|
|
378
|
+
: new loggingConnectorConsole.ConsoleLoggingConnector({
|
|
1393
379
|
config: {
|
|
1394
380
|
translateMessages: true,
|
|
1395
381
|
hideGroups: true
|
|
1396
382
|
}
|
|
1397
383
|
});
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
}
|
|
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;
|
|
1406
391
|
}
|
|
1407
392
|
/**
|
|
1408
393
|
* Load the state.
|
|
@@ -1413,9 +398,9 @@ class EngineCore {
|
|
|
1413
398
|
if (this._stateStorage) {
|
|
1414
399
|
try {
|
|
1415
400
|
this._context.state = ((await this._stateStorage.load(this)) ?? {
|
|
1416
|
-
|
|
401
|
+
componentStates: {}
|
|
1417
402
|
});
|
|
1418
|
-
this._context.state.
|
|
403
|
+
this._context.state.componentStates ??= {};
|
|
1419
404
|
this._context.stateDirty = false;
|
|
1420
405
|
return true;
|
|
1421
406
|
}
|
|
@@ -1428,6 +413,7 @@ class EngineCore {
|
|
|
1428
413
|
}
|
|
1429
414
|
/**
|
|
1430
415
|
* Save the state.
|
|
416
|
+
* @returns True if the state was saved.
|
|
1431
417
|
* @internal
|
|
1432
418
|
*/
|
|
1433
419
|
async stateSave() {
|
|
@@ -1435,90 +421,61 @@ class EngineCore {
|
|
|
1435
421
|
try {
|
|
1436
422
|
await this._stateStorage.save(this, this._context.state);
|
|
1437
423
|
this._context.stateDirty = false;
|
|
424
|
+
return true;
|
|
1438
425
|
}
|
|
1439
426
|
catch (err) {
|
|
1440
427
|
this.logError(core.BaseError.fromError(err));
|
|
1441
428
|
}
|
|
429
|
+
return false;
|
|
1442
430
|
}
|
|
431
|
+
return true;
|
|
1443
432
|
}
|
|
1444
433
|
/**
|
|
1445
434
|
* Bootstrap the engine.
|
|
1446
|
-
* @returns True if the engine can continue.
|
|
1447
435
|
* @internal
|
|
1448
436
|
*/
|
|
1449
437
|
async bootstrap() {
|
|
1450
|
-
let canContinue = true;
|
|
1451
438
|
if (!this._skipBootstrap) {
|
|
1452
439
|
this.logInfo(core.I18n.formatMessage("engineCore.bootstrapStarted"));
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
}
|
|
440
|
+
// First bootstrap the components.
|
|
441
|
+
for (const instance of this._context.componentInstances) {
|
|
442
|
+
if (core.Is.function(instance.component.bootstrap)) {
|
|
443
|
+
const instanceName = this.getInstanceName(instance);
|
|
444
|
+
this.logInfo(core.I18n.formatMessage("engineCore.bootstrapping", {
|
|
445
|
+
element: instanceName
|
|
446
|
+
}));
|
|
447
|
+
const componentState = this._context.state.componentStates[instanceName] ?? {};
|
|
448
|
+
const lastState = core.ObjectHelper.clone(componentState);
|
|
449
|
+
const bootstrapSuccess = await instance.component.bootstrap(this._loggerTypeName, componentState);
|
|
450
|
+
// If the bootstrap method failed then throw an error
|
|
451
|
+
if (!bootstrapSuccess) {
|
|
452
|
+
throw new core.GeneralError(this.CLASS_NAME, "bootstrapFailed", {
|
|
453
|
+
component: `${instance.component.CLASS_NAME}:${instance.instanceType}`
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
if (!core.ObjectHelper.equal(lastState, componentState)) {
|
|
457
|
+
this._context.state.componentStates[instanceName] = componentState;
|
|
458
|
+
this._context.stateDirty = true;
|
|
1473
459
|
}
|
|
1474
460
|
}
|
|
1475
|
-
// Now perform any custom bootstrap operations
|
|
1476
|
-
if (canContinue && core.Is.function(this._customBootstrap)) {
|
|
1477
|
-
await this._customBootstrap(this, this._context);
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
catch (err) {
|
|
1481
|
-
canContinue = false;
|
|
1482
|
-
this.logError(core.BaseError.fromError(err));
|
|
1483
461
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
this.logInfo(core.I18n.formatMessage("engineCore.bootstrapComplete"));
|
|
1488
|
-
}
|
|
462
|
+
// Now perform any custom bootstrap operations
|
|
463
|
+
if (core.Is.function(this._customBootstrap)) {
|
|
464
|
+
await this._customBootstrap(this, this._context);
|
|
1489
465
|
}
|
|
466
|
+
this.logInfo(core.I18n.formatMessage("engineCore.bootstrapComplete"));
|
|
1490
467
|
}
|
|
1491
|
-
return canContinue;
|
|
1492
468
|
}
|
|
1493
469
|
/**
|
|
1494
|
-
*
|
|
470
|
+
* Get the instance name.
|
|
471
|
+
* @param instance The instance to get the name for.
|
|
472
|
+
* @param instance.instanceType The instance type.
|
|
473
|
+
* @param instance.component The component.
|
|
474
|
+
* @returns The instance name.
|
|
1495
475
|
* @internal
|
|
1496
476
|
*/
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
this.addTypeInitialiser("loggingComponent", this._context.config.loggingComponent, initialiseLoggingComponent);
|
|
1500
|
-
this.addTypeInitialiser("backgroundTaskConnector", this._context.config.backgroundTaskConnector, initialiseBackgroundTaskConnector);
|
|
1501
|
-
this.addTypeInitialiser("telemetryConnector", this._context.config.telemetryConnector, initialiseTelemetryConnector);
|
|
1502
|
-
this.addTypeInitialiser("telemetryComponent", this._context.config.telemetryComponent, initialiseTelemetryComponent);
|
|
1503
|
-
this.addTypeInitialiser("entityStorageComponent", this._context.config.entityStorageComponent, initialiseEntityStorageComponent);
|
|
1504
|
-
this.addTypeInitialiser("vaultConnector", this._context.config.vaultConnector, initialiseVaultConnector);
|
|
1505
|
-
this.addTypeInitialiser("blobStorageConnector", this._context.config.blobStorageConnector, initialiseBlobStorageConnector);
|
|
1506
|
-
this.addTypeInitialiser("blobStorageComponent", this._context.config.blobStorageComponent, initialiseBlobStorageComponent);
|
|
1507
|
-
this.addTypeInitialiser("immutableStorageConnector", this._context.config.immutableStorageConnector, initialiseImmutableStorageConnector);
|
|
1508
|
-
this.addTypeInitialiser("walletConnector", this._context.config.walletConnector, initialiseWalletStorage);
|
|
1509
|
-
this.addTypeInitialiser("faucetConnector", this._context.config.faucetConnector, initialiseFaucetConnector);
|
|
1510
|
-
this.addTypeInitialiser("walletConnector", this._context.config.walletConnector, initialiseWalletConnector);
|
|
1511
|
-
this.addTypeInitialiser("identityConnector", this._context.config.identityConnector, initialiseIdentityConnector);
|
|
1512
|
-
this.addTypeInitialiser("identityComponent", this._context.config.identityComponent, initialiseIdentityComponent);
|
|
1513
|
-
this.addTypeInitialiser("identityProfileConnector", this._context.config.identityProfileConnector, initialiseIdentityProfileConnector);
|
|
1514
|
-
this.addTypeInitialiser("identityProfileComponent", this._context.config.identityProfileComponent, initialiseIdentityProfileComponent);
|
|
1515
|
-
this.addTypeInitialiser("nftConnector", this._context.config.nftConnector, initialiseNftConnector);
|
|
1516
|
-
this.addTypeInitialiser("nftComponent", this._context.config.nftComponent, initialiseNftComponent);
|
|
1517
|
-
this.addTypeInitialiser("immutableProofComponent", this._context.config.immutableProofComponent, initialiseImmutableProofComponent);
|
|
1518
|
-
this.addTypeInitialiser("attestationConnector", this._context.config.attestationConnector, initialiseAttestationConnector);
|
|
1519
|
-
this.addTypeInitialiser("attestationComponent", this._context.config.attestationComponent, initialiseAttestationComponent);
|
|
1520
|
-
this.addTypeInitialiser("auditableItemGraphComponent", this._context.config.auditableItemGraphComponent, initialiseAuditableItemGraphComponent);
|
|
1521
|
-
this.addTypeInitialiser("auditableItemStreamComponent", this._context.config.auditableItemStreamComponent, initialiseAuditableItemStreamComponent);
|
|
477
|
+
getInstanceName(instance) {
|
|
478
|
+
return `${instance.component.CLASS_NAME}-${instance.instanceType}`;
|
|
1522
479
|
}
|
|
1523
480
|
}
|
|
1524
481
|
|
|
@@ -1583,6 +540,10 @@ class FileStateStorage {
|
|
|
1583
540
|
engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.saving`, {
|
|
1584
541
|
filename: this._filename
|
|
1585
542
|
}));
|
|
543
|
+
try {
|
|
544
|
+
await promises.mkdir(path.dirname(this._filename), { recursive: true });
|
|
545
|
+
}
|
|
546
|
+
catch { }
|
|
1586
547
|
await promises.writeFile(this._filename, JSON.stringify(state, undefined, "\t"), "utf8");
|
|
1587
548
|
}
|
|
1588
549
|
catch (err) {
|
|
@@ -1607,586 +568,6 @@ class FileStateStorage {
|
|
|
1607
568
|
}
|
|
1608
569
|
}
|
|
1609
570
|
|
|
1610
|
-
// Copyright 2024 IOTA Stiftung.
|
|
1611
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
1612
|
-
/**
|
|
1613
|
-
* Store state in memory.
|
|
1614
|
-
*/
|
|
1615
|
-
class MemoryStateStorage {
|
|
1616
|
-
/**
|
|
1617
|
-
* Runtime name for the class.
|
|
1618
|
-
*/
|
|
1619
|
-
CLASS_NAME = "MemoryStateStorage";
|
|
1620
|
-
/**
|
|
1621
|
-
* Readonly mode state file is not updated.
|
|
1622
|
-
* @internal
|
|
1623
|
-
*/
|
|
1624
|
-
_readonlyMode;
|
|
1625
|
-
/**
|
|
1626
|
-
* The state object.
|
|
1627
|
-
* @internal
|
|
1628
|
-
*/
|
|
1629
|
-
_engineState;
|
|
1630
|
-
/**
|
|
1631
|
-
* Create a new instance of MemoryStateStorage.
|
|
1632
|
-
* @param readonlyMode Whether the file is in read-only mode.
|
|
1633
|
-
*/
|
|
1634
|
-
constructor(readonlyMode = false) {
|
|
1635
|
-
this._readonlyMode = readonlyMode;
|
|
1636
|
-
}
|
|
1637
|
-
/**
|
|
1638
|
-
* Method for loading the state.
|
|
1639
|
-
* @param engineCore The engine core to load the state for.
|
|
1640
|
-
* @returns The state of the engine or undefined if it doesn't exist.
|
|
1641
|
-
*/
|
|
1642
|
-
async load(engineCore) {
|
|
1643
|
-
engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.loading`, {
|
|
1644
|
-
filename: this._engineState
|
|
1645
|
-
}));
|
|
1646
|
-
return this._engineState;
|
|
1647
|
-
}
|
|
1648
|
-
/**
|
|
1649
|
-
* Method for saving the state.
|
|
1650
|
-
* @param engineCore The engine core to save the state for.
|
|
1651
|
-
* @param state The state of the engine to save.
|
|
1652
|
-
* @returns Nothing.
|
|
1653
|
-
*/
|
|
1654
|
-
async save(engineCore, state) {
|
|
1655
|
-
if (!this._readonlyMode) {
|
|
1656
|
-
engineCore.logInfo(core.I18n.formatMessage(`${core.StringHelper.camelCase(this.CLASS_NAME)}.saving`));
|
|
1657
|
-
this._engineState = state;
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
// Copyright 2024 IOTA Stiftung.
|
|
1663
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
1664
|
-
/**
|
|
1665
|
-
* Build the engine core configuration from environment variables.
|
|
1666
|
-
* @param envVars The environment variables.
|
|
1667
|
-
* @returns The config for the core.
|
|
1668
|
-
*/
|
|
1669
|
-
function buildEngineCoreConfiguration(envVars) {
|
|
1670
|
-
envVars.stateFilename ??= "engine-state.json";
|
|
1671
|
-
envVars.storageFileRoot = path.resolve(envVars.storageFileRoot);
|
|
1672
|
-
envVars.stateFilename = path.join(envVars.storageFileRoot, envVars.stateFilename);
|
|
1673
|
-
envVars.attestationAssertionMethodId ??= "attestation-assertion";
|
|
1674
|
-
envVars.immutableProofHashKeyId ??= "immutable-proof-hash";
|
|
1675
|
-
envVars.immutableProofAssertionMethodId ??= "immutable-proof-assertion";
|
|
1676
|
-
envVars.blobStorageEnableEncryption ??= "false";
|
|
1677
|
-
envVars.blobStorageEncryptionKey ??= "blob-encryption";
|
|
1678
|
-
const coreConfig = {
|
|
1679
|
-
debug: core.Coerce.boolean(envVars.debug) ?? false,
|
|
1680
|
-
loggingConnector: [],
|
|
1681
|
-
loggingComponent: [{ type: engineModels.LoggingComponentType.Service }],
|
|
1682
|
-
entityStorageConnector: [],
|
|
1683
|
-
blobStorageConnector: [],
|
|
1684
|
-
blobStorageComponent: [
|
|
1685
|
-
{
|
|
1686
|
-
type: engineModels.BlobStorageComponentType.Service,
|
|
1687
|
-
options: {
|
|
1688
|
-
config: {
|
|
1689
|
-
vaultKeyId: envVars.blobStorageEncryptionKey
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
],
|
|
1694
|
-
backgroundTaskConnector: [],
|
|
1695
|
-
telemetryConnector: [],
|
|
1696
|
-
telemetryComponent: [{ type: engineModels.TelemetryComponentType.Service }],
|
|
1697
|
-
vaultConnector: [],
|
|
1698
|
-
walletConnector: [],
|
|
1699
|
-
faucetConnector: [],
|
|
1700
|
-
immutableStorageConnector: [],
|
|
1701
|
-
nftConnector: [],
|
|
1702
|
-
nftComponent: [{ type: engineModels.NftComponentType.Service }],
|
|
1703
|
-
identityConnector: [],
|
|
1704
|
-
identityComponent: [{ type: engineModels.IdentityComponentType.Service }],
|
|
1705
|
-
identityProfileConnector: [],
|
|
1706
|
-
identityProfileComponent: [{ type: engineModels.IdentityProfileComponentType.Service }],
|
|
1707
|
-
immutableProofComponent: [
|
|
1708
|
-
{
|
|
1709
|
-
type: engineModels.ImmutableProofComponentType.Service,
|
|
1710
|
-
options: {
|
|
1711
|
-
config: {
|
|
1712
|
-
assertionMethodId: envVars.immutableProofAssertionMethodId,
|
|
1713
|
-
proofHashKeyId: envVars.immutableProofHashKeyId
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
],
|
|
1718
|
-
attestationConnector: [],
|
|
1719
|
-
attestationComponent: [
|
|
1720
|
-
{
|
|
1721
|
-
type: engineModels.AttestationComponentType.Service
|
|
1722
|
-
}
|
|
1723
|
-
],
|
|
1724
|
-
auditableItemGraphComponent: [{ type: engineModels.AuditableItemGraphComponentType.Service }],
|
|
1725
|
-
auditableItemStreamComponent: [{ type: engineModels.AuditableItemStreamComponentType.Service }]
|
|
1726
|
-
};
|
|
1727
|
-
configureEntityStorageConnectors(coreConfig, envVars);
|
|
1728
|
-
configureBlobStorageConnectors(coreConfig, envVars);
|
|
1729
|
-
configureVaultConnectors(coreConfig, envVars);
|
|
1730
|
-
configureLogging(coreConfig, envVars);
|
|
1731
|
-
configureBackgroundTaskConnectors(coreConfig, envVars);
|
|
1732
|
-
configureTelemetryConnectors(coreConfig, envVars);
|
|
1733
|
-
configureFaucetConnectors(coreConfig, envVars);
|
|
1734
|
-
configureWalletConnectors(coreConfig, envVars);
|
|
1735
|
-
configureNftConnectors(coreConfig, envVars);
|
|
1736
|
-
configureImmutableStorageConnectors(coreConfig, envVars);
|
|
1737
|
-
configureIdentityConnectors(coreConfig, envVars);
|
|
1738
|
-
configureIdentityProfileConnectors(coreConfig, envVars);
|
|
1739
|
-
configureAttestationConnectors(coreConfig, envVars);
|
|
1740
|
-
return coreConfig;
|
|
1741
|
-
}
|
|
1742
|
-
/**
|
|
1743
|
-
* Configures the entity storage connectors for the core.
|
|
1744
|
-
* @param coreConfig The core config.
|
|
1745
|
-
* @param envVars The environment variables.
|
|
1746
|
-
*/
|
|
1747
|
-
function configureEntityStorageConnectors(coreConfig, envVars) {
|
|
1748
|
-
coreConfig.entityStorageConnector ??= [];
|
|
1749
|
-
if ((core.Coerce.boolean(envVars.entityMemoryEnable) ?? false) ||
|
|
1750
|
-
envVars.blobStorageConnectorType === engineModels.EntityStorageConnectorType.Memory) {
|
|
1751
|
-
coreConfig.entityStorageConnector.push({
|
|
1752
|
-
type: engineModels.EntityStorageConnectorType.Memory
|
|
1753
|
-
});
|
|
1754
|
-
}
|
|
1755
|
-
if ((core.Coerce.boolean(envVars.entityFileEnable) ?? false) ||
|
|
1756
|
-
envVars.entityStorageConnectorType === engineModels.EntityStorageConnectorType.File) {
|
|
1757
|
-
coreConfig.entityStorageConnector.push({
|
|
1758
|
-
type: engineModels.EntityStorageConnectorType.File,
|
|
1759
|
-
options: { config: { directory: envVars.storageFileRoot } }
|
|
1760
|
-
});
|
|
1761
|
-
}
|
|
1762
|
-
if (core.Is.stringValue(envVars.awsDynamodbAccessKeyId)) {
|
|
1763
|
-
coreConfig.entityStorageConnector.push({
|
|
1764
|
-
type: engineModels.EntityStorageConnectorType.AwsDynamoDb,
|
|
1765
|
-
options: {
|
|
1766
|
-
config: {
|
|
1767
|
-
region: envVars.awsDynamodbRegion,
|
|
1768
|
-
accessKeyId: envVars.awsDynamodbAccessKeyId,
|
|
1769
|
-
secretAccessKey: envVars.awsDynamodbSecretAccessKey,
|
|
1770
|
-
endpoint: envVars.awsDynamodbEndpoint
|
|
1771
|
-
},
|
|
1772
|
-
tablePrefix: envVars.entityStorageTablePrefix
|
|
1773
|
-
}
|
|
1774
|
-
});
|
|
1775
|
-
}
|
|
1776
|
-
if (core.Is.stringValue(envVars.azureCosmosdbKey)) {
|
|
1777
|
-
coreConfig.entityStorageConnector.push({
|
|
1778
|
-
type: engineModels.EntityStorageConnectorType.AzureCosmosDb,
|
|
1779
|
-
options: {
|
|
1780
|
-
config: {
|
|
1781
|
-
endpoint: envVars.azureCosmosdbEndpoint,
|
|
1782
|
-
key: envVars.azureCosmosdbKey,
|
|
1783
|
-
databaseId: envVars.azureCosmosdbDatabaseId,
|
|
1784
|
-
containerId: envVars.azureCosmosdbContainerId
|
|
1785
|
-
},
|
|
1786
|
-
tablePrefix: envVars.entityStorageTablePrefix
|
|
1787
|
-
}
|
|
1788
|
-
});
|
|
1789
|
-
}
|
|
1790
|
-
if (core.Is.stringValue(envVars.gcpFirestoreCredentials)) {
|
|
1791
|
-
coreConfig.entityStorageConnector.push({
|
|
1792
|
-
type: engineModels.EntityStorageConnectorType.GcpFirestoreDb,
|
|
1793
|
-
options: {
|
|
1794
|
-
config: {
|
|
1795
|
-
projectId: envVars.gcpFirestoreProjectId,
|
|
1796
|
-
credentials: envVars.gcpFirestoreCredentials,
|
|
1797
|
-
databaseId: envVars.gcpFirestoreDatabaseId,
|
|
1798
|
-
collectionName: envVars.gcpFirestoreCollectionName,
|
|
1799
|
-
endpoint: envVars.gcpFirestoreApiEndpoint
|
|
1800
|
-
},
|
|
1801
|
-
tablePrefix: envVars.entityStorageTablePrefix
|
|
1802
|
-
}
|
|
1803
|
-
});
|
|
1804
|
-
}
|
|
1805
|
-
if (core.Is.stringValue(envVars.scylladbHosts)) {
|
|
1806
|
-
coreConfig.entityStorageConnector.push({
|
|
1807
|
-
type: engineModels.EntityStorageConnectorType.ScyllaDb,
|
|
1808
|
-
options: {
|
|
1809
|
-
config: {
|
|
1810
|
-
hosts: envVars.scylladbHosts.split(","),
|
|
1811
|
-
localDataCenter: envVars.scylladbLocalDataCenter,
|
|
1812
|
-
keyspace: envVars.scylladbKeyspace
|
|
1813
|
-
},
|
|
1814
|
-
tablePrefix: envVars.entityStorageTablePrefix
|
|
1815
|
-
}
|
|
1816
|
-
});
|
|
1817
|
-
}
|
|
1818
|
-
const defaultStorageConnector = envVars.entityStorageConnectorType;
|
|
1819
|
-
if (core.Is.stringValue(defaultStorageConnector)) {
|
|
1820
|
-
for (const config of coreConfig.entityStorageConnector) {
|
|
1821
|
-
if (config.type === defaultStorageConnector) {
|
|
1822
|
-
config.isDefault = true;
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
/**
|
|
1828
|
-
* Configures the blob storage connectors for the core.
|
|
1829
|
-
* @param coreConfig The core config.
|
|
1830
|
-
* @param envVars The environment variables.
|
|
1831
|
-
*/
|
|
1832
|
-
function configureBlobStorageConnectors(coreConfig, envVars) {
|
|
1833
|
-
coreConfig.blobStorageConnector ??= [];
|
|
1834
|
-
if ((core.Coerce.boolean(envVars.blobMemoryEnable) ?? false) ||
|
|
1835
|
-
envVars.blobStorageConnectorType === engineModels.BlobStorageConnectorType.Memory) {
|
|
1836
|
-
coreConfig.blobStorageConnector.push({
|
|
1837
|
-
type: engineModels.BlobStorageConnectorType.Memory
|
|
1838
|
-
});
|
|
1839
|
-
}
|
|
1840
|
-
if ((core.Coerce.boolean(envVars.blobFileEnable) ?? false) ||
|
|
1841
|
-
envVars.blobStorageConnectorType === engineModels.BlobStorageConnectorType.File) {
|
|
1842
|
-
coreConfig.blobStorageConnector.push({
|
|
1843
|
-
type: engineModels.BlobStorageConnectorType.File,
|
|
1844
|
-
options: {
|
|
1845
|
-
config: { directory: envVars.storageFileRoot },
|
|
1846
|
-
storagePrefix: envVars.blobStoragePrefix
|
|
1847
|
-
}
|
|
1848
|
-
});
|
|
1849
|
-
}
|
|
1850
|
-
if (core.Is.stringValue(envVars.ipfsApiUrl)) {
|
|
1851
|
-
coreConfig.blobStorageConnector.push({
|
|
1852
|
-
type: engineModels.BlobStorageConnectorType.Ipfs,
|
|
1853
|
-
options: {
|
|
1854
|
-
config: {
|
|
1855
|
-
apiUrl: envVars.ipfsApiUrl,
|
|
1856
|
-
bearerToken: envVars.ipfsBearerToken
|
|
1857
|
-
}
|
|
1858
|
-
}
|
|
1859
|
-
});
|
|
1860
|
-
}
|
|
1861
|
-
if (core.Is.stringValue(envVars.awsS3AccessKeyId)) {
|
|
1862
|
-
coreConfig.blobStorageConnector.push({
|
|
1863
|
-
type: engineModels.BlobStorageConnectorType.AwsS3,
|
|
1864
|
-
options: {
|
|
1865
|
-
config: {
|
|
1866
|
-
region: envVars.awsS3Region,
|
|
1867
|
-
bucketName: envVars.awsS3BucketName,
|
|
1868
|
-
accessKeyId: envVars.awsS3AccessKeyId,
|
|
1869
|
-
secretAccessKey: envVars.awsS3SecretAccessKey,
|
|
1870
|
-
endpoint: envVars.awsS3Endpoint
|
|
1871
|
-
},
|
|
1872
|
-
storagePrefix: envVars.blobStoragePrefix
|
|
1873
|
-
}
|
|
1874
|
-
});
|
|
1875
|
-
}
|
|
1876
|
-
if (core.Is.stringValue(envVars.azureStorageAccountKey)) {
|
|
1877
|
-
coreConfig.blobStorageConnector.push({
|
|
1878
|
-
type: engineModels.BlobStorageConnectorType.AzureStorage,
|
|
1879
|
-
options: {
|
|
1880
|
-
config: {
|
|
1881
|
-
accountName: envVars.azureStorageAccountName,
|
|
1882
|
-
accountKey: envVars.azureStorageAccountKey,
|
|
1883
|
-
containerName: envVars.azureStorageContainerName,
|
|
1884
|
-
endpoint: envVars.azureStorageEndpoint
|
|
1885
|
-
},
|
|
1886
|
-
storagePrefix: envVars.blobStoragePrefix
|
|
1887
|
-
}
|
|
1888
|
-
});
|
|
1889
|
-
}
|
|
1890
|
-
if (core.Is.stringValue(envVars.gcpStorageCredentials)) {
|
|
1891
|
-
coreConfig.blobStorageConnector.push({
|
|
1892
|
-
type: engineModels.BlobStorageConnectorType.GcpStorage,
|
|
1893
|
-
options: {
|
|
1894
|
-
config: {
|
|
1895
|
-
projectId: envVars.gcpStorageProjectId,
|
|
1896
|
-
credentials: envVars.gcpStorageCredentials,
|
|
1897
|
-
bucketName: envVars.gcpStorageBucketName,
|
|
1898
|
-
apiEndpoint: envVars.gcpFirestoreApiEndpoint
|
|
1899
|
-
},
|
|
1900
|
-
storagePrefix: envVars.blobStoragePrefix
|
|
1901
|
-
}
|
|
1902
|
-
});
|
|
1903
|
-
}
|
|
1904
|
-
const defaultStorageConnectorType = envVars.blobStorageConnectorType;
|
|
1905
|
-
if (core.Is.stringValue(defaultStorageConnectorType)) {
|
|
1906
|
-
for (const config of coreConfig.blobStorageConnector) {
|
|
1907
|
-
if (config.type === defaultStorageConnectorType) {
|
|
1908
|
-
config.isDefault = true;
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
/**
|
|
1914
|
-
* Configures the logging connectors for the core.
|
|
1915
|
-
* @param coreConfig The core config.
|
|
1916
|
-
* @param envVars The environment variables.
|
|
1917
|
-
*/
|
|
1918
|
-
function configureLogging(coreConfig, envVars) {
|
|
1919
|
-
const loggingConnectors = (envVars.loggingConnector ?? "").split(",");
|
|
1920
|
-
for (const loggingConnector of loggingConnectors) {
|
|
1921
|
-
if (loggingConnector === engineModels.LoggingConnectorType.Console) {
|
|
1922
|
-
coreConfig.loggingConnector?.push({
|
|
1923
|
-
type: engineModels.LoggingConnectorType.Console,
|
|
1924
|
-
options: {
|
|
1925
|
-
config: {
|
|
1926
|
-
translateMessages: true,
|
|
1927
|
-
hideGroups: true
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
});
|
|
1931
|
-
}
|
|
1932
|
-
else if (loggingConnector === engineModels.LoggingConnectorType.EntityStorage) {
|
|
1933
|
-
coreConfig.loggingConnector?.push({
|
|
1934
|
-
type: engineModels.LoggingConnectorType.EntityStorage
|
|
1935
|
-
});
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
if (loggingConnectors.length > 1) {
|
|
1939
|
-
coreConfig.loggingConnector?.push({
|
|
1940
|
-
type: engineModels.LoggingConnectorType.Multi,
|
|
1941
|
-
isDefault: true,
|
|
1942
|
-
options: {
|
|
1943
|
-
loggingConnectorTypes: loggingConnectors
|
|
1944
|
-
}
|
|
1945
|
-
});
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
/**
|
|
1949
|
-
* Configures the vault connectors for the core.
|
|
1950
|
-
* @param coreConfig The core config.
|
|
1951
|
-
* @param envVars The environment variables.
|
|
1952
|
-
*/
|
|
1953
|
-
function configureVaultConnectors(coreConfig, envVars) {
|
|
1954
|
-
coreConfig.vaultConnector ??= [];
|
|
1955
|
-
if (envVars.vaultConnector === engineModels.VaultConnectorType.EntityStorage) {
|
|
1956
|
-
coreConfig.vaultConnector.push({
|
|
1957
|
-
type: engineModels.VaultConnectorType.EntityStorage
|
|
1958
|
-
});
|
|
1959
|
-
}
|
|
1960
|
-
else if (envVars.vaultConnector === engineModels.VaultConnectorType.Hashicorp) {
|
|
1961
|
-
coreConfig.vaultConnector.push({
|
|
1962
|
-
type: engineModels.VaultConnectorType.Hashicorp,
|
|
1963
|
-
options: {
|
|
1964
|
-
config: { endpoint: envVars.hashicorpVaultEndpoint, token: envVars.hashicorpVaultToken }
|
|
1965
|
-
}
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
/**
|
|
1970
|
-
* Configures the background task connectors for the core.
|
|
1971
|
-
* @param coreConfig The core config.
|
|
1972
|
-
* @param envVars The environment variables.
|
|
1973
|
-
*/
|
|
1974
|
-
function configureBackgroundTaskConnectors(coreConfig, envVars) {
|
|
1975
|
-
coreConfig.backgroundTaskConnector ??= [];
|
|
1976
|
-
if (envVars.backgroundTaskConnector === engineModels.BackgroundTaskConnectorType.EntityStorage) {
|
|
1977
|
-
coreConfig.backgroundTaskConnector.push({
|
|
1978
|
-
type: engineModels.BackgroundTaskConnectorType.EntityStorage
|
|
1979
|
-
});
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
1982
|
-
/**
|
|
1983
|
-
* Configures the telemetry connectors for the core.
|
|
1984
|
-
* @param coreConfig The core config.
|
|
1985
|
-
* @param envVars The environment variables.
|
|
1986
|
-
*/
|
|
1987
|
-
function configureTelemetryConnectors(coreConfig, envVars) {
|
|
1988
|
-
coreConfig.telemetryConnector ??= [];
|
|
1989
|
-
if (envVars.telemetryConnector === engineModels.TelemetryConnectorType.EntityStorage) {
|
|
1990
|
-
coreConfig.telemetryConnector.push({
|
|
1991
|
-
type: engineModels.TelemetryConnectorType.EntityStorage
|
|
1992
|
-
});
|
|
1993
|
-
}
|
|
1994
|
-
}
|
|
1995
|
-
/**
|
|
1996
|
-
* Configures the faucet connectors for the core.
|
|
1997
|
-
* @param coreConfig The core config.
|
|
1998
|
-
* @param envVars The environment variables.
|
|
1999
|
-
*/
|
|
2000
|
-
function configureFaucetConnectors(coreConfig, envVars) {
|
|
2001
|
-
coreConfig.faucetConnector ??= [];
|
|
2002
|
-
if (envVars.faucetConnector === engineModels.FaucetConnectorType.EntityStorage) {
|
|
2003
|
-
coreConfig.faucetConnector.push({
|
|
2004
|
-
type: engineModels.FaucetConnectorType.EntityStorage
|
|
2005
|
-
});
|
|
2006
|
-
}
|
|
2007
|
-
else if (envVars.faucetConnector === engineModels.FaucetConnectorType.Iota) {
|
|
2008
|
-
coreConfig.faucetConnector.push({
|
|
2009
|
-
type: engineModels.FaucetConnectorType.Iota,
|
|
2010
|
-
options: {
|
|
2011
|
-
config: {
|
|
2012
|
-
endpoint: envVars.iotaFaucetEndpoint,
|
|
2013
|
-
clientOptions: {
|
|
2014
|
-
nodes: [envVars.iotaNodeEndpoint]
|
|
2015
|
-
},
|
|
2016
|
-
bech32Hrp: envVars.iotaBech32Hrp,
|
|
2017
|
-
coinType: core.Coerce.number(envVars.iotaCoinType)
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
});
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
/**
|
|
2024
|
-
* Configures the wallet connectors for the core.
|
|
2025
|
-
* @param coreConfig The core config.
|
|
2026
|
-
* @param envVars The environment variables.
|
|
2027
|
-
*/
|
|
2028
|
-
function configureWalletConnectors(coreConfig, envVars) {
|
|
2029
|
-
coreConfig.walletConnector ??= [];
|
|
2030
|
-
if (envVars.walletConnector === engineModels.WalletConnectorType.EntityStorage) {
|
|
2031
|
-
coreConfig.walletConnector.push({
|
|
2032
|
-
type: engineModels.WalletConnectorType.EntityStorage
|
|
2033
|
-
});
|
|
2034
|
-
}
|
|
2035
|
-
else if (envVars.walletConnector === engineModels.WalletConnectorType.Iota) {
|
|
2036
|
-
coreConfig.walletConnector.push({
|
|
2037
|
-
type: engineModels.WalletConnectorType.Iota,
|
|
2038
|
-
options: {
|
|
2039
|
-
config: {
|
|
2040
|
-
clientOptions: {
|
|
2041
|
-
nodes: [envVars.iotaNodeEndpoint]
|
|
2042
|
-
},
|
|
2043
|
-
bech32Hrp: envVars.iotaBech32Hrp,
|
|
2044
|
-
coinType: core.Coerce.number(envVars.iotaCoinType)
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
});
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
/**
|
|
2051
|
-
* Configures the NFT connectors for the core.
|
|
2052
|
-
* @param coreConfig The core config.
|
|
2053
|
-
* @param envVars The environment variables.
|
|
2054
|
-
*/
|
|
2055
|
-
function configureNftConnectors(coreConfig, envVars) {
|
|
2056
|
-
coreConfig.nftConnector ??= [];
|
|
2057
|
-
if (envVars.nftConnector === engineModels.NftConnectorType.EntityStorage) {
|
|
2058
|
-
coreConfig.nftConnector.push({
|
|
2059
|
-
type: engineModels.NftConnectorType.EntityStorage
|
|
2060
|
-
});
|
|
2061
|
-
}
|
|
2062
|
-
else if (envVars.nftConnector === engineModels.NftConnectorType.Iota) {
|
|
2063
|
-
coreConfig.nftConnector.push({
|
|
2064
|
-
type: engineModels.NftConnectorType.Iota,
|
|
2065
|
-
options: {
|
|
2066
|
-
config: {
|
|
2067
|
-
clientOptions: {
|
|
2068
|
-
nodes: [envVars.iotaNodeEndpoint]
|
|
2069
|
-
},
|
|
2070
|
-
bech32Hrp: envVars.iotaBech32Hrp,
|
|
2071
|
-
coinType: core.Coerce.number(envVars.iotaCoinType)
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
});
|
|
2075
|
-
}
|
|
2076
|
-
}
|
|
2077
|
-
/**
|
|
2078
|
-
* Configures the immutable storage connectors for the core.
|
|
2079
|
-
* @param coreConfig The core config.
|
|
2080
|
-
* @param envVars The environment variables.
|
|
2081
|
-
*/
|
|
2082
|
-
function configureImmutableStorageConnectors(coreConfig, envVars) {
|
|
2083
|
-
coreConfig.immutableStorageConnector ??= [];
|
|
2084
|
-
if (envVars.immutableStorageConnector === engineModels.ImmutableStorageConnectorType.EntityStorage) {
|
|
2085
|
-
coreConfig.immutableStorageConnector.push({
|
|
2086
|
-
type: engineModels.ImmutableStorageConnectorType.EntityStorage
|
|
2087
|
-
});
|
|
2088
|
-
}
|
|
2089
|
-
else if (envVars.immutableStorageConnector === engineModels.ImmutableStorageConnectorType.Iota) {
|
|
2090
|
-
coreConfig.immutableStorageConnector.push({
|
|
2091
|
-
type: engineModels.ImmutableStorageConnectorType.Iota,
|
|
2092
|
-
options: {
|
|
2093
|
-
config: {
|
|
2094
|
-
clientOptions: {
|
|
2095
|
-
nodes: [envVars.iotaNodeEndpoint]
|
|
2096
|
-
},
|
|
2097
|
-
bech32Hrp: envVars.iotaBech32Hrp,
|
|
2098
|
-
coinType: core.Coerce.number(envVars.iotaCoinType)
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
|
-
});
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
/**
|
|
2105
|
-
* Configures the identity connectors for the core.
|
|
2106
|
-
* @param coreConfig The core config.
|
|
2107
|
-
* @param envVars The environment variables.
|
|
2108
|
-
*/
|
|
2109
|
-
function configureIdentityConnectors(coreConfig, envVars) {
|
|
2110
|
-
coreConfig.identityConnector ??= [];
|
|
2111
|
-
if (envVars.identityConnector === engineModels.IdentityConnectorType.EntityStorage) {
|
|
2112
|
-
coreConfig.identityConnector.push({
|
|
2113
|
-
type: engineModels.IdentityConnectorType.EntityStorage
|
|
2114
|
-
});
|
|
2115
|
-
}
|
|
2116
|
-
else if (envVars.identityConnector === engineModels.IdentityConnectorType.Iota) {
|
|
2117
|
-
coreConfig.identityConnector.push({
|
|
2118
|
-
type: engineModels.IdentityConnectorType.Iota,
|
|
2119
|
-
options: {
|
|
2120
|
-
config: {
|
|
2121
|
-
clientOptions: {
|
|
2122
|
-
nodes: [envVars.iotaNodeEndpoint]
|
|
2123
|
-
},
|
|
2124
|
-
bech32Hrp: envVars.iotaBech32Hrp,
|
|
2125
|
-
coinType: core.Coerce.number(envVars.iotaCoinType)
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
});
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
/**
|
|
2132
|
-
* Configures the identity profile connectors for the core.
|
|
2133
|
-
* @param coreConfig The core config.
|
|
2134
|
-
* @param envVars The environment variables.
|
|
2135
|
-
*/
|
|
2136
|
-
function configureIdentityProfileConnectors(coreConfig, envVars) {
|
|
2137
|
-
coreConfig.identityProfileConnector ??= [];
|
|
2138
|
-
if (envVars.identityProfileConnector === engineModels.IdentityConnectorType.EntityStorage) {
|
|
2139
|
-
coreConfig.identityProfileConnector.push({
|
|
2140
|
-
type: engineModels.IdentityProfileConnectorType.EntityStorage
|
|
2141
|
-
});
|
|
2142
|
-
}
|
|
2143
|
-
}
|
|
2144
|
-
/**
|
|
2145
|
-
* Configures the attestation connectors for the core.
|
|
2146
|
-
* @param coreConfig The core config.
|
|
2147
|
-
* @param envVars The environment variables.
|
|
2148
|
-
*/
|
|
2149
|
-
function configureAttestationConnectors(coreConfig, envVars) {
|
|
2150
|
-
coreConfig.attestationConnector ??= [];
|
|
2151
|
-
if (envVars.attestationConnector === engineModels.AttestationConnectorType.EntityStorage) {
|
|
2152
|
-
coreConfig.attestationConnector.push({
|
|
2153
|
-
type: engineModels.AttestationConnectorType.EntityStorage
|
|
2154
|
-
});
|
|
2155
|
-
}
|
|
2156
|
-
else if (envVars.attestationConnector === engineModels.AttestationConnectorType.Iota) {
|
|
2157
|
-
coreConfig.attestationConnector.push({
|
|
2158
|
-
type: engineModels.AttestationConnectorType.Iota
|
|
2159
|
-
});
|
|
2160
|
-
}
|
|
2161
|
-
}
|
|
2162
|
-
|
|
2163
|
-
// Copyright 2024 IOTA Stiftung.
|
|
2164
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
2165
|
-
/**
|
|
2166
|
-
* Environment variable helper.
|
|
2167
|
-
*/
|
|
2168
|
-
class EnvHelper {
|
|
2169
|
-
/**
|
|
2170
|
-
* Get the environment variable as an object with camel cased names.
|
|
2171
|
-
* @param envVars The environment variables.
|
|
2172
|
-
* @param prefix The prefix of the environment variables.
|
|
2173
|
-
* @returns The object with camel cased names.
|
|
2174
|
-
*/
|
|
2175
|
-
static envToJson(envVars, prefix) {
|
|
2176
|
-
const result = {};
|
|
2177
|
-
for (const envVar in envVars) {
|
|
2178
|
-
if (envVar.startsWith(prefix) && core.Is.stringValue(process.env[envVar])) {
|
|
2179
|
-
const camelCaseName = core.StringHelper.camelCase(envVar.replace(prefix, "").toLowerCase());
|
|
2180
|
-
core.ObjectHelper.propertySet(result, camelCaseName, process.env[envVar]);
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
return result;
|
|
2184
|
-
}
|
|
2185
|
-
}
|
|
2186
|
-
|
|
2187
571
|
exports.EngineCore = EngineCore;
|
|
2188
|
-
exports.EnvHelper = EnvHelper;
|
|
2189
572
|
exports.FileStateStorage = FileStateStorage;
|
|
2190
573
|
exports.MemoryStateStorage = MemoryStateStorage;
|
|
2191
|
-
exports.buildEngineCoreConfiguration = buildEngineCoreConfiguration;
|
|
2192
|
-
exports.initialiseEntityStorageConnector = initialiseEntityStorageConnector;
|