@twin.org/engine-types 0.0.1-next.35 → 0.0.1-next.36
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/dist/cjs/index.cjs +92 -90
- package/dist/esm/index.mjs +92 -90
- package/docs/changelog.md +1 -1
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -224,102 +224,104 @@ const EntityStorageConnectorType = {
|
|
|
224
224
|
*/
|
|
225
225
|
function initialiseEntityStorageConnector(engineCore, context, typeCustom, schema) {
|
|
226
226
|
const instanceName = core.StringHelper.kebabCase(schema);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
227
|
+
if (!entityStorageModels.EntityStorageConnectorFactory.hasName(instanceName)) {
|
|
228
|
+
let entityStorageConfig;
|
|
229
|
+
if (core.Is.stringValue(typeCustom)) {
|
|
230
|
+
// A custom type has been specified, so look it up
|
|
231
|
+
entityStorageConfig = context.config.types.entityStorageConnector?.find(c => c.type === typeCustom || c.overrideInstanceType === typeCustom);
|
|
232
|
+
if (core.Is.empty(entityStorageConfig)) {
|
|
233
|
+
throw new core.GeneralError("engineCore", "entityStorageCustomMissing", {
|
|
234
|
+
typeCustom,
|
|
235
|
+
storageName: instanceName
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
// The default entity storage method is either the one with the isDefault flag set
|
|
241
|
+
// or pick the first one if no default is set.
|
|
242
|
+
entityStorageConfig =
|
|
243
|
+
context.config.types.entityStorageConnector?.find(c => c.isDefault ?? false) ??
|
|
244
|
+
context.config.types.entityStorageConnector?.[0];
|
|
245
|
+
if (core.Is.empty(entityStorageConfig)) {
|
|
246
|
+
throw new core.GeneralError("engineCore", "entityStorageMissing", {
|
|
247
|
+
storageName: instanceName
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const type = entityStorageConfig.type;
|
|
252
|
+
let entityStorageConnector;
|
|
253
|
+
engineCore.logInfo(core.I18n.formatMessage("engineCore.configuringEntityStorage", {
|
|
254
|
+
element: "Entity Storage",
|
|
255
|
+
storageName: instanceName,
|
|
256
|
+
storageType: type
|
|
257
|
+
}));
|
|
258
|
+
if (type === EntityStorageConnectorType.Memory) {
|
|
259
|
+
entityStorageConnector = new entityStorageConnectorMemory.MemoryEntityStorageConnector({
|
|
260
|
+
entitySchema: schema
|
|
235
261
|
});
|
|
236
262
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
throw new core.GeneralError("engineCore", "entityStorageMissing", {
|
|
246
|
-
storageName: instanceName
|
|
263
|
+
else if (type === EntityStorageConnectorType.File) {
|
|
264
|
+
entityStorageConnector = new entityStorageConnectorFile.FileEntityStorageConnector({
|
|
265
|
+
entitySchema: schema,
|
|
266
|
+
...entityStorageConfig.options,
|
|
267
|
+
config: {
|
|
268
|
+
...entityStorageConfig.options.config,
|
|
269
|
+
directory: path.join(entityStorageConfig.options.config.directory, `${entityStorageConfig.options.folderPrefix ?? ""}${instanceName}`)
|
|
270
|
+
}
|
|
247
271
|
});
|
|
248
272
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
collectionName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
else if (type === EntityStorageConnectorType.ScyllaDb) {
|
|
303
|
-
entityStorageConnector = new entityStorageConnectorScylladb.ScyllaDBTableConnector({
|
|
304
|
-
entitySchema: schema,
|
|
305
|
-
...entityStorageConfig.options,
|
|
306
|
-
config: {
|
|
307
|
-
...entityStorageConfig.options.config,
|
|
308
|
-
tableName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
314
|
-
type,
|
|
315
|
-
connectorType: "entityStorageConnector"
|
|
273
|
+
else if (type === EntityStorageConnectorType.AwsDynamoDb) {
|
|
274
|
+
entityStorageConnector = new entityStorageConnectorDynamodb.DynamoDbEntityStorageConnector({
|
|
275
|
+
entitySchema: schema,
|
|
276
|
+
...entityStorageConfig.options,
|
|
277
|
+
config: {
|
|
278
|
+
...entityStorageConfig.options.config,
|
|
279
|
+
tableName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
else if (type === EntityStorageConnectorType.AzureCosmosDb) {
|
|
284
|
+
entityStorageConnector = new entityStorageConnectorCosmosdb.CosmosDbEntityStorageConnector({
|
|
285
|
+
entitySchema: schema,
|
|
286
|
+
...entityStorageConfig.options,
|
|
287
|
+
config: {
|
|
288
|
+
...entityStorageConfig.options.config,
|
|
289
|
+
containerId: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
else if (type === EntityStorageConnectorType.GcpFirestoreDb) {
|
|
294
|
+
entityStorageConnector = new entityStorageConnectorGcpFirestore.FirestoreEntityStorageConnector({
|
|
295
|
+
entitySchema: schema,
|
|
296
|
+
...entityStorageConfig.options,
|
|
297
|
+
config: {
|
|
298
|
+
...entityStorageConfig.options.config,
|
|
299
|
+
collectionName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
else if (type === EntityStorageConnectorType.ScyllaDb) {
|
|
304
|
+
entityStorageConnector = new entityStorageConnectorScylladb.ScyllaDBTableConnector({
|
|
305
|
+
entitySchema: schema,
|
|
306
|
+
...entityStorageConfig.options,
|
|
307
|
+
config: {
|
|
308
|
+
...entityStorageConfig.options.config,
|
|
309
|
+
tableName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
throw new core.GeneralError("engineCore", "connectorUnknownType", {
|
|
315
|
+
type,
|
|
316
|
+
connectorType: "entityStorageConnector"
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
context.componentInstances.push({
|
|
320
|
+
instanceType: instanceName,
|
|
321
|
+
component: entityStorageConnector
|
|
316
322
|
});
|
|
323
|
+
entityStorageModels.EntityStorageConnectorFactory.register(instanceName, () => entityStorageConnector);
|
|
317
324
|
}
|
|
318
|
-
context.componentInstances.push({
|
|
319
|
-
instanceType: instanceName,
|
|
320
|
-
component: entityStorageConnector
|
|
321
|
-
});
|
|
322
|
-
entityStorageModels.EntityStorageConnectorFactory.register(instanceName, () => entityStorageConnector);
|
|
323
325
|
}
|
|
324
326
|
/**
|
|
325
327
|
* Initialise the entity storage connector.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -222,102 +222,104 @@ const EntityStorageConnectorType = {
|
|
|
222
222
|
*/
|
|
223
223
|
function initialiseEntityStorageConnector(engineCore, context, typeCustom, schema) {
|
|
224
224
|
const instanceName = StringHelper.kebabCase(schema);
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
225
|
+
if (!EntityStorageConnectorFactory.hasName(instanceName)) {
|
|
226
|
+
let entityStorageConfig;
|
|
227
|
+
if (Is.stringValue(typeCustom)) {
|
|
228
|
+
// A custom type has been specified, so look it up
|
|
229
|
+
entityStorageConfig = context.config.types.entityStorageConnector?.find(c => c.type === typeCustom || c.overrideInstanceType === typeCustom);
|
|
230
|
+
if (Is.empty(entityStorageConfig)) {
|
|
231
|
+
throw new GeneralError("engineCore", "entityStorageCustomMissing", {
|
|
232
|
+
typeCustom,
|
|
233
|
+
storageName: instanceName
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
// The default entity storage method is either the one with the isDefault flag set
|
|
239
|
+
// or pick the first one if no default is set.
|
|
240
|
+
entityStorageConfig =
|
|
241
|
+
context.config.types.entityStorageConnector?.find(c => c.isDefault ?? false) ??
|
|
242
|
+
context.config.types.entityStorageConnector?.[0];
|
|
243
|
+
if (Is.empty(entityStorageConfig)) {
|
|
244
|
+
throw new GeneralError("engineCore", "entityStorageMissing", {
|
|
245
|
+
storageName: instanceName
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const type = entityStorageConfig.type;
|
|
250
|
+
let entityStorageConnector;
|
|
251
|
+
engineCore.logInfo(I18n.formatMessage("engineCore.configuringEntityStorage", {
|
|
252
|
+
element: "Entity Storage",
|
|
253
|
+
storageName: instanceName,
|
|
254
|
+
storageType: type
|
|
255
|
+
}));
|
|
256
|
+
if (type === EntityStorageConnectorType.Memory) {
|
|
257
|
+
entityStorageConnector = new MemoryEntityStorageConnector({
|
|
258
|
+
entitySchema: schema
|
|
233
259
|
});
|
|
234
260
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
throw new GeneralError("engineCore", "entityStorageMissing", {
|
|
244
|
-
storageName: instanceName
|
|
261
|
+
else if (type === EntityStorageConnectorType.File) {
|
|
262
|
+
entityStorageConnector = new FileEntityStorageConnector({
|
|
263
|
+
entitySchema: schema,
|
|
264
|
+
...entityStorageConfig.options,
|
|
265
|
+
config: {
|
|
266
|
+
...entityStorageConfig.options.config,
|
|
267
|
+
directory: path.join(entityStorageConfig.options.config.directory, `${entityStorageConfig.options.folderPrefix ?? ""}${instanceName}`)
|
|
268
|
+
}
|
|
245
269
|
});
|
|
246
270
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
collectionName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
else if (type === EntityStorageConnectorType.ScyllaDb) {
|
|
301
|
-
entityStorageConnector = new ScyllaDBTableConnector({
|
|
302
|
-
entitySchema: schema,
|
|
303
|
-
...entityStorageConfig.options,
|
|
304
|
-
config: {
|
|
305
|
-
...entityStorageConfig.options.config,
|
|
306
|
-
tableName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
throw new GeneralError("engineCore", "connectorUnknownType", {
|
|
312
|
-
type,
|
|
313
|
-
connectorType: "entityStorageConnector"
|
|
271
|
+
else if (type === EntityStorageConnectorType.AwsDynamoDb) {
|
|
272
|
+
entityStorageConnector = new DynamoDbEntityStorageConnector({
|
|
273
|
+
entitySchema: schema,
|
|
274
|
+
...entityStorageConfig.options,
|
|
275
|
+
config: {
|
|
276
|
+
...entityStorageConfig.options.config,
|
|
277
|
+
tableName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
else if (type === EntityStorageConnectorType.AzureCosmosDb) {
|
|
282
|
+
entityStorageConnector = new CosmosDbEntityStorageConnector({
|
|
283
|
+
entitySchema: schema,
|
|
284
|
+
...entityStorageConfig.options,
|
|
285
|
+
config: {
|
|
286
|
+
...entityStorageConfig.options.config,
|
|
287
|
+
containerId: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
else if (type === EntityStorageConnectorType.GcpFirestoreDb) {
|
|
292
|
+
entityStorageConnector = new FirestoreEntityStorageConnector({
|
|
293
|
+
entitySchema: schema,
|
|
294
|
+
...entityStorageConfig.options,
|
|
295
|
+
config: {
|
|
296
|
+
...entityStorageConfig.options.config,
|
|
297
|
+
collectionName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
else if (type === EntityStorageConnectorType.ScyllaDb) {
|
|
302
|
+
entityStorageConnector = new ScyllaDBTableConnector({
|
|
303
|
+
entitySchema: schema,
|
|
304
|
+
...entityStorageConfig.options,
|
|
305
|
+
config: {
|
|
306
|
+
...entityStorageConfig.options.config,
|
|
307
|
+
tableName: `${entityStorageConfig.options.tablePrefix ?? ""}${instanceName}`
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
throw new GeneralError("engineCore", "connectorUnknownType", {
|
|
313
|
+
type,
|
|
314
|
+
connectorType: "entityStorageConnector"
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
context.componentInstances.push({
|
|
318
|
+
instanceType: instanceName,
|
|
319
|
+
component: entityStorageConnector
|
|
314
320
|
});
|
|
321
|
+
EntityStorageConnectorFactory.register(instanceName, () => entityStorageConnector);
|
|
315
322
|
}
|
|
316
|
-
context.componentInstances.push({
|
|
317
|
-
instanceType: instanceName,
|
|
318
|
-
component: entityStorageConnector
|
|
319
|
-
});
|
|
320
|
-
EntityStorageConnectorFactory.register(instanceName, () => entityStorageConnector);
|
|
321
323
|
}
|
|
322
324
|
/**
|
|
323
325
|
* Initialise the entity storage connector.
|
package/docs/changelog.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/engine-types",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.36",
|
|
4
4
|
"description": "Types to use in an engine.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@twin.org/crypto": "next",
|
|
19
19
|
"@twin.org/data-core": "next",
|
|
20
20
|
"@twin.org/data-schema-org": "next",
|
|
21
|
-
"@twin.org/engine-models": "0.0.1-next.
|
|
21
|
+
"@twin.org/engine-models": "0.0.1-next.36",
|
|
22
22
|
"@twin.org/entity": "next",
|
|
23
23
|
"@twin.org/modules": "next",
|
|
24
24
|
"@twin.org/nameof": "next"
|