@elek-io/core 0.1.0 → 0.2.0
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/index.cjs +275 -158
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +99 -47
- package/dist/index.d.ts +99 -47
- package/dist/index.js +297 -179
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -113,11 +113,11 @@ var pathTo = {
|
|
|
113
113
|
`${id}.${language}.json`
|
|
114
114
|
);
|
|
115
115
|
},
|
|
116
|
-
|
|
117
|
-
return import_path.default.join(pathTo.project(projectId), "values");
|
|
116
|
+
sharedValues: (projectId) => {
|
|
117
|
+
return import_path.default.join(pathTo.project(projectId), "shared-values");
|
|
118
118
|
},
|
|
119
|
-
|
|
120
|
-
return import_path.default.join(pathTo.
|
|
119
|
+
sharedValueFile: (projectId, id, language) => {
|
|
120
|
+
return import_path.default.join(pathTo.sharedValues(projectId), `${id}.${language}.json`);
|
|
121
121
|
},
|
|
122
122
|
assets: (projectId) => {
|
|
123
123
|
return import_path.default.join(
|
|
@@ -314,19 +314,19 @@ var AbstractCrudService = class {
|
|
|
314
314
|
*/
|
|
315
315
|
async listReferences(type, projectId, collectionId) {
|
|
316
316
|
switch (type) {
|
|
317
|
-
case import_shared2.
|
|
317
|
+
case import_shared2.objectTypeSchema.Enum.asset:
|
|
318
318
|
if (!projectId) {
|
|
319
319
|
throw new RequiredParameterMissingError("projectId");
|
|
320
320
|
}
|
|
321
321
|
return this.getFileReferences(pathTo.lfs(projectId));
|
|
322
|
-
case import_shared2.
|
|
322
|
+
case import_shared2.objectTypeSchema.Enum.project:
|
|
323
323
|
return this.getFolderReferences(pathTo.projects);
|
|
324
|
-
case import_shared2.
|
|
324
|
+
case import_shared2.objectTypeSchema.Enum.collection:
|
|
325
325
|
if (!projectId) {
|
|
326
326
|
throw new RequiredParameterMissingError("projectId");
|
|
327
327
|
}
|
|
328
328
|
return this.getFolderReferences(pathTo.collections(projectId));
|
|
329
|
-
case import_shared2.
|
|
329
|
+
case import_shared2.objectTypeSchema.Enum.entry:
|
|
330
330
|
if (!projectId) {
|
|
331
331
|
throw new RequiredParameterMissingError("projectId");
|
|
332
332
|
}
|
|
@@ -336,11 +336,11 @@ var AbstractCrudService = class {
|
|
|
336
336
|
return this.getFileReferences(
|
|
337
337
|
pathTo.collection(projectId, collectionId)
|
|
338
338
|
);
|
|
339
|
-
case import_shared2.
|
|
339
|
+
case import_shared2.objectTypeSchema.Enum.sharedValue:
|
|
340
340
|
if (!projectId) {
|
|
341
341
|
throw new RequiredParameterMissingError("projectId");
|
|
342
342
|
}
|
|
343
|
-
return this.getFileReferences(pathTo.
|
|
343
|
+
return this.getFileReferences(pathTo.sharedValues(projectId));
|
|
344
344
|
default:
|
|
345
345
|
throw new Error(`Trying to list files of unsupported type "${type}"`);
|
|
346
346
|
}
|
|
@@ -1020,7 +1020,7 @@ var AssetService = class extends AbstractCrudService {
|
|
|
1020
1020
|
);
|
|
1021
1021
|
const assetFile = {
|
|
1022
1022
|
...props,
|
|
1023
|
-
|
|
1023
|
+
objectType: "asset",
|
|
1024
1024
|
id,
|
|
1025
1025
|
created: (0, import_shared7.currentTimestamp)(),
|
|
1026
1026
|
extension: fileType.extension,
|
|
@@ -1129,7 +1129,7 @@ var AssetService = class extends AbstractCrudService {
|
|
|
1129
1129
|
async list(props) {
|
|
1130
1130
|
import_shared7.listAssetsSchema.parse(props);
|
|
1131
1131
|
const assetReferences = await this.listReferences(
|
|
1132
|
-
import_shared7.
|
|
1132
|
+
import_shared7.objectTypeSchema.Enum.asset,
|
|
1133
1133
|
props.projectId
|
|
1134
1134
|
);
|
|
1135
1135
|
const list = await returnResolved(
|
|
@@ -1155,7 +1155,7 @@ var AssetService = class extends AbstractCrudService {
|
|
|
1155
1155
|
}
|
|
1156
1156
|
async count(props) {
|
|
1157
1157
|
import_shared7.countAssetsSchema.parse(props);
|
|
1158
|
-
const count = (await this.listReferences(import_shared7.
|
|
1158
|
+
const count = (await this.listReferences(import_shared7.objectTypeSchema.Enum.asset, props.projectId)).length;
|
|
1159
1159
|
return count;
|
|
1160
1160
|
}
|
|
1161
1161
|
/**
|
|
@@ -1203,14 +1203,14 @@ var AssetService = class extends AbstractCrudService {
|
|
|
1203
1203
|
const fileBuffer = await import_fs_extra3.default.readFile(filePath);
|
|
1204
1204
|
if ((0, import_is_svg.default)(fileBuffer.toString()) === true) {
|
|
1205
1205
|
return {
|
|
1206
|
-
extension: import_shared7.
|
|
1207
|
-
mimeType: import_shared7.
|
|
1206
|
+
extension: import_shared7.supportedAssetExtensionSchema.Enum.svg,
|
|
1207
|
+
mimeType: import_shared7.supportedAssetMimeTypeSchema.Enum["image/svg+xml"]
|
|
1208
1208
|
};
|
|
1209
1209
|
}
|
|
1210
1210
|
}
|
|
1211
1211
|
const { fileTypeFromFile } = await import("file-type");
|
|
1212
1212
|
const fileType = await fileTypeFromFile(filePath);
|
|
1213
|
-
const result = import_shared7.
|
|
1213
|
+
const result = import_shared7.supportedAssetTypeSchema.parse({
|
|
1214
1214
|
extension: fileType?.ext,
|
|
1215
1215
|
mimeType: fileType?.mime
|
|
1216
1216
|
});
|
|
@@ -1241,7 +1241,7 @@ var CollectionService = class extends AbstractCrudService {
|
|
|
1241
1241
|
);
|
|
1242
1242
|
const collectionFile = {
|
|
1243
1243
|
...props,
|
|
1244
|
-
|
|
1244
|
+
objectType: "collection",
|
|
1245
1245
|
id,
|
|
1246
1246
|
slug: {
|
|
1247
1247
|
singular: (0, import_shared8.slug)(props.slug.singular),
|
|
@@ -1321,7 +1321,7 @@ var CollectionService = class extends AbstractCrudService {
|
|
|
1321
1321
|
async list(props) {
|
|
1322
1322
|
import_shared8.listCollectionsSchema.parse(props);
|
|
1323
1323
|
const references = await this.listReferences(
|
|
1324
|
-
import_shared8.
|
|
1324
|
+
import_shared8.objectTypeSchema.Enum.collection,
|
|
1325
1325
|
props.projectId
|
|
1326
1326
|
);
|
|
1327
1327
|
const list = await returnResolved(
|
|
@@ -1342,7 +1342,10 @@ var CollectionService = class extends AbstractCrudService {
|
|
|
1342
1342
|
}
|
|
1343
1343
|
async count(props) {
|
|
1344
1344
|
import_shared8.countCollectionsSchema.parse(props);
|
|
1345
|
-
const count = (await this.listReferences(
|
|
1345
|
+
const count = (await this.listReferences(
|
|
1346
|
+
import_shared8.objectTypeSchema.Enum.collection,
|
|
1347
|
+
props.projectId
|
|
1348
|
+
)).length;
|
|
1346
1349
|
return count;
|
|
1347
1350
|
}
|
|
1348
1351
|
/**
|
|
@@ -1357,86 +1360,94 @@ var CollectionService = class extends AbstractCrudService {
|
|
|
1357
1360
|
var import_shared10 = require("@elek-io/shared");
|
|
1358
1361
|
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
1359
1362
|
|
|
1360
|
-
// src/service/
|
|
1363
|
+
// src/service/SharedValueService.ts
|
|
1361
1364
|
var import_shared9 = require("@elek-io/shared");
|
|
1362
1365
|
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
1363
|
-
var
|
|
1366
|
+
var SharedValueService = class extends AbstractCrudService {
|
|
1364
1367
|
constructor(options, jsonFileService, gitService, assetService) {
|
|
1365
1368
|
super(import_shared9.serviceTypeSchema.Enum.Value, options);
|
|
1366
1369
|
this.jsonFileService = jsonFileService;
|
|
1367
1370
|
this.gitService = gitService;
|
|
1368
1371
|
}
|
|
1369
1372
|
/**
|
|
1370
|
-
* Creates a new Value
|
|
1373
|
+
* Creates a new shared Value
|
|
1371
1374
|
*/
|
|
1372
1375
|
async create(props) {
|
|
1373
|
-
import_shared9.
|
|
1376
|
+
import_shared9.createSharedValueSchema.parse(props);
|
|
1374
1377
|
const id = (0, import_shared9.uuid)();
|
|
1375
1378
|
const projectPath = pathTo.project(props.projectId);
|
|
1376
|
-
const
|
|
1379
|
+
const sharedValueFilePath = pathTo.sharedValueFile(
|
|
1377
1380
|
props.projectId,
|
|
1378
1381
|
id,
|
|
1379
1382
|
props.language
|
|
1380
1383
|
);
|
|
1381
|
-
const
|
|
1384
|
+
const sharedValueFile = {
|
|
1382
1385
|
...props,
|
|
1383
|
-
|
|
1386
|
+
objectType: "sharedValue",
|
|
1384
1387
|
id,
|
|
1385
1388
|
created: (0, import_shared9.currentTimestamp)()
|
|
1386
1389
|
};
|
|
1390
|
+
this.validate(sharedValueFile);
|
|
1387
1391
|
await this.jsonFileService.create(
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
import_shared9.
|
|
1392
|
+
sharedValueFile,
|
|
1393
|
+
sharedValueFilePath,
|
|
1394
|
+
import_shared9.sharedValueFileSchema
|
|
1391
1395
|
);
|
|
1392
|
-
await this.gitService.add(projectPath, [
|
|
1396
|
+
await this.gitService.add(projectPath, [sharedValueFilePath]);
|
|
1393
1397
|
await this.gitService.commit(projectPath, this.gitMessage.create);
|
|
1394
|
-
return
|
|
1398
|
+
return sharedValueFile;
|
|
1395
1399
|
}
|
|
1396
1400
|
/**
|
|
1397
|
-
* Returns a Value by ID and language
|
|
1401
|
+
* Returns a shared Value by ID and language
|
|
1398
1402
|
*/
|
|
1399
1403
|
async read(props) {
|
|
1400
|
-
import_shared9.
|
|
1401
|
-
const
|
|
1402
|
-
pathTo.
|
|
1403
|
-
|
|
1404
|
+
import_shared9.readSharedValueSchema.parse(props);
|
|
1405
|
+
const sharedValueFile = await this.jsonFileService.read(
|
|
1406
|
+
pathTo.sharedValueFile(
|
|
1407
|
+
props.projectId,
|
|
1408
|
+
props.id,
|
|
1409
|
+
props.language
|
|
1410
|
+
),
|
|
1411
|
+
import_shared9.sharedValueFileSchema
|
|
1404
1412
|
);
|
|
1405
|
-
return
|
|
1413
|
+
return sharedValueFile;
|
|
1406
1414
|
}
|
|
1407
1415
|
/**
|
|
1408
|
-
* Updates given
|
|
1416
|
+
* Updates given shared Values content
|
|
1417
|
+
*
|
|
1418
|
+
* The valueType cannot be changed after creating the shared Value
|
|
1409
1419
|
*/
|
|
1410
1420
|
async update(props) {
|
|
1411
|
-
import_shared9.
|
|
1421
|
+
import_shared9.updateSharedValueSchema.parse(props);
|
|
1412
1422
|
const projectPath = pathTo.project(props.projectId);
|
|
1413
|
-
const
|
|
1423
|
+
const sharedValueFilePath = pathTo.sharedValueFile(
|
|
1414
1424
|
props.projectId,
|
|
1415
1425
|
props.id,
|
|
1416
1426
|
props.language
|
|
1417
1427
|
);
|
|
1418
|
-
const
|
|
1419
|
-
const
|
|
1420
|
-
...
|
|
1421
|
-
|
|
1428
|
+
const prevSharedValueFile = await this.read(props);
|
|
1429
|
+
const sharedValueFile = {
|
|
1430
|
+
...prevSharedValueFile,
|
|
1431
|
+
content: props.content,
|
|
1422
1432
|
updated: (0, import_shared9.currentTimestamp)()
|
|
1423
1433
|
};
|
|
1434
|
+
this.validate(sharedValueFile);
|
|
1424
1435
|
await this.jsonFileService.update(
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
import_shared9.
|
|
1436
|
+
sharedValueFile,
|
|
1437
|
+
sharedValueFilePath,
|
|
1438
|
+
import_shared9.sharedValueFileSchema
|
|
1428
1439
|
);
|
|
1429
|
-
await this.gitService.add(projectPath, [
|
|
1440
|
+
await this.gitService.add(projectPath, [sharedValueFilePath]);
|
|
1430
1441
|
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
1431
|
-
return
|
|
1442
|
+
return sharedValueFile;
|
|
1432
1443
|
}
|
|
1433
1444
|
/**
|
|
1434
|
-
* Deletes given Value
|
|
1445
|
+
* Deletes given shared Value
|
|
1435
1446
|
*/
|
|
1436
1447
|
async delete(props) {
|
|
1437
|
-
import_shared9.
|
|
1448
|
+
import_shared9.deleteSharedValueSchema.parse(props);
|
|
1438
1449
|
const projectPath = pathTo.project(props.projectId);
|
|
1439
|
-
const valueFilePath = pathTo.
|
|
1450
|
+
const valueFilePath = pathTo.sharedValueFile(
|
|
1440
1451
|
props.projectId,
|
|
1441
1452
|
props.id,
|
|
1442
1453
|
props.language
|
|
@@ -1446,9 +1457,9 @@ var ValueService = class extends AbstractCrudService {
|
|
|
1446
1457
|
await this.gitService.commit(projectPath, this.gitMessage.delete);
|
|
1447
1458
|
}
|
|
1448
1459
|
async list(props) {
|
|
1449
|
-
import_shared9.
|
|
1460
|
+
import_shared9.listSharedValuesSchema.parse(props);
|
|
1450
1461
|
const references = await this.listReferences(
|
|
1451
|
-
import_shared9.
|
|
1462
|
+
import_shared9.objectTypeSchema.Enum.sharedValue,
|
|
1452
1463
|
props.projectId
|
|
1453
1464
|
);
|
|
1454
1465
|
const list = await returnResolved(
|
|
@@ -1473,37 +1484,52 @@ var ValueService = class extends AbstractCrudService {
|
|
|
1473
1484
|
}
|
|
1474
1485
|
async count(props) {
|
|
1475
1486
|
import_shared9.countValuesSchema.parse(props);
|
|
1476
|
-
const count = (await this.listReferences(
|
|
1487
|
+
const count = (await this.listReferences(
|
|
1488
|
+
import_shared9.objectTypeSchema.Enum.sharedValue,
|
|
1489
|
+
props.projectId
|
|
1490
|
+
)).length;
|
|
1477
1491
|
return count;
|
|
1478
1492
|
}
|
|
1479
1493
|
/**
|
|
1480
|
-
* Checks if given object is
|
|
1494
|
+
* Checks if given object is a shared Value
|
|
1481
1495
|
*/
|
|
1482
|
-
|
|
1483
|
-
return import_shared9.
|
|
1496
|
+
isSharedValue(obj) {
|
|
1497
|
+
return import_shared9.sharedValueSchema.safeParse(obj).success;
|
|
1484
1498
|
}
|
|
1485
1499
|
/**
|
|
1486
|
-
* Reads the given
|
|
1500
|
+
* Reads the given shared Values content based on it's ValueType
|
|
1487
1501
|
*/
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1502
|
+
validate(sharedValue) {
|
|
1503
|
+
switch (sharedValue.valueType) {
|
|
1504
|
+
case import_shared9.ValueTypeSchema.Enum.boolean:
|
|
1505
|
+
import_shared9.z.boolean().parse(sharedValue.content);
|
|
1506
|
+
break;
|
|
1507
|
+
case import_shared9.ValueTypeSchema.Enum.number:
|
|
1508
|
+
import_shared9.z.number().parse(sharedValue.content);
|
|
1509
|
+
break;
|
|
1510
|
+
case import_shared9.ValueTypeSchema.Enum.string:
|
|
1511
|
+
import_shared9.z.string().parse(sharedValue.content);
|
|
1512
|
+
break;
|
|
1513
|
+
default:
|
|
1514
|
+
throw new Error(
|
|
1515
|
+
`Error validating content of unsupported shared Value with ValueType "${sharedValue.valueType}"`
|
|
1516
|
+
);
|
|
1517
|
+
}
|
|
1493
1518
|
}
|
|
1494
1519
|
};
|
|
1495
1520
|
|
|
1496
1521
|
// src/service/EntryService.ts
|
|
1497
1522
|
var EntryService = class extends AbstractCrudService {
|
|
1498
|
-
constructor(options, jsonFileService, gitService, collectionService,
|
|
1523
|
+
constructor(options, jsonFileService, gitService, collectionService, assetService, sharedValueService) {
|
|
1499
1524
|
super(import_shared10.serviceTypeSchema.Enum.Entry, options);
|
|
1500
1525
|
this.jsonFileService = jsonFileService;
|
|
1501
1526
|
this.gitService = gitService;
|
|
1502
1527
|
this.collectionService = collectionService;
|
|
1503
|
-
this.
|
|
1528
|
+
this.assetService = assetService;
|
|
1529
|
+
this.sharedValueService = sharedValueService;
|
|
1504
1530
|
}
|
|
1505
1531
|
/**
|
|
1506
|
-
* Creates a new Entry
|
|
1532
|
+
* Creates a new Entry for given Collection
|
|
1507
1533
|
*/
|
|
1508
1534
|
async create(props) {
|
|
1509
1535
|
import_shared10.createEntrySchema.parse(props);
|
|
@@ -1519,19 +1545,22 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1519
1545
|
projectId: props.projectId,
|
|
1520
1546
|
id: props.collectionId
|
|
1521
1547
|
});
|
|
1522
|
-
await this.validateValueReferences(
|
|
1523
|
-
props.projectId,
|
|
1524
|
-
props.collectionId,
|
|
1525
|
-
props.valueReferences,
|
|
1526
|
-
collection.valueDefinitions
|
|
1527
|
-
);
|
|
1528
1548
|
const entryFile = {
|
|
1529
|
-
|
|
1549
|
+
objectType: "entry",
|
|
1530
1550
|
id,
|
|
1531
1551
|
language: props.language,
|
|
1532
|
-
|
|
1552
|
+
values: props.values,
|
|
1533
1553
|
created: (0, import_shared10.currentTimestamp)()
|
|
1534
1554
|
};
|
|
1555
|
+
const entry = await this.toEntry({
|
|
1556
|
+
projectId: props.projectId,
|
|
1557
|
+
entryFile
|
|
1558
|
+
});
|
|
1559
|
+
this.validateValues({
|
|
1560
|
+
collectionId: props.collectionId,
|
|
1561
|
+
valueDefinitions: collection.valueDefinitions,
|
|
1562
|
+
values: entry.values
|
|
1563
|
+
});
|
|
1535
1564
|
await this.jsonFileService.create(
|
|
1536
1565
|
entryFile,
|
|
1537
1566
|
entryFilePath,
|
|
@@ -1539,10 +1568,10 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1539
1568
|
);
|
|
1540
1569
|
await this.gitService.add(projectPath, [entryFilePath]);
|
|
1541
1570
|
await this.gitService.commit(projectPath, this.gitMessage.create);
|
|
1542
|
-
return
|
|
1571
|
+
return entry;
|
|
1543
1572
|
}
|
|
1544
1573
|
/**
|
|
1545
|
-
* Returns an Entry by ID and language
|
|
1574
|
+
* Returns an Entry from given Collection by ID and language
|
|
1546
1575
|
*/
|
|
1547
1576
|
async read(props) {
|
|
1548
1577
|
import_shared10.readEntrySchema.parse(props);
|
|
@@ -1555,10 +1584,10 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1555
1584
|
),
|
|
1556
1585
|
import_shared10.entryFileSchema
|
|
1557
1586
|
);
|
|
1558
|
-
return entryFile;
|
|
1587
|
+
return await this.toEntry({ projectId: props.projectId, entryFile });
|
|
1559
1588
|
}
|
|
1560
1589
|
/**
|
|
1561
|
-
* Updates Entry
|
|
1590
|
+
* Updates an Entry of given Collection with new Values and shared Values
|
|
1562
1591
|
*/
|
|
1563
1592
|
async update(props) {
|
|
1564
1593
|
import_shared10.updateEntrySchema.parse(props);
|
|
@@ -1573,12 +1602,6 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1573
1602
|
projectId: props.projectId,
|
|
1574
1603
|
id: props.collectionId
|
|
1575
1604
|
});
|
|
1576
|
-
await this.validateValueReferences(
|
|
1577
|
-
props.projectId,
|
|
1578
|
-
props.collectionId,
|
|
1579
|
-
props.valueReferences,
|
|
1580
|
-
collection.valueDefinitions
|
|
1581
|
-
);
|
|
1582
1605
|
const prevEntryFile = await this.read({
|
|
1583
1606
|
projectId: props.projectId,
|
|
1584
1607
|
collectionId: props.collectionId,
|
|
@@ -1587,9 +1610,18 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1587
1610
|
});
|
|
1588
1611
|
const entryFile = {
|
|
1589
1612
|
...prevEntryFile,
|
|
1590
|
-
|
|
1613
|
+
values: props.values,
|
|
1591
1614
|
updated: (0, import_shared10.currentTimestamp)()
|
|
1592
1615
|
};
|
|
1616
|
+
const entry = await this.toEntry({
|
|
1617
|
+
projectId: props.projectId,
|
|
1618
|
+
entryFile
|
|
1619
|
+
});
|
|
1620
|
+
this.validateValues({
|
|
1621
|
+
collectionId: props.collectionId,
|
|
1622
|
+
valueDefinitions: collection.valueDefinitions,
|
|
1623
|
+
values: entry.values
|
|
1624
|
+
});
|
|
1593
1625
|
await this.jsonFileService.update(
|
|
1594
1626
|
entryFile,
|
|
1595
1627
|
entryFilePath,
|
|
@@ -1597,10 +1629,10 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1597
1629
|
);
|
|
1598
1630
|
await this.gitService.add(projectPath, [entryFilePath]);
|
|
1599
1631
|
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
1600
|
-
return
|
|
1632
|
+
return entry;
|
|
1601
1633
|
}
|
|
1602
1634
|
/**
|
|
1603
|
-
* Deletes given Entry
|
|
1635
|
+
* Deletes given Entry from it's Collection
|
|
1604
1636
|
*/
|
|
1605
1637
|
async delete(props) {
|
|
1606
1638
|
import_shared10.deleteEntrySchema.parse(props);
|
|
@@ -1618,7 +1650,7 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1618
1650
|
async list(props) {
|
|
1619
1651
|
import_shared10.listEntriesSchema.parse(props);
|
|
1620
1652
|
const references = await this.listReferences(
|
|
1621
|
-
import_shared10.
|
|
1653
|
+
import_shared10.objectTypeSchema.Enum.entry,
|
|
1622
1654
|
props.projectId,
|
|
1623
1655
|
props.collectionId
|
|
1624
1656
|
);
|
|
@@ -1646,45 +1678,147 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1646
1678
|
async count(props) {
|
|
1647
1679
|
import_shared10.countEntriesSchema.parse(props);
|
|
1648
1680
|
return (await this.listReferences(
|
|
1649
|
-
import_shared10.
|
|
1681
|
+
import_shared10.objectTypeSchema.Enum.entry,
|
|
1650
1682
|
props.projectId,
|
|
1651
1683
|
props.collectionId
|
|
1652
1684
|
)).length;
|
|
1653
1685
|
}
|
|
1654
1686
|
/**
|
|
1655
|
-
* Checks if given object of
|
|
1656
|
-
* Field, Project or Asset is of type CollectionItem
|
|
1687
|
+
* Checks if given object is of type Entry
|
|
1657
1688
|
*/
|
|
1658
1689
|
isEntry(obj) {
|
|
1659
1690
|
return import_shared10.entrySchema.safeParse(obj).success;
|
|
1660
1691
|
}
|
|
1661
1692
|
/**
|
|
1662
|
-
*
|
|
1663
|
-
*
|
|
1664
|
-
* @todo should probably return all errors occurring during parsing instead of throwing
|
|
1693
|
+
* Returns a Value definition by ID
|
|
1665
1694
|
*/
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1695
|
+
getValueDefinitionById(props) {
|
|
1696
|
+
const definition = props.valueDefinitions.find((def) => {
|
|
1697
|
+
if (def.id === props.id) {
|
|
1698
|
+
return true;
|
|
1699
|
+
}
|
|
1700
|
+
return false;
|
|
1701
|
+
});
|
|
1702
|
+
if (!definition) {
|
|
1703
|
+
throw new Error(
|
|
1704
|
+
`No definition with ID "${props.id}" found in Collection "${props.collectionId}" for given Value reference`
|
|
1705
|
+
);
|
|
1706
|
+
}
|
|
1707
|
+
return definition;
|
|
1708
|
+
}
|
|
1709
|
+
/**
|
|
1710
|
+
* Validates given Values against it's Collections definitions
|
|
1711
|
+
*/
|
|
1712
|
+
validateValues(props) {
|
|
1713
|
+
props.values.map((value) => {
|
|
1714
|
+
const definition = this.getValueDefinitionById({
|
|
1715
|
+
collectionId: props.collectionId,
|
|
1716
|
+
valueDefinitions: props.valueDefinitions,
|
|
1717
|
+
id: value.definitionId
|
|
1718
|
+
});
|
|
1719
|
+
const schema = (0, import_shared10.getValueContentSchemaFromDefinition)(definition);
|
|
1720
|
+
try {
|
|
1721
|
+
schema.parse(value.content);
|
|
1722
|
+
} catch (error) {
|
|
1723
|
+
console.log("Definition:", definition);
|
|
1724
|
+
console.log("Value:", value);
|
|
1725
|
+
throw error;
|
|
1726
|
+
}
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Validates given shared Value references against it's Collections definitions
|
|
1731
|
+
*/
|
|
1732
|
+
// private validateResolvedSharedValues(props: {
|
|
1733
|
+
// collectionId: string;
|
|
1734
|
+
// valueDefinitions: ValueDefinition[];
|
|
1735
|
+
// resolvedSharedValues: ResolvedSharedValueReference[];
|
|
1736
|
+
// }) {
|
|
1737
|
+
// props.resolvedSharedValues.map((value) => {
|
|
1738
|
+
// const definition = this.getValueDefinitionById({
|
|
1739
|
+
// collectionId: props.collectionId,
|
|
1740
|
+
// valueDefinitions: props.valueDefinitions,
|
|
1741
|
+
// id: value.definitionId,
|
|
1742
|
+
// });
|
|
1743
|
+
// const schema = getValueSchemaFromDefinition(definition);
|
|
1744
|
+
// schema.parse(value.resolved.content);
|
|
1745
|
+
// });
|
|
1746
|
+
// }
|
|
1747
|
+
async resolveValueContentReference(props) {
|
|
1748
|
+
switch (props.valueContentReference.referenceObjectType) {
|
|
1749
|
+
case import_shared10.objectTypeSchema.Enum.asset:
|
|
1750
|
+
return this.resolveValueContentReferenceToAsset({
|
|
1751
|
+
projectId: props.projectId,
|
|
1752
|
+
valueContentReferenceToAsset: props.valueContentReference
|
|
1674
1753
|
});
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
}
|
|
1680
|
-
const schema = (0, import_shared10.getValueSchemaFromDefinition)(definition);
|
|
1681
|
-
const value = await this.valueService.read({
|
|
1682
|
-
...reference.references,
|
|
1683
|
-
projectId
|
|
1754
|
+
case import_shared10.objectTypeSchema.Enum.sharedValue:
|
|
1755
|
+
return this.resolveValueContentReferenceToSharedValue({
|
|
1756
|
+
projectId: props.projectId,
|
|
1757
|
+
valueContentReferenceToSharedValue: props.valueContentReference
|
|
1684
1758
|
});
|
|
1685
|
-
|
|
1759
|
+
default:
|
|
1760
|
+
throw new Error(
|
|
1761
|
+
// @ts-ignore
|
|
1762
|
+
`Tried to resolve unsupported Value reference "${props.valueContentReference.referenceObjectType}"`
|
|
1763
|
+
);
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
async resolveValueContentReferenceToAsset(props) {
|
|
1767
|
+
const resolvedReferences = await Promise.all(
|
|
1768
|
+
props.valueContentReferenceToAsset.references.map(async (reference) => {
|
|
1769
|
+
const resolvedAsset = await this.assetService.read({
|
|
1770
|
+
projectId: props.projectId,
|
|
1771
|
+
id: reference.id,
|
|
1772
|
+
language: reference.language
|
|
1773
|
+
});
|
|
1774
|
+
return {
|
|
1775
|
+
...reference,
|
|
1776
|
+
resolved: resolvedAsset
|
|
1777
|
+
};
|
|
1686
1778
|
})
|
|
1687
1779
|
);
|
|
1780
|
+
return {
|
|
1781
|
+
...props.valueContentReferenceToAsset,
|
|
1782
|
+
references: resolvedReferences
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
async resolveValueContentReferenceToSharedValue(props) {
|
|
1786
|
+
const resolvedSharedValue = await this.sharedValueService.read({
|
|
1787
|
+
projectId: props.projectId,
|
|
1788
|
+
id: props.valueContentReferenceToSharedValue.references.id,
|
|
1789
|
+
language: props.valueContentReferenceToSharedValue.references.language
|
|
1790
|
+
});
|
|
1791
|
+
return {
|
|
1792
|
+
...props.valueContentReferenceToSharedValue,
|
|
1793
|
+
references: {
|
|
1794
|
+
...props.valueContentReferenceToSharedValue.references,
|
|
1795
|
+
resolved: resolvedSharedValue
|
|
1796
|
+
}
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* Creates an Entry from given EntryFile by resolving it's Values
|
|
1801
|
+
*/
|
|
1802
|
+
async toEntry(props) {
|
|
1803
|
+
const entry = {
|
|
1804
|
+
...props.entryFile,
|
|
1805
|
+
values: await Promise.all(
|
|
1806
|
+
props.entryFile.values.map(async (value) => {
|
|
1807
|
+
if (value.valueType === import_shared10.ValueTypeSchema.Enum.reference) {
|
|
1808
|
+
const resolvedValueContentReference = await this.resolveValueContentReference({
|
|
1809
|
+
projectId: props.projectId,
|
|
1810
|
+
valueContentReference: value.content
|
|
1811
|
+
});
|
|
1812
|
+
return {
|
|
1813
|
+
...value,
|
|
1814
|
+
content: resolvedValueContentReference
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
return value;
|
|
1818
|
+
})
|
|
1819
|
+
)
|
|
1820
|
+
};
|
|
1821
|
+
return entry;
|
|
1688
1822
|
}
|
|
1689
1823
|
};
|
|
1690
1824
|
|
|
@@ -1719,7 +1853,7 @@ var SearchService = class extends AbstractCrudService {
|
|
|
1719
1853
|
* @param project Project to search in
|
|
1720
1854
|
* @param query Query to search for
|
|
1721
1855
|
*/
|
|
1722
|
-
async search(projectId, query,
|
|
1856
|
+
async search(projectId, query, objectType) {
|
|
1723
1857
|
const results = [];
|
|
1724
1858
|
const normalizedQuery = query.trim();
|
|
1725
1859
|
if (normalizedQuery === "") {
|
|
@@ -1732,7 +1866,7 @@ var SearchService = class extends AbstractCrudService {
|
|
|
1732
1866
|
id: file.id,
|
|
1733
1867
|
language: file.language,
|
|
1734
1868
|
name: file.name,
|
|
1735
|
-
type: file.
|
|
1869
|
+
type: file.objectType,
|
|
1736
1870
|
matches: []
|
|
1737
1871
|
};
|
|
1738
1872
|
for (const [key, value] of Object.entries(file)) {
|
|
@@ -1772,7 +1906,7 @@ var SearchService = class extends AbstractCrudService {
|
|
|
1772
1906
|
|
|
1773
1907
|
// src/service/ProjectService.ts
|
|
1774
1908
|
var ProjectService = class extends AbstractCrudService {
|
|
1775
|
-
constructor(options, jsonFileService, userService, gitService, searchService, assetService, collectionService, entryService
|
|
1909
|
+
constructor(options, jsonFileService, userService, gitService, searchService, assetService, collectionService, entryService) {
|
|
1776
1910
|
super(import_shared12.serviceTypeSchema.Enum.Project, options);
|
|
1777
1911
|
this.jsonFileService = jsonFileService;
|
|
1778
1912
|
this.userService = userService;
|
|
@@ -1781,7 +1915,6 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1781
1915
|
this.assetService = assetService;
|
|
1782
1916
|
this.collectionService = collectionService;
|
|
1783
1917
|
this.entryService = entryService;
|
|
1784
|
-
this.valueService = valueService;
|
|
1785
1918
|
}
|
|
1786
1919
|
/**
|
|
1787
1920
|
* Creates a new Project
|
|
@@ -1801,7 +1934,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1801
1934
|
};
|
|
1802
1935
|
const projectFile = {
|
|
1803
1936
|
...props,
|
|
1804
|
-
|
|
1937
|
+
objectType: "project",
|
|
1805
1938
|
id,
|
|
1806
1939
|
description: props.description || "",
|
|
1807
1940
|
settings: Object.assign({}, defaultSettings, props.settings),
|
|
@@ -1946,7 +2079,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1946
2079
|
if (props) {
|
|
1947
2080
|
import_shared12.listProjectsSchema.parse(props);
|
|
1948
2081
|
}
|
|
1949
|
-
const references = await this.listReferences(import_shared12.
|
|
2082
|
+
const references = await this.listReferences(import_shared12.objectTypeSchema.Enum.project);
|
|
1950
2083
|
const list = await returnResolved(
|
|
1951
2084
|
references.map((reference) => {
|
|
1952
2085
|
return this.read({ id: reference.id });
|
|
@@ -1961,7 +2094,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1961
2094
|
);
|
|
1962
2095
|
}
|
|
1963
2096
|
async count() {
|
|
1964
|
-
return (await this.listReferences(import_shared12.
|
|
2097
|
+
return (await this.listReferences(import_shared12.objectTypeSchema.Enum.project)).length;
|
|
1965
2098
|
}
|
|
1966
2099
|
/**
|
|
1967
2100
|
* Search all models inside the project for given query
|
|
@@ -1982,6 +2115,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1982
2115
|
/**
|
|
1983
2116
|
* Exports given Project to JSON
|
|
1984
2117
|
*
|
|
2118
|
+
* @todo do not read everything before writing to disk -> stream into file given via props
|
|
1985
2119
|
* @todo performance tests
|
|
1986
2120
|
* @todo add progress callback
|
|
1987
2121
|
*/
|
|
@@ -1996,26 +2130,9 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1996
2130
|
collectionId: collection.id,
|
|
1997
2131
|
limit: 0
|
|
1998
2132
|
})).list;
|
|
1999
|
-
const entryExport = await Promise.all(
|
|
2000
|
-
entries.map(async (entry) => {
|
|
2001
|
-
const valueExport = await Promise.all(
|
|
2002
|
-
entry.valueReferences.map(async (valueReference) => {
|
|
2003
|
-
return this.valueService.read({
|
|
2004
|
-
projectId,
|
|
2005
|
-
id: valueReference.references.id,
|
|
2006
|
-
language: valueReference.references.language
|
|
2007
|
-
});
|
|
2008
|
-
})
|
|
2009
|
-
);
|
|
2010
|
-
return {
|
|
2011
|
-
...entry,
|
|
2012
|
-
values: valueExport
|
|
2013
|
-
};
|
|
2014
|
-
})
|
|
2015
|
-
);
|
|
2016
2133
|
return {
|
|
2017
2134
|
...collection,
|
|
2018
|
-
entries
|
|
2135
|
+
entries
|
|
2019
2136
|
};
|
|
2020
2137
|
})
|
|
2021
2138
|
);
|
|
@@ -2066,12 +2183,9 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2066
2183
|
// src/index.ts
|
|
2067
2184
|
var ElekIoCore = class {
|
|
2068
2185
|
constructor(props) {
|
|
2069
|
-
|
|
2070
|
-
import_shared13.constructorElekIoCoreSchema.parse(props);
|
|
2071
|
-
}
|
|
2072
|
-
const environment = import_shared13.environmentSchema.parse(process.env.NODE_ENV);
|
|
2186
|
+
const parsedProps = import_shared13.constructorElekIoCoreSchema.parse(props);
|
|
2073
2187
|
const defaults = {
|
|
2074
|
-
environment,
|
|
2188
|
+
environment: "production",
|
|
2075
2189
|
version: "0.0.0",
|
|
2076
2190
|
file: {
|
|
2077
2191
|
json: {
|
|
@@ -2079,7 +2193,7 @@ var ElekIoCore = class {
|
|
|
2079
2193
|
}
|
|
2080
2194
|
}
|
|
2081
2195
|
};
|
|
2082
|
-
this.options = Object.assign({}, defaults,
|
|
2196
|
+
this.options = Object.assign({}, defaults, parsedProps);
|
|
2083
2197
|
this.jsonFileService = new JsonFileService(this.options);
|
|
2084
2198
|
this.userService = new UserService(this.jsonFileService);
|
|
2085
2199
|
this.gitService = new GitService2(this.options, this.userService);
|
|
@@ -2088,23 +2202,24 @@ var ElekIoCore = class {
|
|
|
2088
2202
|
this.jsonFileService,
|
|
2089
2203
|
this.gitService
|
|
2090
2204
|
);
|
|
2091
|
-
this.
|
|
2205
|
+
this.collectionService = new CollectionService(
|
|
2092
2206
|
this.options,
|
|
2093
2207
|
this.jsonFileService,
|
|
2094
|
-
this.gitService
|
|
2095
|
-
this.assetService
|
|
2208
|
+
this.gitService
|
|
2096
2209
|
);
|
|
2097
|
-
this.
|
|
2210
|
+
this.sharedValueService = new SharedValueService(
|
|
2098
2211
|
this.options,
|
|
2099
2212
|
this.jsonFileService,
|
|
2100
|
-
this.gitService
|
|
2213
|
+
this.gitService,
|
|
2214
|
+
this.assetService
|
|
2101
2215
|
);
|
|
2102
2216
|
this.entryService = new EntryService(
|
|
2103
2217
|
this.options,
|
|
2104
2218
|
this.jsonFileService,
|
|
2105
2219
|
this.gitService,
|
|
2106
2220
|
this.collectionService,
|
|
2107
|
-
this.
|
|
2221
|
+
this.assetService,
|
|
2222
|
+
this.sharedValueService
|
|
2108
2223
|
);
|
|
2109
2224
|
this.searchService = new SearchService(
|
|
2110
2225
|
this.options,
|
|
@@ -2119,13 +2234,15 @@ var ElekIoCore = class {
|
|
|
2119
2234
|
this.searchService,
|
|
2120
2235
|
this.assetService,
|
|
2121
2236
|
this.collectionService,
|
|
2122
|
-
this.entryService
|
|
2123
|
-
this.valueService
|
|
2237
|
+
this.entryService
|
|
2124
2238
|
);
|
|
2125
|
-
if (environment !== "production") {
|
|
2126
|
-
console.info(
|
|
2127
|
-
|
|
2128
|
-
|
|
2239
|
+
if (this.options.environment !== "production") {
|
|
2240
|
+
console.info(
|
|
2241
|
+
`Initializing inside an "${this.options.environment}" environment`,
|
|
2242
|
+
{
|
|
2243
|
+
...this.options
|
|
2244
|
+
}
|
|
2245
|
+
);
|
|
2129
2246
|
}
|
|
2130
2247
|
import_fs_extra8.default.mkdirpSync(pathTo.projects);
|
|
2131
2248
|
import_fs_extra8.default.mkdirpSync(pathTo.tmp);
|
|
@@ -2170,8 +2287,8 @@ var ElekIoCore = class {
|
|
|
2170
2287
|
/**
|
|
2171
2288
|
* CRUD methods to work with Values
|
|
2172
2289
|
*/
|
|
2173
|
-
get
|
|
2174
|
-
return this.
|
|
2290
|
+
get sharedValues() {
|
|
2291
|
+
return this.sharedValueService;
|
|
2175
2292
|
}
|
|
2176
2293
|
};
|
|
2177
2294
|
//# sourceMappingURL=index.cjs.map
|