@elek-io/core 0.2.0 → 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 +122 -274
- 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 +105 -272
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -33,8 +33,8 @@ __export(src_exports, {
|
|
|
33
33
|
default: () => ElekIoCore
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
36
|
+
var import_shared12 = require("@elek-io/shared");
|
|
37
|
+
var import_fs_extra7 = __toESM(require("fs-extra"), 1);
|
|
38
38
|
|
|
39
39
|
// src/service/AssetService.ts
|
|
40
40
|
var import_shared7 = require("@elek-io/shared");
|
|
@@ -107,11 +107,8 @@ var pathTo = {
|
|
|
107
107
|
entries: (projectId, collectionId) => {
|
|
108
108
|
return import_path.default.join(pathTo.collection(projectId, collectionId));
|
|
109
109
|
},
|
|
110
|
-
entryFile: (projectId, collectionId, id
|
|
111
|
-
return import_path.default.join(
|
|
112
|
-
pathTo.entries(projectId, collectionId),
|
|
113
|
-
`${id}.${language}.json`
|
|
114
|
-
);
|
|
110
|
+
entryFile: (projectId, collectionId, id) => {
|
|
111
|
+
return import_path.default.join(pathTo.entries(projectId, collectionId), `${id}.json`);
|
|
115
112
|
},
|
|
116
113
|
sharedValues: (projectId) => {
|
|
117
114
|
return import_path.default.join(pathTo.project(projectId), "shared-values");
|
|
@@ -1357,189 +1354,28 @@ var CollectionService = class extends AbstractCrudService {
|
|
|
1357
1354
|
};
|
|
1358
1355
|
|
|
1359
1356
|
// src/service/EntryService.ts
|
|
1360
|
-
var import_shared10 = require("@elek-io/shared");
|
|
1361
|
-
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
1362
|
-
|
|
1363
|
-
// src/service/SharedValueService.ts
|
|
1364
1357
|
var import_shared9 = require("@elek-io/shared");
|
|
1365
1358
|
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
1366
|
-
var SharedValueService = class extends AbstractCrudService {
|
|
1367
|
-
constructor(options, jsonFileService, gitService, assetService) {
|
|
1368
|
-
super(import_shared9.serviceTypeSchema.Enum.Value, options);
|
|
1369
|
-
this.jsonFileService = jsonFileService;
|
|
1370
|
-
this.gitService = gitService;
|
|
1371
|
-
}
|
|
1372
|
-
/**
|
|
1373
|
-
* Creates a new shared Value
|
|
1374
|
-
*/
|
|
1375
|
-
async create(props) {
|
|
1376
|
-
import_shared9.createSharedValueSchema.parse(props);
|
|
1377
|
-
const id = (0, import_shared9.uuid)();
|
|
1378
|
-
const projectPath = pathTo.project(props.projectId);
|
|
1379
|
-
const sharedValueFilePath = pathTo.sharedValueFile(
|
|
1380
|
-
props.projectId,
|
|
1381
|
-
id,
|
|
1382
|
-
props.language
|
|
1383
|
-
);
|
|
1384
|
-
const sharedValueFile = {
|
|
1385
|
-
...props,
|
|
1386
|
-
objectType: "sharedValue",
|
|
1387
|
-
id,
|
|
1388
|
-
created: (0, import_shared9.currentTimestamp)()
|
|
1389
|
-
};
|
|
1390
|
-
this.validate(sharedValueFile);
|
|
1391
|
-
await this.jsonFileService.create(
|
|
1392
|
-
sharedValueFile,
|
|
1393
|
-
sharedValueFilePath,
|
|
1394
|
-
import_shared9.sharedValueFileSchema
|
|
1395
|
-
);
|
|
1396
|
-
await this.gitService.add(projectPath, [sharedValueFilePath]);
|
|
1397
|
-
await this.gitService.commit(projectPath, this.gitMessage.create);
|
|
1398
|
-
return sharedValueFile;
|
|
1399
|
-
}
|
|
1400
|
-
/**
|
|
1401
|
-
* Returns a shared Value by ID and language
|
|
1402
|
-
*/
|
|
1403
|
-
async read(props) {
|
|
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
|
|
1412
|
-
);
|
|
1413
|
-
return sharedValueFile;
|
|
1414
|
-
}
|
|
1415
|
-
/**
|
|
1416
|
-
* Updates given shared Values content
|
|
1417
|
-
*
|
|
1418
|
-
* The valueType cannot be changed after creating the shared Value
|
|
1419
|
-
*/
|
|
1420
|
-
async update(props) {
|
|
1421
|
-
import_shared9.updateSharedValueSchema.parse(props);
|
|
1422
|
-
const projectPath = pathTo.project(props.projectId);
|
|
1423
|
-
const sharedValueFilePath = pathTo.sharedValueFile(
|
|
1424
|
-
props.projectId,
|
|
1425
|
-
props.id,
|
|
1426
|
-
props.language
|
|
1427
|
-
);
|
|
1428
|
-
const prevSharedValueFile = await this.read(props);
|
|
1429
|
-
const sharedValueFile = {
|
|
1430
|
-
...prevSharedValueFile,
|
|
1431
|
-
content: props.content,
|
|
1432
|
-
updated: (0, import_shared9.currentTimestamp)()
|
|
1433
|
-
};
|
|
1434
|
-
this.validate(sharedValueFile);
|
|
1435
|
-
await this.jsonFileService.update(
|
|
1436
|
-
sharedValueFile,
|
|
1437
|
-
sharedValueFilePath,
|
|
1438
|
-
import_shared9.sharedValueFileSchema
|
|
1439
|
-
);
|
|
1440
|
-
await this.gitService.add(projectPath, [sharedValueFilePath]);
|
|
1441
|
-
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
1442
|
-
return sharedValueFile;
|
|
1443
|
-
}
|
|
1444
|
-
/**
|
|
1445
|
-
* Deletes given shared Value
|
|
1446
|
-
*/
|
|
1447
|
-
async delete(props) {
|
|
1448
|
-
import_shared9.deleteSharedValueSchema.parse(props);
|
|
1449
|
-
const projectPath = pathTo.project(props.projectId);
|
|
1450
|
-
const valueFilePath = pathTo.sharedValueFile(
|
|
1451
|
-
props.projectId,
|
|
1452
|
-
props.id,
|
|
1453
|
-
props.language
|
|
1454
|
-
);
|
|
1455
|
-
await import_fs_extra5.default.remove(valueFilePath);
|
|
1456
|
-
await this.gitService.add(projectPath, [valueFilePath]);
|
|
1457
|
-
await this.gitService.commit(projectPath, this.gitMessage.delete);
|
|
1458
|
-
}
|
|
1459
|
-
async list(props) {
|
|
1460
|
-
import_shared9.listSharedValuesSchema.parse(props);
|
|
1461
|
-
const references = await this.listReferences(
|
|
1462
|
-
import_shared9.objectTypeSchema.Enum.sharedValue,
|
|
1463
|
-
props.projectId
|
|
1464
|
-
);
|
|
1465
|
-
const list = await returnResolved(
|
|
1466
|
-
references.map((reference) => {
|
|
1467
|
-
if (!reference.language) {
|
|
1468
|
-
throw new RequiredParameterMissingError("language");
|
|
1469
|
-
}
|
|
1470
|
-
return this.read({
|
|
1471
|
-
projectId: props.projectId,
|
|
1472
|
-
id: reference.id,
|
|
1473
|
-
language: reference.language
|
|
1474
|
-
});
|
|
1475
|
-
})
|
|
1476
|
-
);
|
|
1477
|
-
return this.paginate(
|
|
1478
|
-
list,
|
|
1479
|
-
props.sort,
|
|
1480
|
-
props.filter,
|
|
1481
|
-
props.limit,
|
|
1482
|
-
props.offset
|
|
1483
|
-
);
|
|
1484
|
-
}
|
|
1485
|
-
async count(props) {
|
|
1486
|
-
import_shared9.countValuesSchema.parse(props);
|
|
1487
|
-
const count = (await this.listReferences(
|
|
1488
|
-
import_shared9.objectTypeSchema.Enum.sharedValue,
|
|
1489
|
-
props.projectId
|
|
1490
|
-
)).length;
|
|
1491
|
-
return count;
|
|
1492
|
-
}
|
|
1493
|
-
/**
|
|
1494
|
-
* Checks if given object is a shared Value
|
|
1495
|
-
*/
|
|
1496
|
-
isSharedValue(obj) {
|
|
1497
|
-
return import_shared9.sharedValueSchema.safeParse(obj).success;
|
|
1498
|
-
}
|
|
1499
|
-
/**
|
|
1500
|
-
* Reads the given shared Values content based on it's ValueType
|
|
1501
|
-
*/
|
|
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
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
};
|
|
1520
|
-
|
|
1521
|
-
// src/service/EntryService.ts
|
|
1522
1359
|
var EntryService = class extends AbstractCrudService {
|
|
1523
|
-
|
|
1524
|
-
|
|
1360
|
+
// private sharedValueService: SharedValueService;
|
|
1361
|
+
constructor(options, jsonFileService, gitService, collectionService, assetService) {
|
|
1362
|
+
super(import_shared9.serviceTypeSchema.Enum.Entry, options);
|
|
1525
1363
|
this.jsonFileService = jsonFileService;
|
|
1526
1364
|
this.gitService = gitService;
|
|
1527
1365
|
this.collectionService = collectionService;
|
|
1528
1366
|
this.assetService = assetService;
|
|
1529
|
-
this.sharedValueService = sharedValueService;
|
|
1530
1367
|
}
|
|
1531
1368
|
/**
|
|
1532
1369
|
* Creates a new Entry for given Collection
|
|
1533
1370
|
*/
|
|
1534
1371
|
async create(props) {
|
|
1535
|
-
|
|
1536
|
-
const id = (0,
|
|
1372
|
+
import_shared9.createEntrySchema.parse(props);
|
|
1373
|
+
const id = (0, import_shared9.uuid)();
|
|
1537
1374
|
const projectPath = pathTo.project(props.projectId);
|
|
1538
1375
|
const entryFilePath = pathTo.entryFile(
|
|
1539
1376
|
props.projectId,
|
|
1540
1377
|
props.collectionId,
|
|
1541
|
-
id
|
|
1542
|
-
props.language
|
|
1378
|
+
id
|
|
1543
1379
|
);
|
|
1544
1380
|
const collection = await this.collectionService.read({
|
|
1545
1381
|
projectId: props.projectId,
|
|
@@ -1548,12 +1384,12 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1548
1384
|
const entryFile = {
|
|
1549
1385
|
objectType: "entry",
|
|
1550
1386
|
id,
|
|
1551
|
-
language: props.language,
|
|
1552
1387
|
values: props.values,
|
|
1553
|
-
created: (0,
|
|
1388
|
+
created: (0, import_shared9.currentTimestamp)()
|
|
1554
1389
|
};
|
|
1555
1390
|
const entry = await this.toEntry({
|
|
1556
1391
|
projectId: props.projectId,
|
|
1392
|
+
collectionId: props.collectionId,
|
|
1557
1393
|
entryFile
|
|
1558
1394
|
});
|
|
1559
1395
|
this.validateValues({
|
|
@@ -1564,7 +1400,7 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1564
1400
|
await this.jsonFileService.create(
|
|
1565
1401
|
entryFile,
|
|
1566
1402
|
entryFilePath,
|
|
1567
|
-
|
|
1403
|
+
import_shared9.entryFileSchema
|
|
1568
1404
|
);
|
|
1569
1405
|
await this.gitService.add(projectPath, [entryFilePath]);
|
|
1570
1406
|
await this.gitService.commit(projectPath, this.gitMessage.create);
|
|
@@ -1574,29 +1410,27 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1574
1410
|
* Returns an Entry from given Collection by ID and language
|
|
1575
1411
|
*/
|
|
1576
1412
|
async read(props) {
|
|
1577
|
-
|
|
1413
|
+
import_shared9.readEntrySchema.parse(props);
|
|
1578
1414
|
const entryFile = await this.jsonFileService.read(
|
|
1579
|
-
pathTo.entryFile(
|
|
1580
|
-
|
|
1581
|
-
props.collectionId,
|
|
1582
|
-
props.id,
|
|
1583
|
-
props.language
|
|
1584
|
-
),
|
|
1585
|
-
import_shared10.entryFileSchema
|
|
1415
|
+
pathTo.entryFile(props.projectId, props.collectionId, props.id),
|
|
1416
|
+
import_shared9.entryFileSchema
|
|
1586
1417
|
);
|
|
1587
|
-
return await this.toEntry({
|
|
1418
|
+
return await this.toEntry({
|
|
1419
|
+
projectId: props.projectId,
|
|
1420
|
+
collectionId: props.collectionId,
|
|
1421
|
+
entryFile
|
|
1422
|
+
});
|
|
1588
1423
|
}
|
|
1589
1424
|
/**
|
|
1590
1425
|
* Updates an Entry of given Collection with new Values and shared Values
|
|
1591
1426
|
*/
|
|
1592
1427
|
async update(props) {
|
|
1593
|
-
|
|
1428
|
+
import_shared9.updateEntrySchema.parse(props);
|
|
1594
1429
|
const projectPath = pathTo.project(props.projectId);
|
|
1595
1430
|
const entryFilePath = pathTo.entryFile(
|
|
1596
1431
|
props.projectId,
|
|
1597
1432
|
props.collectionId,
|
|
1598
|
-
props.id
|
|
1599
|
-
props.language
|
|
1433
|
+
props.id
|
|
1600
1434
|
);
|
|
1601
1435
|
const collection = await this.collectionService.read({
|
|
1602
1436
|
projectId: props.projectId,
|
|
@@ -1605,16 +1439,16 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1605
1439
|
const prevEntryFile = await this.read({
|
|
1606
1440
|
projectId: props.projectId,
|
|
1607
1441
|
collectionId: props.collectionId,
|
|
1608
|
-
id: props.id
|
|
1609
|
-
language: props.language
|
|
1442
|
+
id: props.id
|
|
1610
1443
|
});
|
|
1611
1444
|
const entryFile = {
|
|
1612
1445
|
...prevEntryFile,
|
|
1613
1446
|
values: props.values,
|
|
1614
|
-
updated: (0,
|
|
1447
|
+
updated: (0, import_shared9.currentTimestamp)()
|
|
1615
1448
|
};
|
|
1616
1449
|
const entry = await this.toEntry({
|
|
1617
1450
|
projectId: props.projectId,
|
|
1451
|
+
collectionId: props.collectionId,
|
|
1618
1452
|
entryFile
|
|
1619
1453
|
});
|
|
1620
1454
|
this.validateValues({
|
|
@@ -1625,7 +1459,7 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1625
1459
|
await this.jsonFileService.update(
|
|
1626
1460
|
entryFile,
|
|
1627
1461
|
entryFilePath,
|
|
1628
|
-
|
|
1462
|
+
import_shared9.entryFileSchema
|
|
1629
1463
|
);
|
|
1630
1464
|
await this.gitService.add(projectPath, [entryFilePath]);
|
|
1631
1465
|
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
@@ -1635,35 +1469,30 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1635
1469
|
* Deletes given Entry from it's Collection
|
|
1636
1470
|
*/
|
|
1637
1471
|
async delete(props) {
|
|
1638
|
-
|
|
1472
|
+
import_shared9.deleteEntrySchema.parse(props);
|
|
1639
1473
|
const projectPath = pathTo.project(props.projectId);
|
|
1640
1474
|
const entryFilePath = pathTo.entryFile(
|
|
1641
1475
|
props.projectId,
|
|
1642
1476
|
props.collectionId,
|
|
1643
|
-
props.id
|
|
1644
|
-
props.language
|
|
1477
|
+
props.id
|
|
1645
1478
|
);
|
|
1646
|
-
await
|
|
1479
|
+
await import_fs_extra5.default.remove(entryFilePath);
|
|
1647
1480
|
await this.gitService.add(projectPath, [entryFilePath]);
|
|
1648
1481
|
await this.gitService.commit(projectPath, this.gitMessage.delete);
|
|
1649
1482
|
}
|
|
1650
1483
|
async list(props) {
|
|
1651
|
-
|
|
1484
|
+
import_shared9.listEntriesSchema.parse(props);
|
|
1652
1485
|
const references = await this.listReferences(
|
|
1653
|
-
|
|
1486
|
+
import_shared9.objectTypeSchema.Enum.entry,
|
|
1654
1487
|
props.projectId,
|
|
1655
1488
|
props.collectionId
|
|
1656
1489
|
);
|
|
1657
1490
|
const list = await returnResolved(
|
|
1658
1491
|
references.map((reference) => {
|
|
1659
|
-
if (!reference.language) {
|
|
1660
|
-
throw new RequiredParameterMissingError("language");
|
|
1661
|
-
}
|
|
1662
1492
|
return this.read({
|
|
1663
1493
|
projectId: props.projectId,
|
|
1664
1494
|
collectionId: props.collectionId,
|
|
1665
|
-
id: reference.id
|
|
1666
|
-
language: reference.language
|
|
1495
|
+
id: reference.id
|
|
1667
1496
|
});
|
|
1668
1497
|
})
|
|
1669
1498
|
);
|
|
@@ -1676,9 +1505,9 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1676
1505
|
);
|
|
1677
1506
|
}
|
|
1678
1507
|
async count(props) {
|
|
1679
|
-
|
|
1508
|
+
import_shared9.countEntriesSchema.parse(props);
|
|
1680
1509
|
return (await this.listReferences(
|
|
1681
|
-
|
|
1510
|
+
import_shared9.objectTypeSchema.Enum.entry,
|
|
1682
1511
|
props.projectId,
|
|
1683
1512
|
props.collectionId
|
|
1684
1513
|
)).length;
|
|
@@ -1687,7 +1516,7 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1687
1516
|
* Checks if given object is of type Entry
|
|
1688
1517
|
*/
|
|
1689
1518
|
isEntry(obj) {
|
|
1690
|
-
return
|
|
1519
|
+
return import_shared9.entrySchema.safeParse(obj).success;
|
|
1691
1520
|
}
|
|
1692
1521
|
/**
|
|
1693
1522
|
* Returns a Value definition by ID
|
|
@@ -1716,9 +1545,15 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1716
1545
|
valueDefinitions: props.valueDefinitions,
|
|
1717
1546
|
id: value.definitionId
|
|
1718
1547
|
});
|
|
1719
|
-
const schema = (0,
|
|
1548
|
+
const schema = (0, import_shared9.getValueContentSchemaFromDefinition)(definition);
|
|
1720
1549
|
try {
|
|
1721
|
-
|
|
1550
|
+
if (value.valueType === "reference") {
|
|
1551
|
+
schema.parse(value.content);
|
|
1552
|
+
} else {
|
|
1553
|
+
for (const [language, content] of Object.entries(value.content)) {
|
|
1554
|
+
schema.parse(content);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1722
1557
|
} catch (error) {
|
|
1723
1558
|
console.log("Definition:", definition);
|
|
1724
1559
|
console.log("Value:", value);
|
|
@@ -1746,15 +1581,16 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1746
1581
|
// }
|
|
1747
1582
|
async resolveValueContentReference(props) {
|
|
1748
1583
|
switch (props.valueContentReference.referenceObjectType) {
|
|
1749
|
-
case
|
|
1584
|
+
case import_shared9.objectTypeSchema.Enum.asset:
|
|
1750
1585
|
return this.resolveValueContentReferenceToAsset({
|
|
1751
1586
|
projectId: props.projectId,
|
|
1752
1587
|
valueContentReferenceToAsset: props.valueContentReference
|
|
1753
1588
|
});
|
|
1754
|
-
case
|
|
1755
|
-
return this.
|
|
1589
|
+
case import_shared9.objectTypeSchema.Enum.entry:
|
|
1590
|
+
return this.resolveValueContentReferenceToEntry({
|
|
1756
1591
|
projectId: props.projectId,
|
|
1757
|
-
|
|
1592
|
+
collectionId: props.collectionId,
|
|
1593
|
+
valueContentReferenceToEntry: props.valueContentReference
|
|
1758
1594
|
});
|
|
1759
1595
|
default:
|
|
1760
1596
|
throw new Error(
|
|
@@ -1771,10 +1607,7 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1771
1607
|
id: reference.id,
|
|
1772
1608
|
language: reference.language
|
|
1773
1609
|
});
|
|
1774
|
-
return
|
|
1775
|
-
...reference,
|
|
1776
|
-
resolved: resolvedAsset
|
|
1777
|
-
};
|
|
1610
|
+
return resolvedAsset;
|
|
1778
1611
|
})
|
|
1779
1612
|
);
|
|
1780
1613
|
return {
|
|
@@ -1782,20 +1615,39 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1782
1615
|
references: resolvedReferences
|
|
1783
1616
|
};
|
|
1784
1617
|
}
|
|
1785
|
-
async
|
|
1786
|
-
const
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1618
|
+
async resolveValueContentReferenceToEntry(props) {
|
|
1619
|
+
const resolvedReferences = await Promise.all(
|
|
1620
|
+
props.valueContentReferenceToEntry.references.map(async (reference) => {
|
|
1621
|
+
const resolvedEntry = await this.read({
|
|
1622
|
+
projectId: props.projectId,
|
|
1623
|
+
collectionId: props.collectionId,
|
|
1624
|
+
id: reference.id
|
|
1625
|
+
});
|
|
1626
|
+
return resolvedEntry;
|
|
1627
|
+
})
|
|
1628
|
+
);
|
|
1791
1629
|
return {
|
|
1792
|
-
...props.
|
|
1793
|
-
references:
|
|
1794
|
-
...props.valueContentReferenceToSharedValue.references,
|
|
1795
|
-
resolved: resolvedSharedValue
|
|
1796
|
-
}
|
|
1630
|
+
...props.valueContentReferenceToEntry,
|
|
1631
|
+
references: resolvedReferences
|
|
1797
1632
|
};
|
|
1798
1633
|
}
|
|
1634
|
+
// private async resolveValueContentReferenceToSharedValue(props: {
|
|
1635
|
+
// projectId: string;
|
|
1636
|
+
// valueContentReferenceToSharedValue: ValueContentReferenceToSharedValue;
|
|
1637
|
+
// }): Promise<ResolvedValueContentReferenceToSharedValue> {
|
|
1638
|
+
// const resolvedSharedValue = await this.sharedValueService.read({
|
|
1639
|
+
// projectId: props.projectId,
|
|
1640
|
+
// id: props.valueContentReferenceToSharedValue.references.id,
|
|
1641
|
+
// language: props.valueContentReferenceToSharedValue.references.language,
|
|
1642
|
+
// });
|
|
1643
|
+
// return {
|
|
1644
|
+
// ...props.valueContentReferenceToSharedValue,
|
|
1645
|
+
// references: {
|
|
1646
|
+
// ...props.valueContentReferenceToSharedValue.references,
|
|
1647
|
+
// resolved: resolvedSharedValue,
|
|
1648
|
+
// },
|
|
1649
|
+
// };
|
|
1650
|
+
// }
|
|
1799
1651
|
/**
|
|
1800
1652
|
* Creates an Entry from given EntryFile by resolving it's Values
|
|
1801
1653
|
*/
|
|
@@ -1804,9 +1656,10 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1804
1656
|
...props.entryFile,
|
|
1805
1657
|
values: await Promise.all(
|
|
1806
1658
|
props.entryFile.values.map(async (value) => {
|
|
1807
|
-
if (value.valueType ===
|
|
1659
|
+
if (value.valueType === import_shared9.ValueTypeSchema.Enum.reference) {
|
|
1808
1660
|
const resolvedValueContentReference = await this.resolveValueContentReference({
|
|
1809
1661
|
projectId: props.projectId,
|
|
1662
|
+
collectionId: props.collectionId,
|
|
1810
1663
|
valueContentReference: value.content
|
|
1811
1664
|
});
|
|
1812
1665
|
return {
|
|
@@ -1823,8 +1676,8 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1823
1676
|
};
|
|
1824
1677
|
|
|
1825
1678
|
// src/service/ProjectService.ts
|
|
1826
|
-
var
|
|
1827
|
-
var
|
|
1679
|
+
var import_shared11 = require("@elek-io/shared");
|
|
1680
|
+
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
1828
1681
|
var import_os2 = __toESM(require("os"), 1);
|
|
1829
1682
|
var import_path2 = __toESM(require("path"), 1);
|
|
1830
1683
|
var import_semver = __toESM(require("semver"), 1);
|
|
@@ -1838,10 +1691,10 @@ var ProjectUpgradeError = class extends Error {
|
|
|
1838
1691
|
};
|
|
1839
1692
|
|
|
1840
1693
|
// src/service/SearchService.ts
|
|
1841
|
-
var
|
|
1694
|
+
var import_shared10 = require("@elek-io/shared");
|
|
1842
1695
|
var SearchService = class extends AbstractCrudService {
|
|
1843
1696
|
constructor(options, assetService, collectionService) {
|
|
1844
|
-
super(
|
|
1697
|
+
super(import_shared10.serviceTypeSchema.enum.Search, options);
|
|
1845
1698
|
this.assetService = assetService;
|
|
1846
1699
|
this.collectionService = collectionService;
|
|
1847
1700
|
}
|
|
@@ -1907,7 +1760,7 @@ var SearchService = class extends AbstractCrudService {
|
|
|
1907
1760
|
// src/service/ProjectService.ts
|
|
1908
1761
|
var ProjectService = class extends AbstractCrudService {
|
|
1909
1762
|
constructor(options, jsonFileService, userService, gitService, searchService, assetService, collectionService, entryService) {
|
|
1910
|
-
super(
|
|
1763
|
+
super(import_shared11.serviceTypeSchema.Enum.Project, options);
|
|
1911
1764
|
this.jsonFileService = jsonFileService;
|
|
1912
1765
|
this.userService = userService;
|
|
1913
1766
|
this.gitService = gitService;
|
|
@@ -1920,16 +1773,16 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1920
1773
|
* Creates a new Project
|
|
1921
1774
|
*/
|
|
1922
1775
|
async create(props) {
|
|
1923
|
-
|
|
1776
|
+
import_shared11.createProjectSchema.parse(props);
|
|
1924
1777
|
const user = await this.userService.get();
|
|
1925
1778
|
if (!user) {
|
|
1926
1779
|
throw new NoCurrentUserError();
|
|
1927
1780
|
}
|
|
1928
|
-
const id = (0,
|
|
1781
|
+
const id = (0, import_shared11.uuid)();
|
|
1929
1782
|
const defaultSettings = {
|
|
1930
|
-
|
|
1931
|
-
default: user.
|
|
1932
|
-
supported: [user.
|
|
1783
|
+
language: {
|
|
1784
|
+
default: user.language,
|
|
1785
|
+
supported: [user.language]
|
|
1933
1786
|
}
|
|
1934
1787
|
};
|
|
1935
1788
|
const projectFile = {
|
|
@@ -1938,14 +1791,14 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1938
1791
|
id,
|
|
1939
1792
|
description: props.description || "",
|
|
1940
1793
|
settings: Object.assign({}, defaultSettings, props.settings),
|
|
1941
|
-
created: (0,
|
|
1794
|
+
created: (0, import_shared11.currentTimestamp)(),
|
|
1942
1795
|
coreVersion: this.options.version,
|
|
1943
1796
|
// @todo should be read from package.json to avoid duplicates
|
|
1944
1797
|
status: "todo",
|
|
1945
1798
|
version: "0.0.1"
|
|
1946
1799
|
};
|
|
1947
1800
|
const projectPath = pathTo.project(id);
|
|
1948
|
-
await
|
|
1801
|
+
await import_fs_extra6.default.ensureDir(projectPath);
|
|
1949
1802
|
try {
|
|
1950
1803
|
await this.createFolderStructure(projectPath);
|
|
1951
1804
|
await this.createGitignore(projectPath);
|
|
@@ -1953,12 +1806,12 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1953
1806
|
await this.jsonFileService.create(
|
|
1954
1807
|
projectFile,
|
|
1955
1808
|
pathTo.projectFile(id),
|
|
1956
|
-
|
|
1809
|
+
import_shared11.projectFileSchema
|
|
1957
1810
|
);
|
|
1958
1811
|
await this.gitService.add(projectPath, ["."]);
|
|
1959
1812
|
await this.gitService.commit(
|
|
1960
1813
|
projectPath,
|
|
1961
|
-
`${
|
|
1814
|
+
`${import_shared11.gitCommitIconSchema.enum.INIT} Created this new elek.io project`
|
|
1962
1815
|
);
|
|
1963
1816
|
await this.gitService.switch(projectPath, "stage", { isNew: true });
|
|
1964
1817
|
} catch (error) {
|
|
@@ -1973,10 +1826,10 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1973
1826
|
* Returns a Project by ID
|
|
1974
1827
|
*/
|
|
1975
1828
|
async read(props) {
|
|
1976
|
-
|
|
1829
|
+
import_shared11.readProjectSchema.parse(props);
|
|
1977
1830
|
const projectFile = await this.jsonFileService.read(
|
|
1978
1831
|
pathTo.projectFile(props.id),
|
|
1979
|
-
|
|
1832
|
+
import_shared11.projectFileSchema
|
|
1980
1833
|
);
|
|
1981
1834
|
return projectFile;
|
|
1982
1835
|
}
|
|
@@ -1984,16 +1837,16 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
1984
1837
|
* Updates given Project
|
|
1985
1838
|
*/
|
|
1986
1839
|
async update(props) {
|
|
1987
|
-
|
|
1840
|
+
import_shared11.updateProjectSchema.parse(props);
|
|
1988
1841
|
const projectPath = pathTo.project(props.id);
|
|
1989
1842
|
const filePath = pathTo.projectFile(props.id);
|
|
1990
1843
|
const prevProjectFile = await this.read(props);
|
|
1991
1844
|
const projectFile = {
|
|
1992
1845
|
...prevProjectFile,
|
|
1993
1846
|
...props,
|
|
1994
|
-
updated: (0,
|
|
1847
|
+
updated: (0, import_shared11.currentTimestamp)()
|
|
1995
1848
|
};
|
|
1996
|
-
await this.jsonFileService.update(projectFile, filePath,
|
|
1849
|
+
await this.jsonFileService.update(projectFile, filePath, import_shared11.projectFileSchema);
|
|
1997
1850
|
await this.gitService.add(projectPath, [filePath]);
|
|
1998
1851
|
await this.gitService.commit(projectPath, this.gitMessage.update);
|
|
1999
1852
|
return projectFile;
|
|
@@ -2006,7 +1859,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2006
1859
|
* @todo Find out why using this.snapshotService is throwing isObjWithKeyAndValueOfString of undefined error in gitService (maybe binding issue)
|
|
2007
1860
|
*/
|
|
2008
1861
|
async upgrade(props) {
|
|
2009
|
-
|
|
1862
|
+
import_shared11.upgradeProjectSchema.parse(props);
|
|
2010
1863
|
const project = await this.read(props);
|
|
2011
1864
|
const projectPath = pathTo.project(project.id);
|
|
2012
1865
|
if (import_semver.default.gt(project.coreVersion, this.options.version)) {
|
|
@@ -2072,14 +1925,14 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2072
1925
|
* Or changes that are not pushed to a remote yet, will be lost too.
|
|
2073
1926
|
*/
|
|
2074
1927
|
async delete(props) {
|
|
2075
|
-
|
|
2076
|
-
await
|
|
1928
|
+
import_shared11.deleteProjectSchema.parse(props);
|
|
1929
|
+
await import_fs_extra6.default.remove(pathTo.project(props.id));
|
|
2077
1930
|
}
|
|
2078
1931
|
async list(props) {
|
|
2079
1932
|
if (props) {
|
|
2080
|
-
|
|
1933
|
+
import_shared11.listProjectsSchema.parse(props);
|
|
2081
1934
|
}
|
|
2082
|
-
const references = await this.listReferences(
|
|
1935
|
+
const references = await this.listReferences(import_shared11.objectTypeSchema.Enum.project);
|
|
2083
1936
|
const list = await returnResolved(
|
|
2084
1937
|
references.map((reference) => {
|
|
2085
1938
|
return this.read({ id: reference.id });
|
|
@@ -2094,7 +1947,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2094
1947
|
);
|
|
2095
1948
|
}
|
|
2096
1949
|
async count() {
|
|
2097
|
-
return (await this.listReferences(
|
|
1950
|
+
return (await this.listReferences(import_shared11.objectTypeSchema.Enum.project)).length;
|
|
2098
1951
|
}
|
|
2099
1952
|
/**
|
|
2100
1953
|
* Search all models inside the project for given query
|
|
@@ -2110,7 +1963,7 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2110
1963
|
* Checks if given object is of type Project
|
|
2111
1964
|
*/
|
|
2112
1965
|
isProject(obj) {
|
|
2113
|
-
return
|
|
1966
|
+
return import_shared11.projectFileSchema.safeParse(obj).success;
|
|
2114
1967
|
}
|
|
2115
1968
|
/**
|
|
2116
1969
|
* Exports given Project to JSON
|
|
@@ -2148,11 +2001,11 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2148
2001
|
* committed
|
|
2149
2002
|
*/
|
|
2150
2003
|
async createFolderStructure(path) {
|
|
2151
|
-
const folders2 = Object.values(
|
|
2004
|
+
const folders2 = Object.values(import_shared11.projectFolderSchema.Values);
|
|
2152
2005
|
await Promise.all(
|
|
2153
2006
|
folders2.map(async (folder) => {
|
|
2154
|
-
await
|
|
2155
|
-
await
|
|
2007
|
+
await import_fs_extra6.default.mkdirp(import_path2.default.join(path, folder));
|
|
2008
|
+
await import_fs_extra6.default.writeFile(import_path2.default.join(path, folder, ".gitkeep"), "");
|
|
2156
2009
|
})
|
|
2157
2010
|
);
|
|
2158
2011
|
}
|
|
@@ -2176,14 +2029,15 @@ var ProjectService = class extends AbstractCrudService {
|
|
|
2176
2029
|
// projectFolderSchema.Enum.public + '/',
|
|
2177
2030
|
// projectFolderSchema.Enum.logs + '/',
|
|
2178
2031
|
];
|
|
2179
|
-
await
|
|
2032
|
+
await import_fs_extra6.default.writeFile(import_path2.default.join(path, ".gitignore"), lines.join(import_os2.default.EOL));
|
|
2180
2033
|
}
|
|
2181
2034
|
};
|
|
2182
2035
|
|
|
2183
2036
|
// src/index.ts
|
|
2184
2037
|
var ElekIoCore = class {
|
|
2038
|
+
// private readonly sharedValueService: SharedValueService;
|
|
2185
2039
|
constructor(props) {
|
|
2186
|
-
const parsedProps =
|
|
2040
|
+
const parsedProps = import_shared12.constructorElekIoCoreSchema.parse(props);
|
|
2187
2041
|
const defaults = {
|
|
2188
2042
|
environment: "production",
|
|
2189
2043
|
version: "0.0.0",
|
|
@@ -2207,19 +2061,13 @@ var ElekIoCore = class {
|
|
|
2207
2061
|
this.jsonFileService,
|
|
2208
2062
|
this.gitService
|
|
2209
2063
|
);
|
|
2210
|
-
this.sharedValueService = new SharedValueService(
|
|
2211
|
-
this.options,
|
|
2212
|
-
this.jsonFileService,
|
|
2213
|
-
this.gitService,
|
|
2214
|
-
this.assetService
|
|
2215
|
-
);
|
|
2216
2064
|
this.entryService = new EntryService(
|
|
2217
2065
|
this.options,
|
|
2218
2066
|
this.jsonFileService,
|
|
2219
2067
|
this.gitService,
|
|
2220
2068
|
this.collectionService,
|
|
2221
|
-
this.assetService
|
|
2222
|
-
this.sharedValueService
|
|
2069
|
+
this.assetService
|
|
2070
|
+
// this.sharedValueService
|
|
2223
2071
|
);
|
|
2224
2072
|
this.searchService = new SearchService(
|
|
2225
2073
|
this.options,
|
|
@@ -2244,9 +2092,9 @@ var ElekIoCore = class {
|
|
|
2244
2092
|
}
|
|
2245
2093
|
);
|
|
2246
2094
|
}
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2095
|
+
import_fs_extra7.default.mkdirpSync(pathTo.projects);
|
|
2096
|
+
import_fs_extra7.default.mkdirpSync(pathTo.tmp);
|
|
2097
|
+
import_fs_extra7.default.emptyDirSync(pathTo.tmp);
|
|
2250
2098
|
}
|
|
2251
2099
|
/**
|
|
2252
2100
|
* Utility / helper functions
|
|
@@ -2287,8 +2135,8 @@ var ElekIoCore = class {
|
|
|
2287
2135
|
/**
|
|
2288
2136
|
* CRUD methods to work with Values
|
|
2289
2137
|
*/
|
|
2290
|
-
get sharedValues() {
|
|
2291
|
-
|
|
2292
|
-
}
|
|
2138
|
+
// public get sharedValues(): SharedValueService {
|
|
2139
|
+
// return this.sharedValueService;
|
|
2140
|
+
// }
|
|
2293
2141
|
};
|
|
2294
2142
|
//# sourceMappingURL=index.cjs.map
|