@almadar/runtime 4.13.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OrbitalServerRuntime.js +23 -12
- package/dist/OrbitalServerRuntime.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -798,7 +798,9 @@ var OrbitalServerRuntime = class {
|
|
|
798
798
|
console.log(`[OrbitalRuntime] No instances in schema, generating mock data for ${entity?.name}`);
|
|
799
799
|
}
|
|
800
800
|
if (entity?.name && entity.fields) {
|
|
801
|
-
const fields = entity.fields.
|
|
801
|
+
const fields = entity.fields.filter(
|
|
802
|
+
(f) => typeof f.name === "string" && f.name.length > 0
|
|
803
|
+
).map((f) => ({
|
|
802
804
|
name: f.name,
|
|
803
805
|
type: f.type,
|
|
804
806
|
required: f.required,
|
|
@@ -1064,7 +1066,9 @@ var OrbitalServerRuntime = class {
|
|
|
1064
1066
|
for (const registered of this.orbitals.values()) {
|
|
1065
1067
|
const entity = registered.entity;
|
|
1066
1068
|
if (entity?.name && entity.fields) {
|
|
1067
|
-
const fields = entity.fields.
|
|
1069
|
+
const fields = entity.fields.filter(
|
|
1070
|
+
(f) => typeof f.name === "string" && f.name.length > 0
|
|
1071
|
+
).map((f) => ({
|
|
1068
1072
|
name: f.name,
|
|
1069
1073
|
type: f.type,
|
|
1070
1074
|
required: f.required,
|
|
@@ -1627,23 +1631,25 @@ var OrbitalServerRuntime = class {
|
|
|
1627
1631
|
if (registered.entity.name !== entityType) continue;
|
|
1628
1632
|
for (const field of registered.entity.fields ?? []) {
|
|
1629
1633
|
if (field.type !== "relation") continue;
|
|
1630
|
-
|
|
1634
|
+
if (field.name === void 0) continue;
|
|
1635
|
+
const fieldName = field.name;
|
|
1636
|
+
const value = data[fieldName];
|
|
1631
1637
|
if (value === void 0 || value === null) continue;
|
|
1632
1638
|
const cardinality = field.relation?.cardinality || "one";
|
|
1633
1639
|
if (cardinality === "one" || cardinality === "many-to-one") {
|
|
1634
1640
|
if (Array.isArray(value)) {
|
|
1635
1641
|
throw new Error(
|
|
1636
|
-
`Cardinality violation: ${entityType}.${
|
|
1642
|
+
`Cardinality violation: ${entityType}.${fieldName} has cardinality '${cardinality}' but received an array. Expected a single string ID.`
|
|
1637
1643
|
);
|
|
1638
1644
|
}
|
|
1639
1645
|
} else if (cardinality === "many" || cardinality === "many-to-many" || cardinality === "one-to-many") {
|
|
1640
1646
|
if (typeof value === "string") {
|
|
1641
|
-
data[
|
|
1647
|
+
data[fieldName] = [value];
|
|
1642
1648
|
} else if (Array.isArray(value)) {
|
|
1643
1649
|
const nonStrings = value.filter((v) => typeof v !== "string");
|
|
1644
1650
|
if (nonStrings.length > 0) {
|
|
1645
1651
|
throw new Error(
|
|
1646
|
-
`Cardinality violation: ${entityType}.${
|
|
1652
|
+
`Cardinality violation: ${entityType}.${fieldName} has cardinality '${cardinality}' but array contains non-string values.`
|
|
1647
1653
|
);
|
|
1648
1654
|
}
|
|
1649
1655
|
}
|
|
@@ -1664,11 +1670,13 @@ var OrbitalServerRuntime = class {
|
|
|
1664
1670
|
for (const field of fields) {
|
|
1665
1671
|
if (field.type !== "relation") continue;
|
|
1666
1672
|
if (field.relation?.entity !== entityType) continue;
|
|
1673
|
+
if (field.name === void 0) continue;
|
|
1674
|
+
const fieldName = field.name;
|
|
1667
1675
|
const onDelete = field.relation.onDelete || "restrict";
|
|
1668
1676
|
const referringEntityType = entity.name;
|
|
1669
1677
|
const allRecords = await this.persistence.list(referringEntityType);
|
|
1670
1678
|
const affectedRecords = allRecords.filter((record) => {
|
|
1671
|
-
const fkValue = record[
|
|
1679
|
+
const fkValue = record[fieldName];
|
|
1672
1680
|
if (typeof fkValue === "string") return fkValue === deletedId;
|
|
1673
1681
|
if (Array.isArray(fkValue)) return fkValue.includes(deletedId);
|
|
1674
1682
|
return false;
|
|
@@ -1693,13 +1701,14 @@ var OrbitalServerRuntime = class {
|
|
|
1693
1701
|
case "nullify":
|
|
1694
1702
|
for (const record of affectedRecords) {
|
|
1695
1703
|
const recordId = record.id;
|
|
1696
|
-
if (recordId) {
|
|
1704
|
+
if (recordId && field.name !== void 0) {
|
|
1705
|
+
const fieldName2 = field.name;
|
|
1697
1706
|
const update = {};
|
|
1698
|
-
const fkValue = record[
|
|
1707
|
+
const fkValue = record[fieldName2];
|
|
1699
1708
|
if (Array.isArray(fkValue)) {
|
|
1700
|
-
update[
|
|
1709
|
+
update[fieldName2] = fkValue.filter((id) => id !== deletedId);
|
|
1701
1710
|
} else {
|
|
1702
|
-
update[
|
|
1711
|
+
update[fieldName2] = null;
|
|
1703
1712
|
}
|
|
1704
1713
|
await this.persistence.update(referringEntityType, recordId, update);
|
|
1705
1714
|
}
|
|
@@ -1724,7 +1733,9 @@ var OrbitalServerRuntime = class {
|
|
|
1724
1733
|
let entityFields;
|
|
1725
1734
|
for (const [, registered] of this.orbitals) {
|
|
1726
1735
|
if (registered.entity.name === entityType) {
|
|
1727
|
-
entityFields = registered.entity.fields
|
|
1736
|
+
entityFields = registered.entity.fields.filter(
|
|
1737
|
+
(f) => typeof f.name === "string" && f.name.length > 0
|
|
1738
|
+
);
|
|
1728
1739
|
break;
|
|
1729
1740
|
}
|
|
1730
1741
|
}
|