@twin.org/engine-types 0.0.3-next.1 → 0.0.3-next.3
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.
|
@@ -179,7 +179,8 @@ export function initialiseEntityStorageConnector(engineCore, context, typeCustom
|
|
|
179
179
|
}
|
|
180
180
|
context.componentInstances.push({
|
|
181
181
|
instanceType: instanceName,
|
|
182
|
-
component: entityStorageConnector
|
|
182
|
+
component: entityStorageConnector,
|
|
183
|
+
initialised: false
|
|
183
184
|
});
|
|
184
185
|
EntityStorageConnectorFactory.register(instanceName, () => entityStorageConnector);
|
|
185
186
|
}
|
|
@@ -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,EACJ,EAAE,EACF,YAAY,EAEZ,MAAM,gBAAgB,CAAC;AAExB,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,EAAE,kCAAkC,EAAE,MAAM,iDAAiD,CAAC;AACrG,OAAO,EACN,6BAA6B,EAG7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CAClE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,oBAAoB,KAAK,SAAS,CACjE,CAAC;QAEF,gCAAgC,CAC/B,UAAU,EACV,OAAO,EACP,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EACjC,cAAc,CAAC,OAAO,CAAC,iBAAiB,EACxC,cAAc,CAAC,OAAO,CAAC,mBAAmB,CAC1C,CAAC;QACF,SAAS,GAAG,IAAI,oBAAoB,CAAC;YACpC,iBAAiB,EAAE,SAAS;YAC5B,MAAM,EAAE;gBACP,GAAG,cAAc,CAAC,OAAO,CAAC,MAAM;aAChC;SACD,CAAC,CAAC;QACH,YAAY,GAAG,YAAY,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACjF,CAAC;SAAM,IAAI,cAAc,CAAC,IAAI,KAAK,0BAA0B,CAAC,UAAU,EAAE,CAAC;QAC1E,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QACnF,SAAS,GAAG,IAAI,uBAAuB,CAAC;YACvC,UAAU,EAAE,SAAS;YACrB,GAAG,cAAc,CAAC,OAAO;SACzB,CAAC,CAAC;QACH,YAAY,GAAG,GAAG,4BAAwC,IAAI,SAAS,EAAE,CAAC;IAC3E,CAAC;IAED,OAAO;QACN,SAAS;QACT,YAAY;QACZ,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\tIs,\n\tStringHelper,\n\ttype IComponent\n} from \"@twin.org/core\";\nimport type { IEngineCore, IEngineCoreContext } 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 IEntityStorageComponent,\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\";\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});\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 async function initialiseEntityStorageComponent(\n\tengineCore: IEngineCore<IEngineConfig>,\n\tcontext: IEngineCoreContext<IEngineConfig>,\n\tinstanceConfig: EntityStorageComponentConfig\n): Promise<{\n\tinstanceType?: string;\n\tfactory?: typeof ComponentFactory;\n\tcomponent?: IComponent;\n}> {\n\tlet component: IEntityStorageComponent | undefined;\n\tlet instanceType: string | undefined;\n\n\tif (instanceConfig.type === EntityStorageComponentType.Service) {\n\t\tconst kebabName = StringHelper.kebabCase(instanceConfig.options.entityStorageType);\n\n\t\t// See if there is a custom entity storage for this type, otherwise just use the default one.\n\t\tconst hasCustom = context.config.types.entityStorageConnector?.some(\n\t\t\tc => c.type === kebabName || c.overrideInstanceType === kebabName\n\t\t);\n\n\t\tinitialiseEntityStorageConnector(\n\t\t\tengineCore,\n\t\t\tcontext,\n\t\t\thasCustom ? kebabName : undefined,\n\t\t\tinstanceConfig.options.entityStorageType,\n\t\t\tinstanceConfig.options.partitionContextIds\n\t\t);\n\t\tcomponent = new EntityStorageService({\n\t\t\tentityStorageType: kebabName,\n\t\t\tconfig: {\n\t\t\t\t...instanceConfig.options.config\n\t\t\t}\n\t\t});\n\t\tinstanceType = StringHelper.kebabCase(instanceConfig.options.entityStorageType);\n\t} else if (instanceConfig.type === EntityStorageComponentType.RestClient) {\n\t\tconst kebabName = StringHelper.kebabCase(instanceConfig.options.entityStorageType);\n\t\tcomponent = new EntityStorageRestClient({\n\t\t\tpathPrefix: kebabName,\n\t\t\t...instanceConfig.options\n\t\t});\n\t\tinstanceType = `${nameofKebabCase(EntityStorageRestClient)}-${kebabName}`;\n\t}\n\n\treturn {\n\t\tcomponent,\n\t\tinstanceType,\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,EACJ,EAAE,EACF,YAAY,EAEZ,MAAM,gBAAgB,CAAC;AAExB,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;AAC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,CAAC;QAEnF,6FAA6F;QAC7F,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,IAAI,CAClE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,oBAAoB,KAAK,SAAS,CACjE,CAAC;QAEF,gCAAgC,CAC/B,UAAU,EACV,OAAO,EACP,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EACjC,cAAc,CAAC,OAAO,CAAC,iBAAiB,EACxC,cAAc,CAAC,OAAO,CAAC,mBAAmB,CAC1C,CAAC;QACF,SAAS,GAAG,IAAI,oBAAoB,CAAC;YACpC,iBAAiB,EAAE,SAAS;YAC5B,MAAM,EAAE;gBACP,GAAG,cAAc,CAAC,OAAO,CAAC,MAAM;aAChC;SACD,CAAC,CAAC;QACH,YAAY,GAAG,YAAY,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACjF,CAAC;SAAM,IAAI,cAAc,CAAC,IAAI,KAAK,0BAA0B,CAAC,UAAU,EAAE,CAAC;QAC1E,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QACnF,SAAS,GAAG,IAAI,uBAAuB,CAAC;YACvC,UAAU,EAAE,SAAS;YACrB,GAAG,cAAc,CAAC,OAAO;SACzB,CAAC,CAAC;QACH,YAAY,GAAG,GAAG,4BAAwC,IAAI,SAAS,EAAE,CAAC;IAC3E,CAAC;IAED,OAAO;QACN,SAAS;QACT,YAAY;QACZ,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\tIs,\n\tStringHelper,\n\ttype IComponent\n} from \"@twin.org/core\";\nimport type { IEngineCore, IEngineCoreContext } 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 IEntityStorageComponent,\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\";\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 async function initialiseEntityStorageComponent(\n\tengineCore: IEngineCore<IEngineConfig>,\n\tcontext: IEngineCoreContext<IEngineConfig>,\n\tinstanceConfig: EntityStorageComponentConfig\n): Promise<{\n\tinstanceType?: string;\n\tfactory?: typeof ComponentFactory;\n\tcomponent?: IComponent;\n}> {\n\tlet component: IEntityStorageComponent | undefined;\n\tlet instanceType: string | undefined;\n\n\tif (instanceConfig.type === EntityStorageComponentType.Service) {\n\t\tconst kebabName = StringHelper.kebabCase(instanceConfig.options.entityStorageType);\n\n\t\t// See if there is a custom entity storage for this type, otherwise just use the default one.\n\t\tconst hasCustom = context.config.types.entityStorageConnector?.some(\n\t\t\tc => c.type === kebabName || c.overrideInstanceType === kebabName\n\t\t);\n\n\t\tinitialiseEntityStorageConnector(\n\t\t\tengineCore,\n\t\t\tcontext,\n\t\t\thasCustom ? kebabName : undefined,\n\t\t\tinstanceConfig.options.entityStorageType,\n\t\t\tinstanceConfig.options.partitionContextIds\n\t\t);\n\t\tcomponent = new EntityStorageService({\n\t\t\tentityStorageType: kebabName,\n\t\t\tconfig: {\n\t\t\t\t...instanceConfig.options.config\n\t\t\t}\n\t\t});\n\t\tinstanceType = StringHelper.kebabCase(instanceConfig.options.entityStorageType);\n\t} else if (instanceConfig.type === EntityStorageComponentType.RestClient) {\n\t\tconst kebabName = StringHelper.kebabCase(instanceConfig.options.entityStorageType);\n\t\tcomponent = new EntityStorageRestClient({\n\t\t\tpathPrefix: kebabName,\n\t\t\t...instanceConfig.options\n\t\t});\n\t\tinstanceType = `${nameofKebabCase(EntityStorageRestClient)}-${kebabName}`;\n\t}\n\n\treturn {\n\t\tcomponent,\n\t\tinstanceType,\n\t\tfactory: ComponentFactory\n\t};\n}\n"]}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @twin.org/engine-types - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.3](https://github.com/twinfoundation/engine/compare/engine-types-v0.0.3-next.2...engine-types-v0.0.3-next.3) (2025-11-14)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* make sure stop is called even if start is not implemented ([ece2b9d](https://github.com/twinfoundation/engine/commit/ece2b9de5c6dff2b5ccf2a3115c1a7328a330125))
|
|
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.2 to 0.0.3-next.3
|
|
16
|
+
* @twin.org/engine-models bumped from 0.0.3-next.2 to 0.0.3-next.3
|
|
17
|
+
|
|
18
|
+
## [0.0.3-next.2](https://github.com/twinfoundation/engine/compare/engine-types-v0.0.3-next.1...engine-types-v0.0.3-next.2) (2025-11-13)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* close already started components on startup error ([a55a117](https://github.com/twinfoundation/engine/commit/a55a117a508998288c8ae804e732fc6085cb22fa))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* missing dependency ([e8147fb](https://github.com/twinfoundation/engine/commit/e8147fbd66248efd86877ece23022f2dd58c950a))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Dependencies
|
|
32
|
+
|
|
33
|
+
* The following workspace dependencies were updated
|
|
34
|
+
* dependencies
|
|
35
|
+
* @twin.org/engine-core bumped from 0.0.3-next.1 to 0.0.3-next.2
|
|
36
|
+
* @twin.org/engine-models bumped from 0.0.3-next.1 to 0.0.3-next.2
|
|
37
|
+
|
|
3
38
|
## [0.0.3-next.1](https://github.com/twinfoundation/engine/compare/engine-types-v0.0.3-next.0...engine-types-v0.0.3-next.1) (2025-11-13)
|
|
4
39
|
|
|
5
40
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/engine-types",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.3",
|
|
4
4
|
"description": "Types to use in an engine.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@twin.org/document-management-models": "next",
|
|
55
55
|
"@twin.org/document-management-rest-client": "next",
|
|
56
56
|
"@twin.org/document-management-service": "next",
|
|
57
|
-
"@twin.org/engine-core": "0.0.3-next.
|
|
58
|
-
"@twin.org/engine-models": "0.0.3-next.
|
|
57
|
+
"@twin.org/engine-core": "0.0.3-next.3",
|
|
58
|
+
"@twin.org/engine-models": "0.0.3-next.3",
|
|
59
59
|
"@twin.org/entity": "next",
|
|
60
60
|
"@twin.org/entity-storage-connector-cosmosdb": "next",
|
|
61
61
|
"@twin.org/entity-storage-connector-dynamodb": "next",
|