@twin.org/engine 0.0.1-next.52 → 0.0.1-next.53

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.
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var engineCore = require('@twin.org/engine-core');
4
- var path = require('node:path');
5
4
  var core = require('@twin.org/core');
6
5
  var engineTypes = require('@twin.org/engine-types');
6
+ var entity = require('@twin.org/entity');
7
+ var path = require('node:path');
7
8
 
8
9
  // Copyright 2024 IOTA Stiftung.
9
10
  // SPDX-License-Identifier: Apache-2.0.
@@ -64,6 +65,49 @@ class Engine extends engineCore.EngineCore {
64
65
  this.addTypeInitialiser("dataConverterConnector", this._context.config.types.dataConverterConnector, "@twin.org/engine-types", "initialiseDataConverterConnector");
65
66
  this.addTypeInitialiser("dataExtractorConnector", this._context.config.types.dataExtractorConnector, "@twin.org/engine-types", "initialiseDataExtractorConnector");
66
67
  this.addTypeInitialiser("dataProcessingComponent", this._context.config.types.dataProcessingComponent, "@twin.org/engine-types", "initialiseDataProcessingComponent");
68
+ this.addTypeInitialiser("documentManagementComponent", this._context.config.types.documentManagementComponent, "@twin.org/engine-types", "initialiseDocumentManagementComponent");
69
+ }
70
+ }
71
+
72
+ // Copyright 2024 IOTA Stiftung.
73
+ // SPDX-License-Identifier: Apache-2.0.
74
+ /**
75
+ * Helper methods for engine config.
76
+ */
77
+ class EngineConfigHelper {
78
+ /**
79
+ * Runtime name for the class.
80
+ */
81
+ static CLASS_NAME = "EngineConfigHelper";
82
+ /**
83
+ * Add a custom entity storage to the engine configuration.
84
+ * @param engineConfig The engine configuration.
85
+ * @param entityTypeName The entity type name.
86
+ * @param entitySchema The entity schema.
87
+ * @param restPath The rest path to serve the entity storage from.
88
+ * @param options Additional options.
89
+ * @param options.includeNodeIdentity Whether to include the node identity in the entity, defaults to true.
90
+ * @param options.includeUserIdentity Whether to include the user identity in the entity, defaults to true.
91
+ */
92
+ static addCustomEntityStorage(engineConfig, entityTypeName, entitySchema, restPath, options) {
93
+ core.Guards.object(EngineConfigHelper.CLASS_NAME, "engineConfig", engineConfig);
94
+ core.Guards.stringValue(EngineConfigHelper.CLASS_NAME, "entityTypeName", entityTypeName);
95
+ core.Guards.object(EngineConfigHelper.CLASS_NAME, "entitySchema", entitySchema);
96
+ core.Guards.stringValue(EngineConfigHelper.CLASS_NAME, "restPath", restPath);
97
+ engineConfig.types.entityStorageComponent ??= [];
98
+ entity.EntitySchemaFactory.register(entityTypeName, () => entitySchema);
99
+ engineConfig.types.entityStorageComponent.push({
100
+ type: engineTypes.EntityStorageComponentType.Service,
101
+ options: {
102
+ entityStorageType: entityTypeName,
103
+ config: {
104
+ includeNodeIdentity: options?.includeNodeIdentity ?? true,
105
+ includeUserIdentity: options?.includeUserIdentity ?? true
106
+ }
107
+ },
108
+ overrideInstanceType: core.StringHelper.kebabCase(entityTypeName),
109
+ restPath
110
+ });
67
111
  }
68
112
  }
69
113
 
@@ -89,31 +133,34 @@ function buildEngineConfiguration(envVars) {
89
133
  debug: core.Coerce.boolean(envVars.debug) ?? false,
90
134
  types: {}
91
135
  };
92
- configureEntityStorageConnectors(coreConfig, envVars);
93
- configureBlobStorageConnectors(coreConfig, envVars);
94
- configureVaultConnectors(coreConfig, envVars);
95
- configureLoggingConnectors(coreConfig, envVars);
96
- configureBackgroundTaskConnectors(coreConfig, envVars);
97
- configureEventBusConnectors(coreConfig, envVars);
98
- configureTelemetryConnectors(coreConfig, envVars);
99
- configureMessagingConnectors(coreConfig, envVars);
100
- configureFaucetConnectors(coreConfig, envVars);
101
- configureWalletConnectors(coreConfig, envVars);
102
- configureNftConnectors(coreConfig, envVars);
103
- configureImmutableStorageConnectors(coreConfig, envVars);
104
- configureIdentityConnectors(coreConfig, envVars);
105
- configureIdentityResolverConnectors(coreConfig, envVars);
106
- configureIdentityProfileConnectors(coreConfig, envVars);
107
- configureAttestationConnectors(coreConfig, envVars);
108
- configureDataProcessingConnectors(coreConfig, envVars);
136
+ configureEntityStorage(coreConfig, envVars);
137
+ configureBlobStorage(coreConfig, envVars);
138
+ configureVault(coreConfig, envVars);
139
+ configureLogging(coreConfig, envVars);
140
+ configureBackgroundTask(coreConfig, envVars);
141
+ configureEventBus(coreConfig, envVars);
142
+ configureTelemetry(coreConfig, envVars);
143
+ configureMessaging(coreConfig, envVars);
144
+ configureFaucet(coreConfig, envVars);
145
+ configureWallet(coreConfig, envVars);
146
+ configureNft(coreConfig, envVars);
147
+ configureImmutableStorage(coreConfig, envVars);
148
+ configureIdentity(coreConfig, envVars);
149
+ configureIdentityResolver(coreConfig, envVars);
150
+ configureIdentityProfile(coreConfig, envVars);
151
+ configureAttestation(coreConfig, envVars);
152
+ configureDataProcessing(coreConfig, envVars);
153
+ configureAuditableItemGraph(coreConfig);
154
+ configureAuditableItemStream(coreConfig);
155
+ configureDocumentManagement(coreConfig);
109
156
  return coreConfig;
110
157
  }
111
158
  /**
112
- * Configures the entity storage connectors for the core.
159
+ * Configures the entity storage.
113
160
  * @param coreConfig The core config.
114
161
  * @param envVars The environment variables.
115
162
  */
116
- function configureEntityStorageConnectors(coreConfig, envVars) {
163
+ function configureEntityStorage(coreConfig, envVars) {
117
164
  coreConfig.types ??= {};
118
165
  coreConfig.types.entityStorageConnector ??= [];
119
166
  if ((core.Coerce.boolean(envVars.entityMemoryEnable) ?? false) ||
@@ -258,11 +305,11 @@ function configureEntityStorageConnectors(coreConfig, envVars) {
258
305
  }
259
306
  }
260
307
  /**
261
- * Configures the blob storage connectors for the core.
308
+ * Configures the blob storage.
262
309
  * @param coreConfig The core config.
263
310
  * @param envVars The environment variables.
264
311
  */
265
- function configureBlobStorageConnectors(coreConfig, envVars) {
312
+ function configureBlobStorage(coreConfig, envVars) {
266
313
  coreConfig.types.blobStorageConnector ??= [];
267
314
  if ((core.Coerce.boolean(envVars.blobMemoryEnable) ?? false) ||
268
315
  envVars.blobStorageConnectorType === engineTypes.BlobStorageConnectorType.Memory) {
@@ -359,11 +406,11 @@ function configureBlobStorageConnectors(coreConfig, envVars) {
359
406
  }
360
407
  }
361
408
  /**
362
- * Configures the logging connectors for the core.
409
+ * Configures the logging.
363
410
  * @param coreConfig The core config.
364
411
  * @param envVars The environment variables.
365
412
  */
366
- function configureLoggingConnectors(coreConfig, envVars) {
413
+ function configureLogging(coreConfig, envVars) {
367
414
  coreConfig.types.loggingConnector ??= [];
368
415
  const loggingConnectors = (envVars.loggingConnector ?? "").split(",");
369
416
  for (const loggingConnector of loggingConnectors) {
@@ -401,11 +448,11 @@ function configureLoggingConnectors(coreConfig, envVars) {
401
448
  }
402
449
  }
403
450
  /**
404
- * Configures the vault connectors for the core.
451
+ * Configures the vault.
405
452
  * @param coreConfig The core config.
406
453
  * @param envVars The environment variables.
407
454
  */
408
- function configureVaultConnectors(coreConfig, envVars) {
455
+ function configureVault(coreConfig, envVars) {
409
456
  coreConfig.types.vaultConnector ??= [];
410
457
  if (envVars.vaultConnector === engineTypes.VaultConnectorType.EntityStorage) {
411
458
  coreConfig.types.vaultConnector.push({
@@ -425,11 +472,11 @@ function configureVaultConnectors(coreConfig, envVars) {
425
472
  }
426
473
  }
427
474
  /**
428
- * Configures the background task connectors for the core.
475
+ * Configures the background task.
429
476
  * @param coreConfig The core config.
430
477
  * @param envVars The environment variables.
431
478
  */
432
- function configureBackgroundTaskConnectors(coreConfig, envVars) {
479
+ function configureBackgroundTask(coreConfig, envVars) {
433
480
  coreConfig.types.backgroundTaskConnector ??= [];
434
481
  if (envVars.backgroundTaskConnector === engineTypes.BackgroundTaskConnectorType.EntityStorage) {
435
482
  coreConfig.types.backgroundTaskConnector.push({
@@ -438,11 +485,11 @@ function configureBackgroundTaskConnectors(coreConfig, envVars) {
438
485
  }
439
486
  }
440
487
  /**
441
- * Configures the event bud connectors for the core.
488
+ * Configures the event bud.
442
489
  * @param coreConfig The core config.
443
490
  * @param envVars The environment variables.
444
491
  */
445
- function configureEventBusConnectors(coreConfig, envVars) {
492
+ function configureEventBus(coreConfig, envVars) {
446
493
  coreConfig.types.eventBusConnector ??= [];
447
494
  if (envVars.eventBusConnector === engineTypes.EventBusConnectorType.Local) {
448
495
  coreConfig.types.eventBusConnector.push({
@@ -455,11 +502,11 @@ function configureEventBusConnectors(coreConfig, envVars) {
455
502
  }
456
503
  }
457
504
  /**
458
- * Configures the telemetry connectors for the core.
505
+ * Configures the telemetry.
459
506
  * @param coreConfig The core config.
460
507
  * @param envVars The environment variables.
461
508
  */
462
- function configureTelemetryConnectors(coreConfig, envVars) {
509
+ function configureTelemetry(coreConfig, envVars) {
463
510
  coreConfig.types.telemetryConnector ??= [];
464
511
  if (envVars.telemetryConnector === engineTypes.TelemetryConnectorType.EntityStorage) {
465
512
  coreConfig.types.telemetryConnector.push({
@@ -472,11 +519,11 @@ function configureTelemetryConnectors(coreConfig, envVars) {
472
519
  }
473
520
  }
474
521
  /**
475
- * Configures the messaging connectors for the core.
522
+ * Configures the messaging.
476
523
  * @param coreConfig The core config.
477
524
  * @param envVars The environment variables.
478
525
  */
479
- function configureMessagingConnectors(coreConfig, envVars) {
526
+ function configureMessaging(coreConfig, envVars) {
480
527
  coreConfig.types.messagingEmailConnector ??= [];
481
528
  coreConfig.types.messagingSmsConnector ??= [];
482
529
  coreConfig.types.messagingPushNotificationConnector ??= [];
@@ -546,11 +593,11 @@ function configureMessagingConnectors(coreConfig, envVars) {
546
593
  }
547
594
  }
548
595
  /**
549
- * Configures the faucet connectors for the core.
596
+ * Configures the faucet.
550
597
  * @param coreConfig The core config.
551
598
  * @param envVars The environment variables.
552
599
  */
553
- function configureFaucetConnectors(coreConfig, envVars) {
600
+ function configureFaucet(coreConfig, envVars) {
554
601
  coreConfig.types.faucetConnector ??= [];
555
602
  if (envVars.faucetConnector === engineTypes.FaucetConnectorType.EntityStorage) {
556
603
  coreConfig.types.faucetConnector.push({
@@ -589,11 +636,11 @@ function configureFaucetConnectors(coreConfig, envVars) {
589
636
  }
590
637
  }
591
638
  /**
592
- * Configures the wallet connectors for the core.
639
+ * Configures the wallet.
593
640
  * @param coreConfig The core config.
594
641
  * @param envVars The environment variables.
595
642
  */
596
- function configureWalletConnectors(coreConfig, envVars) {
643
+ function configureWallet(coreConfig, envVars) {
597
644
  coreConfig.types.walletConnector ??= [];
598
645
  if (envVars.walletConnector === engineTypes.WalletConnectorType.EntityStorage) {
599
646
  coreConfig.types.walletConnector.push({
@@ -630,11 +677,11 @@ function configureWalletConnectors(coreConfig, envVars) {
630
677
  }
631
678
  }
632
679
  /**
633
- * Configures the NFT connectors for the core.
680
+ * Configures the NFT.
634
681
  * @param coreConfig The core config.
635
682
  * @param envVars The environment variables.
636
683
  */
637
- function configureNftConnectors(coreConfig, envVars) {
684
+ function configureNft(coreConfig, envVars) {
638
685
  coreConfig.types.nftConnector ??= [];
639
686
  if (envVars.nftConnector === engineTypes.NftConnectorType.EntityStorage) {
640
687
  coreConfig.types.nftConnector.push({
@@ -675,11 +722,11 @@ function configureNftConnectors(coreConfig, envVars) {
675
722
  }
676
723
  }
677
724
  /**
678
- * Configures the immutable storage connectors for the core.
725
+ * Configures the immutable storage.
679
726
  * @param coreConfig The core config.
680
727
  * @param envVars The environment variables.
681
728
  */
682
- function configureImmutableStorageConnectors(coreConfig, envVars) {
729
+ function configureImmutableStorage(coreConfig, envVars) {
683
730
  coreConfig.types.immutableStorageConnector ??= [];
684
731
  if (envVars.immutableStorageConnector === engineTypes.ImmutableStorageConnectorType.EntityStorage) {
685
732
  coreConfig.types.immutableStorageConnector.push({
@@ -740,11 +787,11 @@ function configureImmutableStorageConnectors(coreConfig, envVars) {
740
787
  }
741
788
  }
742
789
  /**
743
- * Configures the identity connectors for the core.
790
+ * Configures the identity.
744
791
  * @param coreConfig The core config.
745
792
  * @param envVars The environment variables.
746
793
  */
747
- function configureIdentityConnectors(coreConfig, envVars) {
794
+ function configureIdentity(coreConfig, envVars) {
748
795
  coreConfig.types.identityConnector ??= [];
749
796
  if (envVars.identityConnector === engineTypes.IdentityConnectorType.EntityStorage) {
750
797
  coreConfig.types.identityConnector.push({
@@ -785,11 +832,11 @@ function configureIdentityConnectors(coreConfig, envVars) {
785
832
  }
786
833
  }
787
834
  /**
788
- * Configures the identity resolver connectors for the core.
835
+ * Configures the identity resolver.
789
836
  * @param coreConfig The core config.
790
837
  * @param envVars The environment variables.
791
838
  */
792
- function configureIdentityResolverConnectors(coreConfig, envVars) {
839
+ function configureIdentityResolver(coreConfig, envVars) {
793
840
  coreConfig.types.identityResolverConnector ??= [];
794
841
  if (envVars.identityResolverConnector === engineTypes.IdentityResolverConnectorType.EntityStorage) {
795
842
  coreConfig.types.identityResolverConnector.push({
@@ -832,11 +879,11 @@ function configureIdentityResolverConnectors(coreConfig, envVars) {
832
879
  }
833
880
  }
834
881
  /**
835
- * Configures the identity profile connectors for the core.
882
+ * Configures the identity profile.
836
883
  * @param coreConfig The core config.
837
884
  * @param envVars The environment variables.
838
885
  */
839
- function configureIdentityProfileConnectors(coreConfig, envVars) {
886
+ function configureIdentityProfile(coreConfig, envVars) {
840
887
  coreConfig.types.identityProfileConnector ??= [];
841
888
  if (envVars.identityProfileConnector === engineTypes.IdentityConnectorType.EntityStorage) {
842
889
  coreConfig.types.identityProfileConnector.push({
@@ -849,11 +896,11 @@ function configureIdentityProfileConnectors(coreConfig, envVars) {
849
896
  }
850
897
  }
851
898
  /**
852
- * Configures the attestation connectors for the core.
899
+ * Configures the attestation.
853
900
  * @param coreConfig The core config.
854
901
  * @param envVars The environment variables.
855
902
  */
856
- function configureAttestationConnectors(coreConfig, envVars) {
903
+ function configureAttestation(coreConfig, envVars) {
857
904
  coreConfig.types.attestationConnector ??= [];
858
905
  if (envVars.attestationConnector === engineTypes.AttestationConnectorType.Nft) {
859
906
  coreConfig.types.attestationConnector.push({
@@ -873,11 +920,37 @@ function configureAttestationConnectors(coreConfig, envVars) {
873
920
  }
874
921
  }
875
922
  /**
876
- * Configures the data processing connectors for the core.
923
+ * Configures the auditable item graph.
877
924
  * @param coreConfig The core config.
878
925
  * @param envVars The environment variables.
879
926
  */
880
- function configureDataProcessingConnectors(coreConfig, envVars) {
927
+ function configureAuditableItemGraph(coreConfig, envVars) {
928
+ if (core.Is.arrayValue(coreConfig.types.immutableStorageConnector)) {
929
+ coreConfig.types.auditableItemGraphComponent ??= [];
930
+ coreConfig.types.auditableItemGraphComponent.push({
931
+ type: engineTypes.AuditableItemGraphComponentType.Service
932
+ });
933
+ }
934
+ }
935
+ /**
936
+ * Configures the auditable item stream.
937
+ * @param coreConfig The core config.
938
+ * @param envVars The environment variables.
939
+ */
940
+ function configureAuditableItemStream(coreConfig, envVars) {
941
+ if (core.Is.arrayValue(coreConfig.types.immutableStorageConnector)) {
942
+ coreConfig.types.auditableItemStreamComponent ??= [];
943
+ coreConfig.types.auditableItemStreamComponent.push({
944
+ type: engineTypes.AuditableItemStreamComponentType.Service
945
+ });
946
+ }
947
+ }
948
+ /**
949
+ * Configures the data processing.
950
+ * @param coreConfig The core config.
951
+ * @param envVars The environment variables.
952
+ */
953
+ function configureDataProcessing(coreConfig, envVars) {
881
954
  coreConfig.types.dataConverterConnector ??= [];
882
955
  coreConfig.types.dataExtractorConnector ??= [];
883
956
  const converterConnectors = envVars.dataConverterConnectors?.split(",") ?? [];
@@ -907,6 +980,22 @@ function configureDataProcessingConnectors(coreConfig, envVars) {
907
980
  coreConfig.types.dataProcessingComponent.push({ type: engineTypes.DataProcessingComponentType.Service });
908
981
  }
909
982
  }
983
+ /**
984
+ * Configures the document management.
985
+ * @param coreConfig The core config.
986
+ * @param envVars The environment variables.
987
+ */
988
+ function configureDocumentManagement(coreConfig, envVars) {
989
+ if (core.Is.arrayValue(coreConfig.types.auditableItemGraphComponent) &&
990
+ core.Is.arrayValue(coreConfig.types.blobStorageComponent) &&
991
+ core.Is.arrayValue(coreConfig.types.attestationComponent)) {
992
+ coreConfig.types.documentManagementComponent ??= [];
993
+ coreConfig.types.documentManagementComponent.push({
994
+ type: engineTypes.DocumentManagementComponentType.Service
995
+ });
996
+ }
997
+ }
910
998
 
911
999
  exports.Engine = Engine;
1000
+ exports.EngineConfigHelper = EngineConfigHelper;
912
1001
  exports.buildEngineConfiguration = buildEngineConfiguration;
@@ -1,7 +1,8 @@
1
1
  import { EngineCore } from '@twin.org/engine-core';
2
+ import { Guards, StringHelper, Is, Coerce } from '@twin.org/core';
3
+ import { EntityStorageComponentType, EntityStorageConnectorType, BlobStorageConnectorType, BlobStorageComponentType, VaultConnectorType, LoggingConnectorType, LoggingComponentType, BackgroundTaskConnectorType, EventBusConnectorType, EventBusComponentType, TelemetryConnectorType, TelemetryComponentType, MessagingEmailConnectorType, MessagingSmsConnectorType, MessagingPushNotificationConnectorType, MessagingComponentType, FaucetConnectorType, WalletConnectorType, NftConnectorType, NftComponentType, ImmutableStorageConnectorType, ImmutableStorageComponentType, ImmutableProofComponentType, AuditableItemGraphComponentType, AuditableItemStreamComponentType, IdentityConnectorType, IdentityComponentType, IdentityResolverConnectorType, IdentityResolverComponentType, IdentityProfileConnectorType, IdentityProfileComponentType, AttestationConnectorType, AttestationComponentType, DataConverterConnectorType, DataExtractorConnectorType, DataProcessingComponentType, DocumentManagementComponentType } from '@twin.org/engine-types';
4
+ import { EntitySchemaFactory } from '@twin.org/entity';
2
5
  import path from 'node:path';
3
- import { Is, Coerce } from '@twin.org/core';
4
- import { EntityStorageConnectorType, BlobStorageConnectorType, BlobStorageComponentType, VaultConnectorType, LoggingConnectorType, LoggingComponentType, BackgroundTaskConnectorType, EventBusConnectorType, EventBusComponentType, TelemetryConnectorType, TelemetryComponentType, MessagingEmailConnectorType, MessagingSmsConnectorType, MessagingPushNotificationConnectorType, MessagingComponentType, FaucetConnectorType, WalletConnectorType, NftConnectorType, NftComponentType, ImmutableStorageConnectorType, ImmutableStorageComponentType, ImmutableProofComponentType, AuditableItemGraphComponentType, AuditableItemStreamComponentType, IdentityConnectorType, IdentityComponentType, IdentityResolverConnectorType, IdentityResolverComponentType, IdentityProfileConnectorType, IdentityProfileComponentType, AttestationConnectorType, AttestationComponentType, DataConverterConnectorType, DataExtractorConnectorType, DataProcessingComponentType } from '@twin.org/engine-types';
5
6
 
6
7
  // Copyright 2024 IOTA Stiftung.
7
8
  // SPDX-License-Identifier: Apache-2.0.
@@ -62,6 +63,49 @@ class Engine extends EngineCore {
62
63
  this.addTypeInitialiser("dataConverterConnector", this._context.config.types.dataConverterConnector, "@twin.org/engine-types", "initialiseDataConverterConnector");
63
64
  this.addTypeInitialiser("dataExtractorConnector", this._context.config.types.dataExtractorConnector, "@twin.org/engine-types", "initialiseDataExtractorConnector");
64
65
  this.addTypeInitialiser("dataProcessingComponent", this._context.config.types.dataProcessingComponent, "@twin.org/engine-types", "initialiseDataProcessingComponent");
66
+ this.addTypeInitialiser("documentManagementComponent", this._context.config.types.documentManagementComponent, "@twin.org/engine-types", "initialiseDocumentManagementComponent");
67
+ }
68
+ }
69
+
70
+ // Copyright 2024 IOTA Stiftung.
71
+ // SPDX-License-Identifier: Apache-2.0.
72
+ /**
73
+ * Helper methods for engine config.
74
+ */
75
+ class EngineConfigHelper {
76
+ /**
77
+ * Runtime name for the class.
78
+ */
79
+ static CLASS_NAME = "EngineConfigHelper";
80
+ /**
81
+ * Add a custom entity storage to the engine configuration.
82
+ * @param engineConfig The engine configuration.
83
+ * @param entityTypeName The entity type name.
84
+ * @param entitySchema The entity schema.
85
+ * @param restPath The rest path to serve the entity storage from.
86
+ * @param options Additional options.
87
+ * @param options.includeNodeIdentity Whether to include the node identity in the entity, defaults to true.
88
+ * @param options.includeUserIdentity Whether to include the user identity in the entity, defaults to true.
89
+ */
90
+ static addCustomEntityStorage(engineConfig, entityTypeName, entitySchema, restPath, options) {
91
+ Guards.object(EngineConfigHelper.CLASS_NAME, "engineConfig", engineConfig);
92
+ Guards.stringValue(EngineConfigHelper.CLASS_NAME, "entityTypeName", entityTypeName);
93
+ Guards.object(EngineConfigHelper.CLASS_NAME, "entitySchema", entitySchema);
94
+ Guards.stringValue(EngineConfigHelper.CLASS_NAME, "restPath", restPath);
95
+ engineConfig.types.entityStorageComponent ??= [];
96
+ EntitySchemaFactory.register(entityTypeName, () => entitySchema);
97
+ engineConfig.types.entityStorageComponent.push({
98
+ type: EntityStorageComponentType.Service,
99
+ options: {
100
+ entityStorageType: entityTypeName,
101
+ config: {
102
+ includeNodeIdentity: options?.includeNodeIdentity ?? true,
103
+ includeUserIdentity: options?.includeUserIdentity ?? true
104
+ }
105
+ },
106
+ overrideInstanceType: StringHelper.kebabCase(entityTypeName),
107
+ restPath
108
+ });
65
109
  }
66
110
  }
67
111
 
@@ -87,31 +131,34 @@ function buildEngineConfiguration(envVars) {
87
131
  debug: Coerce.boolean(envVars.debug) ?? false,
88
132
  types: {}
89
133
  };
90
- configureEntityStorageConnectors(coreConfig, envVars);
91
- configureBlobStorageConnectors(coreConfig, envVars);
92
- configureVaultConnectors(coreConfig, envVars);
93
- configureLoggingConnectors(coreConfig, envVars);
94
- configureBackgroundTaskConnectors(coreConfig, envVars);
95
- configureEventBusConnectors(coreConfig, envVars);
96
- configureTelemetryConnectors(coreConfig, envVars);
97
- configureMessagingConnectors(coreConfig, envVars);
98
- configureFaucetConnectors(coreConfig, envVars);
99
- configureWalletConnectors(coreConfig, envVars);
100
- configureNftConnectors(coreConfig, envVars);
101
- configureImmutableStorageConnectors(coreConfig, envVars);
102
- configureIdentityConnectors(coreConfig, envVars);
103
- configureIdentityResolverConnectors(coreConfig, envVars);
104
- configureIdentityProfileConnectors(coreConfig, envVars);
105
- configureAttestationConnectors(coreConfig, envVars);
106
- configureDataProcessingConnectors(coreConfig, envVars);
134
+ configureEntityStorage(coreConfig, envVars);
135
+ configureBlobStorage(coreConfig, envVars);
136
+ configureVault(coreConfig, envVars);
137
+ configureLogging(coreConfig, envVars);
138
+ configureBackgroundTask(coreConfig, envVars);
139
+ configureEventBus(coreConfig, envVars);
140
+ configureTelemetry(coreConfig, envVars);
141
+ configureMessaging(coreConfig, envVars);
142
+ configureFaucet(coreConfig, envVars);
143
+ configureWallet(coreConfig, envVars);
144
+ configureNft(coreConfig, envVars);
145
+ configureImmutableStorage(coreConfig, envVars);
146
+ configureIdentity(coreConfig, envVars);
147
+ configureIdentityResolver(coreConfig, envVars);
148
+ configureIdentityProfile(coreConfig, envVars);
149
+ configureAttestation(coreConfig, envVars);
150
+ configureDataProcessing(coreConfig, envVars);
151
+ configureAuditableItemGraph(coreConfig);
152
+ configureAuditableItemStream(coreConfig);
153
+ configureDocumentManagement(coreConfig);
107
154
  return coreConfig;
108
155
  }
109
156
  /**
110
- * Configures the entity storage connectors for the core.
157
+ * Configures the entity storage.
111
158
  * @param coreConfig The core config.
112
159
  * @param envVars The environment variables.
113
160
  */
114
- function configureEntityStorageConnectors(coreConfig, envVars) {
161
+ function configureEntityStorage(coreConfig, envVars) {
115
162
  coreConfig.types ??= {};
116
163
  coreConfig.types.entityStorageConnector ??= [];
117
164
  if ((Coerce.boolean(envVars.entityMemoryEnable) ?? false) ||
@@ -256,11 +303,11 @@ function configureEntityStorageConnectors(coreConfig, envVars) {
256
303
  }
257
304
  }
258
305
  /**
259
- * Configures the blob storage connectors for the core.
306
+ * Configures the blob storage.
260
307
  * @param coreConfig The core config.
261
308
  * @param envVars The environment variables.
262
309
  */
263
- function configureBlobStorageConnectors(coreConfig, envVars) {
310
+ function configureBlobStorage(coreConfig, envVars) {
264
311
  coreConfig.types.blobStorageConnector ??= [];
265
312
  if ((Coerce.boolean(envVars.blobMemoryEnable) ?? false) ||
266
313
  envVars.blobStorageConnectorType === BlobStorageConnectorType.Memory) {
@@ -357,11 +404,11 @@ function configureBlobStorageConnectors(coreConfig, envVars) {
357
404
  }
358
405
  }
359
406
  /**
360
- * Configures the logging connectors for the core.
407
+ * Configures the logging.
361
408
  * @param coreConfig The core config.
362
409
  * @param envVars The environment variables.
363
410
  */
364
- function configureLoggingConnectors(coreConfig, envVars) {
411
+ function configureLogging(coreConfig, envVars) {
365
412
  coreConfig.types.loggingConnector ??= [];
366
413
  const loggingConnectors = (envVars.loggingConnector ?? "").split(",");
367
414
  for (const loggingConnector of loggingConnectors) {
@@ -399,11 +446,11 @@ function configureLoggingConnectors(coreConfig, envVars) {
399
446
  }
400
447
  }
401
448
  /**
402
- * Configures the vault connectors for the core.
449
+ * Configures the vault.
403
450
  * @param coreConfig The core config.
404
451
  * @param envVars The environment variables.
405
452
  */
406
- function configureVaultConnectors(coreConfig, envVars) {
453
+ function configureVault(coreConfig, envVars) {
407
454
  coreConfig.types.vaultConnector ??= [];
408
455
  if (envVars.vaultConnector === VaultConnectorType.EntityStorage) {
409
456
  coreConfig.types.vaultConnector.push({
@@ -423,11 +470,11 @@ function configureVaultConnectors(coreConfig, envVars) {
423
470
  }
424
471
  }
425
472
  /**
426
- * Configures the background task connectors for the core.
473
+ * Configures the background task.
427
474
  * @param coreConfig The core config.
428
475
  * @param envVars The environment variables.
429
476
  */
430
- function configureBackgroundTaskConnectors(coreConfig, envVars) {
477
+ function configureBackgroundTask(coreConfig, envVars) {
431
478
  coreConfig.types.backgroundTaskConnector ??= [];
432
479
  if (envVars.backgroundTaskConnector === BackgroundTaskConnectorType.EntityStorage) {
433
480
  coreConfig.types.backgroundTaskConnector.push({
@@ -436,11 +483,11 @@ function configureBackgroundTaskConnectors(coreConfig, envVars) {
436
483
  }
437
484
  }
438
485
  /**
439
- * Configures the event bud connectors for the core.
486
+ * Configures the event bud.
440
487
  * @param coreConfig The core config.
441
488
  * @param envVars The environment variables.
442
489
  */
443
- function configureEventBusConnectors(coreConfig, envVars) {
490
+ function configureEventBus(coreConfig, envVars) {
444
491
  coreConfig.types.eventBusConnector ??= [];
445
492
  if (envVars.eventBusConnector === EventBusConnectorType.Local) {
446
493
  coreConfig.types.eventBusConnector.push({
@@ -453,11 +500,11 @@ function configureEventBusConnectors(coreConfig, envVars) {
453
500
  }
454
501
  }
455
502
  /**
456
- * Configures the telemetry connectors for the core.
503
+ * Configures the telemetry.
457
504
  * @param coreConfig The core config.
458
505
  * @param envVars The environment variables.
459
506
  */
460
- function configureTelemetryConnectors(coreConfig, envVars) {
507
+ function configureTelemetry(coreConfig, envVars) {
461
508
  coreConfig.types.telemetryConnector ??= [];
462
509
  if (envVars.telemetryConnector === TelemetryConnectorType.EntityStorage) {
463
510
  coreConfig.types.telemetryConnector.push({
@@ -470,11 +517,11 @@ function configureTelemetryConnectors(coreConfig, envVars) {
470
517
  }
471
518
  }
472
519
  /**
473
- * Configures the messaging connectors for the core.
520
+ * Configures the messaging.
474
521
  * @param coreConfig The core config.
475
522
  * @param envVars The environment variables.
476
523
  */
477
- function configureMessagingConnectors(coreConfig, envVars) {
524
+ function configureMessaging(coreConfig, envVars) {
478
525
  coreConfig.types.messagingEmailConnector ??= [];
479
526
  coreConfig.types.messagingSmsConnector ??= [];
480
527
  coreConfig.types.messagingPushNotificationConnector ??= [];
@@ -544,11 +591,11 @@ function configureMessagingConnectors(coreConfig, envVars) {
544
591
  }
545
592
  }
546
593
  /**
547
- * Configures the faucet connectors for the core.
594
+ * Configures the faucet.
548
595
  * @param coreConfig The core config.
549
596
  * @param envVars The environment variables.
550
597
  */
551
- function configureFaucetConnectors(coreConfig, envVars) {
598
+ function configureFaucet(coreConfig, envVars) {
552
599
  coreConfig.types.faucetConnector ??= [];
553
600
  if (envVars.faucetConnector === FaucetConnectorType.EntityStorage) {
554
601
  coreConfig.types.faucetConnector.push({
@@ -587,11 +634,11 @@ function configureFaucetConnectors(coreConfig, envVars) {
587
634
  }
588
635
  }
589
636
  /**
590
- * Configures the wallet connectors for the core.
637
+ * Configures the wallet.
591
638
  * @param coreConfig The core config.
592
639
  * @param envVars The environment variables.
593
640
  */
594
- function configureWalletConnectors(coreConfig, envVars) {
641
+ function configureWallet(coreConfig, envVars) {
595
642
  coreConfig.types.walletConnector ??= [];
596
643
  if (envVars.walletConnector === WalletConnectorType.EntityStorage) {
597
644
  coreConfig.types.walletConnector.push({
@@ -628,11 +675,11 @@ function configureWalletConnectors(coreConfig, envVars) {
628
675
  }
629
676
  }
630
677
  /**
631
- * Configures the NFT connectors for the core.
678
+ * Configures the NFT.
632
679
  * @param coreConfig The core config.
633
680
  * @param envVars The environment variables.
634
681
  */
635
- function configureNftConnectors(coreConfig, envVars) {
682
+ function configureNft(coreConfig, envVars) {
636
683
  coreConfig.types.nftConnector ??= [];
637
684
  if (envVars.nftConnector === NftConnectorType.EntityStorage) {
638
685
  coreConfig.types.nftConnector.push({
@@ -673,11 +720,11 @@ function configureNftConnectors(coreConfig, envVars) {
673
720
  }
674
721
  }
675
722
  /**
676
- * Configures the immutable storage connectors for the core.
723
+ * Configures the immutable storage.
677
724
  * @param coreConfig The core config.
678
725
  * @param envVars The environment variables.
679
726
  */
680
- function configureImmutableStorageConnectors(coreConfig, envVars) {
727
+ function configureImmutableStorage(coreConfig, envVars) {
681
728
  coreConfig.types.immutableStorageConnector ??= [];
682
729
  if (envVars.immutableStorageConnector === ImmutableStorageConnectorType.EntityStorage) {
683
730
  coreConfig.types.immutableStorageConnector.push({
@@ -738,11 +785,11 @@ function configureImmutableStorageConnectors(coreConfig, envVars) {
738
785
  }
739
786
  }
740
787
  /**
741
- * Configures the identity connectors for the core.
788
+ * Configures the identity.
742
789
  * @param coreConfig The core config.
743
790
  * @param envVars The environment variables.
744
791
  */
745
- function configureIdentityConnectors(coreConfig, envVars) {
792
+ function configureIdentity(coreConfig, envVars) {
746
793
  coreConfig.types.identityConnector ??= [];
747
794
  if (envVars.identityConnector === IdentityConnectorType.EntityStorage) {
748
795
  coreConfig.types.identityConnector.push({
@@ -783,11 +830,11 @@ function configureIdentityConnectors(coreConfig, envVars) {
783
830
  }
784
831
  }
785
832
  /**
786
- * Configures the identity resolver connectors for the core.
833
+ * Configures the identity resolver.
787
834
  * @param coreConfig The core config.
788
835
  * @param envVars The environment variables.
789
836
  */
790
- function configureIdentityResolverConnectors(coreConfig, envVars) {
837
+ function configureIdentityResolver(coreConfig, envVars) {
791
838
  coreConfig.types.identityResolverConnector ??= [];
792
839
  if (envVars.identityResolverConnector === IdentityResolverConnectorType.EntityStorage) {
793
840
  coreConfig.types.identityResolverConnector.push({
@@ -830,11 +877,11 @@ function configureIdentityResolverConnectors(coreConfig, envVars) {
830
877
  }
831
878
  }
832
879
  /**
833
- * Configures the identity profile connectors for the core.
880
+ * Configures the identity profile.
834
881
  * @param coreConfig The core config.
835
882
  * @param envVars The environment variables.
836
883
  */
837
- function configureIdentityProfileConnectors(coreConfig, envVars) {
884
+ function configureIdentityProfile(coreConfig, envVars) {
838
885
  coreConfig.types.identityProfileConnector ??= [];
839
886
  if (envVars.identityProfileConnector === IdentityConnectorType.EntityStorage) {
840
887
  coreConfig.types.identityProfileConnector.push({
@@ -847,11 +894,11 @@ function configureIdentityProfileConnectors(coreConfig, envVars) {
847
894
  }
848
895
  }
849
896
  /**
850
- * Configures the attestation connectors for the core.
897
+ * Configures the attestation.
851
898
  * @param coreConfig The core config.
852
899
  * @param envVars The environment variables.
853
900
  */
854
- function configureAttestationConnectors(coreConfig, envVars) {
901
+ function configureAttestation(coreConfig, envVars) {
855
902
  coreConfig.types.attestationConnector ??= [];
856
903
  if (envVars.attestationConnector === AttestationConnectorType.Nft) {
857
904
  coreConfig.types.attestationConnector.push({
@@ -871,11 +918,37 @@ function configureAttestationConnectors(coreConfig, envVars) {
871
918
  }
872
919
  }
873
920
  /**
874
- * Configures the data processing connectors for the core.
921
+ * Configures the auditable item graph.
875
922
  * @param coreConfig The core config.
876
923
  * @param envVars The environment variables.
877
924
  */
878
- function configureDataProcessingConnectors(coreConfig, envVars) {
925
+ function configureAuditableItemGraph(coreConfig, envVars) {
926
+ if (Is.arrayValue(coreConfig.types.immutableStorageConnector)) {
927
+ coreConfig.types.auditableItemGraphComponent ??= [];
928
+ coreConfig.types.auditableItemGraphComponent.push({
929
+ type: AuditableItemGraphComponentType.Service
930
+ });
931
+ }
932
+ }
933
+ /**
934
+ * Configures the auditable item stream.
935
+ * @param coreConfig The core config.
936
+ * @param envVars The environment variables.
937
+ */
938
+ function configureAuditableItemStream(coreConfig, envVars) {
939
+ if (Is.arrayValue(coreConfig.types.immutableStorageConnector)) {
940
+ coreConfig.types.auditableItemStreamComponent ??= [];
941
+ coreConfig.types.auditableItemStreamComponent.push({
942
+ type: AuditableItemStreamComponentType.Service
943
+ });
944
+ }
945
+ }
946
+ /**
947
+ * Configures the data processing.
948
+ * @param coreConfig The core config.
949
+ * @param envVars The environment variables.
950
+ */
951
+ function configureDataProcessing(coreConfig, envVars) {
879
952
  coreConfig.types.dataConverterConnector ??= [];
880
953
  coreConfig.types.dataExtractorConnector ??= [];
881
954
  const converterConnectors = envVars.dataConverterConnectors?.split(",") ?? [];
@@ -905,5 +978,20 @@ function configureDataProcessingConnectors(coreConfig, envVars) {
905
978
  coreConfig.types.dataProcessingComponent.push({ type: DataProcessingComponentType.Service });
906
979
  }
907
980
  }
981
+ /**
982
+ * Configures the document management.
983
+ * @param coreConfig The core config.
984
+ * @param envVars The environment variables.
985
+ */
986
+ function configureDocumentManagement(coreConfig, envVars) {
987
+ if (Is.arrayValue(coreConfig.types.auditableItemGraphComponent) &&
988
+ Is.arrayValue(coreConfig.types.blobStorageComponent) &&
989
+ Is.arrayValue(coreConfig.types.attestationComponent)) {
990
+ coreConfig.types.documentManagementComponent ??= [];
991
+ coreConfig.types.documentManagementComponent.push({
992
+ type: DocumentManagementComponentType.Service
993
+ });
994
+ }
995
+ }
908
996
 
909
- export { Engine, buildEngineConfiguration };
997
+ export { Engine, EngineConfigHelper, buildEngineConfiguration };
@@ -1,3 +1,4 @@
1
1
  export * from "./engine";
2
2
  export * from "./models/IEngineEnvironmentVariables";
3
+ export * from "./utils/engineConfigHelper";
3
4
  export * from "./utils/engineEnvBuilder";
@@ -0,0 +1,25 @@
1
+ import { type IEngineConfig } from "@twin.org/engine-types";
2
+ import { type IEntitySchema } from "@twin.org/entity";
3
+ /**
4
+ * Helper methods for engine config.
5
+ */
6
+ export declare class EngineConfigHelper {
7
+ /**
8
+ * Runtime name for the class.
9
+ */
10
+ static readonly CLASS_NAME: string;
11
+ /**
12
+ * Add a custom entity storage to the engine configuration.
13
+ * @param engineConfig The engine configuration.
14
+ * @param entityTypeName The entity type name.
15
+ * @param entitySchema The entity schema.
16
+ * @param restPath The rest path to serve the entity storage from.
17
+ * @param options Additional options.
18
+ * @param options.includeNodeIdentity Whether to include the node identity in the entity, defaults to true.
19
+ * @param options.includeUserIdentity Whether to include the user identity in the entity, defaults to true.
20
+ */
21
+ static addCustomEntityStorage<T>(engineConfig: IEngineConfig, entityTypeName: string, entitySchema: IEntitySchema<T>, restPath: string, options?: {
22
+ includeNodeIdentity?: boolean;
23
+ includeUserIdentity?: true;
24
+ }): void;
25
+ }
@@ -0,0 +1,79 @@
1
+ # Class: EngineConfigHelper
2
+
3
+ Helper methods for engine config.
4
+
5
+ ## Constructors
6
+
7
+ ### new EngineConfigHelper()
8
+
9
+ > **new EngineConfigHelper**(): [`EngineConfigHelper`](EngineConfigHelper.md)
10
+
11
+ #### Returns
12
+
13
+ [`EngineConfigHelper`](EngineConfigHelper.md)
14
+
15
+ ## Properties
16
+
17
+ ### CLASS\_NAME
18
+
19
+ > `readonly` `static` **CLASS\_NAME**: `string`
20
+
21
+ Runtime name for the class.
22
+
23
+ ## Methods
24
+
25
+ ### addCustomEntityStorage()
26
+
27
+ > `static` **addCustomEntityStorage**\<`T`\>(`engineConfig`, `entityTypeName`, `entitySchema`, `restPath`, `options`?): `void`
28
+
29
+ Add a custom entity storage to the engine configuration.
30
+
31
+ #### Type Parameters
32
+
33
+ • **T**
34
+
35
+ #### Parameters
36
+
37
+ ##### engineConfig
38
+
39
+ `IEngineConfig`
40
+
41
+ The engine configuration.
42
+
43
+ ##### entityTypeName
44
+
45
+ `string`
46
+
47
+ The entity type name.
48
+
49
+ ##### entitySchema
50
+
51
+ `IEntitySchema`\<`T`\>
52
+
53
+ The entity schema.
54
+
55
+ ##### restPath
56
+
57
+ `string`
58
+
59
+ The rest path to serve the entity storage from.
60
+
61
+ ##### options?
62
+
63
+ Additional options.
64
+
65
+ ###### includeNodeIdentity?
66
+
67
+ `boolean`
68
+
69
+ Whether to include the node identity in the entity, defaults to true.
70
+
71
+ ###### includeUserIdentity?
72
+
73
+ `true`
74
+
75
+ Whether to include the user identity in the entity, defaults to true.
76
+
77
+ #### Returns
78
+
79
+ `void`
@@ -3,6 +3,7 @@
3
3
  ## Classes
4
4
 
5
5
  - [Engine](classes/Engine.md)
6
+ - [EngineConfigHelper](classes/EngineConfigHelper.md)
6
7
 
7
8
  ## Interfaces
8
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/engine",
3
- "version": "0.0.1-next.52",
3
+ "version": "0.0.1-next.53",
4
4
  "description": "Engine implementation.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,8 +15,9 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
- "@twin.org/engine-core": "0.0.1-next.52",
19
- "@twin.org/engine-types": "0.0.1-next.52"
18
+ "@twin.org/engine-core": "0.0.1-next.53",
19
+ "@twin.org/engine-types": "0.0.1-next.53",
20
+ "@twin.org/entity": "next"
20
21
  },
21
22
  "main": "./dist/cjs/index.cjs",
22
23
  "module": "./dist/esm/index.mjs",