@twin.org/engine-types 0.0.3-next.25 → 0.0.3-next.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/es/components/entityStorage.js +29 -27
- package/dist/es/components/entityStorage.js.map +1 -1
- package/dist/es/components/federatedCatalogue.js +1 -1
- package/dist/es/components/federatedCatalogue.js.map +1 -1
- package/dist/types/components/entityStorage.d.ts +1 -2
- package/docs/changelog.md +31 -1
- package/docs/examples.md +74 -1
- package/docs/reference/classes/EngineTypeHelper.md +5 -5
- package/docs/reference/functions/initialiseEntityStorageConnector.md +4 -6
- package/docs/reference/interfaces/IEngineConfig.md +103 -67
- package/docs/reference/type-aliases/AttestationConnectorConfig.md +3 -3
- package/docs/reference/type-aliases/BackgroundTaskComponentConfig.md +3 -3
- package/docs/reference/type-aliases/DataExtractorConnectorConfig.md +3 -3
- package/docs/reference/type-aliases/DltConfig.md +4 -4
- package/docs/reference/type-aliases/EventBusConnectorConfig.md +3 -3
- package/docs/reference/type-aliases/FederatedCatalogueFilterComponentConfig.md +2 -2
- package/docs/reference/type-aliases/IdentityProfileConnectorConfig.md +3 -3
- package/docs/reference/type-aliases/MessagingAdminComponentConfig.md +3 -3
- package/docs/reference/type-aliases/MessagingComponentConfig.md +3 -3
- package/docs/reference/type-aliases/RightsManagementPdpComponentConfig.md +3 -3
- package/docs/reference/type-aliases/RightsManagementPepComponentConfig.md +3 -3
- package/docs/reference/type-aliases/RightsManagementPipComponentConfig.md +3 -3
- package/docs/reference/type-aliases/RightsManagementPmpComponentConfig.md +3 -3
- package/docs/reference/type-aliases/RightsManagementPolicyExecutionActionComponentConfig.md +3 -3
- package/docs/reference/type-aliases/RightsManagementPolicyNegotiatorComponentConfig.md +3 -3
- package/docs/reference/type-aliases/RightsManagementPolicyObligationEnforcerComponentConfig.md +3 -3
- package/docs/reference/type-aliases/RightsManagementPolicyRequesterComponentConfig.md +3 -3
- package/docs/reference/type-aliases/RightsManagementPxpComponentConfig.md +3 -3
- package/docs/reference/type-aliases/TaskSchedulerComponentConfig.md +3 -3
- package/docs/reference/type-aliases/TelemetryConnectorConfig.md +3 -3
- package/docs/reference/type-aliases/TenantAdminComponentConfig.md +3 -3
- package/docs/reference/type-aliases/TrustComponentConfig.md +3 -3
- package/docs/reference/type-aliases/TrustGeneratorComponentConfig.md +2 -2
- package/docs/reference/type-aliases/TrustVerifierComponentConfig.md +3 -3
- package/docs/reference/variables/AttestationComponentType.md +2 -2
- package/docs/reference/variables/AttestationConnectorType.md +1 -1
- package/docs/reference/variables/AuditableItemGraphComponentType.md +2 -2
- package/docs/reference/variables/AuditableItemStreamComponentType.md +2 -2
- package/docs/reference/variables/BackgroundTaskComponentType.md +1 -1
- package/docs/reference/variables/BlobStorageComponentType.md +2 -2
- package/docs/reference/variables/BlobStorageConnectorType.md +6 -6
- package/docs/reference/variables/ContextIdHandlerComponentType.md +2 -2
- package/docs/reference/variables/DataConverterConnectorType.md +2 -2
- package/docs/reference/variables/DataExtractorConnectorType.md +1 -1
- package/docs/reference/variables/DataProcessingComponentType.md +2 -2
- package/docs/reference/variables/DataspaceControlPlaneComponentType.md +2 -2
- package/docs/reference/variables/DataspaceDataPlaneComponentType.md +3 -3
- package/docs/reference/variables/DltConfigType.md +1 -1
- package/docs/reference/variables/DocumentManagementComponentType.md +2 -2
- package/docs/reference/variables/EntityStorageComponentType.md +2 -2
- package/docs/reference/variables/EntityStorageConnectorType.md +10 -10
- package/docs/reference/variables/EventBusComponentType.md +2 -2
- package/docs/reference/variables/EventBusConnectorType.md +1 -1
- package/docs/reference/variables/FaucetConnectorType.md +2 -2
- package/docs/reference/variables/FederatedCatalogueComponentType.md +2 -2
- package/docs/reference/variables/FederatedCatalogueFilterComponentType.md +1 -1
- package/docs/reference/variables/IdentityComponentType.md +2 -2
- package/docs/reference/variables/IdentityConnectorType.md +2 -2
- package/docs/reference/variables/IdentityProfileComponentType.md +2 -2
- package/docs/reference/variables/IdentityProfileConnectorType.md +1 -1
- package/docs/reference/variables/IdentityResolverComponentType.md +2 -2
- package/docs/reference/variables/IdentityResolverConnectorType.md +3 -3
- package/docs/reference/variables/ImmutableProofComponentType.md +2 -2
- package/docs/reference/variables/LoggingComponentType.md +2 -2
- package/docs/reference/variables/LoggingConnectorType.md +3 -3
- package/docs/reference/variables/MessagingAdminComponentType.md +1 -1
- package/docs/reference/variables/MessagingComponentType.md +1 -1
- package/docs/reference/variables/MessagingEmailConnectorType.md +2 -2
- package/docs/reference/variables/MessagingPushNotificationConnectorType.md +2 -2
- package/docs/reference/variables/MessagingSmsConnectorType.md +2 -2
- package/docs/reference/variables/NftComponentType.md +2 -2
- package/docs/reference/variables/NftConnectorType.md +2 -2
- package/docs/reference/variables/RightsManagementPapComponentType.md +2 -2
- package/docs/reference/variables/RightsManagementPdpComponentType.md +1 -1
- package/docs/reference/variables/RightsManagementPepComponentType.md +2 -2
- package/docs/reference/variables/RightsManagementPipComponentType.md +1 -1
- package/docs/reference/variables/RightsManagementPmpComponentType.md +1 -1
- package/docs/reference/variables/RightsManagementPnapComponentType.md +2 -2
- package/docs/reference/variables/RightsManagementPnpComponentType.md +2 -2
- package/docs/reference/variables/RightsManagementPolicyArbiterComponentType.md +2 -2
- package/docs/reference/variables/RightsManagementPolicyEnforcementProcessorComponentType.md +2 -2
- package/docs/reference/variables/RightsManagementPolicyExecutionActionComponentType.md +1 -1
- package/docs/reference/variables/RightsManagementPolicyInformationSourceComponentType.md +2 -2
- package/docs/reference/variables/RightsManagementPolicyNegotiatorComponentType.md +1 -1
- package/docs/reference/variables/RightsManagementPolicyObligationEnforcerComponentType.md +1 -1
- package/docs/reference/variables/RightsManagementPolicyRequesterComponentType.md +1 -1
- package/docs/reference/variables/RightsManagementPxpComponentType.md +1 -1
- package/docs/reference/variables/SynchronisedStorageComponentType.md +2 -2
- package/docs/reference/variables/TaskSchedulerComponentType.md +1 -1
- package/docs/reference/variables/TelemetryComponentType.md +2 -2
- package/docs/reference/variables/TelemetryConnectorType.md +1 -1
- package/docs/reference/variables/TenantAdminComponentType.md +1 -1
- package/docs/reference/variables/TrustComponentType.md +1 -1
- package/docs/reference/variables/TrustGeneratorComponentType.md +1 -1
- package/docs/reference/variables/TrustVerifierComponentType.md +1 -1
- package/docs/reference/variables/VaultConnectorType.md +2 -2
- package/docs/reference/variables/VerifiableStorageComponentType.md +2 -2
- package/docs/reference/variables/VerifiableStorageConnectorType.md +2 -2
- package/docs/reference/variables/WalletConnectorType.md +2 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# TWIN Engine Types
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Engine Types contains component and connector type definitions used to compose runtime capabilities. It also includes helpers for retrieving and merging configuration so engine setup remains consistent as integrations grow.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -25,35 +25,38 @@ import { EngineTypeHelper } from "../utils/engineTypeHelper.js";
|
|
|
25
25
|
* @param typeCustom Override the type of connector to use instead of default configuration.
|
|
26
26
|
* @param schema The schema for the entity storage.
|
|
27
27
|
* @param partitionContextIds The context IDs to use for partitioning the data.
|
|
28
|
-
* @returns The name of the instance type that was created.
|
|
29
28
|
* @throws GeneralError when the configuration is invalid.
|
|
30
29
|
*/
|
|
31
30
|
export function initialiseEntityStorageConnector(engineCore, context, typeCustom, schema, partitionContextIds) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
31
|
+
const kebabName = StringHelper.kebabCase(schema);
|
|
32
|
+
let instanceName = kebabName;
|
|
33
|
+
let entityStorageConfig;
|
|
34
|
+
if (Is.stringValue(typeCustom)) {
|
|
35
|
+
// A custom type has been specified, so look it up
|
|
36
|
+
entityStorageConfig = context.config.types.entityStorageConnector?.find(c => c.type === typeCustom || c.overrideInstanceType === typeCustom);
|
|
37
|
+
if (Is.empty(entityStorageConfig)) {
|
|
38
|
+
throw new GeneralError("engineTypes", "entityStorageCustomMissing", {
|
|
39
|
+
typeCustom,
|
|
40
|
+
storageName: instanceName
|
|
41
|
+
});
|
|
44
42
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
// Since we have a custom type we need to use that as the instance name for the
|
|
44
|
+
// connector so that it can be looked up by other components
|
|
45
|
+
instanceName = typeCustom;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// The default entity storage method is either the one with the isDefault flag set
|
|
49
|
+
// or pick the first one if no default is set.
|
|
50
|
+
entityStorageConfig =
|
|
51
|
+
context.config.types.entityStorageConnector?.find(c => c.isDefault ?? false) ??
|
|
52
|
+
context.config.types.entityStorageConnector?.[0];
|
|
53
|
+
if (Is.empty(entityStorageConfig)) {
|
|
54
|
+
throw new GeneralError("engineTypes", "entityStorageMissing", {
|
|
55
|
+
storageName: instanceName
|
|
56
|
+
});
|
|
56
57
|
}
|
|
58
|
+
}
|
|
59
|
+
if (!EntityStorageConnectorFactory.hasName(instanceName)) {
|
|
57
60
|
const type = entityStorageConfig.type;
|
|
58
61
|
let entityStorageConnector;
|
|
59
62
|
engineCore.logInfo(I18n.formatMessage("info.engineTypes.configuringEntityStorage", {
|
|
@@ -159,13 +162,13 @@ export function initialiseEntityStorageConnector(engineCore, context, typeCustom
|
|
|
159
162
|
// Create the entity storage that is wrapped by the synchronised connector
|
|
160
163
|
// by removing the custom type it will default to the standard storage
|
|
161
164
|
// mechanism for entity storage
|
|
162
|
-
|
|
165
|
+
initialiseEntityStorageConnector(engineCore, context, undefined, schema, partitionContextIds);
|
|
163
166
|
// Use the wrapped instance name as the entity storage connector type
|
|
164
167
|
// for the synchronised connector
|
|
165
168
|
entityStorageConnector = new SynchronisedEntityStorageConnector({
|
|
166
169
|
entitySchema: schema,
|
|
167
170
|
...entityStorageConfig.options,
|
|
168
|
-
entityStorageConnectorType:
|
|
171
|
+
entityStorageConnectorType: kebabName,
|
|
169
172
|
eventBusComponentType: engineCore.getRegisteredInstanceType("eventBusComponent"),
|
|
170
173
|
config: {
|
|
171
174
|
...entityStorageConfig.options.config
|
|
@@ -185,7 +188,6 @@ export function initialiseEntityStorageConnector(engineCore, context, typeCustom
|
|
|
185
188
|
});
|
|
186
189
|
EntityStorageConnectorFactory.register(instanceName, () => entityStorageConnector);
|
|
187
190
|
}
|
|
188
|
-
return instanceName;
|
|
189
191
|
}
|
|
190
192
|
/**
|
|
191
193
|
* Initialise the entity storage connector.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityStorage.js","sourceRoot":"","sources":["../../../src/components/entityStorage.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACN,gBAAgB,EAChB,YAAY,EACZ,IAAI,EAEJ,EAAE,EACF,YAAY,EACZ,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,+BAA+B,EAAE,MAAM,kDAAkD,CAAC;AACnG,OAAO,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AACzF,OAAO,EAAE,6BAA6B,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,EA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.0.\nimport path from \"node:path\";\nimport {\n\tComponentFactory,\n\tGeneralError,\n\tI18n,\n\ttype IComponent,\n\tIs,\n\tStringHelper\n} from \"@twin.org/core\";\nimport type {\n\tEngineTypeInitialiserReturn,\n\tIEngineCore,\n\tIEngineCoreContext\n} from \"@twin.org/engine-models\";\nimport { CosmosDbEntityStorageConnector } from \"@twin.org/entity-storage-connector-cosmosdb\";\nimport { DynamoDbEntityStorageConnector } from \"@twin.org/entity-storage-connector-dynamodb\";\nimport { FileEntityStorageConnector } from \"@twin.org/entity-storage-connector-file\";\nimport { FirestoreEntityStorageConnector } from \"@twin.org/entity-storage-connector-gcp-firestore\";\nimport { MemoryEntityStorageConnector } from \"@twin.org/entity-storage-connector-memory\";\nimport { MongoDbEntityStorageConnector } from \"@twin.org/entity-storage-connector-mongodb\";\nimport { MySqlEntityStorageConnector } from \"@twin.org/entity-storage-connector-mysql\";\nimport { PostgreSqlEntityStorageConnector } from \"@twin.org/entity-storage-connector-postgresql\";\nimport { ScyllaDBTableConnector } from \"@twin.org/entity-storage-connector-scylladb\";\nimport { SynchronisedEntityStorageConnector } from \"@twin.org/entity-storage-connector-synchronised\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport { EntityStorageRestClient } from \"@twin.org/entity-storage-rest-client\";\nimport { EntityStorageService } from \"@twin.org/entity-storage-service\";\nimport { nameofKebabCase } from \"@twin.org/nameof\";\nimport type { EntityStorageComponentConfig } from \"../models/config/entityStorageComponentConfig.js\";\nimport type { IEngineConfig } from \"../models/IEngineConfig.js\";\nimport { EntityStorageComponentType } from \"../models/types/entityStorageComponentType.js\";\nimport { EntityStorageConnectorType } from \"../models/types/entityStorageConnectorType.js\";\nimport { EngineTypeHelper } from \"../utils/engineTypeHelper.js\";\n\n/**\n * Initialise the entity storage connector.\n * @param engineCore The engine core.\n * @param context The context for the engine.\n * @param typeCustom Override the type of connector to use instead of default configuration.\n * @param schema The schema for the entity storage.\n * @param partitionContextIds The context IDs to use for partitioning the data.\n * @returns The name of the instance type that was created.\n * @throws GeneralError when the configuration is invalid.\n */\nexport function initialiseEntityStorageConnector(\n\tengineCore: IEngineCore<IEngineConfig>,\n\tcontext: IEngineCoreContext<IEngineConfig>,\n\ttypeCustom: string | undefined,\n\tschema: string,\n\tpartitionContextIds: string[]\n): string {\n\tconst instanceName = StringHelper.kebabCase(schema);\n\n\tif (!EntityStorageConnectorFactory.hasName(instanceName)) {\n\t\tlet entityStorageConfig;\n\n\t\tif (Is.stringValue(typeCustom)) {\n\t\t\t// A custom type has been specified, so look it up\n\t\t\tentityStorageConfig = context.config.types.entityStorageConnector?.find(\n\t\t\t\tc => c.type === typeCustom || c.overrideInstanceType === typeCustom\n\t\t\t);\n\t\t\tif (Is.empty(entityStorageConfig)) {\n\t\t\t\tthrow new GeneralError(\"engineTypes\", \"entityStorageCustomMissing\", {\n\t\t\t\t\ttypeCustom,\n\t\t\t\t\tstorageName: instanceName\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\t// The default entity storage method is either the one with the isDefault flag set\n\t\t\t// or pick the first one if no default is set.\n\t\t\tentityStorageConfig =\n\t\t\t\tcontext.config.types.entityStorageConnector?.find(c => c.isDefault ?? false) ??\n\t\t\t\tcontext.config.types.entityStorageConnector?.[0];\n\t\t\tif (Is.empty(entityStorageConfig)) {\n\t\t\t\tthrow new GeneralError(\"engineTypes\", \"entityStorageMissing\", {\n\t\t\t\t\tstorageName: instanceName\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst type = entityStorageConfig.type;\n\t\tlet entityStorageConnector: IEntityStorageConnector;\n\n\t\tengineCore.logInfo(\n\t\t\tI18n.formatMessage(\"info.engineTypes.configuringEntityStorage\", {\n\t\t\t\telement: \"Entity Storage\",\n\t\t\t\tstorageName: instanceName,\n\t\t\t\tstorageType: type\n\t\t\t})\n\t\t);\n\n\t\tif (type === EntityStorageConnectorType.Memory) {\n\t\t\tentityStorageConnector = new MemoryEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.File) {\n\t\t\tentityStorageConnector = new FileEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\tdirectory: path.join(\n\t\t\t\t\t\tentityStorageConfig.options.config.directory,\n\t\t\t\t\t\t`${entityStorageConfig.options.folderPrefix ?? \"\"}${instanceName}`\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.AwsDynamoDb) {\n\t\t\tentityStorageConnector = new DynamoDbEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\ttableName: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.AzureCosmosDb) {\n\t\t\tentityStorageConnector = new CosmosDbEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\tcontainerId: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.GcpFirestoreDb) {\n\t\t\tentityStorageConnector = new FirestoreEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\tcollectionName: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.ScyllaDb) {\n\t\t\tentityStorageConnector = new ScyllaDBTableConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\ttableName: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.MySqlDb) {\n\t\t\tentityStorageConnector = new MySqlEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\ttableName: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.MongoDb) {\n\t\t\tentityStorageConnector = new MongoDbEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\tcollection: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.PostgreSql) {\n\t\t\tentityStorageConnector = new PostgreSqlEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\ttableName: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.Synchronised) {\n\t\t\t// Create the entity storage that is wrapped by the synchronised connector\n\t\t\t// by removing the custom type it will default to the standard storage\n\t\t\t// mechanism for entity storage\n\t\t\tconst wrappedInstanceName = initialiseEntityStorageConnector(\n\t\t\t\tengineCore,\n\t\t\t\tcontext,\n\t\t\t\tundefined,\n\t\t\t\tschema,\n\t\t\t\tpartitionContextIds\n\t\t\t);\n\n\t\t\t// Use the wrapped instance name as the entity storage connector type\n\t\t\t// for the synchronised connector\n\t\t\tentityStorageConnector = new SynchronisedEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tentityStorageConnectorType: wrappedInstanceName,\n\t\t\t\teventBusComponentType: engineCore.getRegisteredInstanceType(\"eventBusComponent\"),\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tthrow new GeneralError(\"engineTypes\", \"connectorUnknownType\", {\n\t\t\t\ttype,\n\t\t\t\tconnectorType: \"entityStorageConnector\"\n\t\t\t});\n\t\t}\n\n\t\tcontext.componentInstances.push({\n\t\t\tinstanceType: instanceName,\n\t\t\tcomponent: entityStorageConnector,\n\t\t\tinitialised: false\n\t\t});\n\t\tEntityStorageConnectorFactory.register(instanceName, () => entityStorageConnector);\n\t}\n\n\treturn instanceName;\n}\n\n/**\n * Initialise the entity storage connector.\n * @param engineCore The engine core.\n * @param context The context for the engine.\n * @param instanceConfig The instance config.\n * @returns The instance created and the factory for it.\n */\nexport function initialiseEntityStorageComponent(\n\tengineCore: IEngineCore<IEngineConfig>,\n\tcontext: IEngineCoreContext<IEngineConfig>,\n\tinstanceConfig: EntityStorageComponentConfig\n): EngineTypeInitialiserReturn<EntityStorageComponentConfig, typeof ComponentFactory> {\n\tlet createComponent;\n\tlet instanceTypeName;\n\n\tif (instanceConfig.type === EntityStorageComponentType.Service) {\n\t\tconst kebabName = StringHelper.kebabCase(instanceConfig.options.entityStorageType);\n\t\tcreateComponent = (createConfig: typeof instanceConfig) => {\n\t\t\t// See if there is a custom entity storage for this type, otherwise just use the default one.\n\t\t\tconst hasCustom = context.config.types.entityStorageConnector?.some(\n\t\t\t\tc => c.type === kebabName || c.overrideInstanceType === kebabName\n\t\t\t);\n\n\t\t\tinitialiseEntityStorageConnector(\n\t\t\t\tengineCore,\n\t\t\t\tcontext,\n\t\t\t\thasCustom ? kebabName : undefined,\n\t\t\t\tcreateConfig.options.entityStorageType,\n\t\t\t\tcreateConfig.options.partitionContextIds\n\t\t\t);\n\n\t\t\treturn new EntityStorageService(\n\t\t\t\tEngineTypeHelper.mergeConfig<(typeof instanceConfig)[\"options\"]>(createConfig.options, {\n\t\t\t\t\tentityStorageType: kebabName\n\t\t\t\t})\n\t\t\t);\n\t\t};\n\t\tinstanceTypeName = kebabName;\n\t} else if (instanceConfig.type === EntityStorageComponentType.RestClient) {\n\t\tconst kebabName = StringHelper.kebabCase(instanceConfig.options.entityStorageType);\n\t\tcreateComponent = (createConfig: typeof instanceConfig) =>\n\t\t\tnew EntityStorageRestClient(\n\t\t\t\tEngineTypeHelper.mergeConfig<(typeof instanceConfig)[\"options\"]>(createConfig.options, {\n\t\t\t\t\tpathPrefix: kebabName\n\t\t\t\t})\n\t\t\t);\n\t\tinstanceTypeName = `${nameofKebabCase(EntityStorageRestClient)}-${kebabName}`;\n\t}\n\n\treturn {\n\t\tcreateComponent: createComponent as (createConfig: typeof instanceConfig) => IComponent,\n\t\tinstanceTypeName,\n\t\tfactory: ComponentFactory\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"entityStorage.js","sourceRoot":"","sources":["../../../src/components/entityStorage.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACN,gBAAgB,EAChB,YAAY,EACZ,IAAI,EAEJ,EAAE,EACF,YAAY,EACZ,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAAE,8B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,0BAA0B,CAAC,UAAU,EAAE,CAAC;QAC1E,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QACnF,eAAe,GAAG,CAAC,YAAmC,EAAE,EAAE,CACzD,IAAI,uBAAuB,CAC1B,gBAAgB,CAAC,WAAW,CAAqC,YAAY,CAAC,OAAO,EAAE;YACtF,UAAU,EAAE,SAAS;SACrB,CAAC,CACF,CAAC;QACH,gBAAgB,GAAG,GAAG,4BAAwC,IAAI,SAAS,EAAE,CAAC;IAC/E,CAAC;IAED,OAAO;QACN,eAAe,EAAE,eAAsE;QACvF,gBAAgB;QAChB,OAAO,EAAE,gBAAgB;KACzB,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport {\n\tComponentFactory,\n\tGeneralError,\n\tI18n,\n\ttype IComponent,\n\tIs,\n\tStringHelper\n} from \"@twin.org/core\";\nimport type {\n\tEngineTypeInitialiserReturn,\n\tIEngineCore,\n\tIEngineCoreContext\n} from \"@twin.org/engine-models\";\nimport { CosmosDbEntityStorageConnector } from \"@twin.org/entity-storage-connector-cosmosdb\";\nimport { DynamoDbEntityStorageConnector } from \"@twin.org/entity-storage-connector-dynamodb\";\nimport { FileEntityStorageConnector } from \"@twin.org/entity-storage-connector-file\";\nimport { FirestoreEntityStorageConnector } from \"@twin.org/entity-storage-connector-gcp-firestore\";\nimport { MemoryEntityStorageConnector } from \"@twin.org/entity-storage-connector-memory\";\nimport { MongoDbEntityStorageConnector } from \"@twin.org/entity-storage-connector-mongodb\";\nimport { MySqlEntityStorageConnector } from \"@twin.org/entity-storage-connector-mysql\";\nimport { PostgreSqlEntityStorageConnector } from \"@twin.org/entity-storage-connector-postgresql\";\nimport { ScyllaDBTableConnector } from \"@twin.org/entity-storage-connector-scylladb\";\nimport { SynchronisedEntityStorageConnector } from \"@twin.org/entity-storage-connector-synchronised\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport { EntityStorageRestClient } from \"@twin.org/entity-storage-rest-client\";\nimport { EntityStorageService } from \"@twin.org/entity-storage-service\";\nimport { nameofKebabCase } from \"@twin.org/nameof\";\nimport type { EntityStorageComponentConfig } from \"../models/config/entityStorageComponentConfig.js\";\nimport type { IEngineConfig } from \"../models/IEngineConfig.js\";\nimport { EntityStorageComponentType } from \"../models/types/entityStorageComponentType.js\";\nimport { EntityStorageConnectorType } from \"../models/types/entityStorageConnectorType.js\";\nimport { EngineTypeHelper } from \"../utils/engineTypeHelper.js\";\n\n/**\n * Initialise the entity storage connector.\n * @param engineCore The engine core.\n * @param context The context for the engine.\n * @param typeCustom Override the type of connector to use instead of default configuration.\n * @param schema The schema for the entity storage.\n * @param partitionContextIds The context IDs to use for partitioning the data.\n * @throws GeneralError when the configuration is invalid.\n */\nexport function initialiseEntityStorageConnector(\n\tengineCore: IEngineCore<IEngineConfig>,\n\tcontext: IEngineCoreContext<IEngineConfig>,\n\ttypeCustom: string | undefined,\n\tschema: string,\n\tpartitionContextIds: string[]\n): void {\n\tconst kebabName = StringHelper.kebabCase(schema);\n\tlet instanceName = kebabName;\n\n\tlet entityStorageConfig;\n\n\tif (Is.stringValue(typeCustom)) {\n\t\t// A custom type has been specified, so look it up\n\t\tentityStorageConfig = context.config.types.entityStorageConnector?.find(\n\t\t\tc => c.type === typeCustom || c.overrideInstanceType === typeCustom\n\t\t);\n\t\tif (Is.empty(entityStorageConfig)) {\n\t\t\tthrow new GeneralError(\"engineTypes\", \"entityStorageCustomMissing\", {\n\t\t\t\ttypeCustom,\n\t\t\t\tstorageName: instanceName\n\t\t\t});\n\t\t}\n\n\t\t// Since we have a custom type we need to use that as the instance name for the\n\t\t// connector so that it can be looked up by other components\n\t\tinstanceName = typeCustom;\n\t} else {\n\t\t// The default entity storage method is either the one with the isDefault flag set\n\t\t// or pick the first one if no default is set.\n\t\tentityStorageConfig =\n\t\t\tcontext.config.types.entityStorageConnector?.find(c => c.isDefault ?? false) ??\n\t\t\tcontext.config.types.entityStorageConnector?.[0];\n\t\tif (Is.empty(entityStorageConfig)) {\n\t\t\tthrow new GeneralError(\"engineTypes\", \"entityStorageMissing\", {\n\t\t\t\tstorageName: instanceName\n\t\t\t});\n\t\t}\n\t}\n\n\tif (!EntityStorageConnectorFactory.hasName(instanceName)) {\n\t\tconst type = entityStorageConfig.type;\n\t\tlet entityStorageConnector: IEntityStorageConnector;\n\n\t\tengineCore.logInfo(\n\t\t\tI18n.formatMessage(\"info.engineTypes.configuringEntityStorage\", {\n\t\t\t\telement: \"Entity Storage\",\n\t\t\t\tstorageName: instanceName,\n\t\t\t\tstorageType: type\n\t\t\t})\n\t\t);\n\n\t\tif (type === EntityStorageConnectorType.Memory) {\n\t\t\tentityStorageConnector = new MemoryEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.File) {\n\t\t\tentityStorageConnector = new FileEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\tdirectory: path.join(\n\t\t\t\t\t\tentityStorageConfig.options.config.directory,\n\t\t\t\t\t\t`${entityStorageConfig.options.folderPrefix ?? \"\"}${instanceName}`\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.AwsDynamoDb) {\n\t\t\tentityStorageConnector = new DynamoDbEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\ttableName: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.AzureCosmosDb) {\n\t\t\tentityStorageConnector = new CosmosDbEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\tcontainerId: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.GcpFirestoreDb) {\n\t\t\tentityStorageConnector = new FirestoreEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\tcollectionName: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.ScyllaDb) {\n\t\t\tentityStorageConnector = new ScyllaDBTableConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\ttableName: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.MySqlDb) {\n\t\t\tentityStorageConnector = new MySqlEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\ttableName: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.MongoDb) {\n\t\t\tentityStorageConnector = new MongoDbEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\tcollection: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.PostgreSql) {\n\t\t\tentityStorageConnector = new PostgreSqlEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\tpartitionContextIds,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config,\n\t\t\t\t\ttableName: `${entityStorageConfig.options.tablePrefix ?? \"\"}${instanceName}`\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (type === EntityStorageConnectorType.Synchronised) {\n\t\t\t// Create the entity storage that is wrapped by the synchronised connector\n\t\t\t// by removing the custom type it will default to the standard storage\n\t\t\t// mechanism for entity storage\n\t\t\tinitialiseEntityStorageConnector(engineCore, context, undefined, schema, partitionContextIds);\n\n\t\t\t// Use the wrapped instance name as the entity storage connector type\n\t\t\t// for the synchronised connector\n\t\t\tentityStorageConnector = new SynchronisedEntityStorageConnector({\n\t\t\t\tentitySchema: schema,\n\t\t\t\t...entityStorageConfig.options,\n\t\t\t\tentityStorageConnectorType: kebabName,\n\t\t\t\teventBusComponentType: engineCore.getRegisteredInstanceType(\"eventBusComponent\"),\n\t\t\t\tconfig: {\n\t\t\t\t\t...entityStorageConfig.options.config\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tthrow new GeneralError(\"engineTypes\", \"connectorUnknownType\", {\n\t\t\t\ttype,\n\t\t\t\tconnectorType: \"entityStorageConnector\"\n\t\t\t});\n\t\t}\n\n\t\tcontext.componentInstances.push({\n\t\t\tinstanceType: instanceName,\n\t\t\tcomponent: entityStorageConnector,\n\t\t\tinitialised: false\n\t\t});\n\t\tEntityStorageConnectorFactory.register(instanceName, () => entityStorageConnector);\n\t}\n}\n\n/**\n * Initialise the entity storage connector.\n * @param engineCore The engine core.\n * @param context The context for the engine.\n * @param instanceConfig The instance config.\n * @returns The instance created and the factory for it.\n */\nexport function initialiseEntityStorageComponent(\n\tengineCore: IEngineCore<IEngineConfig>,\n\tcontext: IEngineCoreContext<IEngineConfig>,\n\tinstanceConfig: EntityStorageComponentConfig\n): EngineTypeInitialiserReturn<EntityStorageComponentConfig, typeof ComponentFactory> {\n\tlet createComponent;\n\tlet instanceTypeName;\n\n\tif (instanceConfig.type === EntityStorageComponentType.Service) {\n\t\tconst kebabName = StringHelper.kebabCase(instanceConfig.options.entityStorageType);\n\t\tcreateComponent = (createConfig: typeof instanceConfig) => {\n\t\t\t// See if there is a custom entity storage for this type, otherwise just use the default one.\n\t\t\tconst hasCustom = context.config.types.entityStorageConnector?.some(\n\t\t\t\tc => c.type === kebabName || c.overrideInstanceType === kebabName\n\t\t\t);\n\n\t\t\tinitialiseEntityStorageConnector(\n\t\t\t\tengineCore,\n\t\t\t\tcontext,\n\t\t\t\thasCustom ? kebabName : undefined,\n\t\t\t\tcreateConfig.options.entityStorageType,\n\t\t\t\tcreateConfig.options.partitionContextIds\n\t\t\t);\n\n\t\t\treturn new EntityStorageService(\n\t\t\t\tEngineTypeHelper.mergeConfig<(typeof instanceConfig)[\"options\"]>(createConfig.options, {\n\t\t\t\t\tentityStorageType: kebabName\n\t\t\t\t})\n\t\t\t);\n\t\t};\n\t\tinstanceTypeName = kebabName;\n\t} else if (instanceConfig.type === EntityStorageComponentType.RestClient) {\n\t\tconst kebabName = StringHelper.kebabCase(instanceConfig.options.entityStorageType);\n\t\tcreateComponent = (createConfig: typeof instanceConfig) =>\n\t\t\tnew EntityStorageRestClient(\n\t\t\t\tEngineTypeHelper.mergeConfig<(typeof instanceConfig)[\"options\"]>(createConfig.options, {\n\t\t\t\t\tpathPrefix: kebabName\n\t\t\t\t})\n\t\t\t);\n\t\tinstanceTypeName = `${nameofKebabCase(EntityStorageRestClient)}-${kebabName}`;\n\t}\n\n\treturn {\n\t\tcreateComponent: createComponent as (createConfig: typeof instanceConfig) => IComponent,\n\t\tinstanceTypeName,\n\t\tfactory: ComponentFactory\n\t};\n}\n"]}
|
|
@@ -20,7 +20,7 @@ export function initialiseFederatedCatalogueComponent(engineCore, context, insta
|
|
|
20
20
|
if (instanceConfig.type === FederatedCatalogueComponentType.Service) {
|
|
21
21
|
createComponent = (createConfig) => {
|
|
22
22
|
initSchemaFederatedCatalogue();
|
|
23
|
-
initialiseEntityStorageConnector(engineCore, context, createConfig.options?.
|
|
23
|
+
initialiseEntityStorageConnector(engineCore, context, createConfig.options?.datasetEntityStorageType, "Dataset", ContextIdHelper.pickKeysFromAvailable(engineCore.getContextIdKeys(), [ContextIdKeys.Node]));
|
|
24
24
|
return new FederatedCatalogueService(EngineTypeHelper.mergeConfig({ loggingComponentType: engineCore.getRegisteredInstanceType("loggingComponent") }, createConfig.options));
|
|
25
25
|
};
|
|
26
26
|
instanceTypeName = "federated-catalogue-service";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"federatedCatalogue.js","sourceRoot":"","sources":["../../../src/components/federatedCatalogue.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAOlD,OAAO,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AACzF,OAAO,EAEN,yBAAyB,EACzB,UAAU,IAAI,4BAA4B,EAC1C,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAGtE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE;;;;;;GAM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BAAqB,CAAC,UAAU,CAAC,gBAAgB,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAC1F,CAAC;YACF,OAAO,IAAI,yBAAyB,CACnC,gBAAgB,CAAC,WAAW,CAC3B,EAAE,oBAAoB,EAAE,UAAU,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,EAAE,EAClF,YAAY,CAAC,OAAO,CACpB,CACD,CAAC;QACH,CAAC,CAAC;QACF,gBAAgB,gCAA6C,CAAC;IAC/D,CAAC;SAAM,IAAI,cAAc,CAAC,IAAI,KAAK,+BAA+B,CAAC,UAAU,EAAE,CAAC;QAC/E,eAAe,GAAG,CAAC,YAAmC,EAAE,EAAE,CACzD,IAAI,4BAA4B,CAC/B,gBAAgB,CAAC,WAAW,CAAqC,YAAY,CAAC,OAAO,CAAC,CACtF,CAAC;QACH,gBAAgB,oCAAgD,CAAC;IAClE,CAAC;IAED,OAAO;QACN,eAAe,EAAE,eAAsE;QACvF,gBAAgB;QAEhB,OAAO,EAAE,gBAAgB;KACzB,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ContextIdHelper, ContextIdKeys } from \"@twin.org/context\";\nimport { ComponentFactory } from \"@twin.org/core\";\nimport type { IComponent } from \"@twin.org/core\";\nimport type {\n\tEngineTypeInitialiserReturn,\n\tIEngineCore,\n\tIEngineCoreContext\n} from \"@twin.org/engine-models\";\nimport { FederatedCatalogueRestClient } from \"@twin.org/federated-catalogue-rest-client\";\nimport {\n\ttype Dataset,\n\tFederatedCatalogueService,\n\tinitSchema as initSchemaFederatedCatalogue\n} from \"@twin.org/federated-catalogue-service\";\nimport { nameof, nameofKebabCase } from \"@twin.org/nameof\";\nimport { initialiseEntityStorageConnector } from \"./entityStorage.js\";\nimport type { FederatedCatalogueComponentConfig } from \"../models/config/federatedCatalogueComponentConfig.js\";\nimport type { IEngineConfig } from \"../models/IEngineConfig.js\";\nimport { FederatedCatalogueComponentType } from \"../models/types/federatedCatalogueComponentType.js\";\nimport { EngineTypeHelper } from \"../utils/engineTypeHelper.js\";\n\n/**\n * Initialise the federated catalogue component.\n * @param engineCore The engine core.\n * @param context The context for the engine.\n * @param instanceConfig The instance config.\n * @returns The instance created and the factory for it.\n */\nexport function initialiseFederatedCatalogueComponent(\n\tengineCore: IEngineCore<IEngineConfig>,\n\tcontext: IEngineCoreContext<IEngineConfig>,\n\tinstanceConfig: FederatedCatalogueComponentConfig\n): EngineTypeInitialiserReturn<typeof instanceConfig, typeof ComponentFactory> {\n\tlet createComponent;\n\tlet instanceTypeName;\n\n\tif (instanceConfig.type === FederatedCatalogueComponentType.Service) {\n\t\tcreateComponent = (createConfig: typeof instanceConfig) => {\n\t\t\tinitSchemaFederatedCatalogue();\n\t\t\tinitialiseEntityStorageConnector(\n\t\t\t\tengineCore,\n\t\t\t\tcontext,\n\t\t\t\tcreateConfig.options?.datasetEntityStorageType,\n\t\t\t\tnameof<Dataset>(),\n\t\t\t\tContextIdHelper.pickKeysFromAvailable(engineCore.getContextIdKeys(), [ContextIdKeys.Node])\n\t\t\t);\n\t\t\treturn new FederatedCatalogueService(\n\t\t\t\tEngineTypeHelper.mergeConfig<(typeof instanceConfig)[\"options\"]>(\n\t\t\t\t\t{ loggingComponentType: engineCore.getRegisteredInstanceType(\"loggingComponent\") },\n\t\t\t\t\tcreateConfig.options\n\t\t\t\t)\n\t\t\t);\n\t\t};\n\t\tinstanceTypeName = nameofKebabCase(FederatedCatalogueService);\n\t} else if (instanceConfig.type === FederatedCatalogueComponentType.RestClient) {\n\t\tcreateComponent = (createConfig: typeof instanceConfig) =>\n\t\t\tnew FederatedCatalogueRestClient(\n\t\t\t\tEngineTypeHelper.mergeConfig<(typeof instanceConfig)[\"options\"]>(createConfig.options)\n\t\t\t);\n\t\tinstanceTypeName = nameofKebabCase(FederatedCatalogueRestClient);\n\t}\n\n\treturn {\n\t\tcreateComponent: createComponent as (createConfig: typeof instanceConfig) => IComponent,\n\t\tinstanceTypeName,\n\n\t\tfactory: ComponentFactory\n\t};\n}\n"]}
|
|
@@ -9,10 +9,9 @@ import type { IEngineConfig } from "../models/IEngineConfig.js";
|
|
|
9
9
|
* @param typeCustom Override the type of connector to use instead of default configuration.
|
|
10
10
|
* @param schema The schema for the entity storage.
|
|
11
11
|
* @param partitionContextIds The context IDs to use for partitioning the data.
|
|
12
|
-
* @returns The name of the instance type that was created.
|
|
13
12
|
* @throws GeneralError when the configuration is invalid.
|
|
14
13
|
*/
|
|
15
|
-
export declare function initialiseEntityStorageConnector(engineCore: IEngineCore<IEngineConfig>, context: IEngineCoreContext<IEngineConfig>, typeCustom: string | undefined, schema: string, partitionContextIds: string[]):
|
|
14
|
+
export declare function initialiseEntityStorageConnector(engineCore: IEngineCore<IEngineConfig>, context: IEngineCoreContext<IEngineConfig>, typeCustom: string | undefined, schema: string, partitionContextIds: string[]): void;
|
|
16
15
|
/**
|
|
17
16
|
* Initialise the entity storage connector.
|
|
18
17
|
* @param engineCore The engine core.
|
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.27](https://github.com/twinfoundation/engine/compare/engine-types-v0.0.3-next.26...engine-types-v0.0.3-next.27) (2026-03-20)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* update dependencies ([e6ebe42](https://github.com/twinfoundation/engine/commit/e6ebe42b9d61066227ad8b45dae14c8f8615b760))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/engine-core bumped from 0.0.3-next.26 to 0.0.3-next.27
|
|
16
|
+
* @twin.org/engine-models bumped from 0.0.3-next.26 to 0.0.3-next.27
|
|
17
|
+
|
|
18
|
+
## [0.0.3-next.26](https://github.com/twinfoundation/engine/compare/engine-types-v0.0.3-next.25...engine-types-v0.0.3-next.26) (2026-03-05)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* use custom instance type for entity storage registration ([#90](https://github.com/twinfoundation/engine/issues/90)) ([2c23995](https://github.com/twinfoundation/engine/commit/2c239953dab4510a4cf97063ee90d048210bf4a6))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Dependencies
|
|
27
|
+
|
|
28
|
+
* The following workspace dependencies were updated
|
|
29
|
+
* dependencies
|
|
30
|
+
* @twin.org/engine-core bumped from 0.0.3-next.25 to 0.0.3-next.26
|
|
31
|
+
* @twin.org/engine-models bumped from 0.0.3-next.25 to 0.0.3-next.26
|
|
2
32
|
|
|
3
33
|
## [0.0.3-next.25](https://github.com/twinfoundation/engine/compare/engine-types-v0.0.3-next.24...engine-types-v0.0.3-next.25) (2026-03-02)
|
|
4
34
|
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,74 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Engine Types Examples
|
|
2
|
+
|
|
3
|
+
These examples show how to compose type-safe engine configuration and retrieve merged options for specific component instances.
|
|
4
|
+
|
|
5
|
+
## EngineTypeHelper
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import {
|
|
9
|
+
EngineTypeHelper,
|
|
10
|
+
EntityStorageComponentType,
|
|
11
|
+
LoggingConnectorType,
|
|
12
|
+
type IEngineConfig
|
|
13
|
+
} from '@twin.org/engine-types';
|
|
14
|
+
|
|
15
|
+
const engineConfig: IEngineConfig = {
|
|
16
|
+
debug: false,
|
|
17
|
+
silent: true,
|
|
18
|
+
types: {
|
|
19
|
+
loggingConnector: [{ type: LoggingConnectorType.Console, isDefault: true }],
|
|
20
|
+
entityStorageComponent: [
|
|
21
|
+
{
|
|
22
|
+
type: EntityStorageComponentType.Service,
|
|
23
|
+
options: {
|
|
24
|
+
entityStorageType: 'product'
|
|
25
|
+
},
|
|
26
|
+
isDefault: true
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const loggingConfig = EngineTypeHelper.getConfigOfType(
|
|
33
|
+
engineConfig,
|
|
34
|
+
'loggingConnector',
|
|
35
|
+
LoggingConnectorType.Console
|
|
36
|
+
);
|
|
37
|
+
const mergedEntityOptions = EngineTypeHelper.mergeConfig(
|
|
38
|
+
{ entityStorageType: 'product', partitionContextIds: ['node'] },
|
|
39
|
+
{ partitionContextIds: ['node', 'tenant'] }
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
console.log(loggingConfig?.type); // "console"
|
|
43
|
+
console.log(mergedEntityOptions.partitionContextIds); // ["node", "tenant"]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Building Config with Shared Type Constants
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import {
|
|
50
|
+
EntityStorageComponentType,
|
|
51
|
+
EntityStorageConnectorType,
|
|
52
|
+
LoggingComponentType,
|
|
53
|
+
LoggingConnectorType,
|
|
54
|
+
TelemetryComponentType,
|
|
55
|
+
TelemetryConnectorType,
|
|
56
|
+
type IEngineConfig
|
|
57
|
+
} from '@twin.org/engine-types';
|
|
58
|
+
|
|
59
|
+
const config: IEngineConfig = {
|
|
60
|
+
debug: true,
|
|
61
|
+
silent: false,
|
|
62
|
+
types: {
|
|
63
|
+
loggingConnector: [{ type: LoggingConnectorType.Console }],
|
|
64
|
+
loggingComponent: [{ type: LoggingComponentType.Service }],
|
|
65
|
+
entityStorageConnector: [{ type: EntityStorageConnectorType.Memory }],
|
|
66
|
+
entityStorageComponent: [{ type: EntityStorageComponentType.Service }],
|
|
67
|
+
telemetryConnector: [{ type: TelemetryConnectorType.EntityStorage }],
|
|
68
|
+
telemetryComponent: [{ type: TelemetryComponentType.Service }]
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
console.log(config.types.entityStorageConnector?.[0].type); // "memory"
|
|
73
|
+
console.log(config.types.telemetryComponent?.[0].type); // "service"
|
|
74
|
+
```
|
|
@@ -14,7 +14,7 @@ Helper methods for engine config types.
|
|
|
14
14
|
|
|
15
15
|
## Properties
|
|
16
16
|
|
|
17
|
-
### CLASS\_NAME
|
|
17
|
+
### CLASS\_NAME {#class_name}
|
|
18
18
|
|
|
19
19
|
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
20
20
|
|
|
@@ -22,9 +22,9 @@ Runtime name for the class.
|
|
|
22
22
|
|
|
23
23
|
## Methods
|
|
24
24
|
|
|
25
|
-
### getConfigOfType()
|
|
25
|
+
### getConfigOfType() {#getconfigoftype}
|
|
26
26
|
|
|
27
|
-
> `static` **getConfigOfType**\<`T`\>(`engineConfig`, `component`, `type`): `
|
|
27
|
+
> `static` **getConfigOfType**\<`T`\>(`engineConfig`, `component`, `type`): `IEngineCoreTypeConfig`\<`T`\> \| `undefined`
|
|
28
28
|
|
|
29
29
|
Get the config for the specified component and type.
|
|
30
30
|
|
|
@@ -56,13 +56,13 @@ The type name.
|
|
|
56
56
|
|
|
57
57
|
#### Returns
|
|
58
58
|
|
|
59
|
-
`
|
|
59
|
+
`IEngineCoreTypeConfig`\<`T`\> \| `undefined`
|
|
60
60
|
|
|
61
61
|
The config for the specified component and type or undefined if it does not exist.
|
|
62
62
|
|
|
63
63
|
***
|
|
64
64
|
|
|
65
|
-
### mergeConfig()
|
|
65
|
+
### mergeConfig() {#mergeconfig}
|
|
66
66
|
|
|
67
67
|
> `static` **mergeConfig**\<`T`\>(`config1?`, `config2?`, `config3?`, `config4?`, `config5?`): `T`
|
|
68
68
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Function: initialiseEntityStorageConnector()
|
|
2
2
|
|
|
3
|
-
> **initialiseEntityStorageConnector**(`engineCore`, `context`, `typeCustom`, `schema`, `partitionContextIds`): `
|
|
3
|
+
> **initialiseEntityStorageConnector**(`engineCore`, `context`, `typeCustom`, `schema`, `partitionContextIds`): `void`
|
|
4
4
|
|
|
5
5
|
Initialise the entity storage connector.
|
|
6
6
|
|
|
@@ -20,9 +20,9 @@ The context for the engine.
|
|
|
20
20
|
|
|
21
21
|
### typeCustom
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
`string` \| `undefined`
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Override the type of connector to use instead of default configuration.
|
|
26
26
|
|
|
27
27
|
### schema
|
|
28
28
|
|
|
@@ -38,9 +38,7 @@ The context IDs to use for partitioning the data.
|
|
|
38
38
|
|
|
39
39
|
## Returns
|
|
40
40
|
|
|
41
|
-
`
|
|
42
|
-
|
|
43
|
-
The name of the instance type that was created.
|
|
41
|
+
`void`
|
|
44
42
|
|
|
45
43
|
## Throws
|
|
46
44
|
|