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