@elek-io/core 0.1.1 → 0.2.1
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 +268 -151
- 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 +289 -170
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -18,13 +18,13 @@ import {
|
|
|
18
18
|
createAssetSchema,
|
|
19
19
|
currentTimestamp,
|
|
20
20
|
deleteAssetSchema,
|
|
21
|
-
fileTypeSchema as fileTypeSchema2,
|
|
22
21
|
listAssetsSchema,
|
|
22
|
+
objectTypeSchema as objectTypeSchema2,
|
|
23
23
|
readAssetSchema,
|
|
24
24
|
serviceTypeSchema as serviceTypeSchema3,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
supportedAssetExtensionSchema,
|
|
26
|
+
supportedAssetMimeTypeSchema,
|
|
27
|
+
supportedAssetTypeSchema,
|
|
28
28
|
updateAssetSchema,
|
|
29
29
|
uuid as uuid2
|
|
30
30
|
} from "@elek-io/shared";
|
|
@@ -103,11 +103,11 @@ var pathTo = {
|
|
|
103
103
|
`${id}.${language}.json`
|
|
104
104
|
);
|
|
105
105
|
},
|
|
106
|
-
|
|
107
|
-
return Path.join(pathTo.project(projectId), "values");
|
|
106
|
+
sharedValues: (projectId) => {
|
|
107
|
+
return Path.join(pathTo.project(projectId), "shared-values");
|
|
108
108
|
},
|
|
109
|
-
|
|
110
|
-
return Path.join(pathTo.
|
|
109
|
+
sharedValueFile: (projectId, id, language) => {
|
|
110
|
+
return Path.join(pathTo.sharedValues(projectId), `${id}.${language}.json`);
|
|
111
111
|
},
|
|
112
112
|
assets: (projectId) => {
|
|
113
113
|
return Path.join(
|
|
@@ -235,8 +235,8 @@ function getDuplicates(arr, key) {
|
|
|
235
235
|
// src/service/AbstractCrudService.ts
|
|
236
236
|
import {
|
|
237
237
|
fileReferenceSchema,
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
gitCommitIconSchema,
|
|
239
|
+
objectTypeSchema
|
|
240
240
|
} from "@elek-io/shared";
|
|
241
241
|
import { orderBy, remove } from "lodash-es";
|
|
242
242
|
var AbstractCrudService = class {
|
|
@@ -308,19 +308,19 @@ var AbstractCrudService = class {
|
|
|
308
308
|
*/
|
|
309
309
|
async listReferences(type, projectId, collectionId) {
|
|
310
310
|
switch (type) {
|
|
311
|
-
case
|
|
311
|
+
case objectTypeSchema.Enum.asset:
|
|
312
312
|
if (!projectId) {
|
|
313
313
|
throw new RequiredParameterMissingError("projectId");
|
|
314
314
|
}
|
|
315
315
|
return this.getFileReferences(pathTo.lfs(projectId));
|
|
316
|
-
case
|
|
316
|
+
case objectTypeSchema.Enum.project:
|
|
317
317
|
return this.getFolderReferences(pathTo.projects);
|
|
318
|
-
case
|
|
318
|
+
case objectTypeSchema.Enum.collection:
|
|
319
319
|
if (!projectId) {
|
|
320
320
|
throw new RequiredParameterMissingError("projectId");
|
|
321
321
|
}
|
|
322
322
|
return this.getFolderReferences(pathTo.collections(projectId));
|
|
323
|
-
case
|
|
323
|
+
case objectTypeSchema.Enum.entry:
|
|
324
324
|
if (!projectId) {
|
|
325
325
|
throw new RequiredParameterMissingError("projectId");
|
|
326
326
|
}
|
|
@@ -330,11 +330,11 @@ var AbstractCrudService = class {
|
|
|
330
330
|
return this.getFileReferences(
|
|
331
331
|
pathTo.collection(projectId, collectionId)
|
|
332
332
|
);
|
|
333
|
-
case
|
|
333
|
+
case objectTypeSchema.Enum.sharedValue:
|
|
334
334
|
if (!projectId) {
|
|
335
335
|
throw new RequiredParameterMissingError("projectId");
|
|
336
336
|
}
|
|
337
|
-
return this.getFileReferences(pathTo.
|
|
337
|
+
return this.getFileReferences(pathTo.sharedValues(projectId));
|
|
338
338
|
default:
|
|
339
339
|
throw new Error(`Trying to list files of unsupported type "${type}"`);
|
|
340
340
|
}
|
|
@@ -1032,7 +1032,7 @@ var AssetService = class extends AbstractCrudService {
|
|
|
1032
1032
|
);
|
|
1033
1033
|
const assetFile = {
|
|
1034
1034
|
...props,
|
|
1035
|
-
|
|
1035
|
+
objectType: "asset",
|
|
1036
1036
|
id,
|
|
1037
1037
|
created: currentTimestamp(),
|
|
1038
1038
|
extension: fileType.extension,
|
|
@@ -1141,7 +1141,7 @@ var AssetService = class extends AbstractCrudService {
|
|
|
1141
1141
|
async list(props) {
|
|
1142
1142
|
listAssetsSchema.parse(props);
|
|
1143
1143
|
const assetReferences = await this.listReferences(
|
|
1144
|
-
|
|
1144
|
+
objectTypeSchema2.Enum.asset,
|
|
1145
1145
|
props.projectId
|
|
1146
1146
|
);
|
|
1147
1147
|
const list = await returnResolved(
|
|
@@ -1167,7 +1167,7 @@ var AssetService = class extends AbstractCrudService {
|
|
|
1167
1167
|
}
|
|
1168
1168
|
async count(props) {
|
|
1169
1169
|
countAssetsSchema.parse(props);
|
|
1170
|
-
const count = (await this.listReferences(
|
|
1170
|
+
const count = (await this.listReferences(objectTypeSchema2.Enum.asset, props.projectId)).length;
|
|
1171
1171
|
return count;
|
|
1172
1172
|
}
|
|
1173
1173
|
/**
|
|
@@ -1215,14 +1215,14 @@ var AssetService = class extends AbstractCrudService {
|
|
|
1215
1215
|
const fileBuffer = await Fs3.readFile(filePath);
|
|
1216
1216
|
if (IsSvg(fileBuffer.toString()) === true) {
|
|
1217
1217
|
return {
|
|
1218
|
-
extension:
|
|
1219
|
-
mimeType:
|
|
1218
|
+
extension: supportedAssetExtensionSchema.Enum.svg,
|
|
1219
|
+
mimeType: supportedAssetMimeTypeSchema.Enum["image/svg+xml"]
|
|
1220
1220
|
};
|
|
1221
1221
|
}
|
|
1222
1222
|
}
|
|
1223
1223
|
const { fileTypeFromFile } = await import("file-type");
|
|
1224
1224
|
const fileType = await fileTypeFromFile(filePath);
|
|
1225
|
-
const result =
|
|
1225
|
+
const result = supportedAssetTypeSchema.parse({
|
|
1226
1226
|
extension: fileType?.ext,
|
|
1227
1227
|
mimeType: fileType?.mime
|
|
1228
1228
|
});
|
|
@@ -1237,8 +1237,8 @@ import {
|
|
|
1237
1237
|
createCollectionSchema,
|
|
1238
1238
|
currentTimestamp as currentTimestamp2,
|
|
1239
1239
|
deleteCollectionSchema,
|
|
1240
|
-
fileTypeSchema as fileTypeSchema3,
|
|
1241
1240
|
listCollectionsSchema,
|
|
1241
|
+
objectTypeSchema as objectTypeSchema3,
|
|
1242
1242
|
readCollectionSchema,
|
|
1243
1243
|
serviceTypeSchema as serviceTypeSchema4,
|
|
1244
1244
|
slug,
|
|
@@ -1266,7 +1266,7 @@ var CollectionService = class extends AbstractCrudService {
|
|
|
1266
1266
|
);
|
|
1267
1267
|
const collectionFile = {
|
|
1268
1268
|
...props,
|
|
1269
|
-
|
|
1269
|
+
objectType: "collection",
|
|
1270
1270
|
id,
|
|
1271
1271
|
slug: {
|
|
1272
1272
|
singular: slug(props.slug.singular),
|
|
@@ -1346,7 +1346,7 @@ var CollectionService = class extends AbstractCrudService {
|
|
|
1346
1346
|
async list(props) {
|
|
1347
1347
|
listCollectionsSchema.parse(props);
|
|
1348
1348
|
const references = await this.listReferences(
|
|
1349
|
-
|
|
1349
|
+
objectTypeSchema3.Enum.collection,
|
|
1350
1350
|
props.projectId
|
|
1351
1351
|
);
|
|
1352
1352
|
const list = await returnResolved(
|
|
@@ -1367,7 +1367,10 @@ var CollectionService = class extends AbstractCrudService {
|
|
|
1367
1367
|
}
|
|
1368
1368
|
async count(props) {
|
|
1369
1369
|
countCollectionsSchema.parse(props);
|
|
1370
|
-
const count = (await this.listReferences(
|
|
1370
|
+
const count = (await this.listReferences(
|
|
1371
|
+
objectTypeSchema3.Enum.collection,
|
|
1372
|
+
props.projectId
|
|
1373
|
+
)).length;
|
|
1371
1374
|
return count;
|
|
1372
1375
|
}
|
|
1373
1376
|
/**
|
|
@@ -1380,15 +1383,16 @@ var CollectionService = class extends AbstractCrudService {
|
|
|
1380
1383
|
|
|
1381
1384
|
// src/service/EntryService.ts
|
|
1382
1385
|
import {
|
|
1386
|
+
ValueTypeSchema as ValueTypeSchema2,
|
|
1383
1387
|
countEntriesSchema,
|
|
1384
1388
|
createEntrySchema,
|
|
1385
1389
|
currentTimestamp as currentTimestamp4,
|
|
1386
1390
|
deleteEntrySchema,
|
|
1387
1391
|
entryFileSchema,
|
|
1388
1392
|
entrySchema,
|
|
1389
|
-
|
|
1390
|
-
getValueSchemaFromDefinition as getValueSchemaFromDefinition2,
|
|
1393
|
+
getValueContentSchemaFromDefinition,
|
|
1391
1394
|
listEntriesSchema,
|
|
1395
|
+
objectTypeSchema as objectTypeSchema5,
|
|
1392
1396
|
readEntrySchema,
|
|
1393
1397
|
serviceTypeSchema as serviceTypeSchema6,
|
|
1394
1398
|
updateEntrySchema,
|
|
@@ -1396,100 +1400,109 @@ import {
|
|
|
1396
1400
|
} from "@elek-io/shared";
|
|
1397
1401
|
import Fs6 from "fs-extra";
|
|
1398
1402
|
|
|
1399
|
-
// src/service/
|
|
1403
|
+
// src/service/SharedValueService.ts
|
|
1400
1404
|
import {
|
|
1405
|
+
ValueTypeSchema,
|
|
1401
1406
|
countValuesSchema,
|
|
1402
|
-
|
|
1407
|
+
createSharedValueSchema,
|
|
1403
1408
|
currentTimestamp as currentTimestamp3,
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
readValueSchema,
|
|
1409
|
+
deleteSharedValueSchema,
|
|
1410
|
+
listSharedValuesSchema,
|
|
1411
|
+
objectTypeSchema as objectTypeSchema4,
|
|
1412
|
+
readSharedValueSchema,
|
|
1409
1413
|
serviceTypeSchema as serviceTypeSchema5,
|
|
1410
|
-
|
|
1414
|
+
sharedValueFileSchema,
|
|
1415
|
+
sharedValueSchema,
|
|
1416
|
+
updateSharedValueSchema,
|
|
1411
1417
|
uuid as uuid4,
|
|
1412
|
-
|
|
1413
|
-
valueFileSchema
|
|
1418
|
+
z
|
|
1414
1419
|
} from "@elek-io/shared";
|
|
1415
1420
|
import Fs5 from "fs-extra";
|
|
1416
|
-
var
|
|
1421
|
+
var SharedValueService = class extends AbstractCrudService {
|
|
1417
1422
|
constructor(options, jsonFileService, gitService, assetService) {
|
|
1418
1423
|
super(serviceTypeSchema5.Enum.Value, options);
|
|
1419
1424
|
this.jsonFileService = jsonFileService;
|
|
1420
1425
|
this.gitService = gitService;
|
|
1421
1426
|
}
|
|
1422
1427
|
/**
|
|
1423
|
-
* Creates a new Value
|
|
1428
|
+
* Creates a new shared Value
|
|
1424
1429
|
*/
|
|
1425
1430
|
async create(props) {
|
|
1426
|
-
|
|
1431
|
+
createSharedValueSchema.parse(props);
|
|
1427
1432
|
const id = uuid4();
|
|
1428
1433
|
const projectPath = pathTo.project(props.projectId);
|
|
1429
|
-
const
|
|
1434
|
+
const sharedValueFilePath = pathTo.sharedValueFile(
|
|
1430
1435
|
props.projectId,
|
|
1431
1436
|
id,
|
|
1432
1437
|
props.language
|
|
1433
1438
|
);
|
|
1434
|
-
const
|
|
1439
|
+
const sharedValueFile = {
|
|
1435
1440
|
...props,
|
|
1436
|
-
|
|
1441
|
+
objectType: "sharedValue",
|
|
1437
1442
|
id,
|
|
1438
1443
|
created: currentTimestamp3()
|
|
1439
1444
|
};
|
|
1445
|
+
this.validate(sharedValueFile);
|
|
1440
1446
|
await this.jsonFileService.create(
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1447
|
+
sharedValueFile,
|
|
1448
|
+
sharedValueFilePath,
|
|
1449
|
+
sharedValueFileSchema
|
|
1444
1450
|
);
|
|
1445
|
-
await this.gitService.add(projectPath, [
|
|
1451
|
+
await this.gitService.add(projectPath, [sharedValueFilePath]);
|
|
1446
1452
|
await this.gitService.commit(projectPath, this.gitMessage.create);
|
|
1447
|
-
return
|
|
1453
|
+
return sharedValueFile;
|
|
1448
1454
|
}
|
|
1449
1455
|
/**
|
|
1450
|
-
* Returns a Value by ID and language
|
|
1456
|
+
* Returns a shared Value by ID and language
|
|
1451
1457
|
*/
|
|
1452
1458
|
async read(props) {
|
|
1453
|
-
|
|
1454
|
-
const
|
|
1455
|
-
pathTo.
|
|
1456
|
-
|
|
1459
|
+
readSharedValueSchema.parse(props);
|
|
1460
|
+
const sharedValueFile = await this.jsonFileService.read(
|
|
1461
|
+
pathTo.sharedValueFile(
|
|
1462
|
+
props.projectId,
|
|
1463
|
+
props.id,
|
|
1464
|
+
props.language
|
|
1465
|
+
),
|
|
1466
|
+
sharedValueFileSchema
|
|
1457
1467
|
);
|
|
1458
|
-
return
|
|
1468
|
+
return sharedValueFile;
|
|
1459
1469
|
}
|
|
1460
1470
|
/**
|
|
1461
|
-
* Updates given
|
|
1471
|
+
* Updates given shared Values content
|
|
1472
|
+
*
|
|
1473
|
+
* The valueType cannot be changed after creating the shared Value
|
|
1462
1474
|
*/
|
|
1463
1475
|
async update(props) {
|
|
1464
|
-
|
|
1476
|
+
updateSharedValueSchema.parse(props);
|
|
1465
1477
|
const projectPath = pathTo.project(props.projectId);
|
|
1466
|
-
const
|
|
1478
|
+
const sharedValueFilePath = pathTo.sharedValueFile(
|
|
1467
1479
|
props.projectId,
|
|
1468
1480
|
props.id,
|
|
1469
1481
|
props.language
|
|
1470
1482
|
);
|
|
1471
|
-
const
|
|
1472
|
-
const
|
|
1473
|
-
...
|
|
1474
|
-
|
|
1483
|
+
const prevSharedValueFile = await this.read(props);
|
|
1484
|
+
const sharedValueFile = {
|
|
1485
|
+
...prevSharedValueFile,
|
|
1486
|
+
content: props.content,
|
|
1475
1487
|
updated: currentTimestamp3()
|
|
1476
1488
|
};
|
|
1489
|
+
this.validate(sharedValueFile);
|
|
1477
1490
|
await this.jsonFileService.update(
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1491
|
+
sharedValueFile,
|
|
1492
|
+
sharedValueFilePath,
|
|
1493
|
+
sharedValueFileSchema
|
|
1481
1494
|
);
|
|
1482
|
-
await this.gitService.add(projectPath, [
|
|
1495
|
+
await this.gitService.add(projectPath, [sharedValueFilePath]);
|
|
1483
1496
|
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
1484
|
-
return
|
|
1497
|
+
return sharedValueFile;
|
|
1485
1498
|
}
|
|
1486
1499
|
/**
|
|
1487
|
-
* Deletes given Value
|
|
1500
|
+
* Deletes given shared Value
|
|
1488
1501
|
*/
|
|
1489
1502
|
async delete(props) {
|
|
1490
|
-
|
|
1503
|
+
deleteSharedValueSchema.parse(props);
|
|
1491
1504
|
const projectPath = pathTo.project(props.projectId);
|
|
1492
|
-
const valueFilePath = pathTo.
|
|
1505
|
+
const valueFilePath = pathTo.sharedValueFile(
|
|
1493
1506
|
props.projectId,
|
|
1494
1507
|
props.id,
|
|
1495
1508
|
props.language
|
|
@@ -1499,9 +1512,9 @@ var ValueService = class extends AbstractCrudService {
|
|
|
1499
1512
|
await this.gitService.commit(projectPath, this.gitMessage.delete);
|
|
1500
1513
|
}
|
|
1501
1514
|
async list(props) {
|
|
1502
|
-
|
|
1515
|
+
listSharedValuesSchema.parse(props);
|
|
1503
1516
|
const references = await this.listReferences(
|
|
1504
|
-
|
|
1517
|
+
objectTypeSchema4.Enum.sharedValue,
|
|
1505
1518
|
props.projectId
|
|
1506
1519
|
);
|
|
1507
1520
|
const list = await returnResolved(
|
|
@@ -1526,37 +1539,52 @@ var ValueService = class extends AbstractCrudService {
|
|
|
1526
1539
|
}
|
|
1527
1540
|
async count(props) {
|
|
1528
1541
|
countValuesSchema.parse(props);
|
|
1529
|
-
const count = (await this.listReferences(
|
|
1542
|
+
const count = (await this.listReferences(
|
|
1543
|
+
objectTypeSchema4.Enum.sharedValue,
|
|
1544
|
+
props.projectId
|
|
1545
|
+
)).length;
|
|
1530
1546
|
return count;
|
|
1531
1547
|
}
|
|
1532
1548
|
/**
|
|
1533
|
-
* Checks if given object is
|
|
1549
|
+
* Checks if given object is a shared Value
|
|
1534
1550
|
*/
|
|
1535
|
-
|
|
1536
|
-
return
|
|
1551
|
+
isSharedValue(obj) {
|
|
1552
|
+
return sharedValueSchema.safeParse(obj).success;
|
|
1537
1553
|
}
|
|
1538
1554
|
/**
|
|
1539
|
-
* Reads the given
|
|
1555
|
+
* Reads the given shared Values content based on it's ValueType
|
|
1540
1556
|
*/
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1557
|
+
validate(sharedValue) {
|
|
1558
|
+
switch (sharedValue.valueType) {
|
|
1559
|
+
case ValueTypeSchema.Enum.boolean:
|
|
1560
|
+
z.boolean().parse(sharedValue.content);
|
|
1561
|
+
break;
|
|
1562
|
+
case ValueTypeSchema.Enum.number:
|
|
1563
|
+
z.number().parse(sharedValue.content);
|
|
1564
|
+
break;
|
|
1565
|
+
case ValueTypeSchema.Enum.string:
|
|
1566
|
+
z.string().parse(sharedValue.content);
|
|
1567
|
+
break;
|
|
1568
|
+
default:
|
|
1569
|
+
throw new Error(
|
|
1570
|
+
`Error validating content of unsupported shared Value with ValueType "${sharedValue.valueType}"`
|
|
1571
|
+
);
|
|
1572
|
+
}
|
|
1546
1573
|
}
|
|
1547
1574
|
};
|
|
1548
1575
|
|
|
1549
1576
|
// src/service/EntryService.ts
|
|
1550
1577
|
var EntryService = class extends AbstractCrudService {
|
|
1551
|
-
constructor(options, jsonFileService, gitService, collectionService,
|
|
1578
|
+
constructor(options, jsonFileService, gitService, collectionService, assetService, sharedValueService) {
|
|
1552
1579
|
super(serviceTypeSchema6.Enum.Entry, options);
|
|
1553
1580
|
this.jsonFileService = jsonFileService;
|
|
1554
1581
|
this.gitService = gitService;
|
|
1555
1582
|
this.collectionService = collectionService;
|
|
1556
|
-
this.
|
|
1583
|
+
this.assetService = assetService;
|
|
1584
|
+
this.sharedValueService = sharedValueService;
|
|
1557
1585
|
}
|
|
1558
1586
|
/**
|
|
1559
|
-
* Creates a new Entry
|
|
1587
|
+
* Creates a new Entry for given Collection
|
|
1560
1588
|
*/
|
|
1561
1589
|
async create(props) {
|
|
1562
1590
|
createEntrySchema.parse(props);
|
|
@@ -1572,19 +1600,22 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1572
1600
|
projectId: props.projectId,
|
|
1573
1601
|
id: props.collectionId
|
|
1574
1602
|
});
|
|
1575
|
-
await this.validateValueReferences(
|
|
1576
|
-
props.projectId,
|
|
1577
|
-
props.collectionId,
|
|
1578
|
-
props.valueReferences,
|
|
1579
|
-
collection.valueDefinitions
|
|
1580
|
-
);
|
|
1581
1603
|
const entryFile = {
|
|
1582
|
-
|
|
1604
|
+
objectType: "entry",
|
|
1583
1605
|
id,
|
|
1584
1606
|
language: props.language,
|
|
1585
|
-
|
|
1607
|
+
values: props.values,
|
|
1586
1608
|
created: currentTimestamp4()
|
|
1587
1609
|
};
|
|
1610
|
+
const entry = await this.toEntry({
|
|
1611
|
+
projectId: props.projectId,
|
|
1612
|
+
entryFile
|
|
1613
|
+
});
|
|
1614
|
+
this.validateValues({
|
|
1615
|
+
collectionId: props.collectionId,
|
|
1616
|
+
valueDefinitions: collection.valueDefinitions,
|
|
1617
|
+
values: entry.values
|
|
1618
|
+
});
|
|
1588
1619
|
await this.jsonFileService.create(
|
|
1589
1620
|
entryFile,
|
|
1590
1621
|
entryFilePath,
|
|
@@ -1592,10 +1623,10 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1592
1623
|
);
|
|
1593
1624
|
await this.gitService.add(projectPath, [entryFilePath]);
|
|
1594
1625
|
await this.gitService.commit(projectPath, this.gitMessage.create);
|
|
1595
|
-
return
|
|
1626
|
+
return entry;
|
|
1596
1627
|
}
|
|
1597
1628
|
/**
|
|
1598
|
-
* Returns an Entry by ID and language
|
|
1629
|
+
* Returns an Entry from given Collection by ID and language
|
|
1599
1630
|
*/
|
|
1600
1631
|
async read(props) {
|
|
1601
1632
|
readEntrySchema.parse(props);
|
|
@@ -1608,10 +1639,10 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1608
1639
|
),
|
|
1609
1640
|
entryFileSchema
|
|
1610
1641
|
);
|
|
1611
|
-
return entryFile;
|
|
1642
|
+
return await this.toEntry({ projectId: props.projectId, entryFile });
|
|
1612
1643
|
}
|
|
1613
1644
|
/**
|
|
1614
|
-
* Updates Entry
|
|
1645
|
+
* Updates an Entry of given Collection with new Values and shared Values
|
|
1615
1646
|
*/
|
|
1616
1647
|
async update(props) {
|
|
1617
1648
|
updateEntrySchema.parse(props);
|
|
@@ -1626,12 +1657,6 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1626
1657
|
projectId: props.projectId,
|
|
1627
1658
|
id: props.collectionId
|
|
1628
1659
|
});
|
|
1629
|
-
await this.validateValueReferences(
|
|
1630
|
-
props.projectId,
|
|
1631
|
-
props.collectionId,
|
|
1632
|
-
props.valueReferences,
|
|
1633
|
-
collection.valueDefinitions
|
|
1634
|
-
);
|
|
1635
1660
|
const prevEntryFile = await this.read({
|
|
1636
1661
|
projectId: props.projectId,
|
|
1637
1662
|
collectionId: props.collectionId,
|
|
@@ -1640,9 +1665,18 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1640
1665
|
});
|
|
1641
1666
|
const entryFile = {
|
|
1642
1667
|
...prevEntryFile,
|
|
1643
|
-
|
|
1668
|
+
values: props.values,
|
|
1644
1669
|
updated: currentTimestamp4()
|
|
1645
1670
|
};
|
|
1671
|
+
const entry = await this.toEntry({
|
|
1672
|
+
projectId: props.projectId,
|
|
1673
|
+
entryFile
|
|
1674
|
+
});
|
|
1675
|
+
this.validateValues({
|
|
1676
|
+
collectionId: props.collectionId,
|
|
1677
|
+
valueDefinitions: collection.valueDefinitions,
|
|
1678
|
+
values: entry.values
|
|
1679
|
+
});
|
|
1646
1680
|
await this.jsonFileService.update(
|
|
1647
1681
|
entryFile,
|
|
1648
1682
|
entryFilePath,
|
|
@@ -1650,10 +1684,10 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1650
1684
|
);
|
|
1651
1685
|
await this.gitService.add(projectPath, [entryFilePath]);
|
|
1652
1686
|
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
1653
|
-
return
|
|
1687
|
+
return entry;
|
|
1654
1688
|
}
|
|
1655
1689
|
/**
|
|
1656
|
-
* Deletes given Entry
|
|
1690
|
+
* Deletes given Entry from it's Collection
|
|
1657
1691
|
*/
|
|
1658
1692
|
async delete(props) {
|
|
1659
1693
|
deleteEntrySchema.parse(props);
|
|
@@ -1671,7 +1705,7 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1671
1705
|
async list(props) {
|
|
1672
1706
|
listEntriesSchema.parse(props);
|
|
1673
1707
|
const references = await this.listReferences(
|
|
1674
|
-
|
|
1708
|
+
objectTypeSchema5.Enum.entry,
|
|
1675
1709
|
props.projectId,
|
|
1676
1710
|
props.collectionId
|
|
1677
1711
|
);
|
|
@@ -1699,45 +1733,147 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1699
1733
|
async count(props) {
|
|
1700
1734
|
countEntriesSchema.parse(props);
|
|
1701
1735
|
return (await this.listReferences(
|
|
1702
|
-
|
|
1736
|
+
objectTypeSchema5.Enum.entry,
|
|
1703
1737
|
props.projectId,
|
|
1704
1738
|
props.collectionId
|
|
1705
1739
|
)).length;
|
|
1706
1740
|
}
|
|
1707
1741
|
/**
|
|
1708
|
-
* Checks if given object of
|
|
1709
|
-
* Field, Project or Asset is of type CollectionItem
|
|
1742
|
+
* Checks if given object is of type Entry
|
|
1710
1743
|
*/
|
|
1711
1744
|
isEntry(obj) {
|
|
1712
1745
|
return entrySchema.safeParse(obj).success;
|
|
1713
1746
|
}
|
|
1714
1747
|
/**
|
|
1715
|
-
*
|
|
1716
|
-
*
|
|
1717
|
-
* @todo should probably return all errors occurring during parsing instead of throwing
|
|
1748
|
+
* Returns a Value definition by ID
|
|
1718
1749
|
*/
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1750
|
+
getValueDefinitionById(props) {
|
|
1751
|
+
const definition = props.valueDefinitions.find((def) => {
|
|
1752
|
+
if (def.id === props.id) {
|
|
1753
|
+
return true;
|
|
1754
|
+
}
|
|
1755
|
+
return false;
|
|
1756
|
+
});
|
|
1757
|
+
if (!definition) {
|
|
1758
|
+
throw new Error(
|
|
1759
|
+
`No definition with ID "${props.id}" found in Collection "${props.collectionId}" for given Value reference`
|
|
1760
|
+
);
|
|
1761
|
+
}
|
|
1762
|
+
return definition;
|
|
1763
|
+
}
|
|
1764
|
+
/**
|
|
1765
|
+
* Validates given Values against it's Collections definitions
|
|
1766
|
+
*/
|
|
1767
|
+
validateValues(props) {
|
|
1768
|
+
props.values.map((value) => {
|
|
1769
|
+
const definition = this.getValueDefinitionById({
|
|
1770
|
+
collectionId: props.collectionId,
|
|
1771
|
+
valueDefinitions: props.valueDefinitions,
|
|
1772
|
+
id: value.definitionId
|
|
1773
|
+
});
|
|
1774
|
+
const schema = getValueContentSchemaFromDefinition(definition);
|
|
1775
|
+
try {
|
|
1776
|
+
schema.parse(value.content);
|
|
1777
|
+
} catch (error) {
|
|
1778
|
+
console.log("Definition:", definition);
|
|
1779
|
+
console.log("Value:", value);
|
|
1780
|
+
throw error;
|
|
1781
|
+
}
|
|
1782
|
+
});
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* Validates given shared Value references against it's Collections definitions
|
|
1786
|
+
*/
|
|
1787
|
+
// private validateResolvedSharedValues(props: {
|
|
1788
|
+
// collectionId: string;
|
|
1789
|
+
// valueDefinitions: ValueDefinition[];
|
|
1790
|
+
// resolvedSharedValues: ResolvedSharedValueReference[];
|
|
1791
|
+
// }) {
|
|
1792
|
+
// props.resolvedSharedValues.map((value) => {
|
|
1793
|
+
// const definition = this.getValueDefinitionById({
|
|
1794
|
+
// collectionId: props.collectionId,
|
|
1795
|
+
// valueDefinitions: props.valueDefinitions,
|
|
1796
|
+
// id: value.definitionId,
|
|
1797
|
+
// });
|
|
1798
|
+
// const schema = getValueSchemaFromDefinition(definition);
|
|
1799
|
+
// schema.parse(value.resolved.content);
|
|
1800
|
+
// });
|
|
1801
|
+
// }
|
|
1802
|
+
async resolveValueContentReference(props) {
|
|
1803
|
+
switch (props.valueContentReference.referenceObjectType) {
|
|
1804
|
+
case objectTypeSchema5.Enum.asset:
|
|
1805
|
+
return this.resolveValueContentReferenceToAsset({
|
|
1806
|
+
projectId: props.projectId,
|
|
1807
|
+
valueContentReferenceToAsset: props.valueContentReference
|
|
1727
1808
|
});
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
}
|
|
1733
|
-
const schema = getValueSchemaFromDefinition2(definition);
|
|
1734
|
-
const value = await this.valueService.read({
|
|
1735
|
-
...reference.references,
|
|
1736
|
-
projectId
|
|
1809
|
+
case objectTypeSchema5.Enum.sharedValue:
|
|
1810
|
+
return this.resolveValueContentReferenceToSharedValue({
|
|
1811
|
+
projectId: props.projectId,
|
|
1812
|
+
valueContentReferenceToSharedValue: props.valueContentReference
|
|
1737
1813
|
});
|
|
1738
|
-
|
|
1814
|
+
default:
|
|
1815
|
+
throw new Error(
|
|
1816
|
+
// @ts-ignore
|
|
1817
|
+
`Tried to resolve unsupported Value reference "${props.valueContentReference.referenceObjectType}"`
|
|
1818
|
+
);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
async resolveValueContentReferenceToAsset(props) {
|
|
1822
|
+
const resolvedReferences = await Promise.all(
|
|
1823
|
+
props.valueContentReferenceToAsset.references.map(async (reference) => {
|
|
1824
|
+
const resolvedAsset = await this.assetService.read({
|
|
1825
|
+
projectId: props.projectId,
|
|
1826
|
+
id: reference.id,
|
|
1827
|
+
language: reference.language
|
|
1828
|
+
});
|
|
1829
|
+
return {
|
|
1830
|
+
...reference,
|
|
1831
|
+
resolved: resolvedAsset
|
|
1832
|
+
};
|
|
1739
1833
|
})
|
|
1740
1834
|
);
|
|
1835
|
+
return {
|
|
1836
|
+
...props.valueContentReferenceToAsset,
|
|
1837
|
+
references: resolvedReferences
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
async resolveValueContentReferenceToSharedValue(props) {
|
|
1841
|
+
const resolvedSharedValue = await this.sharedValueService.read({
|
|
1842
|
+
projectId: props.projectId,
|
|
1843
|
+
id: props.valueContentReferenceToSharedValue.references.id,
|
|
1844
|
+
language: props.valueContentReferenceToSharedValue.references.language
|
|
1845
|
+
});
|
|
1846
|
+
return {
|
|
1847
|
+
...props.valueContentReferenceToSharedValue,
|
|
1848
|
+
references: {
|
|
1849
|
+
...props.valueContentReferenceToSharedValue.references,
|
|
1850
|
+
resolved: resolvedSharedValue
|
|
1851
|
+
}
|
|
1852
|
+
};
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Creates an Entry from given EntryFile by resolving it's Values
|
|
1856
|
+
*/
|
|
1857
|
+
async toEntry(props) {
|
|
1858
|
+
const entry = {
|
|
1859
|
+
...props.entryFile,
|
|
1860
|
+
values: await Promise.all(
|
|
1861
|
+
props.entryFile.values.map(async (value) => {
|
|
1862
|
+
if (value.valueType === ValueTypeSchema2.Enum.reference) {
|
|
1863
|
+
const resolvedValueContentReference = await this.resolveValueContentReference({
|
|
1864
|
+
projectId: props.projectId,
|
|
1865
|
+
valueContentReference: value.content
|
|
1866
|
+
});
|
|
1867
|
+
return {
|
|
1868
|
+
...value,
|
|
1869
|
+
content: resolvedValueContentReference
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
return value;
|
|
1873
|
+
})
|
|
1874
|
+
)
|
|
1875
|
+
};
|
|
1876
|
+
return entry;
|
|
1741
1877
|
}
|
|
1742
1878
|
};
|
|
1743
1879
|
|
|
@@ -1746,9 +1882,9 @@ import {
|
|
|
1746
1882
|
createProjectSchema,
|
|
1747
1883
|
currentTimestamp as currentTimestamp5,
|
|
1748
1884
|
deleteProjectSchema,
|
|
1749
|
-
fileTypeSchema as fileTypeSchema6,
|
|
1750
1885
|
gitCommitIconSchema as gitCommitIconSchema2,
|
|
1751
1886
|
listProjectsSchema,
|
|
1887
|
+
objectTypeSchema as objectTypeSchema6,
|
|
1752
1888
|
projectFileSchema,
|
|
1753
1889
|
projectFolderSchema as projectFolderSchema2,
|
|
1754
1890
|
readProjectSchema,
|
|
@@ -1788,7 +1924,7 @@ var SearchService = class extends AbstractCrudService {
|
|
|
1788
1924
|
* @param project Project to search in
|
|
1789
1925
|
* @param query Query to search for
|
|
1790
1926
|
*/
|
|
1791
|
-
async search(projectId, query,
|
|
1927
|
+
async search(projectId, query, objectType) {
|
|
1792
1928
|
const results = [];
|
|
1793
1929
|
const normalizedQuery = query.trim();
|
|
1794
1930
|
if (normalizedQuery === "") {
|
|
@@ -1801,7 +1937,7 @@ var SearchService = class extends AbstractCrudService {
|
|
|
1801
1937
|
id: file.id,
|
|
1802
1938
|
language: file.language,
|
|
1803
1939
|
name: file.name,
|
|
1804
|
-
type: file.
|
|
1940
|
+
type: file.objectType,
|
|
1805
1941
|
matches: []
|
|
1806
1942
|
};
|
|
1807
1943
|
for (const [key, value] of Object.entries(file)) {
|
|
@@ -1841,7 +1977,7 @@ var SearchService = class extends AbstractCrudService {
|
|
|
1841
1977
|
|
|
1842
1978
|
// src/service/ProjectService.ts
|
|
1843
1979
|
var ProjectService = class extends AbstractCrudService {
|
|
1844
|
-
constructor(options, jsonFileService, userService, gitService, searchService, assetService, collectionService, entryService
|
|
1980
|
+
constructor(options, jsonFileService, userService, gitService, searchService, assetService, collectionService, entryService) {
|
|
1845
1981
|
super(serviceTypeSchema8.Enum.Project, options);
|
|
1846
1982
|
this.jsonFileService = jsonFileService;
|
|
1847
1983
|
this.userService = userService;
|
|
@@ -1850,7 +1986,6 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1850
1986
|
this.assetService = assetService;
|
|
1851
1987
|
this.collectionService = collectionService;
|
|
1852
1988
|
this.entryService = entryService;
|
|
1853
|
-
this.valueService = valueService;
|
|
1854
1989
|
}
|
|
1855
1990
|
/**
|
|
1856
1991
|
* Creates a new Project
|
|
@@ -1863,14 +1998,14 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1863
1998
|
}
|
|
1864
1999
|
const id = uuid6();
|
|
1865
2000
|
const defaultSettings = {
|
|
1866
|
-
|
|
1867
|
-
default: user.
|
|
1868
|
-
supported: [user.
|
|
2001
|
+
language: {
|
|
2002
|
+
default: user.language,
|
|
2003
|
+
supported: [user.language]
|
|
1869
2004
|
}
|
|
1870
2005
|
};
|
|
1871
2006
|
const projectFile = {
|
|
1872
2007
|
...props,
|
|
1873
|
-
|
|
2008
|
+
objectType: "project",
|
|
1874
2009
|
id,
|
|
1875
2010
|
description: props.description || "",
|
|
1876
2011
|
settings: Object.assign({}, defaultSettings, props.settings),
|
|
@@ -2015,7 +2150,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2015
2150
|
if (props) {
|
|
2016
2151
|
listProjectsSchema.parse(props);
|
|
2017
2152
|
}
|
|
2018
|
-
const references = await this.listReferences(
|
|
2153
|
+
const references = await this.listReferences(objectTypeSchema6.Enum.project);
|
|
2019
2154
|
const list = await returnResolved(
|
|
2020
2155
|
references.map((reference) => {
|
|
2021
2156
|
return this.read({ id: reference.id });
|
|
@@ -2030,7 +2165,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2030
2165
|
);
|
|
2031
2166
|
}
|
|
2032
2167
|
async count() {
|
|
2033
|
-
return (await this.listReferences(
|
|
2168
|
+
return (await this.listReferences(objectTypeSchema6.Enum.project)).length;
|
|
2034
2169
|
}
|
|
2035
2170
|
/**
|
|
2036
2171
|
* Search all models inside the project for given query
|
|
@@ -2051,6 +2186,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2051
2186
|
/**
|
|
2052
2187
|
* Exports given Project to JSON
|
|
2053
2188
|
*
|
|
2189
|
+
* @todo do not read everything before writing to disk -> stream into file given via props
|
|
2054
2190
|
* @todo performance tests
|
|
2055
2191
|
* @todo add progress callback
|
|
2056
2192
|
*/
|
|
@@ -2065,26 +2201,9 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2065
2201
|
collectionId: collection.id,
|
|
2066
2202
|
limit: 0
|
|
2067
2203
|
})).list;
|
|
2068
|
-
const entryExport = await Promise.all(
|
|
2069
|
-
entries.map(async (entry) => {
|
|
2070
|
-
const valueExport = await Promise.all(
|
|
2071
|
-
entry.valueReferences.map(async (valueReference) => {
|
|
2072
|
-
return this.valueService.read({
|
|
2073
|
-
projectId,
|
|
2074
|
-
id: valueReference.references.id,
|
|
2075
|
-
language: valueReference.references.language
|
|
2076
|
-
});
|
|
2077
|
-
})
|
|
2078
|
-
);
|
|
2079
|
-
return {
|
|
2080
|
-
...entry,
|
|
2081
|
-
values: valueExport
|
|
2082
|
-
};
|
|
2083
|
-
})
|
|
2084
|
-
);
|
|
2085
2204
|
return {
|
|
2086
2205
|
...collection,
|
|
2087
|
-
entries
|
|
2206
|
+
entries
|
|
2088
2207
|
};
|
|
2089
2208
|
})
|
|
2090
2209
|
);
|
|
@@ -2154,23 +2273,24 @@ var ElekIoCore = class {
|
|
|
2154
2273
|
this.jsonFileService,
|
|
2155
2274
|
this.gitService
|
|
2156
2275
|
);
|
|
2157
|
-
this.
|
|
2276
|
+
this.collectionService = new CollectionService(
|
|
2158
2277
|
this.options,
|
|
2159
2278
|
this.jsonFileService,
|
|
2160
|
-
this.gitService
|
|
2161
|
-
this.assetService
|
|
2279
|
+
this.gitService
|
|
2162
2280
|
);
|
|
2163
|
-
this.
|
|
2281
|
+
this.sharedValueService = new SharedValueService(
|
|
2164
2282
|
this.options,
|
|
2165
2283
|
this.jsonFileService,
|
|
2166
|
-
this.gitService
|
|
2284
|
+
this.gitService,
|
|
2285
|
+
this.assetService
|
|
2167
2286
|
);
|
|
2168
2287
|
this.entryService = new EntryService(
|
|
2169
2288
|
this.options,
|
|
2170
2289
|
this.jsonFileService,
|
|
2171
2290
|
this.gitService,
|
|
2172
2291
|
this.collectionService,
|
|
2173
|
-
this.
|
|
2292
|
+
this.assetService,
|
|
2293
|
+
this.sharedValueService
|
|
2174
2294
|
);
|
|
2175
2295
|
this.searchService = new SearchService(
|
|
2176
2296
|
this.options,
|
|
@@ -2185,8 +2305,7 @@ var ElekIoCore = class {
|
|
|
2185
2305
|
this.searchService,
|
|
2186
2306
|
this.assetService,
|
|
2187
2307
|
this.collectionService,
|
|
2188
|
-
this.entryService
|
|
2189
|
-
this.valueService
|
|
2308
|
+
this.entryService
|
|
2190
2309
|
);
|
|
2191
2310
|
if (this.options.environment !== "production") {
|
|
2192
2311
|
console.info(
|
|
@@ -2239,8 +2358,8 @@ var ElekIoCore = class {
|
|
|
2239
2358
|
/**
|
|
2240
2359
|
* CRUD methods to work with Values
|
|
2241
2360
|
*/
|
|
2242
|
-
get
|
|
2243
|
-
return this.
|
|
2361
|
+
get sharedValues() {
|
|
2362
|
+
return this.sharedValueService;
|
|
2244
2363
|
}
|
|
2245
2364
|
};
|
|
2246
2365
|
export {
|