@elek-io/core 0.2.1 → 0.3.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/README.md +12 -10
- package/dist/index.cjs +119 -271
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -99
- package/dist/index.d.ts +5 -99
- package/dist/index.js +102 -269
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var __export = (target, all) => {
|
|
|
8
8
|
import {
|
|
9
9
|
constructorElekIoCoreSchema
|
|
10
10
|
} from "@elek-io/shared";
|
|
11
|
-
import
|
|
11
|
+
import Fs7 from "fs-extra";
|
|
12
12
|
|
|
13
13
|
// src/service/AssetService.ts
|
|
14
14
|
import {
|
|
@@ -97,11 +97,8 @@ var pathTo = {
|
|
|
97
97
|
entries: (projectId, collectionId) => {
|
|
98
98
|
return Path.join(pathTo.collection(projectId, collectionId));
|
|
99
99
|
},
|
|
100
|
-
entryFile: (projectId, collectionId, id
|
|
101
|
-
return Path.join(
|
|
102
|
-
pathTo.entries(projectId, collectionId),
|
|
103
|
-
`${id}.${language}.json`
|
|
104
|
-
);
|
|
100
|
+
entryFile: (projectId, collectionId, id) => {
|
|
101
|
+
return Path.join(pathTo.entries(projectId, collectionId), `${id}.json`);
|
|
105
102
|
},
|
|
106
103
|
sharedValues: (projectId) => {
|
|
107
104
|
return Path.join(pathTo.project(projectId), "shared-values");
|
|
@@ -1383,218 +1380,42 @@ var CollectionService = class extends AbstractCrudService {
|
|
|
1383
1380
|
|
|
1384
1381
|
// src/service/EntryService.ts
|
|
1385
1382
|
import {
|
|
1386
|
-
ValueTypeSchema
|
|
1383
|
+
ValueTypeSchema,
|
|
1387
1384
|
countEntriesSchema,
|
|
1388
1385
|
createEntrySchema,
|
|
1389
|
-
currentTimestamp as
|
|
1386
|
+
currentTimestamp as currentTimestamp3,
|
|
1390
1387
|
deleteEntrySchema,
|
|
1391
1388
|
entryFileSchema,
|
|
1392
1389
|
entrySchema,
|
|
1393
1390
|
getValueContentSchemaFromDefinition,
|
|
1394
1391
|
listEntriesSchema,
|
|
1395
|
-
objectTypeSchema as objectTypeSchema5,
|
|
1396
|
-
readEntrySchema,
|
|
1397
|
-
serviceTypeSchema as serviceTypeSchema6,
|
|
1398
|
-
updateEntrySchema,
|
|
1399
|
-
uuid as uuid5
|
|
1400
|
-
} from "@elek-io/shared";
|
|
1401
|
-
import Fs6 from "fs-extra";
|
|
1402
|
-
|
|
1403
|
-
// src/service/SharedValueService.ts
|
|
1404
|
-
import {
|
|
1405
|
-
ValueTypeSchema,
|
|
1406
|
-
countValuesSchema,
|
|
1407
|
-
createSharedValueSchema,
|
|
1408
|
-
currentTimestamp as currentTimestamp3,
|
|
1409
|
-
deleteSharedValueSchema,
|
|
1410
|
-
listSharedValuesSchema,
|
|
1411
1392
|
objectTypeSchema as objectTypeSchema4,
|
|
1412
|
-
|
|
1393
|
+
readEntrySchema,
|
|
1413
1394
|
serviceTypeSchema as serviceTypeSchema5,
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
updateSharedValueSchema,
|
|
1417
|
-
uuid as uuid4,
|
|
1418
|
-
z
|
|
1395
|
+
updateEntrySchema,
|
|
1396
|
+
uuid as uuid4
|
|
1419
1397
|
} from "@elek-io/shared";
|
|
1420
1398
|
import Fs5 from "fs-extra";
|
|
1421
|
-
var SharedValueService = class extends AbstractCrudService {
|
|
1422
|
-
constructor(options, jsonFileService, gitService, assetService) {
|
|
1423
|
-
super(serviceTypeSchema5.Enum.Value, options);
|
|
1424
|
-
this.jsonFileService = jsonFileService;
|
|
1425
|
-
this.gitService = gitService;
|
|
1426
|
-
}
|
|
1427
|
-
/**
|
|
1428
|
-
* Creates a new shared Value
|
|
1429
|
-
*/
|
|
1430
|
-
async create(props) {
|
|
1431
|
-
createSharedValueSchema.parse(props);
|
|
1432
|
-
const id = uuid4();
|
|
1433
|
-
const projectPath = pathTo.project(props.projectId);
|
|
1434
|
-
const sharedValueFilePath = pathTo.sharedValueFile(
|
|
1435
|
-
props.projectId,
|
|
1436
|
-
id,
|
|
1437
|
-
props.language
|
|
1438
|
-
);
|
|
1439
|
-
const sharedValueFile = {
|
|
1440
|
-
...props,
|
|
1441
|
-
objectType: "sharedValue",
|
|
1442
|
-
id,
|
|
1443
|
-
created: currentTimestamp3()
|
|
1444
|
-
};
|
|
1445
|
-
this.validate(sharedValueFile);
|
|
1446
|
-
await this.jsonFileService.create(
|
|
1447
|
-
sharedValueFile,
|
|
1448
|
-
sharedValueFilePath,
|
|
1449
|
-
sharedValueFileSchema
|
|
1450
|
-
);
|
|
1451
|
-
await this.gitService.add(projectPath, [sharedValueFilePath]);
|
|
1452
|
-
await this.gitService.commit(projectPath, this.gitMessage.create);
|
|
1453
|
-
return sharedValueFile;
|
|
1454
|
-
}
|
|
1455
|
-
/**
|
|
1456
|
-
* Returns a shared Value by ID and language
|
|
1457
|
-
*/
|
|
1458
|
-
async read(props) {
|
|
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
|
|
1467
|
-
);
|
|
1468
|
-
return sharedValueFile;
|
|
1469
|
-
}
|
|
1470
|
-
/**
|
|
1471
|
-
* Updates given shared Values content
|
|
1472
|
-
*
|
|
1473
|
-
* The valueType cannot be changed after creating the shared Value
|
|
1474
|
-
*/
|
|
1475
|
-
async update(props) {
|
|
1476
|
-
updateSharedValueSchema.parse(props);
|
|
1477
|
-
const projectPath = pathTo.project(props.projectId);
|
|
1478
|
-
const sharedValueFilePath = pathTo.sharedValueFile(
|
|
1479
|
-
props.projectId,
|
|
1480
|
-
props.id,
|
|
1481
|
-
props.language
|
|
1482
|
-
);
|
|
1483
|
-
const prevSharedValueFile = await this.read(props);
|
|
1484
|
-
const sharedValueFile = {
|
|
1485
|
-
...prevSharedValueFile,
|
|
1486
|
-
content: props.content,
|
|
1487
|
-
updated: currentTimestamp3()
|
|
1488
|
-
};
|
|
1489
|
-
this.validate(sharedValueFile);
|
|
1490
|
-
await this.jsonFileService.update(
|
|
1491
|
-
sharedValueFile,
|
|
1492
|
-
sharedValueFilePath,
|
|
1493
|
-
sharedValueFileSchema
|
|
1494
|
-
);
|
|
1495
|
-
await this.gitService.add(projectPath, [sharedValueFilePath]);
|
|
1496
|
-
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
1497
|
-
return sharedValueFile;
|
|
1498
|
-
}
|
|
1499
|
-
/**
|
|
1500
|
-
* Deletes given shared Value
|
|
1501
|
-
*/
|
|
1502
|
-
async delete(props) {
|
|
1503
|
-
deleteSharedValueSchema.parse(props);
|
|
1504
|
-
const projectPath = pathTo.project(props.projectId);
|
|
1505
|
-
const valueFilePath = pathTo.sharedValueFile(
|
|
1506
|
-
props.projectId,
|
|
1507
|
-
props.id,
|
|
1508
|
-
props.language
|
|
1509
|
-
);
|
|
1510
|
-
await Fs5.remove(valueFilePath);
|
|
1511
|
-
await this.gitService.add(projectPath, [valueFilePath]);
|
|
1512
|
-
await this.gitService.commit(projectPath, this.gitMessage.delete);
|
|
1513
|
-
}
|
|
1514
|
-
async list(props) {
|
|
1515
|
-
listSharedValuesSchema.parse(props);
|
|
1516
|
-
const references = await this.listReferences(
|
|
1517
|
-
objectTypeSchema4.Enum.sharedValue,
|
|
1518
|
-
props.projectId
|
|
1519
|
-
);
|
|
1520
|
-
const list = await returnResolved(
|
|
1521
|
-
references.map((reference) => {
|
|
1522
|
-
if (!reference.language) {
|
|
1523
|
-
throw new RequiredParameterMissingError("language");
|
|
1524
|
-
}
|
|
1525
|
-
return this.read({
|
|
1526
|
-
projectId: props.projectId,
|
|
1527
|
-
id: reference.id,
|
|
1528
|
-
language: reference.language
|
|
1529
|
-
});
|
|
1530
|
-
})
|
|
1531
|
-
);
|
|
1532
|
-
return this.paginate(
|
|
1533
|
-
list,
|
|
1534
|
-
props.sort,
|
|
1535
|
-
props.filter,
|
|
1536
|
-
props.limit,
|
|
1537
|
-
props.offset
|
|
1538
|
-
);
|
|
1539
|
-
}
|
|
1540
|
-
async count(props) {
|
|
1541
|
-
countValuesSchema.parse(props);
|
|
1542
|
-
const count = (await this.listReferences(
|
|
1543
|
-
objectTypeSchema4.Enum.sharedValue,
|
|
1544
|
-
props.projectId
|
|
1545
|
-
)).length;
|
|
1546
|
-
return count;
|
|
1547
|
-
}
|
|
1548
|
-
/**
|
|
1549
|
-
* Checks if given object is a shared Value
|
|
1550
|
-
*/
|
|
1551
|
-
isSharedValue(obj) {
|
|
1552
|
-
return sharedValueSchema.safeParse(obj).success;
|
|
1553
|
-
}
|
|
1554
|
-
/**
|
|
1555
|
-
* Reads the given shared Values content based on it's ValueType
|
|
1556
|
-
*/
|
|
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
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
};
|
|
1575
|
-
|
|
1576
|
-
// src/service/EntryService.ts
|
|
1577
1399
|
var EntryService = class extends AbstractCrudService {
|
|
1578
|
-
|
|
1579
|
-
|
|
1400
|
+
// private sharedValueService: SharedValueService;
|
|
1401
|
+
constructor(options, jsonFileService, gitService, collectionService, assetService) {
|
|
1402
|
+
super(serviceTypeSchema5.Enum.Entry, options);
|
|
1580
1403
|
this.jsonFileService = jsonFileService;
|
|
1581
1404
|
this.gitService = gitService;
|
|
1582
1405
|
this.collectionService = collectionService;
|
|
1583
1406
|
this.assetService = assetService;
|
|
1584
|
-
this.sharedValueService = sharedValueService;
|
|
1585
1407
|
}
|
|
1586
1408
|
/**
|
|
1587
1409
|
* Creates a new Entry for given Collection
|
|
1588
1410
|
*/
|
|
1589
1411
|
async create(props) {
|
|
1590
1412
|
createEntrySchema.parse(props);
|
|
1591
|
-
const id =
|
|
1413
|
+
const id = uuid4();
|
|
1592
1414
|
const projectPath = pathTo.project(props.projectId);
|
|
1593
1415
|
const entryFilePath = pathTo.entryFile(
|
|
1594
1416
|
props.projectId,
|
|
1595
1417
|
props.collectionId,
|
|
1596
|
-
id
|
|
1597
|
-
props.language
|
|
1418
|
+
id
|
|
1598
1419
|
);
|
|
1599
1420
|
const collection = await this.collectionService.read({
|
|
1600
1421
|
projectId: props.projectId,
|
|
@@ -1603,12 +1424,12 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1603
1424
|
const entryFile = {
|
|
1604
1425
|
objectType: "entry",
|
|
1605
1426
|
id,
|
|
1606
|
-
language: props.language,
|
|
1607
1427
|
values: props.values,
|
|
1608
|
-
created:
|
|
1428
|
+
created: currentTimestamp3()
|
|
1609
1429
|
};
|
|
1610
1430
|
const entry = await this.toEntry({
|
|
1611
1431
|
projectId: props.projectId,
|
|
1432
|
+
collectionId: props.collectionId,
|
|
1612
1433
|
entryFile
|
|
1613
1434
|
});
|
|
1614
1435
|
this.validateValues({
|
|
@@ -1631,15 +1452,14 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1631
1452
|
async read(props) {
|
|
1632
1453
|
readEntrySchema.parse(props);
|
|
1633
1454
|
const entryFile = await this.jsonFileService.read(
|
|
1634
|
-
pathTo.entryFile(
|
|
1635
|
-
props.projectId,
|
|
1636
|
-
props.collectionId,
|
|
1637
|
-
props.id,
|
|
1638
|
-
props.language
|
|
1639
|
-
),
|
|
1455
|
+
pathTo.entryFile(props.projectId, props.collectionId, props.id),
|
|
1640
1456
|
entryFileSchema
|
|
1641
1457
|
);
|
|
1642
|
-
return await this.toEntry({
|
|
1458
|
+
return await this.toEntry({
|
|
1459
|
+
projectId: props.projectId,
|
|
1460
|
+
collectionId: props.collectionId,
|
|
1461
|
+
entryFile
|
|
1462
|
+
});
|
|
1643
1463
|
}
|
|
1644
1464
|
/**
|
|
1645
1465
|
* Updates an Entry of given Collection with new Values and shared Values
|
|
@@ -1650,8 +1470,7 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1650
1470
|
const entryFilePath = pathTo.entryFile(
|
|
1651
1471
|
props.projectId,
|
|
1652
1472
|
props.collectionId,
|
|
1653
|
-
props.id
|
|
1654
|
-
props.language
|
|
1473
|
+
props.id
|
|
1655
1474
|
);
|
|
1656
1475
|
const collection = await this.collectionService.read({
|
|
1657
1476
|
projectId: props.projectId,
|
|
@@ -1660,16 +1479,16 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1660
1479
|
const prevEntryFile = await this.read({
|
|
1661
1480
|
projectId: props.projectId,
|
|
1662
1481
|
collectionId: props.collectionId,
|
|
1663
|
-
id: props.id
|
|
1664
|
-
language: props.language
|
|
1482
|
+
id: props.id
|
|
1665
1483
|
});
|
|
1666
1484
|
const entryFile = {
|
|
1667
1485
|
...prevEntryFile,
|
|
1668
1486
|
values: props.values,
|
|
1669
|
-
updated:
|
|
1487
|
+
updated: currentTimestamp3()
|
|
1670
1488
|
};
|
|
1671
1489
|
const entry = await this.toEntry({
|
|
1672
1490
|
projectId: props.projectId,
|
|
1491
|
+
collectionId: props.collectionId,
|
|
1673
1492
|
entryFile
|
|
1674
1493
|
});
|
|
1675
1494
|
this.validateValues({
|
|
@@ -1695,30 +1514,25 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1695
1514
|
const entryFilePath = pathTo.entryFile(
|
|
1696
1515
|
props.projectId,
|
|
1697
1516
|
props.collectionId,
|
|
1698
|
-
props.id
|
|
1699
|
-
props.language
|
|
1517
|
+
props.id
|
|
1700
1518
|
);
|
|
1701
|
-
await
|
|
1519
|
+
await Fs5.remove(entryFilePath);
|
|
1702
1520
|
await this.gitService.add(projectPath, [entryFilePath]);
|
|
1703
1521
|
await this.gitService.commit(projectPath, this.gitMessage.delete);
|
|
1704
1522
|
}
|
|
1705
1523
|
async list(props) {
|
|
1706
1524
|
listEntriesSchema.parse(props);
|
|
1707
1525
|
const references = await this.listReferences(
|
|
1708
|
-
|
|
1526
|
+
objectTypeSchema4.Enum.entry,
|
|
1709
1527
|
props.projectId,
|
|
1710
1528
|
props.collectionId
|
|
1711
1529
|
);
|
|
1712
1530
|
const list = await returnResolved(
|
|
1713
1531
|
references.map((reference) => {
|
|
1714
|
-
if (!reference.language) {
|
|
1715
|
-
throw new RequiredParameterMissingError("language");
|
|
1716
|
-
}
|
|
1717
1532
|
return this.read({
|
|
1718
1533
|
projectId: props.projectId,
|
|
1719
1534
|
collectionId: props.collectionId,
|
|
1720
|
-
id: reference.id
|
|
1721
|
-
language: reference.language
|
|
1535
|
+
id: reference.id
|
|
1722
1536
|
});
|
|
1723
1537
|
})
|
|
1724
1538
|
);
|
|
@@ -1733,7 +1547,7 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1733
1547
|
async count(props) {
|
|
1734
1548
|
countEntriesSchema.parse(props);
|
|
1735
1549
|
return (await this.listReferences(
|
|
1736
|
-
|
|
1550
|
+
objectTypeSchema4.Enum.entry,
|
|
1737
1551
|
props.projectId,
|
|
1738
1552
|
props.collectionId
|
|
1739
1553
|
)).length;
|
|
@@ -1773,7 +1587,13 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1773
1587
|
});
|
|
1774
1588
|
const schema = getValueContentSchemaFromDefinition(definition);
|
|
1775
1589
|
try {
|
|
1776
|
-
|
|
1590
|
+
if (value.valueType === "reference") {
|
|
1591
|
+
schema.parse(value.content);
|
|
1592
|
+
} else {
|
|
1593
|
+
for (const [language, content] of Object.entries(value.content)) {
|
|
1594
|
+
schema.parse(content);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1777
1597
|
} catch (error) {
|
|
1778
1598
|
console.log("Definition:", definition);
|
|
1779
1599
|
console.log("Value:", value);
|
|
@@ -1801,15 +1621,16 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1801
1621
|
// }
|
|
1802
1622
|
async resolveValueContentReference(props) {
|
|
1803
1623
|
switch (props.valueContentReference.referenceObjectType) {
|
|
1804
|
-
case
|
|
1624
|
+
case objectTypeSchema4.Enum.asset:
|
|
1805
1625
|
return this.resolveValueContentReferenceToAsset({
|
|
1806
1626
|
projectId: props.projectId,
|
|
1807
1627
|
valueContentReferenceToAsset: props.valueContentReference
|
|
1808
1628
|
});
|
|
1809
|
-
case
|
|
1810
|
-
return this.
|
|
1629
|
+
case objectTypeSchema4.Enum.entry:
|
|
1630
|
+
return this.resolveValueContentReferenceToEntry({
|
|
1811
1631
|
projectId: props.projectId,
|
|
1812
|
-
|
|
1632
|
+
collectionId: props.collectionId,
|
|
1633
|
+
valueContentReferenceToEntry: props.valueContentReference
|
|
1813
1634
|
});
|
|
1814
1635
|
default:
|
|
1815
1636
|
throw new Error(
|
|
@@ -1826,10 +1647,7 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1826
1647
|
id: reference.id,
|
|
1827
1648
|
language: reference.language
|
|
1828
1649
|
});
|
|
1829
|
-
return
|
|
1830
|
-
...reference,
|
|
1831
|
-
resolved: resolvedAsset
|
|
1832
|
-
};
|
|
1650
|
+
return resolvedAsset;
|
|
1833
1651
|
})
|
|
1834
1652
|
);
|
|
1835
1653
|
return {
|
|
@@ -1837,20 +1655,39 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1837
1655
|
references: resolvedReferences
|
|
1838
1656
|
};
|
|
1839
1657
|
}
|
|
1840
|
-
async
|
|
1841
|
-
const
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1658
|
+
async resolveValueContentReferenceToEntry(props) {
|
|
1659
|
+
const resolvedReferences = await Promise.all(
|
|
1660
|
+
props.valueContentReferenceToEntry.references.map(async (reference) => {
|
|
1661
|
+
const resolvedEntry = await this.read({
|
|
1662
|
+
projectId: props.projectId,
|
|
1663
|
+
collectionId: props.collectionId,
|
|
1664
|
+
id: reference.id
|
|
1665
|
+
});
|
|
1666
|
+
return resolvedEntry;
|
|
1667
|
+
})
|
|
1668
|
+
);
|
|
1846
1669
|
return {
|
|
1847
|
-
...props.
|
|
1848
|
-
references:
|
|
1849
|
-
...props.valueContentReferenceToSharedValue.references,
|
|
1850
|
-
resolved: resolvedSharedValue
|
|
1851
|
-
}
|
|
1670
|
+
...props.valueContentReferenceToEntry,
|
|
1671
|
+
references: resolvedReferences
|
|
1852
1672
|
};
|
|
1853
1673
|
}
|
|
1674
|
+
// private async resolveValueContentReferenceToSharedValue(props: {
|
|
1675
|
+
// projectId: string;
|
|
1676
|
+
// valueContentReferenceToSharedValue: ValueContentReferenceToSharedValue;
|
|
1677
|
+
// }): Promise<ResolvedValueContentReferenceToSharedValue> {
|
|
1678
|
+
// const resolvedSharedValue = await this.sharedValueService.read({
|
|
1679
|
+
// projectId: props.projectId,
|
|
1680
|
+
// id: props.valueContentReferenceToSharedValue.references.id,
|
|
1681
|
+
// language: props.valueContentReferenceToSharedValue.references.language,
|
|
1682
|
+
// });
|
|
1683
|
+
// return {
|
|
1684
|
+
// ...props.valueContentReferenceToSharedValue,
|
|
1685
|
+
// references: {
|
|
1686
|
+
// ...props.valueContentReferenceToSharedValue.references,
|
|
1687
|
+
// resolved: resolvedSharedValue,
|
|
1688
|
+
// },
|
|
1689
|
+
// };
|
|
1690
|
+
// }
|
|
1854
1691
|
/**
|
|
1855
1692
|
* Creates an Entry from given EntryFile by resolving it's Values
|
|
1856
1693
|
*/
|
|
@@ -1859,9 +1696,10 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1859
1696
|
...props.entryFile,
|
|
1860
1697
|
values: await Promise.all(
|
|
1861
1698
|
props.entryFile.values.map(async (value) => {
|
|
1862
|
-
if (value.valueType ===
|
|
1699
|
+
if (value.valueType === ValueTypeSchema.Enum.reference) {
|
|
1863
1700
|
const resolvedValueContentReference = await this.resolveValueContentReference({
|
|
1864
1701
|
projectId: props.projectId,
|
|
1702
|
+
collectionId: props.collectionId,
|
|
1865
1703
|
valueContentReference: value.content
|
|
1866
1704
|
});
|
|
1867
1705
|
return {
|
|
@@ -1880,20 +1718,20 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1880
1718
|
// src/service/ProjectService.ts
|
|
1881
1719
|
import {
|
|
1882
1720
|
createProjectSchema,
|
|
1883
|
-
currentTimestamp as
|
|
1721
|
+
currentTimestamp as currentTimestamp4,
|
|
1884
1722
|
deleteProjectSchema,
|
|
1885
1723
|
gitCommitIconSchema as gitCommitIconSchema2,
|
|
1886
1724
|
listProjectsSchema,
|
|
1887
|
-
objectTypeSchema as
|
|
1725
|
+
objectTypeSchema as objectTypeSchema5,
|
|
1888
1726
|
projectFileSchema,
|
|
1889
1727
|
projectFolderSchema as projectFolderSchema2,
|
|
1890
1728
|
readProjectSchema,
|
|
1891
|
-
serviceTypeSchema as
|
|
1729
|
+
serviceTypeSchema as serviceTypeSchema7,
|
|
1892
1730
|
updateProjectSchema,
|
|
1893
1731
|
upgradeProjectSchema,
|
|
1894
|
-
uuid as
|
|
1732
|
+
uuid as uuid5
|
|
1895
1733
|
} from "@elek-io/shared";
|
|
1896
|
-
import
|
|
1734
|
+
import Fs6 from "fs-extra";
|
|
1897
1735
|
import Os2 from "os";
|
|
1898
1736
|
import Path2 from "path";
|
|
1899
1737
|
import Semver from "semver";
|
|
@@ -1908,11 +1746,11 @@ var ProjectUpgradeError = class extends Error {
|
|
|
1908
1746
|
|
|
1909
1747
|
// src/service/SearchService.ts
|
|
1910
1748
|
import {
|
|
1911
|
-
serviceTypeSchema as
|
|
1749
|
+
serviceTypeSchema as serviceTypeSchema6
|
|
1912
1750
|
} from "@elek-io/shared";
|
|
1913
1751
|
var SearchService = class extends AbstractCrudService {
|
|
1914
1752
|
constructor(options, assetService, collectionService) {
|
|
1915
|
-
super(
|
|
1753
|
+
super(serviceTypeSchema6.enum.Search, options);
|
|
1916
1754
|
this.assetService = assetService;
|
|
1917
1755
|
this.collectionService = collectionService;
|
|
1918
1756
|
}
|
|
@@ -1978,7 +1816,7 @@ var SearchService = class extends AbstractCrudService {
|
|
|
1978
1816
|
// src/service/ProjectService.ts
|
|
1979
1817
|
var ProjectService = class extends AbstractCrudService {
|
|
1980
1818
|
constructor(options, jsonFileService, userService, gitService, searchService, assetService, collectionService, entryService) {
|
|
1981
|
-
super(
|
|
1819
|
+
super(serviceTypeSchema7.Enum.Project, options);
|
|
1982
1820
|
this.jsonFileService = jsonFileService;
|
|
1983
1821
|
this.userService = userService;
|
|
1984
1822
|
this.gitService = gitService;
|
|
@@ -1996,7 +1834,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1996
1834
|
if (!user) {
|
|
1997
1835
|
throw new NoCurrentUserError();
|
|
1998
1836
|
}
|
|
1999
|
-
const id =
|
|
1837
|
+
const id = uuid5();
|
|
2000
1838
|
const defaultSettings = {
|
|
2001
1839
|
language: {
|
|
2002
1840
|
default: user.language,
|
|
@@ -2009,14 +1847,14 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2009
1847
|
id,
|
|
2010
1848
|
description: props.description || "",
|
|
2011
1849
|
settings: Object.assign({}, defaultSettings, props.settings),
|
|
2012
|
-
created:
|
|
1850
|
+
created: currentTimestamp4(),
|
|
2013
1851
|
coreVersion: this.options.version,
|
|
2014
1852
|
// @todo should be read from package.json to avoid duplicates
|
|
2015
1853
|
status: "todo",
|
|
2016
1854
|
version: "0.0.1"
|
|
2017
1855
|
};
|
|
2018
1856
|
const projectPath = pathTo.project(id);
|
|
2019
|
-
await
|
|
1857
|
+
await Fs6.ensureDir(projectPath);
|
|
2020
1858
|
try {
|
|
2021
1859
|
await this.createFolderStructure(projectPath);
|
|
2022
1860
|
await this.createGitignore(projectPath);
|
|
@@ -2062,7 +1900,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2062
1900
|
const projectFile = {
|
|
2063
1901
|
...prevProjectFile,
|
|
2064
1902
|
...props,
|
|
2065
|
-
updated:
|
|
1903
|
+
updated: currentTimestamp4()
|
|
2066
1904
|
};
|
|
2067
1905
|
await this.jsonFileService.update(projectFile, filePath, projectFileSchema);
|
|
2068
1906
|
await this.gitService.add(projectPath, [filePath]);
|
|
@@ -2144,13 +1982,13 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2144
1982
|
*/
|
|
2145
1983
|
async delete(props) {
|
|
2146
1984
|
deleteProjectSchema.parse(props);
|
|
2147
|
-
await
|
|
1985
|
+
await Fs6.remove(pathTo.project(props.id));
|
|
2148
1986
|
}
|
|
2149
1987
|
async list(props) {
|
|
2150
1988
|
if (props) {
|
|
2151
1989
|
listProjectsSchema.parse(props);
|
|
2152
1990
|
}
|
|
2153
|
-
const references = await this.listReferences(
|
|
1991
|
+
const references = await this.listReferences(objectTypeSchema5.Enum.project);
|
|
2154
1992
|
const list = await returnResolved(
|
|
2155
1993
|
references.map((reference) => {
|
|
2156
1994
|
return this.read({ id: reference.id });
|
|
@@ -2165,7 +2003,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2165
2003
|
);
|
|
2166
2004
|
}
|
|
2167
2005
|
async count() {
|
|
2168
|
-
return (await this.listReferences(
|
|
2006
|
+
return (await this.listReferences(objectTypeSchema5.Enum.project)).length;
|
|
2169
2007
|
}
|
|
2170
2008
|
/**
|
|
2171
2009
|
* Search all models inside the project for given query
|
|
@@ -2222,8 +2060,8 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2222
2060
|
const folders2 = Object.values(projectFolderSchema2.Values);
|
|
2223
2061
|
await Promise.all(
|
|
2224
2062
|
folders2.map(async (folder) => {
|
|
2225
|
-
await
|
|
2226
|
-
await
|
|
2063
|
+
await Fs6.mkdirp(Path2.join(path, folder));
|
|
2064
|
+
await Fs6.writeFile(Path2.join(path, folder, ".gitkeep"), "");
|
|
2227
2065
|
})
|
|
2228
2066
|
);
|
|
2229
2067
|
}
|
|
@@ -2247,12 +2085,13 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2247
2085
|
// projectFolderSchema.Enum.public + '/',
|
|
2248
2086
|
// projectFolderSchema.Enum.logs + '/',
|
|
2249
2087
|
];
|
|
2250
|
-
await
|
|
2088
|
+
await Fs6.writeFile(Path2.join(path, ".gitignore"), lines.join(Os2.EOL));
|
|
2251
2089
|
}
|
|
2252
2090
|
};
|
|
2253
2091
|
|
|
2254
2092
|
// src/index.ts
|
|
2255
2093
|
var ElekIoCore = class {
|
|
2094
|
+
// private readonly sharedValueService: SharedValueService;
|
|
2256
2095
|
constructor(props) {
|
|
2257
2096
|
const parsedProps = constructorElekIoCoreSchema.parse(props);
|
|
2258
2097
|
const defaults = {
|
|
@@ -2278,19 +2117,13 @@ var ElekIoCore = class {
|
|
|
2278
2117
|
this.jsonFileService,
|
|
2279
2118
|
this.gitService
|
|
2280
2119
|
);
|
|
2281
|
-
this.sharedValueService = new SharedValueService(
|
|
2282
|
-
this.options,
|
|
2283
|
-
this.jsonFileService,
|
|
2284
|
-
this.gitService,
|
|
2285
|
-
this.assetService
|
|
2286
|
-
);
|
|
2287
2120
|
this.entryService = new EntryService(
|
|
2288
2121
|
this.options,
|
|
2289
2122
|
this.jsonFileService,
|
|
2290
2123
|
this.gitService,
|
|
2291
2124
|
this.collectionService,
|
|
2292
|
-
this.assetService
|
|
2293
|
-
this.sharedValueService
|
|
2125
|
+
this.assetService
|
|
2126
|
+
// this.sharedValueService
|
|
2294
2127
|
);
|
|
2295
2128
|
this.searchService = new SearchService(
|
|
2296
2129
|
this.options,
|
|
@@ -2315,9 +2148,9 @@ var ElekIoCore = class {
|
|
|
2315
2148
|
}
|
|
2316
2149
|
);
|
|
2317
2150
|
}
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2151
|
+
Fs7.mkdirpSync(pathTo.projects);
|
|
2152
|
+
Fs7.mkdirpSync(pathTo.tmp);
|
|
2153
|
+
Fs7.emptyDirSync(pathTo.tmp);
|
|
2321
2154
|
}
|
|
2322
2155
|
/**
|
|
2323
2156
|
* Utility / helper functions
|
|
@@ -2358,9 +2191,9 @@ var ElekIoCore = class {
|
|
|
2358
2191
|
/**
|
|
2359
2192
|
* CRUD methods to work with Values
|
|
2360
2193
|
*/
|
|
2361
|
-
get sharedValues() {
|
|
2362
|
-
|
|
2363
|
-
}
|
|
2194
|
+
// public get sharedValues(): SharedValueService {
|
|
2195
|
+
// return this.sharedValueService;
|
|
2196
|
+
// }
|
|
2364
2197
|
};
|
|
2365
2198
|
export {
|
|
2366
2199
|
ElekIoCore as default
|