@almadar/runtime 4.13.3 → 5.1.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 +47 -14
- package/dist/OrbitalServerRuntime.js.map +1 -1
- package/dist/{chunk-S5OLFFHT.js → chunk-T343XTYB.js} +36 -5
- package/dist/chunk-T343XTYB.js.map +1 -0
- package/dist/index.js +25 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-S5OLFFHT.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, StateMachineManager, createContextFromBindings, EffectExecutor } from './chunk-
|
|
2
|
-
export { InMemoryPersistence } from './chunk-
|
|
1
|
+
import { createLogger, EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, StateMachineManager, createContextFromBindings, EffectExecutor } from './chunk-T343XTYB.js';
|
|
2
|
+
export { InMemoryPersistence } from './chunk-T343XTYB.js';
|
|
3
3
|
import './chunk-PZ5AY32C.js';
|
|
4
4
|
import { Router } from 'express';
|
|
5
5
|
import * as fs from 'fs';
|
|
@@ -359,6 +359,7 @@ function createOsHandlers(ctx) {
|
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
// src/OrbitalServerRuntime.ts
|
|
362
|
+
var effectLog = createLogger("almadar:runtime:effects");
|
|
362
363
|
function collectDeclaredConfigDefaults(trait) {
|
|
363
364
|
if (!trait) return void 0;
|
|
364
365
|
const schema = trait.config;
|
|
@@ -798,7 +799,9 @@ var OrbitalServerRuntime = class {
|
|
|
798
799
|
console.log(`[OrbitalRuntime] No instances in schema, generating mock data for ${entity?.name}`);
|
|
799
800
|
}
|
|
800
801
|
if (entity?.name && entity.fields) {
|
|
801
|
-
const fields = entity.fields.
|
|
802
|
+
const fields = entity.fields.filter(
|
|
803
|
+
(f) => typeof f.name === "string" && f.name.length > 0
|
|
804
|
+
).map((f) => ({
|
|
802
805
|
name: f.name,
|
|
803
806
|
type: f.type,
|
|
804
807
|
required: f.required,
|
|
@@ -1064,7 +1067,9 @@ var OrbitalServerRuntime = class {
|
|
|
1064
1067
|
for (const registered of this.orbitals.values()) {
|
|
1065
1068
|
const entity = registered.entity;
|
|
1066
1069
|
if (entity?.name && entity.fields) {
|
|
1067
|
-
const fields = entity.fields.
|
|
1070
|
+
const fields = entity.fields.filter(
|
|
1071
|
+
(f) => typeof f.name === "string" && f.name.length > 0
|
|
1072
|
+
).map((f) => ({
|
|
1068
1073
|
name: f.name,
|
|
1069
1074
|
type: f.type,
|
|
1070
1075
|
required: f.required,
|
|
@@ -1187,6 +1192,12 @@ var OrbitalServerRuntime = class {
|
|
|
1187
1192
|
};
|
|
1188
1193
|
this.eventBus.emit(event, eventPayload, stamp);
|
|
1189
1194
|
emittedEvents.push({ event, payload: eventPayload });
|
|
1195
|
+
effectLog.debug("emit:push", {
|
|
1196
|
+
event,
|
|
1197
|
+
cumulativeEmittedCount: emittedEvents.length,
|
|
1198
|
+
sourceTrait: stamp.trait,
|
|
1199
|
+
sourceOrbital: stamp.orbital
|
|
1200
|
+
});
|
|
1190
1201
|
},
|
|
1191
1202
|
set: async (targetId, field, value) => {
|
|
1192
1203
|
const id = targetId || entityId;
|
|
@@ -1285,6 +1296,7 @@ var OrbitalServerRuntime = class {
|
|
|
1285
1296
|
}
|
|
1286
1297
|
const type = targetEntityType || entityType;
|
|
1287
1298
|
let resultData;
|
|
1299
|
+
const sizeBefore = (await this.persistence.list(type)).length;
|
|
1288
1300
|
try {
|
|
1289
1301
|
if (action === "create" || action === "update") {
|
|
1290
1302
|
this.validateRelationCardinality(type, data || {});
|
|
@@ -1315,6 +1327,15 @@ var OrbitalServerRuntime = class {
|
|
|
1315
1327
|
break;
|
|
1316
1328
|
}
|
|
1317
1329
|
}
|
|
1330
|
+
const sizeAfter = (await this.persistence.list(type)).length;
|
|
1331
|
+
effectLog.debug("persist:store-mutate", {
|
|
1332
|
+
action,
|
|
1333
|
+
entityType: type,
|
|
1334
|
+
resultId: resultData?.id,
|
|
1335
|
+
sizeBefore,
|
|
1336
|
+
sizeAfter,
|
|
1337
|
+
delta: sizeAfter - sizeBefore
|
|
1338
|
+
});
|
|
1318
1339
|
effectResults.push({
|
|
1319
1340
|
effect: "persist",
|
|
1320
1341
|
action,
|
|
@@ -1323,6 +1344,11 @@ var OrbitalServerRuntime = class {
|
|
|
1323
1344
|
success: true
|
|
1324
1345
|
});
|
|
1325
1346
|
} catch (err) {
|
|
1347
|
+
effectLog.error("persist:store-mutate-error", {
|
|
1348
|
+
action,
|
|
1349
|
+
entityType: type,
|
|
1350
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1351
|
+
});
|
|
1326
1352
|
effectResults.push({
|
|
1327
1353
|
effect: "persist",
|
|
1328
1354
|
action,
|
|
@@ -1627,23 +1653,25 @@ var OrbitalServerRuntime = class {
|
|
|
1627
1653
|
if (registered.entity.name !== entityType) continue;
|
|
1628
1654
|
for (const field of registered.entity.fields ?? []) {
|
|
1629
1655
|
if (field.type !== "relation") continue;
|
|
1630
|
-
|
|
1656
|
+
if (field.name === void 0) continue;
|
|
1657
|
+
const fieldName = field.name;
|
|
1658
|
+
const value = data[fieldName];
|
|
1631
1659
|
if (value === void 0 || value === null) continue;
|
|
1632
1660
|
const cardinality = field.relation?.cardinality || "one";
|
|
1633
1661
|
if (cardinality === "one" || cardinality === "many-to-one") {
|
|
1634
1662
|
if (Array.isArray(value)) {
|
|
1635
1663
|
throw new Error(
|
|
1636
|
-
`Cardinality violation: ${entityType}.${
|
|
1664
|
+
`Cardinality violation: ${entityType}.${fieldName} has cardinality '${cardinality}' but received an array. Expected a single string ID.`
|
|
1637
1665
|
);
|
|
1638
1666
|
}
|
|
1639
1667
|
} else if (cardinality === "many" || cardinality === "many-to-many" || cardinality === "one-to-many") {
|
|
1640
1668
|
if (typeof value === "string") {
|
|
1641
|
-
data[
|
|
1669
|
+
data[fieldName] = [value];
|
|
1642
1670
|
} else if (Array.isArray(value)) {
|
|
1643
1671
|
const nonStrings = value.filter((v) => typeof v !== "string");
|
|
1644
1672
|
if (nonStrings.length > 0) {
|
|
1645
1673
|
throw new Error(
|
|
1646
|
-
`Cardinality violation: ${entityType}.${
|
|
1674
|
+
`Cardinality violation: ${entityType}.${fieldName} has cardinality '${cardinality}' but array contains non-string values.`
|
|
1647
1675
|
);
|
|
1648
1676
|
}
|
|
1649
1677
|
}
|
|
@@ -1664,11 +1692,13 @@ var OrbitalServerRuntime = class {
|
|
|
1664
1692
|
for (const field of fields) {
|
|
1665
1693
|
if (field.type !== "relation") continue;
|
|
1666
1694
|
if (field.relation?.entity !== entityType) continue;
|
|
1695
|
+
if (field.name === void 0) continue;
|
|
1696
|
+
const fieldName = field.name;
|
|
1667
1697
|
const onDelete = field.relation.onDelete || "restrict";
|
|
1668
1698
|
const referringEntityType = entity.name;
|
|
1669
1699
|
const allRecords = await this.persistence.list(referringEntityType);
|
|
1670
1700
|
const affectedRecords = allRecords.filter((record) => {
|
|
1671
|
-
const fkValue = record[
|
|
1701
|
+
const fkValue = record[fieldName];
|
|
1672
1702
|
if (typeof fkValue === "string") return fkValue === deletedId;
|
|
1673
1703
|
if (Array.isArray(fkValue)) return fkValue.includes(deletedId);
|
|
1674
1704
|
return false;
|
|
@@ -1693,13 +1723,14 @@ var OrbitalServerRuntime = class {
|
|
|
1693
1723
|
case "nullify":
|
|
1694
1724
|
for (const record of affectedRecords) {
|
|
1695
1725
|
const recordId = record.id;
|
|
1696
|
-
if (recordId) {
|
|
1726
|
+
if (recordId && field.name !== void 0) {
|
|
1727
|
+
const fieldName2 = field.name;
|
|
1697
1728
|
const update = {};
|
|
1698
|
-
const fkValue = record[
|
|
1729
|
+
const fkValue = record[fieldName2];
|
|
1699
1730
|
if (Array.isArray(fkValue)) {
|
|
1700
|
-
update[
|
|
1731
|
+
update[fieldName2] = fkValue.filter((id) => id !== deletedId);
|
|
1701
1732
|
} else {
|
|
1702
|
-
update[
|
|
1733
|
+
update[fieldName2] = null;
|
|
1703
1734
|
}
|
|
1704
1735
|
await this.persistence.update(referringEntityType, recordId, update);
|
|
1705
1736
|
}
|
|
@@ -1724,7 +1755,9 @@ var OrbitalServerRuntime = class {
|
|
|
1724
1755
|
let entityFields;
|
|
1725
1756
|
for (const [, registered] of this.orbitals) {
|
|
1726
1757
|
if (registered.entity.name === entityType) {
|
|
1727
|
-
entityFields = registered.entity.fields
|
|
1758
|
+
entityFields = registered.entity.fields.filter(
|
|
1759
|
+
(f) => typeof f.name === "string" && f.name.length > 0
|
|
1760
|
+
);
|
|
1728
1761
|
break;
|
|
1729
1762
|
}
|
|
1730
1763
|
}
|