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