@almadar/runtime 6.13.0 → 6.14.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,5 +1,5 @@
1
1
  import { Router } from 'express';
2
- import { I as IEventBus, g as RuntimeEvent, f as EventListener, U as Unsubscribe, T as TraitDefinition, R as RuntimeConfig, i as TransitionObserver, C as ConfigContext, h as TraitState, j as TransitionResult, E as EvaluationContextExtensions, a as EffectHandlers } from './types-ymgqmXOq.js';
2
+ import { I as IEventBus, g as RuntimeEvent, f as EventListener, U as Unsubscribe, T as TraitDefinition, R as RuntimeConfig, i as TransitionObserver, C as ConfigContext, h as TraitState, j as TransitionResult, E as EvaluationContextExtensions, a as EffectHandlers } from './types-GFwSbdv_.js';
3
3
  import { EventPayload, EntityRow, DeclaredTraitConfig, TraitConfig, OrbitalSchema, Orbital, Trait, PatternConfig, ResolvedPatternProps, SExpr, BusEventSource, OrbitalDefinition, Entity, TraitTick } from '@almadar/core';
4
4
  import { P as PersistenceAdapter } from './PersistenceAdapter-B6dQCbbU.js';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import 'express';
2
- export { C as ClientEffectTuple, B as ClientNavigateTuple, D as ClientNotifyTuple, F as ClientRenderUITuple, G as EffectResult, H as LoaderConfig, O as OrbitalEventRequest, e as OrbitalEventResponse, J as OrbitalServerRuntime, f as OrbitalServerRuntimeConfig, R as RegisteredOrbital, j as RuntimeOrbital, k as RuntimeOrbitalSchema, l as RuntimeTrait, K as RuntimeTraitTick, n as collectDeclaredConfigDefaults, M as createOrbitalServerRuntime } from './OrbitalServerRuntime-DJTOyqkh.js';
3
- import './types-ymgqmXOq.js';
2
+ export { C as ClientEffectTuple, B as ClientNavigateTuple, D as ClientNotifyTuple, F as ClientRenderUITuple, G as EffectResult, H as LoaderConfig, O as OrbitalEventRequest, e as OrbitalEventResponse, J as OrbitalServerRuntime, f as OrbitalServerRuntimeConfig, R as RegisteredOrbital, j as RuntimeOrbital, k as RuntimeOrbitalSchema, l as RuntimeTrait, K as RuntimeTraitTick, n as collectDeclaredConfigDefaults, M as createOrbitalServerRuntime } from './OrbitalServerRuntime-Cg1CiUdz.js';
3
+ import './types-GFwSbdv_.js';
4
4
  import '@almadar/core';
5
5
  export { I as InMemoryPersistence, P as PersistenceAdapter } from './PersistenceAdapter-B6dQCbbU.js';
@@ -1,5 +1,5 @@
1
- import { EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, StateMachineManager, createContextFromBindings, validateEventPayload, formatPayloadValidationError, collectDeclaredConfigDefaults, EffectExecutor } from './chunk-QJ4UEHGC.js';
2
- export { InMemoryPersistence, collectDeclaredConfigDefaults } from './chunk-QJ4UEHGC.js';
1
+ import { EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, StateMachineManager, createContextFromBindings, validateEventPayload, formatPayloadValidationError, collectDeclaredConfigDefaults, EffectExecutor } from './chunk-QVGSVPYW.js';
2
+ export { InMemoryPersistence, collectDeclaredConfigDefaults } from './chunk-QVGSVPYW.js';
3
3
  import './chunk-PZ5AY32C.js';
4
4
  import { createLogger } from '@almadar/logger';
5
5
  import * as nodeModule from 'module';
@@ -1,4 +1,4 @@
1
- import { I as IEventBus } from './types-ymgqmXOq.js';
1
+ import { I as IEventBus } from './types-GFwSbdv_.js';
2
2
  import { EventPayload } from '@almadar/core';
3
3
 
4
4
  /**
@@ -306,6 +306,9 @@ function createContextFromBindings(bindings, strictBindings, contextExtensions)
306
306
  if (bindings.config) {
307
307
  ctx.config = bindings.config;
308
308
  }
309
+ if (bindings.locals) {
310
+ ctx.locals = bindings.locals;
311
+ }
309
312
  if (contextExtensions) {
310
313
  Object.assign(ctx, contextExtensions);
311
314
  }
@@ -854,7 +857,7 @@ function resolveArgs(args, bindings, strictBindings, contextExtensions) {
854
857
  const ctx = createContextFromBindings(bindings, strictBindings, contextExtensions);
855
858
  return args.map((arg) => interpolateValue(arg, ctx));
856
859
  }
857
- var EffectExecutor = class {
860
+ var EffectExecutor = class _EffectExecutor {
858
861
  handlers;
859
862
  bindings;
860
863
  context;
@@ -941,7 +944,7 @@ var EffectExecutor = class {
941
944
  registered.push(name);
942
945
  }
943
946
  }
944
- registered.push("do", "when");
947
+ registered.push("do", "when", "let", "if");
945
948
  return registered;
946
949
  }
947
950
  /**
@@ -956,7 +959,7 @@ var EffectExecutor = class {
956
959
  return;
957
960
  }
958
961
  const { operator, args } = parsed;
959
- const isCompound = operator === "do" || operator === "when";
962
+ const isCompound = operator === "do" || operator === "when" || operator === "let" || operator === "if";
960
963
  const isSetPathForm = operator === "set" && args.length >= 2 && typeof args[0] === "string" && args[0].startsWith("@entity.");
961
964
  const isFetchLike = (operator === "fetch" || operator === "ref" || operator === "deref" || operator === "os/watch-collection" || operator === "os/watch") && args.length >= 2 && args[1] !== null && typeof args[1] === "object" && !Array.isArray(args[1]);
962
965
  let resolvedArgs;
@@ -1038,7 +1041,7 @@ var EffectExecutor = class {
1038
1041
  }
1039
1042
  const start = Date.now();
1040
1043
  const { operator, args: rawArgs } = parsed;
1041
- const isCompound = operator === "do" || operator === "when";
1044
+ const isCompound = operator === "do" || operator === "when" || operator === "let" || operator === "if";
1042
1045
  const resolvedArgs = isCompound ? rawArgs : resolveArgs(rawArgs, this.bindings, this.strictBindings, this.contextExtensions);
1043
1046
  try {
1044
1047
  await this.dispatch(operator, resolvedArgs);
@@ -1463,6 +1466,41 @@ var EffectExecutor = class {
1463
1466
  }
1464
1467
  break;
1465
1468
  }
1469
+ case "if": {
1470
+ const ctx = createContextFromBindings(this.bindings, false, this.contextExtensions);
1471
+ const cond = interpolateValue(args[0], ctx);
1472
+ const branch = cond ? args[1] : args[2];
1473
+ if (Array.isArray(branch)) {
1474
+ await this.execute(branch);
1475
+ }
1476
+ break;
1477
+ }
1478
+ case "let": {
1479
+ const rawBindings = args[0];
1480
+ const body = args[1];
1481
+ const locals = new Map(this.bindings.locals);
1482
+ const pairs = Array.isArray(rawBindings) ? rawBindings.flatMap(
1483
+ (b) => Array.isArray(b) && typeof b[0] === "string" ? [[b[0], b[1]]] : []
1484
+ ) : Object.entries(rawBindings);
1485
+ for (const [name, valueExpr] of pairs) {
1486
+ const ctx = createContextFromBindings(
1487
+ { ...this.bindings, locals },
1488
+ false,
1489
+ this.contextExtensions
1490
+ );
1491
+ locals.set(name, interpolateValue(valueExpr, ctx));
1492
+ }
1493
+ const bodyExecutor = new _EffectExecutor({
1494
+ handlers: this.handlers,
1495
+ bindings: { ...this.bindings, locals },
1496
+ context: this.context,
1497
+ debug: this.debug,
1498
+ strictBindings: this.strictBindings,
1499
+ contextExtensions: this.contextExtensions
1500
+ });
1501
+ await bodyExecutor.execute(body);
1502
+ break;
1503
+ }
1466
1504
  // OS trigger operators (server-side only)
1467
1505
  //
1468
1506
  // Each may carry `emit:` inside a trailing options object. The
@@ -3674,5 +3712,5 @@ var InMemoryPersistence = class {
3674
3712
  };
3675
3713
 
3676
3714
  export { EffectExecutor, EventBus, HANDLER_MANIFEST, InMemoryPersistence, MockPersistenceAdapter, StateMachineManager, buildEmitsFromTraits, collectDeclaredConfigDefaults, containsBindings, createContextFromBindings, createInitialTraitState, createMockPersistence, createTestExecutor, createUnifiedLoader, extractBindings, findInitialState, findTransition, formatPayloadValidationError, getIsolatedCollectionName, getNamespacedEvent, interpolateProps, interpolateValue, isBrowser, isElectron, isNamespacedEvent, isNode, normalizeEventKey, parseNamespacedEvent, preprocessSchema, processEvent, validateEventPayload, validatePayloadShapes };
3677
- //# sourceMappingURL=chunk-QJ4UEHGC.js.map
3678
- //# sourceMappingURL=chunk-QJ4UEHGC.js.map
3715
+ //# sourceMappingURL=chunk-QVGSVPYW.js.map
3716
+ //# sourceMappingURL=chunk-QVGSVPYW.js.map