@almadar/runtime 2.6.1 → 2.7.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.
@@ -1,6 +1,6 @@
1
1
  import { Router } from 'express';
2
- import { I as IEventBus, f as RuntimeEvent, e as EventListener, U as Unsubscribe, T as TraitDefinition, R as RuntimeConfig, h as TransitionObserver, g as TraitState, i as TransitionResult, d as Effect, E as EffectHandlers } from './types-DYcUvi4H.js';
3
- import { EventPayload, EntityRow, OrbitalSchema, Orbital, Trait } from '@almadar/core';
2
+ import { I as IEventBus, g as RuntimeEvent, f as EventListener, U as Unsubscribe, T as TraitDefinition, R as RuntimeConfig, i as TransitionObserver, h as TraitState, j as TransitionResult, E as EvaluationContextExtensions, a as EffectHandlers } from './types-CvYnmqkg.js';
3
+ import { EventPayload, EntityRow, OrbitalSchema, Orbital, Trait, OrbitalDefinition, Entity, TraitTick } from '@almadar/core';
4
4
 
5
5
  /**
6
6
  * EventBus - Platform-Agnostic Pub/Sub Implementation
@@ -126,6 +126,11 @@ interface ProcessEventOptions {
126
126
  * When true, log warnings when bindings resolve to undefined. (RCG-01)
127
127
  */
128
128
  strictBindings?: boolean;
129
+ /**
130
+ * Additional fields to spread onto EvaluationContext for guard evaluation.
131
+ * Used to inject module contexts (e.g., { agent: AgentContext }).
132
+ */
133
+ contextExtensions?: EvaluationContextExtensions;
129
134
  }
130
135
  /**
131
136
  * Process an event through a trait's state machine.
@@ -238,6 +243,48 @@ declare class StateMachineManager {
238
243
  resetAll(): void;
239
244
  }
240
245
 
246
+ /**
247
+ * LocalPersistenceAdapter - Filesystem CRUD for `persistence: "local"` entities.
248
+ *
249
+ * One directory per entity type, one JSON file per instance.
250
+ * Language-level feature: benefits all .orb programs, not just the agent.
251
+ * Offline-first apps, CLI tools, config managers, local databases all use it.
252
+ *
253
+ * @packageDocumentation
254
+ */
255
+
256
+ /**
257
+ * Filesystem-backed persistence adapter.
258
+ *
259
+ * Storage layout:
260
+ * ```
261
+ * {root}/
262
+ * {entityType}/
263
+ * {id}.json
264
+ * ```
265
+ */
266
+ declare class LocalPersistenceAdapter implements PersistenceAdapter {
267
+ private readonly root;
268
+ constructor(root: string);
269
+ private entityDir;
270
+ private filePath;
271
+ create(entityType: string, data: EntityRow): Promise<{
272
+ id: string;
273
+ }>;
274
+ update(entityType: string, id: string, data: EntityRow): Promise<void>;
275
+ delete(entityType: string, id: string): Promise<void>;
276
+ getById(entityType: string, id: string): Promise<EntityRow | null>;
277
+ list(entityType: string): Promise<EntityRow[]>;
278
+ /**
279
+ * Remove all data for an entity type.
280
+ */
281
+ clear(entityType: string): Promise<void>;
282
+ /**
283
+ * Remove all local data.
284
+ */
285
+ clearAll(): Promise<void>;
286
+ }
287
+
241
288
  /**
242
289
  * External Orbital Loader
243
290
  *
@@ -575,75 +622,23 @@ declare function parseNamespacedEvent(eventName: string): {
575
622
  * @packageDocumentation
576
623
  */
577
624
 
578
- /**
579
- * Simplified OrbitalSchema for runtime registration
580
- * (Subset of full OrbitalSchema - just what's needed for execution)
581
- */
582
- interface RuntimeOrbitalSchema {
583
- name: string;
584
- version?: string;
585
- orbitals: RuntimeOrbital[];
586
- }
587
- interface RuntimeOrbital {
588
- name: string;
589
- entity: {
590
- name: string;
591
- fields?: Array<{
592
- name: string;
593
- type: string;
594
- relation?: {
595
- entity?: string;
596
- cardinality?: string;
597
- onDelete?: string;
598
- };
599
- }>;
600
- /** Pre-defined entity instances to seed on registration */
601
- instances?: Array<EntityRow>;
602
- };
603
- traits: RuntimeTrait[];
604
- }
605
- /**
606
- * Tick definition for scheduled effects
607
- */
608
- interface RuntimeTraitTick {
609
- /** Unique name for this tick */
610
- name: string;
611
- /** Interval in milliseconds, or cron expression string */
612
- interval: number | string;
613
- /** Guard condition (S-expression) - tick only executes if guard passes */
614
- guard?: unknown;
615
- /** Effects to execute when tick fires */
616
- effects: Effect[];
617
- /** Filter to specific entity IDs (optional) */
618
- appliesTo?: string[];
619
- }
620
- interface RuntimeTrait {
621
- name: string;
622
- states: Array<{
623
- name: string;
624
- isInitial?: boolean;
625
- }>;
626
- transitions: Array<{
627
- from: string;
628
- to: string;
629
- event: string;
630
- guard?: unknown;
631
- effects?: Effect[];
632
- }>;
633
- listens?: Array<{
634
- event: string;
635
- triggers: string;
636
- payloadMapping?: EventPayload;
637
- }>;
638
- emits?: string[];
639
- /** Scheduled ticks for this trait */
640
- ticks?: RuntimeTraitTick[];
641
- }
625
+ /** @deprecated Use OrbitalSchema from @almadar/core */
626
+ type RuntimeOrbitalSchema = OrbitalSchema;
627
+ /** @deprecated Use OrbitalDefinition from @almadar/core */
628
+ type RuntimeOrbital = OrbitalDefinition;
629
+ /** @deprecated Use Trait from @almadar/core */
630
+ type RuntimeTrait = Trait;
631
+ /** @deprecated Use TraitTick from @almadar/core */
632
+ type RuntimeTraitTick = TraitTick;
642
633
  /**
643
634
  * Registered orbital with runtime state
644
635
  */
645
636
  interface RegisteredOrbital {
646
- schema: RuntimeOrbital;
637
+ schema: OrbitalDefinition;
638
+ /** Resolved entity (never a string ref at runtime) */
639
+ entity: Entity;
640
+ /** Resolved inline traits (string refs filtered out) */
641
+ traits: Trait[];
647
642
  manager: StateMachineManager;
648
643
  entityData: Map<string, EntityRow>;
649
644
  }
@@ -694,8 +689,12 @@ interface EffectResult {
694
689
  action?: string;
695
690
  /** Entity type affected (for persist/set/ref/deref/swap) */
696
691
  entityType?: string;
697
- /** Result data from the effect */
698
- data?: EntityRow;
692
+ /** Result data from the effect (entity row for CRUD, summary for batch) */
693
+ data?: EntityRow | {
694
+ operations: EntityRow[];
695
+ completedCount: number;
696
+ totalCount: number;
697
+ };
699
698
  /** Whether the effect succeeded */
700
699
  success: boolean;
701
700
  /** Error message if failed */
@@ -750,6 +749,17 @@ interface OrbitalServerRuntimeConfig {
750
749
  * Default: true
751
750
  */
752
751
  namespaceEvents?: boolean;
752
+ /**
753
+ * Root directory for `persistence: "local"` entities.
754
+ * Default: ~/.orb/data/
755
+ */
756
+ localStorageRoot?: string;
757
+ /**
758
+ * Additional fields to spread onto every EvaluationContext.
759
+ * Use this to inject module contexts (e.g., { agent: AgentContext }).
760
+ * The evaluator dispatches agent/* operators to ctx.agent.
761
+ */
762
+ contextExtensions?: EvaluationContextExtensions;
753
763
  }
754
764
  /**
755
765
  * Adapter for persisting entity data
@@ -775,6 +785,7 @@ declare class OrbitalServerRuntime {
775
785
  private entitySharingMap;
776
786
  private eventNamespaceMap;
777
787
  private osHandlers;
788
+ private localPersistence;
778
789
  constructor(config?: OrbitalServerRuntimeConfig);
779
790
  /**
780
791
  * Register an OrbitalSchema for execution.
@@ -784,13 +795,13 @@ declare class OrbitalServerRuntime {
784
795
  *
785
796
  * For explicit preprocessing control, use `registerWithPreprocess()`.
786
797
  */
787
- register(schema: RuntimeOrbitalSchema): Promise<void>;
798
+ register(schema: OrbitalSchema): Promise<void>;
788
799
  /**
789
800
  * Register an OrbitalSchema synchronously (for backward compatibility).
790
801
  * Note: This version doesn't wait for instance seeding to complete.
791
802
  * Use async register() for guaranteed instance seeding.
792
803
  */
793
- registerSync(schema: RuntimeOrbitalSchema): void;
804
+ registerSync(schema: OrbitalSchema): void;
794
805
  /**
795
806
  * Register an OrbitalSchema with preprocessing to resolve `uses` imports.
796
807
  *
@@ -820,7 +831,7 @@ declare class OrbitalServerRuntime {
820
831
  * }
821
832
  * ```
822
833
  */
823
- registerWithPreprocess(schema: RuntimeOrbitalSchema, options?: {
834
+ registerWithPreprocess(schema: OrbitalSchema, options?: {
824
835
  sourcePath?: string;
825
836
  }): Promise<{
826
837
  success: boolean;
@@ -954,4 +965,4 @@ declare class OrbitalServerRuntime {
954
965
  */
955
966
  declare function createOrbitalServerRuntime(config?: OrbitalServerRuntimeConfig): OrbitalServerRuntime;
956
967
 
957
- export { type EntitySharingMap as E, type LoaderConfig as L, type OrbitalEventRequest as O, type PersistenceAdapter as P, type RegisteredOrbital as R, StateMachineManager as S, EventBus as a, type EventNamespaceMap as b, type OrbitalEventResponse as c, type OrbitalServerRuntimeConfig as d, type PreprocessOptions as e, type PreprocessResult as f, type PreprocessedSchema as g, type ProcessEventOptions as h, type RuntimeOrbital as i, type RuntimeOrbitalSchema as j, type RuntimeTrait as k, createInitialTraitState as l, findInitialState as m, findTransition as n, getIsolatedCollectionName as o, getNamespacedEvent as p, isNamespacedEvent as q, normalizeEventKey as r, parseNamespacedEvent as s, preprocessSchema as t, processEvent as u, type EffectResult as v, OrbitalServerRuntime as w, type RuntimeTraitTick as x, createOrbitalServerRuntime as y };
968
+ export { type EntitySharingMap as E, type LoaderConfig as L, type OrbitalEventRequest as O, type PersistenceAdapter as P, type RegisteredOrbital as R, StateMachineManager as S, EventBus as a, type EventNamespaceMap as b, type OrbitalEventResponse as c, type OrbitalServerRuntimeConfig as d, type PreprocessOptions as e, type PreprocessResult as f, type PreprocessedSchema as g, type ProcessEventOptions as h, type RuntimeOrbital as i, type RuntimeOrbitalSchema as j, type RuntimeTrait as k, createInitialTraitState as l, findInitialState as m, findTransition as n, getIsolatedCollectionName as o, getNamespacedEvent as p, isNamespacedEvent as q, normalizeEventKey as r, parseNamespacedEvent as s, preprocessSchema as t, processEvent as u, type EffectResult as v, LocalPersistenceAdapter as w, OrbitalServerRuntime as x, type RuntimeTraitTick as y, createOrbitalServerRuntime as z };
@@ -1,4 +1,4 @@
1
1
  import 'express';
2
- export { v as EffectResult, L as LoaderConfig, O as OrbitalEventRequest, c as OrbitalEventResponse, w as OrbitalServerRuntime, d as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RegisteredOrbital, i as RuntimeOrbital, j as RuntimeOrbitalSchema, k as RuntimeTrait, x as RuntimeTraitTick, y as createOrbitalServerRuntime } from './OrbitalServerRuntime-B-QeKtKd.js';
3
- import './types-DYcUvi4H.js';
2
+ export { v as EffectResult, L as LoaderConfig, w as LocalPersistenceAdapter, O as OrbitalEventRequest, c as OrbitalEventResponse, x as OrbitalServerRuntime, d as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RegisteredOrbital, i as RuntimeOrbital, j as RuntimeOrbitalSchema, k as RuntimeTrait, y as RuntimeTraitTick, z as createOrbitalServerRuntime } from './OrbitalServerRuntime-CJYMN0d3.js';
3
+ import './types-CvYnmqkg.js';
4
4
  import '@almadar/core';
@@ -1,11 +1,85 @@
1
- import { EventBus, createUnifiedLoader, preprocessSchema, StateMachineManager, createContextFromBindings, EffectExecutor } from './chunk-ESNML4B4.js';
1
+ import { EventBus, createUnifiedLoader, preprocessSchema, StateMachineManager, createContextFromBindings, EffectExecutor } from './chunk-ZYH3XSOL.js';
2
2
  import { Router } from 'express';
3
+ import * as fs from 'fs';
4
+ import fs__default from 'fs';
5
+ import path from 'path';
3
6
  import { evaluateGuard, evaluate } from '@almadar/evaluator';
7
+ import { isInlineTrait } from '@almadar/core';
4
8
  import { faker } from '@faker-js/faker';
5
- import * as fs from 'fs';
6
9
  import * as net from 'net';
7
10
  import { execSync } from 'child_process';
8
11
 
12
+ var LocalPersistenceAdapter = class {
13
+ root;
14
+ constructor(root) {
15
+ this.root = root;
16
+ fs__default.mkdirSync(root, { recursive: true });
17
+ }
18
+ entityDir(entityType) {
19
+ const dir = path.join(this.root, entityType.toLowerCase());
20
+ fs__default.mkdirSync(dir, { recursive: true });
21
+ return dir;
22
+ }
23
+ filePath(entityType, id) {
24
+ return path.join(this.entityDir(entityType), `${id}.json`);
25
+ }
26
+ async create(entityType, data) {
27
+ const id = data.id || `${entityType.toLowerCase()}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
28
+ const record = { ...data, id };
29
+ const filePath = this.filePath(entityType, id);
30
+ fs__default.writeFileSync(filePath, JSON.stringify(record, null, 2), "utf-8");
31
+ return { id };
32
+ }
33
+ async update(entityType, id, data) {
34
+ const filePath = this.filePath(entityType, id);
35
+ let existing = { id };
36
+ if (fs__default.existsSync(filePath)) {
37
+ existing = JSON.parse(fs__default.readFileSync(filePath, "utf-8"));
38
+ }
39
+ const merged = { ...existing, ...data, id };
40
+ fs__default.writeFileSync(filePath, JSON.stringify(merged, null, 2), "utf-8");
41
+ }
42
+ async delete(entityType, id) {
43
+ const filePath = this.filePath(entityType, id);
44
+ if (fs__default.existsSync(filePath)) {
45
+ fs__default.unlinkSync(filePath);
46
+ }
47
+ }
48
+ async getById(entityType, id) {
49
+ const filePath = this.filePath(entityType, id);
50
+ if (!fs__default.existsSync(filePath)) return null;
51
+ return JSON.parse(fs__default.readFileSync(filePath, "utf-8"));
52
+ }
53
+ async list(entityType) {
54
+ const dir = this.entityDir(entityType);
55
+ if (!fs__default.existsSync(dir)) return [];
56
+ const files = fs__default.readdirSync(dir).filter((f) => f.endsWith(".json"));
57
+ const results = [];
58
+ for (const file of files) {
59
+ const content = fs__default.readFileSync(path.join(dir, file), "utf-8");
60
+ results.push(JSON.parse(content));
61
+ }
62
+ return results;
63
+ }
64
+ /**
65
+ * Remove all data for an entity type.
66
+ */
67
+ async clear(entityType) {
68
+ const dir = path.join(this.root, entityType.toLowerCase());
69
+ if (fs__default.existsSync(dir)) {
70
+ fs__default.rmSync(dir, { recursive: true, force: true });
71
+ }
72
+ }
73
+ /**
74
+ * Remove all local data.
75
+ */
76
+ async clearAll() {
77
+ if (fs__default.existsSync(this.root)) {
78
+ fs__default.rmSync(this.root, { recursive: true, force: true });
79
+ fs__default.mkdirSync(this.root, { recursive: true });
80
+ }
81
+ }
82
+ };
9
83
  var MockPersistenceAdapter = class {
10
84
  stores = /* @__PURE__ */ new Map();
11
85
  schemas = /* @__PURE__ */ new Map();
@@ -562,6 +636,7 @@ var OrbitalServerRuntime = class {
562
636
  entitySharingMap = {};
563
637
  eventNamespaceMap = {};
564
638
  osHandlers = null;
639
+ localPersistence = null;
565
640
  constructor(config = {}) {
566
641
  this.config = {
567
642
  mode: "mock",
@@ -590,6 +665,9 @@ var OrbitalServerRuntime = class {
590
665
  } else {
591
666
  this.persistence = config.persistence || new InMemoryPersistence();
592
667
  }
668
+ if (config.localStorageRoot) {
669
+ this.localPersistence = new LocalPersistenceAdapter(config.localStorageRoot);
670
+ }
593
671
  this.osHandlers = createOsHandlers({
594
672
  emitEvent: (type, payload) => this.eventBus.emit(type, payload)
595
673
  });
@@ -744,10 +822,11 @@ var OrbitalServerRuntime = class {
744
822
  * Register a single orbital
745
823
  */
746
824
  async registerOrbitalAsync(orbital) {
747
- const traitDefs = (orbital.traits || []).map((t) => {
748
- const stateMachine = t.stateMachine;
749
- const states = t.states || stateMachine?.states || [];
750
- const transitions = t.transitions || stateMachine?.transitions || [];
825
+ const inlineTraits = (orbital.traits || []).filter(isInlineTrait);
826
+ const traitDefs = inlineTraits.map((t) => {
827
+ const sm = t.stateMachine;
828
+ const states = sm?.states || [];
829
+ const transitions = sm?.transitions || [];
751
830
  return {
752
831
  name: t.name,
753
832
  states,
@@ -755,13 +834,18 @@ var OrbitalServerRuntime = class {
755
834
  listens: t.listens
756
835
  };
757
836
  });
758
- const manager = new StateMachineManager(traitDefs);
837
+ const manager = new StateMachineManager(traitDefs, {
838
+ contextExtensions: this.config.contextExtensions
839
+ });
840
+ const entityRef = orbital.entity;
841
+ const entity = typeof entityRef === "string" ? { name: entityRef, fields: [] } : entityRef;
759
842
  this.orbitals.set(orbital.name, {
760
843
  schema: orbital,
844
+ entity,
845
+ traits: inlineTraits,
761
846
  manager,
762
847
  entityData: /* @__PURE__ */ new Map()
763
848
  });
764
- const entity = orbital.entity;
765
849
  if (entity?.name && entity.instances && Array.isArray(entity.instances)) {
766
850
  const instances = entity.instances;
767
851
  if (instances.length > 0) {
@@ -822,7 +906,7 @@ var OrbitalServerRuntime = class {
822
906
  }
823
907
  this.listenerCleanups = [];
824
908
  for (const [orbitalName, registered] of this.orbitals) {
825
- for (const trait of registered.schema.traits || []) {
909
+ for (const trait of registered.traits) {
826
910
  if (!trait.listens) continue;
827
911
  for (const listener of trait.listens) {
828
912
  const cleanup = this.eventBus.on(listener.event, async (event) => {
@@ -861,7 +945,7 @@ var OrbitalServerRuntime = class {
861
945
  setupTicks() {
862
946
  this.cleanupTicks();
863
947
  for (const [orbitalName, registered] of this.orbitals) {
864
- for (const trait of registered.schema.traits || []) {
948
+ for (const trait of registered.traits || []) {
865
949
  if (!trait.ticks || trait.ticks.length === 0) continue;
866
950
  for (const tick of trait.ticks) {
867
951
  this.registerTick(orbitalName, trait.name, tick, registered);
@@ -932,7 +1016,7 @@ var OrbitalServerRuntime = class {
932
1016
  * Execute a tick for all applicable entities
933
1017
  */
934
1018
  async executeTick(orbitalName, traitName, tick, registered) {
935
- const entityType = registered.schema.entity.name;
1019
+ const entityType = registered.entity.name;
936
1020
  const emittedEvents = [];
937
1021
  try {
938
1022
  let entities = await this.persistence.list(entityType);
@@ -952,7 +1036,7 @@ var OrbitalServerRuntime = class {
952
1036
  entity,
953
1037
  payload: {},
954
1038
  state: registered.manager.getState(traitName)?.currentState || "unknown"
955
- });
1039
+ }, false, this.config.contextExtensions);
956
1040
  const guardPasses = evaluateGuard(
957
1041
  tick.guard,
958
1042
  ctx
@@ -1059,7 +1143,7 @@ var OrbitalServerRuntime = class {
1059
1143
  let entityData = {};
1060
1144
  if (entityId) {
1061
1145
  const stored = await this.persistence.getById(
1062
- registered.schema.entity.name,
1146
+ registered.entity.name,
1063
1147
  entityId
1064
1148
  );
1065
1149
  if (stored) {
@@ -1095,9 +1179,8 @@ var OrbitalServerRuntime = class {
1095
1179
  }
1096
1180
  }
1097
1181
  const refTypes = /* @__PURE__ */ new Set();
1098
- for (const trait of registered.schema.traits || []) {
1099
- const sm = trait.stateMachine;
1100
- const transitions = sm?.transitions ?? trait.transitions ?? [];
1182
+ for (const trait of registered.traits) {
1183
+ const transitions = trait.stateMachine?.transitions ?? [];
1101
1184
  for (const trans of transitions) {
1102
1185
  for (const eff of trans.effects ?? []) {
1103
1186
  if (Array.isArray(eff) && eff[0] === "ref" && typeof eff[1] === "string") {
@@ -1140,7 +1223,7 @@ var OrbitalServerRuntime = class {
1140
1223
  * Execute effects from a transition
1141
1224
  */
1142
1225
  async executeEffects(registered, traitName, effects, payload, entityData, entityId, emittedEvents, fetchedData, clientEffects, effectResults, user) {
1143
- const entityType = registered.schema.entity.name;
1226
+ const entityType = registered.entity.name;
1144
1227
  let bindingsRef = null;
1145
1228
  let contextRef = null;
1146
1229
  const handlers = {
@@ -1430,7 +1513,7 @@ var OrbitalServerRuntime = class {
1430
1513
  current,
1431
1514
  entity: entityData,
1432
1515
  payload
1433
- });
1516
+ }, false, this.config.contextExtensions);
1434
1517
  let newData;
1435
1518
  if (Array.isArray(transform)) {
1436
1519
  const result = evaluate(
@@ -1483,7 +1566,8 @@ var OrbitalServerRuntime = class {
1483
1566
  handlers,
1484
1567
  bindings: bindingsRef ?? {},
1485
1568
  context: contextRef ?? { traitName, state: "unknown", transition: "unknown" },
1486
- debug: this.config.debug
1569
+ debug: this.config.debug,
1570
+ contextExtensions: this.config.contextExtensions
1487
1571
  });
1488
1572
  for (const innerEffect of atomicEffects) {
1489
1573
  if (atomicFailed) break;
@@ -1512,8 +1596,8 @@ var OrbitalServerRuntime = class {
1512
1596
  renderUI: (slot, pattern, props, priority) => {
1513
1597
  clientEffects.push(["render-ui", slot, pattern, props, priority]);
1514
1598
  },
1515
- navigate: (path, params) => {
1516
- clientEffects.push(["navigate", path, params]);
1599
+ navigate: (path2, params) => {
1600
+ clientEffects.push(["navigate", path2, params]);
1517
1601
  },
1518
1602
  notify: (message, type) => {
1519
1603
  if (this.config.debug) {
@@ -1551,7 +1635,8 @@ var OrbitalServerRuntime = class {
1551
1635
  handlers,
1552
1636
  bindings,
1553
1637
  context,
1554
- debug: this.config.debug
1638
+ debug: this.config.debug,
1639
+ contextExtensions: this.config.contextExtensions
1555
1640
  });
1556
1641
  await executor.executeAll(effects);
1557
1642
  }
@@ -1574,8 +1659,8 @@ var OrbitalServerRuntime = class {
1574
1659
  */
1575
1660
  validateRelationCardinality(entityType, data) {
1576
1661
  for (const [, registered] of this.orbitals) {
1577
- if (registered.schema.entity.name !== entityType) continue;
1578
- for (const field of registered.schema.entity.fields ?? []) {
1662
+ if (registered.entity.name !== entityType) continue;
1663
+ for (const field of registered.entity.fields ?? []) {
1579
1664
  if (field.type !== "relation") continue;
1580
1665
  const value = data[field.name];
1581
1666
  if (value === void 0 || value === null) continue;
@@ -1609,13 +1694,13 @@ var OrbitalServerRuntime = class {
1609
1694
  */
1610
1695
  async enforceOnDeleteRules(entityType, deletedId) {
1611
1696
  for (const [, registered] of this.orbitals) {
1612
- const schema = registered.schema;
1613
- const fields = schema.entity.fields ?? [];
1697
+ const entity = registered.entity;
1698
+ const fields = entity.fields ?? [];
1614
1699
  for (const field of fields) {
1615
1700
  if (field.type !== "relation") continue;
1616
1701
  if (field.relation?.entity !== entityType) continue;
1617
1702
  const onDelete = field.relation.onDelete || "restrict";
1618
- const referringEntityType = schema.entity.name;
1703
+ const referringEntityType = entity.name;
1619
1704
  const allRecords = await this.persistence.list(referringEntityType);
1620
1705
  const affectedRecords = allRecords.filter((record) => {
1621
1706
  const fkValue = record[field.name];
@@ -1673,8 +1758,8 @@ var OrbitalServerRuntime = class {
1673
1758
  visited.add(entityType);
1674
1759
  let entityFields;
1675
1760
  for (const [, registered] of this.orbitals) {
1676
- if (registered.schema.entity.name === entityType) {
1677
- entityFields = registered.schema.entity.fields;
1761
+ if (registered.entity.name === entityType) {
1762
+ entityFields = registered.entity.fields;
1678
1763
  break;
1679
1764
  }
1680
1765
  }
@@ -1728,17 +1813,31 @@ var OrbitalServerRuntime = class {
1728
1813
  const populatedFieldName = includeField.endsWith("Id") ? includeField.slice(0, -2) : includeField;
1729
1814
  for (const entity of entities) {
1730
1815
  const fkValue = entity[foreignKeyField];
1731
- const entityRecord = entity;
1732
1816
  if (cardinality === "one" || cardinality === "many-to-one") {
1733
1817
  if (typeof fkValue === "string" && relatedEntities.has(fkValue)) {
1734
- entityRecord[populatedFieldName] = relatedEntities.get(fkValue);
1818
+ Object.defineProperty(entity, populatedFieldName, {
1819
+ value: relatedEntities.get(fkValue),
1820
+ writable: true,
1821
+ enumerable: true,
1822
+ configurable: true
1823
+ });
1735
1824
  }
1736
1825
  } else {
1737
1826
  if (Array.isArray(fkValue)) {
1738
1827
  const fkIds = fkValue.filter((id) => typeof id === "string");
1739
- entityRecord[populatedFieldName] = fkIds.map((id) => relatedEntities.get(id)).filter(Boolean);
1828
+ Object.defineProperty(entity, populatedFieldName, {
1829
+ value: fkIds.map((id) => relatedEntities.get(id)).filter(Boolean),
1830
+ writable: true,
1831
+ enumerable: true,
1832
+ configurable: true
1833
+ });
1740
1834
  } else if (typeof fkValue === "string" && relatedEntities.has(fkValue)) {
1741
- entityRecord[populatedFieldName] = [relatedEntities.get(fkValue)];
1835
+ Object.defineProperty(entity, populatedFieldName, {
1836
+ value: [relatedEntities.get(fkValue)],
1837
+ writable: true,
1838
+ enumerable: true,
1839
+ configurable: true
1840
+ });
1742
1841
  }
1743
1842
  }
1744
1843
  }
@@ -1767,8 +1866,8 @@ var OrbitalServerRuntime = class {
1767
1866
  const orbitals = Array.from(this.orbitals.entries()).map(
1768
1867
  ([name, reg]) => ({
1769
1868
  name,
1770
- entity: reg.schema.entity?.name,
1771
- traits: (reg.schema.traits || []).map((t) => t.name)
1869
+ entity: reg.entity?.name,
1870
+ traits: (reg.traits || []).map((t) => t.name)
1772
1871
  })
1773
1872
  );
1774
1873
  res.json({ success: true, orbitals });
@@ -1788,12 +1887,12 @@ var OrbitalServerRuntime = class {
1788
1887
  success: true,
1789
1888
  orbital: {
1790
1889
  name: orbitalName,
1791
- entity: registered.schema.entity,
1792
- traits: (registered.schema.traits || []).map((t) => ({
1890
+ entity: registered.entity,
1891
+ traits: registered.traits.map((t) => ({
1793
1892
  name: t.name,
1794
1893
  currentState: states[t.name],
1795
- states: (t.states || []).map((s) => s.name),
1796
- events: [...new Set((t.transitions || []).map((tr) => tr.event))]
1894
+ states: (t.stateMachine?.states || []).map((s) => s.name),
1895
+ events: [...new Set((t.stateMachine?.transitions || []).map((tr) => tr.event))]
1797
1896
  }))
1798
1897
  }
1799
1898
  });
@@ -1873,6 +1972,6 @@ function createOrbitalServerRuntime(config) {
1873
1972
  return new OrbitalServerRuntime(config);
1874
1973
  }
1875
1974
 
1876
- export { OrbitalServerRuntime, createOrbitalServerRuntime };
1975
+ export { LocalPersistenceAdapter, OrbitalServerRuntime, createOrbitalServerRuntime };
1877
1976
  //# sourceMappingURL=OrbitalServerRuntime.js.map
1878
1977
  //# sourceMappingURL=OrbitalServerRuntime.js.map