@almadar/runtime 2.2.1 → 2.2.2

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,4 +1,4 @@
1
- import { EventBus, createUnifiedLoader, preprocessSchema, StateMachineManager, createContextFromBindings, EffectExecutor } from './chunk-54P2HYHQ.js';
1
+ import { EventBus, createUnifiedLoader, preprocessSchema, StateMachineManager, createContextFromBindings, EffectExecutor } from './chunk-57PUFAKH.js';
2
2
  import { Router } from 'express';
3
3
  import { evaluateGuard } from '@almadar/evaluator';
4
4
  import { faker } from '@faker-js/faker';
@@ -1113,6 +1113,7 @@ var OrbitalServerRuntime = class {
1113
1113
  */
1114
1114
  async executeEffects(registered, traitName, effects, payload, entityData, entityId, emittedEvents, fetchedData, clientEffects, effectResults, user) {
1115
1115
  const entityType = registered.schema.entity.name;
1116
+ let bindingsRef = null;
1116
1117
  const handlers = {
1117
1118
  emit: (event, eventPayload) => {
1118
1119
  if (this.config.debug) {
@@ -1319,6 +1320,16 @@ var OrbitalServerRuntime = class {
1319
1320
  fetchedData[fetchEntityType] = entities;
1320
1321
  result = entities;
1321
1322
  }
1323
+ if (bindingsRef && result) {
1324
+ const records = Array.isArray(result) ? result : [result];
1325
+ if (records.length > 0) {
1326
+ const merged = Object.assign([...records], records[0]);
1327
+ bindingsRef[fetchEntityType] = merged;
1328
+ if (fetchEntityType === entityType) {
1329
+ bindingsRef.entity = merged;
1330
+ }
1331
+ }
1332
+ }
1322
1333
  return result;
1323
1334
  } catch (error) {
1324
1335
  console.error(`[OrbitalRuntime] Fetch error for ${fetchEntityType}:`, error);
@@ -1353,6 +1364,10 @@ var OrbitalServerRuntime = class {
1353
1364
  user
1354
1365
  // @user bindings from Firebase auth
1355
1366
  };
1367
+ if (entityType) {
1368
+ bindings[entityType] = entityData;
1369
+ }
1370
+ bindingsRef = bindings;
1356
1371
  const context = {
1357
1372
  traitName,
1358
1373
  state: state?.currentState || "unknown",